Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

controllers: scale down ocs-client-op csv in non-provider mode #474

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions controllers/storagesystem_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,9 @@ func (r *StorageSystemReconciler) ensureSubscriptions(instance *odfv1alpha1.Stor
}

func (r *StorageSystemReconciler) isVendorCsvReady(instance *odfv1alpha1.StorageSystem, logger logr.Logger) error {
if err := ScaleDownClientOperator(r.Client, instance.Spec.Kind); err != nil {
return err
}

csvNames, err := GetVendorCsvNames(r.Client, instance.Spec.Kind)
if err != nil {
Expand Down
4 changes: 4 additions & 0 deletions controllers/subscription_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,10 @@ func (r *SubscriptionReconciler) ensureSubscriptions(logger logr.Logger, namespa
}

for kind := range subsList {
if err := ScaleDownClientOperator(r.Client, kind); err != nil {
return err
}

csvNames, csvErr := GetVendorCsvNames(r.Client, kind)
if csvErr != nil {
return csvErr
Expand Down
54 changes: 54 additions & 0 deletions controllers/subscriptions.go
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,60 @@ func GetOdfSubscription(cli client.Client) (*operatorv1alpha1.Subscription, erro
return nil, fmt.Errorf("odf-operator subscription not found")
}

// Scales down deployments in all client-op CSVs for non-provider mode deployments
func ScaleDownClientOperator(cli client.Client, kind odfv1alpha1.StorageKind) error {
if kind != VendorStorageCluster() {
return nil
}

isProvider, err := isProviderMode(cli)
if err != nil {
return err
}
// no change in desired state for provider mode, scaling down is required for non-provider mode only irrespective of any other conditions
if isProvider {
return nil
}

ctx := context.Background()
csvList := &operatorv1alpha1.ClusterServiceVersionList{}
labelKey := fmt.Sprintf("operators.coreos.com/ocs-client-operator.%s", OperatorNamespace)
if err = cli.List(ctx,
csvList,
client.InNamespace(OperatorNamespace),
client.MatchingLabels(map[string]string{labelKey: ""})); err != nil {
return err
}

var replicas int32 = 0
for csvIdx := range csvList.Items {
csv := &csvList.Items[csvIdx]
for deploymentIdx := range csv.Spec.InstallStrategy.StrategySpec.DeploymentSpecs {
csvDeployment := &csv.Spec.InstallStrategy.StrategySpec.DeploymentSpecs[deploymentIdx]
csvDeployment.Spec.Replicas = &replicas

// TODO: It is observed when there are two CSVs, installing & replacing phase only updating the
// replicas in CSV for the deployments isn't scaling down corresponding deployment.
// If we running in non-provider mode we can scale these deployments w/o any side-effects
deployment := &appsv1.Deployment{}
deployment.Name = csvDeployment.Name
deployment.Namespace = OperatorNamespace
if err := cli.Get(ctx, client.ObjectKeyFromObject(deployment), deployment); err != nil {
return fmt.Errorf("failed to get deployment with name %s: %v", deployment.Name, err)
}
deployment.Spec.Replicas = &replicas
if err := cli.Update(ctx, deployment); err != nil {
return fmt.Errorf("failed to set deployment replicas of %s to 0: %v", deployment.Name, err)
}
}
if err = cli.Update(ctx, csv); err != nil {
return fmt.Errorf("failed to set deployment replicas in csv %s to 0: %v", csv.Name, err)
}
}

return nil
}

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

var csvNames []string
Expand Down
Loading