Skip to content

Commit

Permalink
[ST] Install CO with OLM without need of specifying OLM version for l…
Browse files Browse the repository at this point in the history
…atest released operator (#10681)

Signed-off-by: Lukas Kral <[email protected]>
  • Loading branch information
im-konge authored Oct 8, 2024
1 parent 4ffe9f1 commit 714df88
Show file tree
Hide file tree
Showing 10 changed files with 152 additions and 67 deletions.
2 changes: 1 addition & 1 deletion development-docs/TESTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@ All environment variables are defined in [Environment](systemtest/src/main/java/
| OLM_OPERATOR_NAME | Operator name in manifests CSV | strimzi |
| OLM_SOURCE_NAME | CatalogSource name which contains desired operator | strimzi-source |
| OLM_APP_BUNDLE_PREFIX | CSV bundle name | strimzi |
| OLM_OPERATOR_VERSION | Version of the operator which will be installed | v0.16.2 |
| OLM_OPERATOR_CHANNEL | Channel of the operator, from which will be the latest available version installed | v0.16.2 |
| DEFAULT_TO_DENY_NETWORK_POLICIES | Determines how will be network policies set - to deny-all (true) or allow-all (false) | true |
| STRIMZI_EXEC_MAX_LOG_OUTPUT_CHARACTERS | Set maximum count of characters printed from [Executor](test/src/main/java/io/strimzi/test/executor/Exec.java) stdout and stderr | 20000 |
| RESOURCE_ALLOCATION_STRATEGY | Set memory allocation for strimzi pod set | SHARE_MEMORY_FOR_ALL_COMPONENTS |
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ public class Environment {
private static final String OLM_SOURCE_NAME_ENV = "OLM_SOURCE_NAME";
private static final String OLM_SOURCE_NAMESPACE_ENV = "OLM_SOURCE_NAMESPACE";
private static final String OLM_APP_BUNDLE_PREFIX_ENV = "OLM_APP_BUNDLE_PREFIX";
private static final String OLM_OPERATOR_VERSION_ENV = "OLM_OPERATOR_VERSION";
private static final String OLM_OPERATOR_CHANNEL_ENV = "OLM_OPERATOR_CHANNEL";
/**
* Allows network policies
*/
Expand Down Expand Up @@ -202,6 +202,7 @@ public class Environment {
public static final String OLM_OPERATOR_DEPLOYMENT_NAME_DEFAULT = TestConstants.STRIMZI_DEPLOYMENT_NAME;
public static final String OLM_SOURCE_NAME_DEFAULT = "community-operators";
public static final String OLM_APP_BUNDLE_PREFIX_DEFAULT = "strimzi-cluster-operator";
public static final String OLM_OPERATOR_CHANNEL_DEFAULT = "stable";
private static final boolean DEFAULT_TO_DENY_NETWORK_POLICIES_DEFAULT = true;
private static final ClusterOperatorInstallType CLUSTER_OPERATOR_INSTALL_TYPE_DEFAULT = ClusterOperatorInstallType.BUNDLE;
private static final boolean LB_FINALIZERS_DEFAULT = false;
Expand All @@ -212,7 +213,6 @@ public class Environment {
private static final String ST_CLIENTS_KAFKA_VERSION_DEFAULT = "3.8.0";
public static final String TEST_CLIENTS_VERSION_DEFAULT = "0.9.1";
public static final String ST_FILE_PLUGIN_URL_DEFAULT = "https://repo1.maven.org/maven2/org/apache/kafka/connect-file/" + ST_KAFKA_VERSION_DEFAULT + "/connect-file-" + ST_KAFKA_VERSION_DEFAULT + ".jar";
public static final String OLM_OPERATOR_VERSION_DEFAULT = "0.43.0";

public static final String IP_FAMILY_DEFAULT = "ipv4";
public static final String IP_FAMILY_VERSION_6 = "ipv6";
Expand Down Expand Up @@ -259,7 +259,7 @@ public class Environment {
public static final String OLM_SOURCE_NAME = getOrDefault(OLM_SOURCE_NAME_ENV, OLM_SOURCE_NAME_DEFAULT);
public static final String OLM_SOURCE_NAMESPACE = getOrDefault(OLM_SOURCE_NAMESPACE_ENV, OpenShift.OLM_SOURCE_NAMESPACE);
public static final String OLM_APP_BUNDLE_PREFIX = getOrDefault(OLM_APP_BUNDLE_PREFIX_ENV, OLM_APP_BUNDLE_PREFIX_DEFAULT);
public static final String OLM_OPERATOR_LATEST_RELEASE_VERSION = getOrDefault(OLM_OPERATOR_VERSION_ENV, OLM_OPERATOR_VERSION_DEFAULT);
public static final String OLM_OPERATOR_CHANNEL = getOrDefault(OLM_OPERATOR_CHANNEL_ENV, OLM_OPERATOR_CHANNEL_DEFAULT);
// NetworkPolicy variable
public static final boolean DEFAULT_TO_DENY_NETWORK_POLICIES = getOrDefault(DEFAULT_TO_DENY_NETWORK_POLICIES_ENV, Boolean::parseBoolean, DEFAULT_TO_DENY_NETWORK_POLICIES_DEFAULT);
// Cluster Operator installation type variable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,13 @@ public void upgradeClusterOperator(String namespaceName, OlmConfiguration olmCon
}

updateSubscription(olmConfiguration);
OlmUtils.waitUntilNonUsedInstallPlanWithSpecificCsvIsPresentAndApprove(namespaceInstallTo, olmConfiguration.getCsvName());
// Because we are updating to latest available CO, we want to wait for new install plan with CSV prefix, not with the exact CSV (containing the prefix and version)
OlmUtils.waitForNonApprovedInstallPlanWithCsvNameOrPrefix(namespaceInstallTo, olmConfiguration.getOlmAppBundlePrefix());
String newDeploymentName = OlmUtils.approveNonApprovedInstallPlanAndReturnDeploymentName(namespaceInstallTo, olmConfiguration.getOlmAppBundlePrefix());

olmConfiguration.setOlmOperatorDeploymentName(kubeClient().getDeploymentNameByPrefix(olmConfiguration.getNamespaceName(), newDeploymentName));
DeploymentUtils.waitForCreationOfDeploymentWithPrefix(namespaceInstallTo, olmConfiguration.getOlmOperatorDeploymentName());

DeploymentUtils.waitForDeploymentAndPodsReady(namespaceInstallTo, olmConfiguration.getOlmOperatorDeploymentName(), 1);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,16 @@ public class OlmConfiguration {
private ExtensionContext extensionContext;
private String namespaceName;
private String namespaceToWatch;
private String featureGates = Environment.STRIMZI_FEATURE_GATES;
private String olmAppBundlePrefix = Environment.OLM_APP_BUNDLE_PREFIX;
private String olmOperatorName = Environment.OLM_OPERATOR_NAME;
private final String featureGates = Environment.STRIMZI_FEATURE_GATES;
private final String olmAppBundlePrefix = Environment.OLM_APP_BUNDLE_PREFIX;
private final String olmOperatorName = Environment.OLM_OPERATOR_NAME;
private final String olmSourceName = Environment.OLM_SOURCE_NAME;
private final String olmSourceNamespace = Environment.OLM_SOURCE_NAMESPACE;
private String olmOperatorDeploymentNamePrefix = Environment.OLM_OPERATOR_DEPLOYMENT_NAME;
private String olmSourceName = Environment.OLM_SOURCE_NAME;
private String olmSourceNamespace = Environment.OLM_SOURCE_NAMESPACE;
// Init value is needed due to UWF_FIELD_NOT_INITIALIZED_IN_CONSTRUCTOR
private String operatorVersion = "";
private String olmOperatorDeploymentName = "";
private String operatorVersion;
private OlmInstallationStrategy olmInstallationStrategy;
private String channelName;
private String channelName = Environment.OLM_OPERATOR_CHANNEL;
private List<EnvVar> envVars;
private long reconciliationInterval;
private long operationTimeout;
Expand Down Expand Up @@ -68,7 +68,7 @@ public OlmInstallationStrategy getOlmInstallationStrategy() {
}

public void setOperatorVersion(String operatorVersion) {
this.operatorVersion = operatorVersion != null && operatorVersion.isEmpty() ? Environment.OLM_OPERATOR_LATEST_RELEASE_VERSION : operatorVersion;
this.operatorVersion = operatorVersion;
}

public String getOperatorVersion() {
Expand All @@ -80,7 +80,7 @@ public String getCsvName() {
}

public void setChannelName(String channelName) {
this.channelName = channelName == null && operatorVersion.equals(Environment.OLM_OPERATOR_LATEST_RELEASE_VERSION) ? "stable" : channelName;
this.channelName = channelName == null ? this.channelName : channelName;
}

public String getChannelName() {
Expand Down Expand Up @@ -119,8 +119,16 @@ public String getOlmAppBundlePrefix() {
return olmAppBundlePrefix;
}

public String getOlmOperatorDeploymentNamePrefix() {
return olmOperatorDeploymentNamePrefix;
}

public void setOlmOperatorDeploymentName(String olmOperatorDeploymentName) {
this.olmOperatorDeploymentName = olmOperatorDeploymentName;
}

public String getOlmOperatorDeploymentName() {
return olmOperatorDeploymentNamePrefix + "-v" + operatorVersion;
return olmOperatorDeploymentName;
}

public String getOlmOperatorName() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import io.strimzi.systemtest.resources.operator.configuration.OlmConfiguration;
import io.strimzi.systemtest.utils.kubeUtils.controllers.DeploymentUtils;
import io.strimzi.systemtest.utils.specific.OlmUtils;
import io.strimzi.test.TestUtils;
import io.strimzi.test.k8s.KubeClusterResource;
import io.vertx.core.json.JsonArray;
import io.vertx.core.json.JsonObject;
Expand All @@ -33,7 +32,6 @@
import java.util.Stack;
import java.util.stream.Collectors;

import static io.strimzi.systemtest.resources.ResourceManager.CR_CREATION_TIMEOUT;
import static io.strimzi.test.k8s.KubeClusterResource.kubeClient;

public class OlmResource implements SpecificResourceType {
Expand Down Expand Up @@ -63,18 +61,19 @@ public void create() {

// Manual installation needs to be approved with a patch
if (olmConfiguration.getOlmInstallationStrategy() == OlmInstallationStrategy.Manual) {
OlmUtils.waitUntilNonUsedInstallPlanWithSpecificCsvIsPresentAndApprove(olmConfiguration.getNamespaceName(), olmConfiguration.getCsvName());
OlmUtils.waitForNonApprovedInstallPlanWithCsvNameOrPrefix(olmConfiguration.getNamespaceName(), olmConfiguration.getCsvName());
OlmUtils.approveNonApprovedInstallPlan(olmConfiguration.getNamespaceName(), olmConfiguration.getCsvName());
}

// Make sure that operator will be created
TestUtils.waitFor("Cluster Operator deployment creation", TestConstants.GLOBAL_POLL_INTERVAL, CR_CREATION_TIMEOUT,
() -> kubeClient(olmConfiguration.getNamespaceName()).getDeploymentNameByPrefix(olmConfiguration.getOlmOperatorDeploymentName()) != null);
DeploymentUtils.waitForCreationOfDeploymentWithPrefix(olmConfiguration.getNamespaceName(), olmConfiguration.getOlmOperatorDeploymentNamePrefix());

deploymentName = kubeClient(olmConfiguration.getNamespaceName()).getDeploymentNameByPrefix(olmConfiguration.getOlmOperatorDeploymentName());
deploymentName = kubeClient(olmConfiguration.getNamespaceName()).getDeploymentNameByPrefix(olmConfiguration.getOlmOperatorDeploymentNamePrefix());
ResourceManager.setCoDeploymentName(deploymentName);
olmConfiguration.setOlmOperatorDeploymentName(deploymentName);

// Wait for operator creation
DeploymentUtils.waitForDeploymentAndPodsReady(olmConfiguration.getNamespaceName(), deploymentName, 1);
DeploymentUtils.waitForDeploymentAndPodsReady(olmConfiguration.getNamespaceName(), olmConfiguration.getOlmOperatorDeploymentName(), 1);

exampleResources = parseExamplesFromCsv();
}
Expand Down Expand Up @@ -115,6 +114,7 @@ private void createAndModifySubscription() {

ResourceManager.getInstance().createResourceWithWait(subscription);
}

public void updateSubscription(OlmConfiguration olmConfiguration) {
this.olmConfiguration = olmConfiguration;
// add CSV resource to the end of the stack -> to be deleted after the subscription and operator group
Expand All @@ -132,7 +132,7 @@ public void updateSubscription(OlmConfiguration olmConfiguration) {
}

public Subscription prepareSubscription(OlmConfiguration olmConfiguration) {
Subscription subscription = new SubscriptionBuilder()
SubscriptionBuilder subscriptionBuilder = new SubscriptionBuilder()
.editOrNewMetadata()
.withName("strimzi-sub")
.withNamespace(olmConfiguration.getNamespaceName())
Expand All @@ -143,13 +143,18 @@ public Subscription prepareSubscription(OlmConfiguration olmConfiguration) {
.withSource(olmConfiguration.getOlmSourceName())
.withSourceNamespace(olmConfiguration.getOlmSourceNamespace())
.withChannel(olmConfiguration.getChannelName())
.withStartingCSV(olmConfiguration.getCsvName())
.withInstallPlanApproval(olmConfiguration.getOlmInstallationStrategy().toString())
.editOrNewConfig()
.withEnv(olmConfiguration.getAllEnvVariablesForOlm())
.endConfig()
.endSpec()
.build();
.endSpec();

if (olmConfiguration.getOperatorVersion() != null && !olmConfiguration.getOperatorVersion().isEmpty()) {
subscriptionBuilder
.editSpec()
.withStartingCSV(olmConfiguration.getCsvName())
.endSpec();
}

// Change default values for Cluster Operator memory when RESOURCE_ALLOCATION_STRATEGY is not set to NOT_SHARED
if (KubeClusterResource.getInstance().fipsEnabled()) {
Expand All @@ -160,19 +165,15 @@ public Subscription prepareSubscription(OlmConfiguration olmConfiguration) {
TestConstants.CO_LIMITS_CPU)))
.build();

subscription.getSpec().getConfig().setResources(resourceRequirements);
subscriptionBuilder
.editSpec()
.editOrNewConfig()
.withResources(resourceRequirements)
.endConfig()
.endSpec();
}

return subscription;
}

/**
* Approves non-approved InstallPlan.
* Used for manual installation type.
*/
private void approveNotApprovedInstallPlan() {
String notApprovedIPName = kubeClient().getNonApprovedInstallPlan(olmConfiguration.getNamespaceName()).getMetadata().getName();
kubeClient().approveInstallPlan(olmConfiguration.getNamespaceName(), notApprovedIPName);
return subscriptionBuilder.build();
}

private Map<String, JsonObject> parseExamplesFromCsv() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.type.CollectionType;
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;
import io.strimzi.systemtest.Environment;
import io.strimzi.systemtest.utils.TestKafkaVersion;
import io.strimzi.test.TestUtils;
import org.apache.logging.log4j.LogManager;
Expand Down Expand Up @@ -79,8 +78,6 @@ public void loadOlmUpgradeData() {
try {
ObjectMapper mapper = new ObjectMapper(new YAMLFactory());
this.olmUpgradeData = mapper.readValue(new File(TestUtils.USER_PATH + "/src/test/resources/upgrade/OlmUpgrade.yaml"), OlmVersionModificationData.class);
// By default upgrade to the latest released version
this.olmUpgradeData.setToVersion(Environment.OLM_OPERATOR_LATEST_RELEASE_VERSION);
// Create and set procedures -> replace kafka version after operator upgrade.
// This is needed, because for upgrade it's generated by method which generated data for parametrized test
this.olmUpgradeData.setProcedures(new UpgradeKafkaVersion(TestKafkaVersion.getDefaultSupportedKafkaVersion()));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -203,4 +203,9 @@ public static void waitForDeploymentDeletion(String namespaceName, String name)
});
LOGGER.debug("Deployment: {}/{} was deleted", namespaceName, name);
}

public static void waitForCreationOfDeploymentWithPrefix(String namespaceName, String deploymentNamePrefix) {
TestUtils.waitFor(String.join("creation of Deployment with prefix: %s in Namespace: %s", deploymentNamePrefix, namespaceName), TestConstants.GLOBAL_POLL_INTERVAL, TestConstants.GLOBAL_STATUS_TIMEOUT,
() -> kubeClient().getDeploymentNameByPrefix(namespaceName, deploymentNamePrefix) != null);
}
}
Loading

0 comments on commit 714df88

Please sign in to comment.