Skip to content

Commit

Permalink
updated BYO EDB operator handling (#2202)
Browse files Browse the repository at this point in the history
- enables configuration via ibm-cpp-config
- with EDB_USER_MANAGED_OPERATOR_ENABLED: "true"
- which updates default CS CR with operatorConfig for
  internal-use-only-edb and sets userManaged
- internal-use-only-edb is new entry that references package for EDB,
  but has no-op so ODLM does not install it even if user creates
OperandRequest for it

Signed-off-by: Henry Li <[email protected]>
  • Loading branch information
bitscuit authored Sep 16, 2024
1 parent 2b8b4ef commit cb866cc
Show file tree
Hide file tree
Showing 3 changed files with 76 additions and 0 deletions.
61 changes: 61 additions & 0 deletions controllers/bootstrap/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -1885,3 +1885,64 @@ func (b *Bootstrap) UpdateResourceWithLabel(resources *unstructured.Unstructured
}
return nil
}

func (b *Bootstrap) UpdateEDBUserManaged() error {
operatorNamespace, err := util.GetOperatorNamespace()
if err != nil {
return err
}
defaultCsCR := &apiv3.CommonService{}
csName := "common-service"
if err := b.Client.Get(context.TODO(), types.NamespacedName{Name: csName, Namespace: operatorNamespace}, defaultCsCR); err != nil {
return err
}
servicesNamespace := string(defaultCsCR.Spec.ServicesNamespace)

config := &corev1.ConfigMap{}
if err := b.Client.Get(context.TODO(), types.NamespacedName{Name: constant.IBMCPPCONFIG, Namespace: servicesNamespace}, config); err != nil {
if errors.IsNotFound(err) {
return nil
}
return err
}
userManaged := config.Data["EDB_USER_MANAGED_OPERATOR_ENABLED"]
if userManaged != "true" {
unsetEDBUserManaged(defaultCsCR)
} else {
setEDBUserManaged(defaultCsCR)
}

if err := b.Client.Update(context.TODO(), defaultCsCR); err != nil {
return err
}
return nil
}

func unsetEDBUserManaged(instance *apiv3.CommonService) {
if instance.Spec.OperatorConfigs == nil {
return
}
for i := range instance.Spec.OperatorConfigs {
i := i
if instance.Spec.OperatorConfigs[i].Name == "internal-use-only-edb" {
instance.Spec.OperatorConfigs[i].UserManaged = false
}
}
}

func setEDBUserManaged(instance *apiv3.CommonService) {
if instance.Spec.OperatorConfigs == nil {
instance.Spec.OperatorConfigs = []apiv3.OperatorConfig{}
}
isExist := false
for i := range instance.Spec.OperatorConfigs {
i := i
if instance.Spec.OperatorConfigs[i].Name == "internal-use-only-edb" {
instance.Spec.OperatorConfigs[i].UserManaged = true
isExist = true
}
}
if !isExist {
instance.Spec.OperatorConfigs = append(instance.Spec.OperatorConfigs, apiv3.OperatorConfig{Name: "internal-use-only-edb", UserManaged: true})
}
}
8 changes: 8 additions & 0 deletions controllers/commonservice_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,14 @@ func (r *CommonServiceReconciler) ReconcileMasterCR(ctx context.Context, instanc
r.Recorder.Event(instance, corev1.EventTypeNormal, "Noeffect", fmt.Sprintf("No update, resource sizings in the OperandConfig %s/%s are larger than the profile from CommonService CR %s/%s", r.Bootstrap.CSData.OperatorNs, "common-service", instance.Namespace, instance.Name))
}

if err := r.Bootstrap.UpdateEDBUserManaged(); err != nil {
if statusErr := r.updatePhase(ctx, instance, CRFailed); statusErr != nil {
klog.Error(statusErr)
}
klog.Errorf("Fail to reconcile %s/%s: %v", instance.Namespace, instance.Name, err)
return ctrl.Result{}, statusErr
}

if isEqual, statusErr = r.updateOperatorConfig(ctx, instance.Spec.OperatorConfigs); statusErr != nil {
if statusErr := r.updatePhase(ctx, instance, CRFailed); statusErr != nil {
klog.Error(statusErr)
Expand Down
7 changes: 7 additions & 0 deletions controllers/constant/odlm.go
Original file line number Diff line number Diff line change
Expand Up @@ -1604,6 +1604,13 @@ spec:
scope: public
installPlanApproval: {{ .ApprovalMode }}
operatorConfig: cloud-native-postgresql-operator-config
- channel: stable
name: internal-use-only-edb
namespace: "{{ .CPFSNs }}"
packageName: cloud-native-postgresql
scope: public
installPlanApproval: {{ .ApprovalMode }}
installMode: no-op
- channel: stable-v1.22
fallbackChannels:
- stable
Expand Down

0 comments on commit cb866cc

Please sign in to comment.