From 80575e25966c288855c534231eb84e63fd88107a Mon Sep 17 00:00:00 2001 From: Matej Kralik Date: Wed, 3 Jul 2024 21:21:27 +0200 Subject: [PATCH] Update certmanageroperator to get version dynamicly (#704) --- pkg/certmanageroperator/install.go | 18 +++++++++++------- pkg/util/operator/operators.go | 10 ++++++++++ 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/pkg/certmanageroperator/install.go b/pkg/certmanageroperator/install.go index e523b129..cfabb9c2 100644 --- a/pkg/certmanageroperator/install.go +++ b/pkg/certmanageroperator/install.go @@ -19,12 +19,13 @@ var ( rootCA string certManagerOperatorNs = "cert-manager-operator" + certManagerCSVName = "cert-manager-operator" certManagerNs = "cert-manager" - certmanagerVersion = "cert-manager-operator.v1.13.0" + certmanagerMinVersion = certManagerCSVName + ".v1.13.0" ) func InstallIfNotExist(t test.TestHelper) { - if operator.OperatorExists(t, certmanagerVersion) { + if operator.OperatorExists(t, certmanagerMinVersion) { t.Log("cert-manager-operator is already installed") } else { t.Log("cert-manager-operator is not installed, starting installation") @@ -34,7 +35,7 @@ func InstallIfNotExist(t test.TestHelper) { func install(t test.TestHelper) { installOperator(t) - waitOperatorSucceded(t, certManagerOperatorNs) + waitOperatorSucceded(t) t.LogStep("Create root ca") oc.ApplyString(t, certManagerNs, rootCA) @@ -43,7 +44,8 @@ func install(t test.TestHelper) { func Uninstall(t test.TestHelper) { oc.DeleteFromString(t, certManagerNs, rootCA) - oc.DeleteFromTemplate(t, certManagerOperatorNs, certManagerOperator, map[string]string{"Version": certmanagerVersion}) + exactOperatorVersion := operator.GetCsvName(t, certManagerOperatorNs, certManagerCSVName) + oc.DeleteFromTemplate(t, certManagerOperatorNs, certManagerOperator, map[string]string{"Version": exactOperatorVersion}) oc.DeleteNamespace(t, certManagerOperatorNs) oc.DeleteNamespace(t, certManagerNs) } @@ -53,10 +55,12 @@ func installOperator(t test.TestHelper) { oc.CreateNamespace(t, certManagerOperatorNs) t.LogStep("Install cert-manager-operator") - oc.ApplyTemplate(t, certManagerOperatorNs, certManagerOperator, map[string]string{"Version": certmanagerVersion}) + oc.ApplyTemplate(t, certManagerOperatorNs, certManagerOperator, map[string]string{"Version": certmanagerMinVersion}) + operator.WaitForCsvReady(t, certManagerCSVName) } -func waitOperatorSucceded(t test.TestHelper, certManagerOperatorNs string) { - operator.WaitForOperatorReady(t, certManagerOperatorNs, "name=cert-manager-operator", certmanagerVersion) +func waitOperatorSucceded(t test.TestHelper) { + fullCsvName := operator.GetCsvName(t, certManagerOperatorNs, certManagerCSVName) + operator.WaitForOperatorReady(t, certManagerOperatorNs, "name="+certManagerCSVName, fullCsvName) oc.WaitPodReadyWithOptions(t, retry.Options().MaxAttempts(70).DelayBetweenAttempts(5*time.Second), pod.MatchingSelector("app=cert-manager", certManagerNs)) } diff --git a/pkg/util/operator/operators.go b/pkg/util/operator/operators.go index e14291dd..a4c4a622 100644 --- a/pkg/util/operator/operators.go +++ b/pkg/util/operator/operators.go @@ -17,6 +17,16 @@ func GetCsvName(t test.TestHelper, operatorNamespace string, partialName string) return strings.TrimSpace(output) } +func WaitForCsvReady(t test.TestHelper, partialName string) { + t.Logf("Waiting for csv %s is ready", partialName) + retry.UntilSuccessWithOptions(t, retry.Options().DelayBetweenAttempts(1*time.Second).MaxAttempts(20), func(t test.TestHelper) { + output := shell.Execute(t, fmt.Sprintf(`oc get csv -A -o custom-columns="NAME:.metadata.name" |grep %s ||true`, partialName)) + if output == "" { + t.Errorf("CSV %s is not ready yet", partialName) + } + }) +} + func OperatorExists(t test.TestHelper, csvVersion string) bool { output := shell.Execute(t, fmt.Sprintf(`oc get csv -A -o custom-columns="NAME:.metadata.name,REPLACES:.spec.replaces" |grep %s ||true`, csvVersion)) return strings.Contains(output, csvVersion)