Skip to content

Commit

Permalink
Update certmanageroperator to get version dynamicly (#704)
Browse files Browse the repository at this point in the history
  • Loading branch information
mkralik3 authored Jul 3, 2024
1 parent 7d4a966 commit 80575e2
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 7 deletions.
18 changes: 11 additions & 7 deletions pkg/certmanageroperator/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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)
Expand All @@ -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)
}
Expand All @@ -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))
}
10 changes: 10 additions & 0 deletions pkg/util/operator/operators.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 80575e2

Please sign in to comment.