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
4 changes: 4 additions & 0 deletions api/v3/commonservice_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,10 @@ type OperatorConfig struct {
// zero and not specified. Defaults to 1.
// +optional
Replicas *int32 `json:"replicas,omitempty" protobuf:"varint,1,opt,name=replicas"`
// UserManaged is a flag that indicates whether the operator is managed by
// user or not. If set the value will propagate down to UserManaged field
// in the OperandRegistry
UserManaged bool `json:"userManaged,omitempty"`
}

// LicenseList defines the license specification in CSV
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ metadata:
capabilities: Seamless Upgrades
cloudPakThemesVersion: styles470.css
containerImage: icr.io/cpopen/common-service-operator:latest
createdAt: "2024-04-11T02:45:28Z"
createdAt: "2024-09-09T21:00:30Z"
description: The IBM Cloud Pak foundational services operator is used to deploy IBM foundational services.
nss.operator.ibm.com/managed-operators: ibm-common-service-operator
nss.operator.ibm.com/managed-webhooks: ""
Expand Down Expand Up @@ -395,15 +395,15 @@ spec:
ephemeral-storage: 256Mi
memory: 200Mi
securityContext:
seccompProfile:
type: RuntimeDefault
allowPrivilegeEscalation: false
capabilities:
drop:
- ALL
privileged: false
readOnlyRootFilesystem: true
runAsNonRoot: true
seccompProfile:
type: RuntimeDefault
volumeMounts:
- mountPath: /tmp/k8s-webhook-server/serving-certs
name: cert
Expand Down
6 changes: 6 additions & 0 deletions bundle/manifests/operator.ibm.com_commonservices.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,12 @@ spec:
zero and not specified. Defaults to 1.
format: int32
type: integer
userManaged:
description: |-
UserManaged is a flag that indicates whether the operator is managed by
user or not. If set the value will propagate down to UserManaged field
in the OperandRegistry
type: boolean
type: object
type: array
x-kubernetes-preserve-unknown-fields: true
Expand Down
6 changes: 6 additions & 0 deletions config/crd/bases/operator.ibm.com_commonservices.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,12 @@ spec:
zero and not specified. Defaults to 1.
format: int32
type: integer
userManaged:
description: |-
UserManaged is a flag that indicates whether the operator is managed by
user or not. If set the value will propagate down to UserManaged field
in the OperandRegistry
type: boolean
type: object
type: array
x-kubernetes-preserve-unknown-fields: true
Expand Down
27 changes: 27 additions & 0 deletions controllers/common/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ import (
apiv3 "github.com/IBM/ibm-common-service-operator/v4/api/v3"
"github.com/IBM/ibm-common-service-operator/v4/controllers/constant"
nssv1 "github.com/IBM/ibm-namespace-scope-operator/v4/api/v1"
odlm "github.com/IBM/operand-deployment-lifecycle-manager/v4/api/v1alpha1"
)

type CsMaps struct {
Expand Down Expand Up @@ -871,3 +872,29 @@ func SanitizeData(data interface{}, valueType string, isEmpty bool) interface{}
return nil
}
}

func UpdateOpRegUserManaged(opreg *odlm.OperandRegistry, operatorName string, value bool) error {
packageName := GetPackageNameByServiceName(opreg, operatorName)
if packageName == "" {
return fmt.Errorf("failed to find package name while updating OperandRegistry with user managed field")
}
for i := range opreg.Spec.Operators {
i := i
if opreg.Spec.Operators[i].PackageName != packageName {
continue
}

opreg.Spec.Operators[i].UserManaged = value
}
return nil
}

func GetPackageNameByServiceName(opreg *odlm.OperandRegistry, operatorName string) string {
for _, v := range opreg.Spec.Operators {
v := v
if v.Name == operatorName {
return v.PackageName
}
}
return ""
}
33 changes: 33 additions & 0 deletions controllers/operatorconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
"k8s.io/klog"

v3 "github.com/IBM/ibm-common-service-operator/v4/api/v3"
util "github.com/IBM/ibm-common-service-operator/v4/controllers/common"
"github.com/IBM/ibm-common-service-operator/v4/controllers/constant"
odlm "github.com/IBM/operand-deployment-lifecycle-manager/v4/api/v1alpha1"
)
Expand All @@ -35,6 +36,9 @@ func (r *CommonServiceReconciler) updateOperatorConfig(ctx context.Context, conf
klog.Info("Applying OperatorConfig")

if configList == nil {
if err := r.clearAllUserManaged(ctx); err != nil {
return false, err
}
return true, nil
}

Expand All @@ -48,6 +52,9 @@ func (r *CommonServiceReconciler) updateOperatorConfig(ctx context.Context, conf
if packageName != "cloud-native-postgresql" {
return false, errors.New("failed to update OperatorConfig. This feature is only available for cloud-native-postgresql operator")
}
if err := r.updateUserManaged(ctx, config.Name, config.UserManaged); err != nil {
return false, err
}
if config.Replicas == nil {
return true, nil
}
Expand Down Expand Up @@ -88,3 +95,29 @@ func (r *CommonServiceReconciler) fetchPackageNameFromOpReg(ctx context.Context,
}
return "", nil
}

func (r *CommonServiceReconciler) updateUserManaged(ctx context.Context, operatorName string, value bool) error {
opreg := &odlm.OperandRegistry{}
if err := r.Reader.Get(ctx, types.NamespacedName{Namespace: util.GetServicesNamespace(r.Reader), Name: "common-service"}, opreg); err != nil {
return err
}
if err := util.UpdateOpRegUserManaged(opreg, operatorName, value); err != nil {
return err
}
if err := r.Client.Update(ctx, opreg); err != nil {
return err
}
return nil
}

func (r *CommonServiceReconciler) clearAllUserManaged(ctx context.Context) error {
opreg := &odlm.OperandRegistry{}
if err := r.Reader.Get(ctx, types.NamespacedName{Namespace: util.GetServicesNamespace(r.Reader), Name: "common-service"}, opreg); err != nil {
return err
}
for i := range opreg.Spec.Operators {
i := i
opreg.Spec.Operators[i].UserManaged = false
}
return r.Client.Update(ctx, opreg)
}