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
8 changes: 4 additions & 4 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ VERSION ?= $(shell git describe --exact-match 2> /dev/null || \
RELEASE_VERSION ?= $(shell cat ./version/version.go | grep "Version =" | awk '{ print $$3}' | tr -d '"')
LATEST_VERSION ?= latest
OPERATOR_SDK_VERSION=v1.32.0
YQ_VERSION=v4.17.2
YQ_VERSION=v4.42.1
DEFAULT_CHANNEL ?= v$(shell cat ./version/version.go | grep "Version =" | awk '{ print $$3}' | tr -d '"' | cut -d '.' -f1,2)
CHANNELS ?= $(DEFAULT_CHANNEL)

Expand Down Expand Up @@ -208,14 +208,14 @@ bundle-manifests:
$(KUSTOMIZE) build config/manifests | $(OPERATOR_SDK) generate bundle \
-q --overwrite --version $(OPERATOR_VERSION) $(BUNDLE_METADATA_OPTS)
$(OPERATOR_SDK) bundle validate ./bundle
$(YQ) eval-all -i '.spec.relatedImages = load("config/manifests/bases/operand-deployment-lifecycle-manager.clusterserviceversion.yaml").spec.relatedImages' bundle/manifests/operand-deployment-lifecycle-manager.clusterserviceversion.yaml
$(YQ) eval-all -i '.spec.relatedImages |= load("config/manifests/bases/operand-deployment-lifecycle-manager.clusterserviceversion.yaml").spec.relatedImages' bundle/manifests/operand-deployment-lifecycle-manager.clusterserviceversion.yaml
@# Need to replace fields this way to avoid changing PROJECT name and CSV file name, which may or may not impact CICD automation
$(YQ) e -i '.annotations["operators.operatorframework.io.bundle.package.v1"] = "ibm-odlm"' bundle/metadata/annotations.yaml
sed -i'' s/operand-deployment-lifecycle-manager/ibm-odlm/ bundle.Dockerfile

generate-all: manifests kustomize operator-sdk ## Generate bundle manifests, metadata and package manifests
generate-all: yq manifests kustomize operator-sdk ## Generate bundle manifests, metadata and package manifests
$(OPERATOR_SDK) generate kustomize manifests -q
- make bundle-manifests CHANNELS=v4.2 DEFAULT_CHANNEL=v4.2
- make bundle-manifests CHANNELS=v4.3 DEFAULT_CHANNEL=v4.3

##@ Test

Expand Down
23 changes: 23 additions & 0 deletions api/v1alpha1/operandconfig_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ type ConfigService struct {
Resources []ConfigResource `json:"resources,omitempty"`
}

// +kubebuilder:pruning:PreserveUnknownFields
// ConfigResource defines the resource needed for the service
type ConfigResource struct {
// Name is the resource name.
Expand All @@ -75,6 +76,28 @@ type ConfigResource struct {
// +nullable
// +optional
Data *runtime.RawExtension `json:"data,omitempty"`
// OwnerReferences is the list of owner references.
// +optional
OwnerReferences []OwnerReference `json:"ownerReferences,omitempty"`
}

type OwnerReference struct {
// API version of the referent.
APIVersion string `json:"apiVersion"`
// Kind of the referent.
Kind string `json:"kind"`
// Name of the referent.
Name string `json:"name"`
// If true, this reference points to the managing controller.
// Default is false.
// +optional
Controller *bool `json:"controller,omitempty"`
// If true, AND if the owner has the "foregroundDeletion" finalizer, then
// the owner cannot be deleted from the key-value store until this
// reference is removed.
// Defaults to false.
// +optional
BlockOwnerDeletion *bool `json:"blockOwnerDeletion,omitempty"`
}

// OperandConfigStatus defines the observed state of OperandConfig.
Expand Down
2 changes: 1 addition & 1 deletion bundle.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ LABEL operators.operatorframework.io.bundle.metadata.v1=metadata/
LABEL operators.operatorframework.io.bundle.package.v1=ibm-odlm
LABEL operators.operatorframework.io.bundle.channels.v1=v4.3
LABEL operators.operatorframework.io.bundle.channel.default.v1=v4.3
LABEL operators.operatorframework.io.metrics.builder=operator-sdk-v1.29.0
LABEL operators.operatorframework.io.metrics.builder=operator-sdk-v1.32.0
LABEL operators.operatorframework.io.metrics.mediatype.v1=metrics+v1
LABEL operators.operatorframework.io.metrics.project_layout=go.kubebuilder.io/v3

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ metadata:
nss.operator.ibm.com/managed-operators: ibm-odlm
olm.skipRange: '>=1.2.0 <4.3.0'
operators.openshift.io/infrastructure-features: '["disconnected"]'
operators.operatorframework.io/builder: operator-sdk-v1.29.0
operators.operatorframework.io/builder: operator-sdk-v1.32.0
operators.operatorframework.io/project_layout: go.kubebuilder.io/v3
repository: https://github.com/IBM/operand-deployment-lifecycle-manager
support: IBM
Expand All @@ -149,7 +149,7 @@ spec:
apiservicedefinitions: {}
customresourcedefinitions:
owned:
- description: OperandBindInfo is the Schema for the operandbindinfoes API. Documentation For additional details regarding install parameters check https://ibm.biz/icpfs39install. License By installing this product you accept the license terms https://ibm.biz/icpfs39license
- description: OperandBindInfo is the Schema for the operandbindinfoes API.
displayName: OperandBindInfo
kind: OperandBindInfo
name: operandbindinfos.operator.ibm.com
Expand All @@ -160,7 +160,7 @@ spec:
x-descriptors:
- urn:alm:descriptor:io.kubernetes.phase
version: v1alpha1
- description: OperandConfig is the Schema for the operandconfigs API. Documentation For additional details regarding install parameters check https://ibm.biz/icpfs39install. License By installing this product you accept the license terms https://ibm.biz/icpfs39license
- description: OperandConfig is the Schema for the operandconfigs API.
displayName: OperandConfig
kind: OperandConfig
name: operandconfigs.operator.ibm.com
Expand All @@ -175,7 +175,7 @@ spec:
x-descriptors:
- urn:alm:descriptor:io.kubernetes.phase
version: v1alpha1
- description: OperandRegistry is the Schema for the operandregistries API. Documentation For additional details regarding install parameters check https://ibm.biz/icpfs39install. License By installing this product you accept the license terms https://ibm.biz/icpfs39license
- description: OperandRegistry is the Schema for the operandregistries API.
displayName: OperandRegistry
kind: OperandRegistry
name: operandregistries.operator.ibm.com
Expand All @@ -195,7 +195,7 @@ spec:
x-descriptors:
- urn:alm:descriptor:io.kubernetes.phase
version: v1alpha1
- description: OperandRequest is the Schema for the operandrequests API. Documentation For additional details regarding install parameters check https://ibm.biz/icpfs39install. License By installing this product you accept the license terms https://ibm.biz/icpfs39license
- description: OperandRequest is the Schema for the operandrequests API.
displayName: OperandRequest
kind: OperandRequest
name: operandrequests.operator.ibm.com
Expand Down
30 changes: 30 additions & 0 deletions bundle/manifests/operator.ibm.com_operandconfigs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -102,11 +102,41 @@ spec:
namespace:
description: Namespace is the namespace of the resource.
type: string
ownerReferences:
description: OwnerReferences is the list of owner references.
items:
properties:
apiVersion:
description: API version of the referent.
type: string
blockOwnerDeletion:
description: If true, AND if the owner has the "foregroundDeletion"
finalizer, then the owner cannot be deleted from
the key-value store until this reference is removed.
Defaults to false.
type: boolean
controller:
description: If true, this reference points to the
managing controller. Default is false.
type: boolean
kind:
description: Kind of the referent.
type: string
name:
description: Name of the referent.
type: string
required:
- apiVersion
- kind
- name
type: object
type: array
required:
- apiVersion
- kind
- name
type: object
x-kubernetes-preserve-unknown-fields: true
type: array
spec:
additionalProperties:
Expand Down
2 changes: 1 addition & 1 deletion bundle/metadata/annotations.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ annotations:
operators.operatorframework.io.bundle.package.v1: ibm-odlm
operators.operatorframework.io.bundle.channels.v1: v4.3
operators.operatorframework.io.bundle.channel.default.v1: v4.3
operators.operatorframework.io.metrics.builder: operator-sdk-v1.29.0
operators.operatorframework.io.metrics.builder: operator-sdk-v1.32.0
operators.operatorframework.io.metrics.mediatype.v1: metrics+v1
operators.operatorframework.io.metrics.project_layout: go.kubebuilder.io/v3
# Annotations for testing.
Expand Down
30 changes: 30 additions & 0 deletions config/crd/bases/operator.ibm.com_operandconfigs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -100,11 +100,41 @@ spec:
namespace:
description: Namespace is the namespace of the resource.
type: string
ownerReferences:
description: OwnerReferences is the list of owner references.
items:
properties:
apiVersion:
description: API version of the referent.
type: string
blockOwnerDeletion:
description: If true, AND if the owner has the "foregroundDeletion"
finalizer, then the owner cannot be deleted from
the key-value store until this reference is removed.
Defaults to false.
type: boolean
controller:
description: If true, this reference points to the
managing controller. Default is false.
type: boolean
kind:
description: Kind of the referent.
type: string
name:
description: Name of the referent.
type: string
required:
- apiVersion
- kind
- name
type: object
type: array
required:
- apiVersion
- kind
- name
type: object
x-kubernetes-preserve-unknown-fields: true
type: array
spec:
additionalProperties:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ spec:
apiservicedefinitions: {}
customresourcedefinitions:
owned:
- description: OperandBindInfo is the Schema for the operandbindinfoes API. Documentation For additional details regarding install parameters check https://ibm.biz/icpfs39install. License By installing this product you accept the license terms https://ibm.biz/icpfs39license
- description: OperandBindInfo is the Schema for the operandbindinfoes API.
displayName: OperandBindInfo
kind: OperandBindInfo
name: operandbindinfos.operator.ibm.com
Expand All @@ -39,7 +39,7 @@ spec:
x-descriptors:
- urn:alm:descriptor:io.kubernetes.phase
version: v1alpha1
- description: OperandConfig is the Schema for the operandconfigs API. Documentation For additional details regarding install parameters check https://ibm.biz/icpfs39install. License By installing this product you accept the license terms https://ibm.biz/icpfs39license
- description: OperandConfig is the Schema for the operandconfigs API.
displayName: OperandConfig
kind: OperandConfig
name: operandconfigs.operator.ibm.com
Expand All @@ -54,7 +54,7 @@ spec:
x-descriptors:
- urn:alm:descriptor:io.kubernetes.phase
version: v1alpha1
- description: OperandRegistry is the Schema for the operandregistries API. Documentation For additional details regarding install parameters check https://ibm.biz/icpfs39install. License By installing this product you accept the license terms https://ibm.biz/icpfs39license
- description: OperandRegistry is the Schema for the operandregistries API.
displayName: OperandRegistry
kind: OperandRegistry
name: operandregistries.operator.ibm.com
Expand All @@ -74,7 +74,7 @@ spec:
x-descriptors:
- urn:alm:descriptor:io.kubernetes.phase
version: v1alpha1
- description: OperandRequest is the Schema for the operandrequests API. Documentation For additional details regarding install parameters check https://ibm.biz/icpfs39install. License By installing this product you accept the license terms https://ibm.biz/icpfs39license
- description: OperandRequest is the Schema for the operandrequests API.
displayName: OperandRequest
kind: OperandRequest
name: operandrequests.operator.ibm.com
Expand Down
45 changes: 40 additions & 5 deletions controllers/operandrequest/reconcile_operand.go
Original file line number Diff line number Diff line change
Expand Up @@ -265,14 +265,14 @@ func (r *Reconciler) reconcileCRwithConfig(ctx context.Context, service *operato
if err != nil && !apierrors.IsNotFound(err) {
merr.Add(errors.Wrapf(err, "failed to get k8s resource %s/%s", k8sResNs, res.Name))
} else if apierrors.IsNotFound(err) {
if err := r.createK8sResource(ctx, k8sRes, res.Data, res.Labels, res.Annotations); err != nil {
if err := r.createK8sResource(ctx, k8sRes, res.Data, res.Labels, res.Annotations, &res.OwnerReferences); err != nil {
merr.Add(err)
}
} else {
if res.Force {
// Update k8s resource
klog.V(3).Info("Found existing k8s resource: " + res.Name)
if err := r.updateK8sResource(ctx, k8sRes, res.Data, res.Labels, res.Annotations); err != nil {
if err := r.updateK8sResource(ctx, k8sRes, res.Data, res.Labels, res.Annotations, &res.OwnerReferences); err != nil {
merr.Add(err)
}
} else {
Expand Down Expand Up @@ -939,7 +939,7 @@ func (r *Reconciler) checkCustomResource(ctx context.Context, requestInstance *o
return nil
}

func (r *Reconciler) createK8sResource(ctx context.Context, k8sResTemplate unstructured.Unstructured, k8sResConfig *runtime.RawExtension, newLabels, newAnnotations map[string]string) error {
func (r *Reconciler) createK8sResource(ctx context.Context, k8sResTemplate unstructured.Unstructured, k8sResConfig *runtime.RawExtension, newLabels, newAnnotations map[string]string, ownerReferences *[]operatorv1alpha1.OwnerReference) error {
kind := k8sResTemplate.GetKind()
name := k8sResTemplate.GetName()
namespace := k8sResTemplate.GetNamespace()
Expand All @@ -959,6 +959,9 @@ func (r *Reconciler) createK8sResource(ctx context.Context, k8sResTemplate unstr
r.EnsureLabel(k8sResTemplate, map[string]string{constant.OpreqLabel: "true"})
r.EnsureLabel(k8sResTemplate, newLabels)
r.EnsureAnnotation(k8sResTemplate, newAnnotations)
if err := r.setOwnerReferences(ctx, &k8sResTemplate, ownerReferences); err != nil {
return errors.Wrap(err, "failed to set ownerReferences for k8s resource")
}

// Create the k8s resource
err := r.Create(ctx, &k8sResTemplate)
Expand All @@ -971,7 +974,7 @@ func (r *Reconciler) createK8sResource(ctx context.Context, k8sResTemplate unstr
return nil
}

func (r *Reconciler) updateK8sResource(ctx context.Context, existingK8sRes unstructured.Unstructured, k8sResConfig *runtime.RawExtension, newLabels, newAnnotations map[string]string) error {
func (r *Reconciler) updateK8sResource(ctx context.Context, existingK8sRes unstructured.Unstructured, k8sResConfig *runtime.RawExtension, newLabels, newAnnotations map[string]string, ownerReferences *[]operatorv1alpha1.OwnerReference) error {
kind := existingK8sRes.GetKind()
apiversion := existingK8sRes.GetAPIVersion()
name := existingK8sRes.GetName()
Expand Down Expand Up @@ -1023,7 +1026,7 @@ func (r *Reconciler) updateK8sResource(ctx context.Context, existingK8sRes unstr
if err := r.deleteK8sResource(ctx, existingK8sRes, namespace); err != nil {
return errors.Wrap(err, "failed to update k8s resource")
}
if err := r.createK8sResource(ctx, templatek8sRes, k8sResConfig, newLabels, newAnnotations); err != nil {
if err := r.createK8sResource(ctx, templatek8sRes, k8sResConfig, newLabels, newAnnotations, ownerReferences); err != nil {
return errors.Wrap(err, "failed to update k8s resource")
}
}
Expand Down Expand Up @@ -1076,6 +1079,9 @@ func (r *Reconciler) updateK8sResource(ctx context.Context, existingK8sRes unstr

r.EnsureAnnotation(existingK8sRes, newAnnotations)
r.EnsureLabel(existingK8sRes, newLabels)
if err := r.setOwnerReferences(ctx, &existingK8sRes, ownerReferences); err != nil {
return false, errors.Wrapf(err, "failed to set ownerReferences for k8s resource -- Kind: %s, NamespacedName: %s/%s", kind, namespace, name)
}

klog.V(2).Infof("updating k8s resource with apiversion: %s, kind: %s, %s/%s", apiversion, kind, namespace, name)

Expand Down Expand Up @@ -1279,3 +1285,32 @@ func (r *Reconciler) ResourceForKind(gvk schema.GroupVersionKind, namespace stri
}
return &mapping.Resource, nil
}

func (r *Reconciler) setOwnerReferences(ctx context.Context, controlledRes *unstructured.Unstructured, ownerReferences *[]operatorv1alpha1.OwnerReference) error {
if ownerReferences != nil {
for _, owner := range *ownerReferences {
ownerObj := unstructured.Unstructured{}
ownerObj.SetAPIVersion(owner.APIVersion)
ownerObj.SetKind(owner.Kind)
ownerObj.SetName(owner.Name)

if err := r.Reader.Get(ctx, types.NamespacedName{
Name: owner.Name,
Namespace: controlledRes.GetNamespace(),
}, &ownerObj); err != nil {
return errors.Wrapf(err, "failed to get owner object -- Kind: %s, NamespacedName: %s/%s", owner.Kind, controlledRes.GetNamespace(), owner.Name)
}
if owner.Controller != nil && *owner.Controller {
if err := controllerutil.SetControllerReference(&ownerObj, controlledRes, r.Scheme); err != nil {
return errors.Wrapf(err, "failed to set controller ownerReference for k8s resource -- Kind: %s, NamespacedName: %s/%s", controlledRes.GetKind(), controlledRes.GetNamespace(), controlledRes.GetName())
}
} else {
if err := controllerutil.SetOwnerReference(&ownerObj, controlledRes, r.Scheme); err != nil {
return errors.Wrapf(err, "failed to set ownerReference for k8s resource -- Kind: %s, NamespacedName: %s/%s", controlledRes.GetKind(), controlledRes.GetNamespace(), controlledRes.GetName())
}
}
klog.Infof("Set %s with name %s as Owner for k8s resource -- Kind: %s, NamespacedName: %s/%s", owner.Kind, owner.Name, controlledRes.GetKind(), controlledRes.GetNamespace(), controlledRes.GetName())
}
}
return nil
}
Loading