Skip to content

Commit

Permalink
controllers: Skip checking the CSV if it is upgrading cluster
Browse files Browse the repository at this point in the history
The CSVs check was implemted to make sure that all the required CRDS
exists for the UI to proceed. But this check create problems in the
cluster where the odf is being upgraded as odf-operator csv never gets
into the Succeeded state because of the operator readiness check.

Signed-off-by: Nitin Goyal <[email protected]>
  • Loading branch information
iamniting committed Nov 20, 2024
1 parent 27cc08e commit 808d92d
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions pkg/util/readiness.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,15 @@ package util
import (
"fmt"
"net/http"
"strings"

opv1a1 "github.com/operator-framework/api/pkg/operators/v1alpha1"
"sigs.k8s.io/controller-runtime/pkg/client"
"sigs.k8s.io/controller-runtime/pkg/healthz"
)

func CheckCSVPhase(c client.Client, namespace string, csvNames ...string) healthz.Checker {

csvMap := map[string]struct{}{}
for _, name := range csvNames {
csvMap[name] = struct{}{}
Expand All @@ -35,6 +37,14 @@ func CheckCSVPhase(c client.Client, namespace string, csvNames ...string) health
if err := c.List(r.Context(), csvList, client.InNamespace(namespace)); err != nil {
return err
}

// Check if it is upgrade from 4.17 to 4.18
// The new CSVs won't exists while upgrading
// They will exists only after new operator has created a new subscription
if AreMultipleOdfOperatorCsvsPresent(csvList) {
return nil
}

for idx := range csvList.Items {
csv := &csvList.Items[idx]
_, exists := csvMap[csv.Name]
Expand All @@ -54,3 +64,16 @@ func CheckCSVPhase(c client.Client, namespace string, csvNames ...string) health
return nil
}
}

func AreMultipleOdfOperatorCsvsPresent(csvs *opv1a1.ClusterServiceVersionList) bool {

count := 0

for _, csv := range csvs.Items {
if strings.HasPrefix(csv.Name, "odf-operator") {
count += 1
}
}

return count > 1
}

0 comments on commit 808d92d

Please sign in to comment.