Skip to content
Merged
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
5 changes: 5 additions & 0 deletions controllers/operator/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -392,6 +392,11 @@ func (m *ODLMOperator) GetSubscription(ctx context.Context, name, operatorNs, se

// GetClusterServiceVersion gets the ClusterServiceVersion from the subscription
func (m *ODLMOperator) GetClusterServiceVersion(ctx context.Context, sub *olmv1alpha1.Subscription) (*olmv1alpha1.ClusterServiceVersion, error) {
// Check if subscription is nil
if sub == nil {
klog.Error("The subscription is nil")
return nil, fmt.Errorf("the subscription is nil")
}
// Check the ClusterServiceVersion status in the subscription
if sub.Status.InstalledCSV == "" {
klog.Warningf("The ClusterServiceVersion for Subscription %s is not ready. Will check it again", sub.Name)
Expand Down
31 changes: 23 additions & 8 deletions controllers/operatorconfig/operatorconfig_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ import (
"sigs.k8s.io/controller-runtime/pkg/source"

operatorv1alpha1 "github.com/IBM/operand-deployment-lifecycle-manager/api/v1alpha1"
"github.com/IBM/operand-deployment-lifecycle-manager/controllers/constant"
deploy "github.com/IBM/operand-deployment-lifecycle-manager/controllers/operator"
)

Expand Down Expand Up @@ -73,19 +74,25 @@ func (r *Reconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Resu
operand := u
operator := registry.GetOperator(operand.Name)
if operator.OperatorConfig == "" {
break
continue
}

var sub *olmv1alpha1.Subscription
sub, err = r.GetSubscription(ctx, operator.Name, operator.Namespace, registry.Namespace, operator.PackageName)
if err != nil {
return ctrl.Result{}, err
} else if sub == nil {
klog.Infof("Subscription for Operator %s/%s not found", operator.Name, operator.PackageName)
return ctrl.Result{RequeueAfter: constant.DefaultRequeueDuration}, nil
}

var csv *olmv1alpha1.ClusterServiceVersion
csv, err = r.GetClusterServiceVersion(ctx, sub)
if err != nil {
return ctrl.Result{}, err
} else if csv == nil {
klog.Infof("ClusterServiceVersion for Operator %s/%s not found", operator.Name, operator.PackageName)
return ctrl.Result{RequeueAfter: constant.DefaultRequeueDuration}, nil
}

klog.Infof("Fetching OperatorConfig: %s", operator.OperatorConfig)
Expand All @@ -94,12 +101,16 @@ func (r *Reconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Resu
Name: operator.OperatorConfig,
Namespace: registry.Namespace,
}, config); err != nil {
return ctrl.Result{}, client.IgnoreNotFound(err)
if client.IgnoreNotFound(err) != nil {
return ctrl.Result{}, err
}
klog.Infof("OperatorConfig %s/%s does not exist for operand %s in request %s, %s", registry.Namespace, operator.OperatorConfig, operator.Name, instance.Namespace, instance.Name)
continue
}
serviceConfig := config.GetConfigForOperator(operator.Name)
if serviceConfig == nil {
klog.Infof("OperatorConfig: %s, does not have configuration for operator: %s", operator.OperatorConfig, operator.Name)
return ctrl.Result{}, nil
continue
}

copyToCast, err := deepcopy.Anything(csv)
Expand All @@ -108,13 +119,17 @@ func (r *Reconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Resu
}
csvToUpdate := copyToCast.(*olmv1alpha1.ClusterServiceVersion)
klog.Infof("Applying OperatorConfig: %s to Operator: %s via CSV: %s, %s", operator.OperatorConfig, operator.Name, csv.Name, csv.Namespace)
return r.configCsv(ctx, csvToUpdate, serviceConfig)
if err := r.configCsv(ctx, csvToUpdate, serviceConfig); err != nil {
klog.Errorf("Failed to apply OperatorConfig %s/%s to Operator: %s via CSV: %s, %s", registry.Namespace, operator.OperatorConfig, operator.Name, csv.Namespace, csv.Name)
return ctrl.Result{}, err
}
}
}
return ctrl.Result{}, nil
klog.Infof("Finished reconciling OperatorConfig for request: %s, %s", instance.Namespace, instance.Name)
return ctrl.Result{RequeueAfter: constant.DefaultSyncPeriod}, nil
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why do we need to requeue if reconcile was successful?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The main reason is to check if the changes made in CSV was reverted back to original state by OLM, or in the case that CSV was updated to a new version, so ODLM could have the chance to re-apply the settings every three hours.

The most ideal way is to watch CSVs proactively, but it would cause OOM possibly in All Namespace mode if we did not handle the cache properly.....

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got it. Yea, we will need more complex way of handling the CSV caching in the next release.

}

func (r *Reconciler) configCsv(ctx context.Context, csv *olmv1alpha1.ClusterServiceVersion, config *operatorv1alpha1.ServiceOperatorConfig) (ctrl.Result, error) {
func (r *Reconciler) configCsv(ctx context.Context, csv *olmv1alpha1.ClusterServiceVersion, config *operatorv1alpha1.ServiceOperatorConfig) error {
if config.Replicas != nil {
csv.Spec.InstallStrategy.StrategySpec.DeploymentSpecs[0].Spec.Replicas = config.Replicas
}
Expand All @@ -125,9 +140,9 @@ func (r *Reconciler) configCsv(ctx context.Context, csv *olmv1alpha1.ClusterServ
csv.Spec.InstallStrategy.StrategySpec.DeploymentSpecs[0].Spec.Template.Spec.TopologySpreadConstraints = config.TopologySpreadConstraints
}
if err := r.Client.Update(ctx, csv); err != nil {
return ctrl.Result{}, err
return err
}
return ctrl.Result{}, nil
return nil
}

func (r *Reconciler) requestsFromMapFunc(ctx context.Context) handler.MapFunc {
Expand Down