Skip to content

Commit

Permalink
[Deploy] Replace deployCrd with installCluster
Browse files Browse the repository at this point in the history
  • Loading branch information
avano committed Oct 19, 2020
1 parent 2788628 commit e0344fa
Show file tree
Hide file tree
Showing 4 changed files with 3 additions and 62 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ public class OperatorValidationSteps {

@Given("^deploy Syndesis CRD$")
public void deployCRD() {
ResourceFactory.get(Syndesis.class).deployCrd();
ResourceFactory.get(Syndesis.class).installCluster();
}

@Given("^install cluster resources$")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ public void upgradeUsingOperator() {
Syndesis syndesis = ResourceFactory.get(Syndesis.class);
syndesis.defaultValues();
syndesis.pullOperatorImage();
syndesis.deployCrd();
syndesis.installCluster();
syndesis.grantPermissions();
syndesis.deployOperator();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ public void deploy() {
log.info(" Cluster: " + TestConfiguration.openShiftUrl());
log.info(" Namespace: " + TestConfiguration.openShiftNamespace());
super.createPullSecret();
super.deployCrd();
super.pullOperatorImage();
super.installCluster();
super.grantPermissions();
super.deployOperator();
deploySyndesisViaOperator();
Expand Down
59 changes: 0 additions & 59 deletions utilities/src/main/java/io/syndesis/qe/resource/impl/Syndesis.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,7 @@
import io.fabric8.kubernetes.api.model.Pod;
import io.fabric8.kubernetes.api.model.ServiceAccount;
import io.fabric8.kubernetes.api.model.apiextensions.CustomResourceDefinition;
import io.fabric8.kubernetes.api.model.apiextensions.CustomResourceDefinitionFluent;
import io.fabric8.kubernetes.api.model.apiextensions.CustomResourceDefinitionVersion;
import io.fabric8.kubernetes.api.model.apiextensions.DoneableCustomResourceDefinition;
import io.fabric8.kubernetes.api.model.apps.Deployment;
import io.fabric8.kubernetes.client.KubernetesClientException;
import io.fabric8.kubernetes.client.dsl.base.CustomResourceDefinitionContext;
Expand Down Expand Up @@ -89,7 +87,6 @@ public void deploy() {
log.info(" Cluster: " + TestConfiguration.openShiftUrl());
log.info(" Namespace: " + TestConfiguration.openShiftNamespace());
createPullSecret();
deployCrd();
pullOperatorImage();
installCluster();
grantPermissions();
Expand Down Expand Up @@ -370,62 +367,6 @@ private CustomResourceDefinitionContext makeSyndesisContext(String version) {
return builder.build();
}

public void deployCrd() {
log.info("Creating custom resource definition from " + crdUrl);
CustomResourceDefinition newCrd;
try (InputStream is = new URL(crdUrl).openStream()) {
newCrd = OpenShiftUtils.getInstance().customResourceDefinitions().load(is).get();
} catch (IOException ex) {
throw new IllegalArgumentException("Unable to load CRD", ex);
}

CustomResourceDefinition existingCrd = OpenShiftUtils.getInstance().customResourceDefinitions()
.withName(newCrd.getMetadata().getName()).get();
if (existingCrd == null) {
// Just create a new CRD
OpenShiftUtils.getInstance().customResourceDefinitions().create(newCrd);
} else {
// Edit the existing CRD, if it doesn't contain the version we want to deploy now
// else do nothing, as the existing crd and new crd are probably the same
List<CustomResourceDefinitionVersion> versions = OpenShiftUtils.getInstance().customResourceDefinitions()
.withName(existingCrd.getMetadata().getName()).get().getSpec().getVersions();
if (existingCrd.getSpec().getVersions().stream().noneMatch(v -> newCrd.getSpec().getVersion().equals(v.getName()))) {
CustomResourceDefinitionFluent.SpecNested<DoneableCustomResourceDefinition> crd =
OpenShiftUtils.getInstance().customResourceDefinitions().withName(existingCrd.getMetadata().getName())
.edit()
.editSpec()
// Add a new version
.addNewVersion()
.withName(newCrd.getSpec().getVersion())
.withServed(true)
.withStorage(true)
.endVersion();
versions.stream().filter(v -> !v.getName().equals(newCrd.getSpec().getVersion()))
.forEach(v -> crd.editMatchingVersion(mv -> mv.getName().equals(v.getName())).withServed(true).withStorage(false).endVersion());
crd.endSpec()
.editStatus()
// Also add it to stored versions
.addToStoredVersions(newCrd.getSpec().getVersion())
.endStatus()
.done();
} else {
// We need to make "current" CRD version "served" and with "storage"
CustomResourceDefinitionFluent.SpecNested<DoneableCustomResourceDefinition> crd =
OpenShiftUtils.getInstance().customResourceDefinitions().withName(existingCrd.getMetadata().getName())
.edit()
.editSpec()
// Edit the version we want to deploy now
.editMatchingVersion(v -> v.getName().equals(newCrd.getSpec().getVersion()))
.withServed(true)
.withStorage(true)
.endVersion();
versions.stream().filter(v -> !v.getName().equals(newCrd.getSpec().getVersion()))
.forEach(v -> crd.editMatchingVersion(mv -> mv.getName().equals(v.getName())).withServed(true).withStorage(false).endVersion());
crd.endSpec().done();
}
}
}

public List<HasMetadata> getOperatorResources() {
String imageName = StringUtils.substringBeforeLast(operatorImage, ":");
String imageTag = StringUtils.substringAfterLast(operatorImage, ":");
Expand Down

0 comments on commit e0344fa

Please sign in to comment.