Skip to content

Commit

Permalink
controllers: Do not update client operator in provider mode
Browse files Browse the repository at this point in the history
Client operator manages its own upgrade life cycle in the provider mode,
Do not update its channel in the provider mode.

Signed-off-by: Nitin Goyal <[email protected]>
  • Loading branch information
iamniting committed Apr 2, 2024
1 parent 36a1b6e commit eca9ef5
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 7 deletions.
5 changes: 4 additions & 1 deletion controllers/storagesystem_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,10 @@ func (r *StorageSystemReconciler) ensureSubscriptions(instance *odfv1alpha1.Stor

func (r *StorageSystemReconciler) isVendorCsvReady(instance *odfv1alpha1.StorageSystem, logger logr.Logger) error {

csvNames := GetVendorCsvNames(instance.Spec.Kind)
csvNames, err := GetVendorCsvNames(r.Client, instance.Spec.Kind)
if err != nil {
return err
}

var returnErr error
for _, csvName := range csvNames {
Expand Down
19 changes: 17 additions & 2 deletions controllers/subscription_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,12 @@ func (r *SubscriptionReconciler) ensureSubscriptions(logger logr.Logger, namespa
}

for kind := range subsList {
for _, csvName := range GetVendorCsvNames(kind) {
csvNames, csvErr := GetVendorCsvNames(r.Client, kind)
if csvErr != nil {
return csvErr
}

for _, csvName := range csvNames {
_, csvErr := EnsureVendorCsv(r.Client, csvName)
if csvErr != nil {
multierr.AppendInto(&err, csvErr)
Expand All @@ -140,7 +145,17 @@ func (r *SubscriptionReconciler) setOperatorCondition(logger logr.Logger, namesp
return err
}

condNames := append(GetVendorCsvNames(StorageClusterKind), GetVendorCsvNames(FlashSystemKind)...)
condNames, err := GetVendorCsvNames(r.Client, StorageClusterKind)
if err != nil {
return err
}

condNamesFlashSystem, err := GetVendorCsvNames(r.Client, FlashSystemKind)
if err != nil {
return err
}

condNames = append(condNames, condNamesFlashSystem...)

condMap := make(map[string]struct{}, len(condNames))
for i := range condNames {
Expand Down
43 changes: 39 additions & 4 deletions controllers/subscriptions.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import (
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"

operatorv1alpha1 "github.com/operator-framework/api/pkg/operators/v1alpha1"
ocsv1 "github.com/red-hat-storage/ocs-operator/api/v4/v1"
odfv1alpha1 "github.com/red-hat-storage/odf-operator/api/v1alpha1"
"github.com/red-hat-storage/odf-operator/pkg/util"
)
Expand All @@ -51,6 +52,14 @@ func CheckExistingSubscriptions(cli client.Client, desiredSubscription *operator
odfSub.Spec.Config = &operatorv1alpha1.SubscriptionConfig{}
}

var isProvider bool
if desiredSubscription.Spec.Package == OcsClientSubscriptionPackage {
isProvider, err = isProviderServer(cli)
if err != nil {
return nil, err
}
}

subsList := &operatorv1alpha1.SubscriptionList{}
err = cli.List(context.TODO(), subsList, &client.ListOptions{Namespace: desiredSubscription.Namespace})
if err != nil {
Expand All @@ -68,7 +77,10 @@ func CheckExistingSubscriptions(cli client.Client, desiredSubscription *operator
return nil, fmt.Errorf("multiple Subscriptions found for package '%s': %v", pkgName, foundSubs)
}
actualSub = &subsList.Items[i]
actualSub.Spec.Channel = desiredSubscription.Spec.Channel

if !isProvider {
actualSub.Spec.Channel = desiredSubscription.Spec.Channel
}

if actualSub.Spec.Config == nil && desiredSubscription.Spec.Config == nil {
actualSub.Spec.Config = &operatorv1alpha1.SubscriptionConfig{}
Expand Down Expand Up @@ -102,6 +114,23 @@ func CheckExistingSubscriptions(cli client.Client, desiredSubscription *operator
return desiredSubscription, nil
}

func isProviderServer(cli client.Client) (bool, error) {

storageclusters := &ocsv1.StorageClusterList{}
err := cli.List(context.TODO(), storageclusters)
if err != nil {
return false, err
}

for _, storagecluster := range storageclusters.Items {
if storagecluster.Spec.AllowRemoteStorageConsumers {
return true, nil
}
}

return false, nil
}

func getMergedTolerations(tol1, tol2 []corev1.Toleration) []corev1.Toleration {

if len(tol1) == 0 {
Expand Down Expand Up @@ -216,18 +245,24 @@ func GetOdfSubscription(cli client.Client) (*operatorv1alpha1.Subscription, erro
return nil, fmt.Errorf("odf-operator subscription not found")
}

func GetVendorCsvNames(kind odfv1alpha1.StorageKind) []string {
func GetVendorCsvNames(cli client.Client, kind odfv1alpha1.StorageKind) ([]string, error) {

var csvNames []string
var err error
var isProvider bool

if kind == VendorFlashSystemCluster() {
csvNames = []string{IbmSubscriptionStartingCSV}
} else if kind == VendorStorageCluster() {
csvNames = []string{OcsSubscriptionStartingCSV, RookSubscriptionStartingCSV, NoobaaSubscriptionStartingCSV,
CSIAddonsSubscriptionStartingCSV, OcsClientSubscriptionStartingCSV, PrometheusSubscriptionStartingCSV}
CSIAddonsSubscriptionStartingCSV, PrometheusSubscriptionStartingCSV}

if isProvider, err = isProviderServer(cli); !isProvider {
csvNames = append(csvNames, OcsClientSubscriptionStartingCSV)
}
}

return csvNames
return csvNames, err
}

func EnsureVendorCsv(cli client.Client, csvName string) (*operatorv1alpha1.ClusterServiceVersion, error) {
Expand Down

0 comments on commit eca9ef5

Please sign in to comment.