From 21f78bda559857b2506381e26a942e5375bed5a1 Mon Sep 17 00:00:00 2001 From: Lukas Kral Date: Fri, 13 Dec 2024 16:22:37 +0100 Subject: [PATCH] [ST] Specify correct registry, org, and tag for Helm and remove unused code for OCP Signed-off-by: Lukas Kral --- .../io/strimzi/systemtest/Environment.java | 9 ++++++++- .../operator/SetupClusterOperator.java | 18 ++---------------- .../operator/specific/HelmResource.java | 6 +++--- 3 files changed, 13 insertions(+), 20 deletions(-) diff --git a/systemtest/src/main/java/io/strimzi/systemtest/Environment.java b/systemtest/src/main/java/io/strimzi/systemtest/Environment.java index 0c09331c011..ade664a0e75 100644 --- a/systemtest/src/main/java/io/strimzi/systemtest/Environment.java +++ b/systemtest/src/main/java/io/strimzi/systemtest/Environment.java @@ -189,6 +189,7 @@ public class Environment { /** * Defaults */ + public static final String STRIMZI_TAG_DEFAULT = "latest"; public static final String STRIMZI_ORG_DEFAULT = "strimzi"; public static final String STRIMZI_REGISTRY_DEFAULT = "quay.io"; public static final String TEST_CLIENTS_ORG_DEFAULT = "strimzi-test-clients"; @@ -243,7 +244,9 @@ public class Environment { private static final String TEST_CLIENTS_VERSION = getOrDefault(TEST_CLIENTS_VERSION_ENV, TEST_CLIENTS_VERSION_DEFAULT); private static final String TEST_CLIENTS_IMAGE_DEFAULT = STRIMZI_REGISTRY_DEFAULT + "/" + TEST_CLIENTS_ORG_DEFAULT + "/test-clients:" + TEST_CLIENTS_VERSION + "-kafka-" + CLIENTS_KAFKA_VERSION; public static final String TEST_CLIENTS_IMAGE = getOrDefault(TEST_CLIENTS_IMAGE_ENV, TEST_CLIENTS_IMAGE_DEFAULT); - private static final String SCRAPER_IMAGE_DEFAULT = STRIMZI_REGISTRY + "/" + STRIMZI_ORG + "/kafka:" + STRIMZI_TAG + "-kafka-" + ST_KAFKA_VERSION; + private static final String SCRAPER_IMAGE_DEFAULT = getIfNotEmptyOrDefault(STRIMZI_REGISTRY, STRIMZI_REGISTRY_DEFAULT) + "/" + + getIfNotEmptyOrDefault(STRIMZI_ORG, STRIMZI_ORG_DEFAULT) + "/kafka:" + + getIfNotEmptyOrDefault(STRIMZI_TAG, STRIMZI_TAG_DEFAULT) + "-kafka-" + ST_KAFKA_VERSION; public static final String SCRAPER_IMAGE = getOrDefault(SCRAPER_IMAGE_ENV, SCRAPER_IMAGE_DEFAULT); // variables for kafka bridge image @@ -449,4 +452,8 @@ private static boolean isWriteable(String var, String value) { public static boolean isEnvVarSet(String envVarName) { return System.getenv(envVarName) != null; } + + public static String getIfNotEmptyOrDefault(String envVar, String defaultValue) { + return envVar.isEmpty() ? defaultValue : envVar; + } } diff --git a/systemtest/src/main/java/io/strimzi/systemtest/resources/operator/SetupClusterOperator.java b/systemtest/src/main/java/io/strimzi/systemtest/resources/operator/SetupClusterOperator.java index 5814f228685..7c0cb184e9e 100644 --- a/systemtest/src/main/java/io/strimzi/systemtest/resources/operator/SetupClusterOperator.java +++ b/systemtest/src/main/java/io/strimzi/systemtest/resources/operator/SetupClusterOperator.java @@ -41,10 +41,7 @@ import io.strimzi.systemtest.utils.specific.OlmUtils; import io.strimzi.test.ReadWriteUtils; import io.strimzi.test.TestUtils; -import io.strimzi.test.executor.Exec; import io.strimzi.test.k8s.KubeClusterResource; -import io.strimzi.test.k8s.cluster.OpenShift; -import org.apache.logging.log4j.Level; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.junit.jupiter.api.extension.ExtensionContext; @@ -288,7 +285,7 @@ private void bundleInstallation() { LOGGER.info("Install Cluster Operator via Yaml bundle"); // check if namespace is already created createClusterOperatorNamespaceIfPossible(); - prepareEnvForOperator(namespaceInstallTo, bindingsNamespaces); + prepareEnvForOperator(namespaceInstallTo); // if we manage directly in the individual test one of the Role, ClusterRole, RoleBindings and ClusterRoleBinding we must do it // everything by ourselves in scope of RBAC permissions otherwise we apply the default one if (this.isRolesAndBindingsManagedByAnUser()) { @@ -554,21 +551,10 @@ public SetupClusterOperator createInstallation() { * Prepare environment for cluster operator which includes creation of namespaces, custom resources and operator * specific config files such as ServiceAccount, Roles and CRDs. * @param clientNamespace namespace which will be created and used as default by kube client - * @param namespaces list of namespaces which will be created */ - public void prepareEnvForOperator(String clientNamespace, List namespaces) { + public void prepareEnvForOperator(String clientNamespace) { assumeTrue(!Environment.isHelmInstall() && !Environment.isOlmInstall()); applyClusterOperatorInstallFiles(clientNamespace); - - if (cluster.cluster() instanceof OpenShift) { - // This is needed in case you are using internal kubernetes registry and you want to pull images from there - if (kubeClient().getNamespace(Environment.STRIMZI_ORG) != null) { - for (String namespace : namespaces) { - LOGGER.debug("Setting group policy for Openshift registry in Namespace: " + namespace); - Exec.exec(null, Arrays.asList("oc", "policy", "add-role-to-group", "system:image-puller", "system:serviceaccounts:" + namespace, "-n", Environment.STRIMZI_ORG), 0, Level.DEBUG, false); - } - } - } } public String changeLeaseNameInResourceIfNeeded(String yamlPath) { diff --git a/systemtest/src/main/java/io/strimzi/systemtest/resources/operator/specific/HelmResource.java b/systemtest/src/main/java/io/strimzi/systemtest/resources/operator/specific/HelmResource.java index 466a4e1b1d3..882ad4e18b3 100644 --- a/systemtest/src/main/java/io/strimzi/systemtest/resources/operator/specific/HelmResource.java +++ b/systemtest/src/main/java/io/strimzi/systemtest/resources/operator/specific/HelmResource.java @@ -57,15 +57,15 @@ private void clusterOperator(long operationTimeout, long reconciliationInterval, Map values = new HashMap<>(); // image registry config - values.put("defaultImageRegistry", Environment.STRIMZI_REGISTRY); + values.put("defaultImageRegistry", Environment.getIfNotEmptyOrDefault(Environment.STRIMZI_REGISTRY, Environment.STRIMZI_REGISTRY_DEFAULT)); values.put("kafkaBridge.image.registry", Environment.STRIMZI_REGISTRY_DEFAULT); // image repository config - values.put("defaultImageRepository", Environment.STRIMZI_ORG); + values.put("defaultImageRepository", Environment.getIfNotEmptyOrDefault(Environment.STRIMZI_ORG, Environment.STRIMZI_ORG_DEFAULT)); values.put("kafkaBridge.image.repository", Environment.STRIMZI_ORG_DEFAULT); // image tags config - values.put("defaultImageTag", Environment.STRIMZI_TAG); + values.put("defaultImageTag", Environment.getIfNotEmptyOrDefault(Environment.STRIMZI_TAG, Environment.STRIMZI_TAG_DEFAULT)); values.put("kafkaBridge.image.tag", BridgeUtils.getBridgeVersion()); // Additional config