Skip to content

Commit

Permalink
Fix passing of custom images to upstream operator
Browse files Browse the repository at this point in the history
  • Loading branch information
michalxo committed Oct 23, 2023
1 parent 2b12d4f commit 9dc0fd8
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ public EnvironmentOperator() {
keycloakVersion = System.getProperty(Constants.EV_KEYCLOAK_VERSION, getDefaultKeycloakVersion());

printAllUsedTestVariables();
checkSetProvidedImages();
}

@SuppressWarnings("checkstyle:NPathComplexity")
Expand Down Expand Up @@ -198,7 +197,7 @@ public Database getDatabase() {
return null;
}

private void checkSetProvidedImages() {
public void checkSetProvidedImages() {
Path operatorFile = ArtemisFileProvider.getOperatorInstallFile();

if (brokerImage != null && !brokerImage.equals("")) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ protected void setupEnvironment() {
if (!setupPerformed) {
testEnvironmentOperator = ResourceManager.getEnvironment();
setupLoggingLevel();
testEnvironmentOperator.checkSetProvidedImages();
ResourceManager.getInstance(testEnvironmentOperator);
// Following log is added for debugging purposes, when OkHttpClient leaks connection
java.util.logging.Logger.getLogger(OkHttpClient.class.getName()).setLevel(java.util.logging.Level.FINE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,11 +48,6 @@ public class ArtemisCloudClusterOperatorFile extends ArtemisCloudClusterOperator
private Path operatorUpdatedFile;
private Path clusterRoleBindingUpdatedFile;


// public FileInstallation(String deploymentNamespace, boolean isNamespaced, List<String> watchedNamespaces) {
// this(deploymentNamespace, isNamespaced, watchedNamespaces);
// }

public ArtemisCloudClusterOperatorFile(String deploymentNamespace, boolean isNamespaced, List<String> watchedNamespaces) {
super(deploymentNamespace, isNamespaced, watchedNamespaces);

Expand All @@ -65,7 +60,6 @@ public ArtemisCloudClusterOperatorFile(String deploymentNamespace, boolean isNam
}
}


public static void deployOperatorCRDs() {
DEFAULT_OPERATOR_INSTALL_CRD_FILES.forEach(fileName -> {
try {
Expand Down Expand Up @@ -113,7 +107,6 @@ public void deployOperator(boolean waitForDeployment) {
LOGGER.info("[{}] Cluster operator {} successfully deployed!", deploymentNamespace, operatorName);
}


@Override
public void undeployOperator(boolean waitForUndeployment) {
getUsedOperatorInstallFilesReversed().forEach(fileName -> {
Expand Down Expand Up @@ -145,7 +138,6 @@ public void updateClusterRoleBinding(String namespace) {
filesToDeploy.remove(clusterRoleBindingFile);
filesToDeploy.add(updatedClusterRoleBindingFile);
setArtemisClusterRoleBindingFile(updatedClusterRoleBindingFile);

} else {
LOGGER.error("[{}] Namespaced operator does not use ClusterRoleBinding!", namespace);
throw new RuntimeException("Incorrect ClusterOperator operation!");
Expand Down Expand Up @@ -228,20 +220,27 @@ public void setArtemisClusterRoleBindingFile(Path clusterRoleBindingFile) {
public static void updateImagesInOperatorFile(Path operatorFile, String imageType, String imageUrl, String version) {
List<EnvVar> envVars;
String imageTypeVersion = null;
Deployment operator = TestUtils.configFromYaml(operatorFile.toFile(), Deployment.class);

if (version != null) {
imageTypeVersion = imageType + version.replace(".", "");
if (version.equals("main")) {
imageTypeVersion = imageType + getLastVersionFromOperatorFile(imageType, operator);
} else {
imageTypeVersion = imageType + version.replace(".", "");
}
}
Deployment operator = TestUtils.configFromYaml(operatorFile.toFile(), Deployment.class);

if (imageType.equals(ArtemisConstants.OPERATOR_IMAGE_OPERATOR_PREFIX)) {
operator.getSpec().getTemplate().getSpec().getContainers().get(0).setImage(imageUrl);
LOGGER.info("[Operator] Updating OperatorImage -> {}", imageUrl);
}

if (imageType.equals(ArtemisConstants.BROKER_IMAGE_OPERATOR_PREFIX) || imageType.equals(ArtemisConstants.BROKER_INIT_IMAGE_OPERATOR_PREFIX)) {
envVars = operator.getSpec().getTemplate().getSpec().getContainers().get(0).getEnv();
String finalImageTypeVersion = imageTypeVersion;
EnvVar brokerImageEV = envVars.stream().filter(envVar -> envVar.getName().equals(finalImageTypeVersion)).findFirst().get();
brokerImageEV.setValue(imageUrl);
LOGGER.info("[Operator] Updating {} -> {}", finalImageTypeVersion, imageUrl);
}

TestUtils.configToYaml(operatorFile.toFile(), operator);
Expand Down Expand Up @@ -282,4 +281,18 @@ public static String getOperatorControllerManagerName(Path yamlFile) {
return operatorCODeployment.getMetadata().getName();
}

public static String getLastVersionFromOperatorFile(String imageType, Deployment operator) {
List<EnvVar> envVars1 = operator.getSpec().getTemplate().getSpec().getContainers().get(0).getEnv();
List<Integer> versions = new ArrayList<>();

for (EnvVar var : envVars1) {
if (var.getName().startsWith(imageType)) {
versions.add(Integer.valueOf(var.getName().substring(imageType.length())));
}
}
Collections.sort(versions);
LOGGER.trace("[Operator] Discovered latest version: {}{}", imageType, versions.get(versions.size() - 1));
return String.valueOf(versions.get(versions.size() - 1));
}

}

0 comments on commit 9dc0fd8

Please sign in to comment.