-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #77 from kabir/kabir-changes
The ability to use Helm {{--set}} overrides
- Loading branch information
Showing
5 changed files
with
276 additions
and
0 deletions.
There are no files selected for viewing
154 changes: 154 additions & 0 deletions
154
...stsuite/provision/openshift/WildflyHelmChartExistingValuesOpenShiftExampleApplicaton.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,154 @@ | ||
/** | ||
* Copyright (C) 2023 Red Hat, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.jboss.intersmash.testsuite.provision.openshift; | ||
|
||
import java.net.URL; | ||
import java.nio.file.Path; | ||
import java.util.Collections; | ||
import java.util.HashMap; | ||
import java.util.List; | ||
import java.util.Map; | ||
|
||
import org.jboss.intersmash.deployments.IntersmashDelpoyableWildflyApplication; | ||
import org.jboss.intersmash.model.helm.charts.values.wildfly.HelmWildflyRelease; | ||
import org.jboss.intersmash.tools.IntersmashConfig; | ||
import org.jboss.intersmash.tools.application.openshift.helm.HelmChartRelease; | ||
import org.jboss.intersmash.tools.application.openshift.helm.WildflyHelmChartOpenShiftApplication; | ||
|
||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory; | ||
import com.fasterxml.jackson.dataformat.yaml.YAMLGenerator; | ||
|
||
import io.fabric8.kubernetes.api.model.Secret; | ||
|
||
public class WildflyHelmChartExistingValuesOpenShiftExampleApplicaton | ||
implements WildflyHelmChartOpenShiftApplication, IntersmashDelpoyableWildflyApplication { | ||
private static final String APP_NAME = "wildfly-helm-helloworld-qs"; | ||
|
||
private final HelmChartRelease release; | ||
private final Map<String, String> setOverrides = new HashMap<>(); | ||
|
||
public WildflyHelmChartExistingValuesOpenShiftExampleApplicaton() { | ||
this.release = new HelmChartRelease(loadRelease()); | ||
} | ||
|
||
WildflyHelmChartExistingValuesOpenShiftExampleApplicaton addSetOverride(String name, String value) { | ||
setOverrides.put(name, value); | ||
return this; | ||
} | ||
|
||
@Override | ||
public Map<String, String> getSetOverrides() { | ||
return setOverrides; | ||
} | ||
|
||
private HelmWildflyRelease loadRelease() { | ||
URL url = this.getClass().getResource("wildfly-helm-values.yaml"); | ||
if (url == null) { | ||
throw new IllegalStateException("No wildfly-helm-values.yaml found"); | ||
} | ||
try { | ||
Path valuePath = Path.of(url.toURI()); | ||
ObjectMapper mapper = new ObjectMapper(new YAMLFactory().disable(YAMLGenerator.Feature.WRITE_DOC_START_MARKER)); | ||
return mapper.readValue(valuePath.toFile(), HelmWildflyRelease.class); | ||
} catch (Error | RuntimeException e) { | ||
throw e; | ||
} catch (Exception e) { | ||
throw new RuntimeException(e); | ||
} | ||
} | ||
|
||
@Override | ||
public HelmChartRelease getRelease() { | ||
return release; | ||
} | ||
|
||
@Override | ||
public List<Secret> getSecrets() { | ||
return Collections.emptyList(); | ||
} | ||
|
||
@Override | ||
public String getName() { | ||
return APP_NAME; | ||
} | ||
|
||
@Override | ||
public String getHelmChartsRepositoryUrl() { | ||
return IntersmashConfig.getWildflyHelmChartsRepo(); | ||
} | ||
|
||
@Override | ||
public String getHelmChartsRepositoryRef() { | ||
return IntersmashConfig.getWildflyHelmChartsBranch(); | ||
} | ||
|
||
@Override | ||
public String getHelmChartsRepositoryName() { | ||
return IntersmashConfig.getWildflyHelmChartsName(); | ||
} | ||
|
||
@Override | ||
public String getBuilderImage() { | ||
return IntersmashConfig.wildflyImageURL(); | ||
} | ||
|
||
@Override | ||
public String getRuntimeImage() { | ||
return IntersmashConfig.wildflyRuntimeImageURL(); | ||
} | ||
|
||
@Override | ||
public String bomServerVersionPropertyValue() { | ||
return IntersmashConfig.getWildflyBomsEeServerVersion(); | ||
} | ||
|
||
@Override | ||
public String eeFeaturePackLocation() { | ||
// this value is supposed to be overridden by the CI Jenkins job by passing e.g. | ||
// "mvn ... -Dwildfly.ee-feature-pack.location=" | ||
return IntersmashConfig.getWildflyEeFeaturePackLocation(); | ||
} | ||
|
||
@Override | ||
public String cloudFeaturePackLocation() { | ||
// this value is supposed to be overridden by the CI Jenkins job by passing e.g. | ||
// "mvn ... -Dwildfly.cloud-feature-pack.location=" | ||
return IntersmashConfig.getWildflyCloudFeaturePackLocation(); | ||
} | ||
|
||
@Override | ||
public String eeChannelLocation() { | ||
// this value is supposed to be overridden by the CI Jenkins job by passing e.g. | ||
// "mvn ... -Dwildfly.ee-channel.location=" | ||
return IntersmashConfig.getWildflyEeChannelLocation(); | ||
} | ||
|
||
@Override | ||
public String wildflyMavenPluginGroupId() { | ||
return IntersmashConfig.getWildflyMavenPluginGroupId(); | ||
} | ||
|
||
@Override | ||
public String wildflyMavenPluginArtifactId() { | ||
return IntersmashConfig.getWildflyMavenPluginArtifactId(); | ||
} | ||
|
||
@Override | ||
public String wildflyMavenPluginVersion() { | ||
return IntersmashConfig.getWildflyMavenPluginVersion(); | ||
} | ||
} |
72 changes: 72 additions & 0 deletions
72
...tersmash/testsuite/provision/openshift/WildflyHelmChartExistingValuesProvisionerTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
/** | ||
* Copyright (C) 2023 Red Hat, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package org.jboss.intersmash.testsuite.provision.openshift; | ||
|
||
import org.jboss.intersmash.tools.IntersmashConfig; | ||
import org.jboss.intersmash.tools.provision.helm.HelmChartOpenShiftProvisioner; | ||
import org.jboss.intersmash.tools.provision.helm.WildflyHelmChartOpenShiftProvisioner; | ||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import cz.xtf.junit5.annotations.CleanBeforeAll; | ||
|
||
/** | ||
* Test case to verify the basic {@link HelmChartOpenShiftProvisioner} | ||
* life cycle management operations on a WildFly application which provides | ||
* a Helm values file AND {@code --set} overrides | ||
*/ | ||
@CleanBeforeAll | ||
public class WildflyHelmChartExistingValuesProvisionerTest { | ||
|
||
@Test | ||
public void basicProvisioningTest() { | ||
// initialize the application service descriptor | ||
final WildflyHelmChartExistingValuesOpenShiftExampleApplicaton application = new WildflyHelmChartExistingValuesOpenShiftExampleApplicaton(); | ||
application | ||
.addSetOverride("build.uri", IntersmashConfig.deploymentsRepositoryUrl()) | ||
.addSetOverride("build.ref", IntersmashConfig.deploymentsRepositoryRef()) | ||
.addSetOverride("deploy.builderImage", application.getBuilderImage()) | ||
.addSetOverride("deployRuntimeImage", application.getRuntimeImage()); | ||
|
||
// and now get an EAP 8/WildFly provisioner for that application | ||
final WildflyHelmChartOpenShiftProvisioner provisioner = new WildflyHelmChartOpenShiftProvisioner(application); | ||
// deploy | ||
provisioner.preDeploy(); | ||
try { | ||
provisioner.deploy(); | ||
try { | ||
Assertions.assertEquals(1, provisioner.getPods().size(), | ||
"Unexpected number of cluster operator pods for '" | ||
+ provisioner.getApplication().getName() + "' after deploy"); | ||
|
||
// scale | ||
int scaledNum = provisioner.getApplication().getRelease().getReplicas() + 1; | ||
provisioner.scale(scaledNum, true); | ||
Assertions.assertEquals(scaledNum, provisioner.getPods().size(), | ||
"Unexpected number of cluster operator pods for '" | ||
+ provisioner.getApplication().getName() | ||
+ "' after scaling"); | ||
} finally { | ||
// undeploy | ||
provisioner.undeploy(); | ||
Assertions.assertEquals(0, provisioner.getPods().size(), | ||
"Unexpected number of pods after undeploy"); | ||
} | ||
} finally { | ||
provisioner.postUndeploy(); | ||
} | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
...est/resources/org/jboss/intersmash/testsuite/provision/openshift/wildfly-helm-values.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
build: | ||
enabled: true | ||
mode: "s2i" | ||
# uri and ref will be specified via Helm --set arguments | ||
contextDir: "deployments/openshift-jakarta-sample-standalone" | ||
env: | ||
- name: "MAVEN_ARGS_APPEND" | ||
value: "-Denforcer.skip=true" | ||
s2i: | ||
kind: "DockerImage" | ||
buildApplicationImage: true | ||
# builderImage and runtimeImage will be specified via Helm --set arguments | ||
deploy: | ||
enabled: true | ||
replicas: 1 | ||
env: [] | ||
envFrom: [] | ||
volumeMounts: [] | ||
volumes: [] | ||
initContainers: [] | ||
extraContainers: [] | ||
'imagePullSecrets:': [] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters