Skip to content

Commit 044e86d

Browse files
committed
only apply CRDs and RBAC once per containerImage
Adds a new ContainerImage status field to display the deployed ContainerImage. If this matches the currently configured operator image then applying CRDs and RBAC can be skipped as it was already applied. Operator deployments are still reconciled each time to ensure they remain in place.
1 parent f06dc64 commit 044e86d

File tree

5 files changed

+31
-7
lines changed

5 files changed

+31
-7
lines changed

apis/bases/operator.openstack.org_openstacks.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ spec:
5858
- type
5959
type: object
6060
type: array
61+
containerImage:
62+
type: string
6163
deployedOperatorCount:
6264
type: integer
6365
observedGeneration:

apis/operator/v1beta1/openstack_types.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,9 @@ type OpenStackStatus struct {
3737

3838
// ObservedGeneration - the most recent generation observed for this object.
3939
ObservedGeneration int64 `json:"observedGeneration,omitempty"` // no spec yet so maybe we don't need this
40+
41+
// ContainerImage - the container image that has been successfully deployed
42+
ContainerImage *string `json:"containerImage,omitempty"`
4043
}
4144

4245
// +kubebuilder:object:root=true

apis/operator/v1beta1/zz_generated.deepcopy.go

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

config/crd/bases/operator.openstack.org_openstacks.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,8 @@ spec:
5858
- type
5959
type: object
6060
type: array
61+
containerImage:
62+
type: string
6163
deployedOperatorCount:
6264
type: integer
6365
observedGeneration:

controllers/operator/openstack_controller.go

Lines changed: 19 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -354,6 +354,14 @@ func (r *OpenStackReconciler) countDeployments(ctx context.Context, instance *op
354354
return count, nil
355355
}
356356

357+
// containerImageMatch - returns true if the deployedContainerImage matches the operatorImage
358+
func containerImageMatch(instance *operatorv1beta1.OpenStack) bool {
359+
if instance.Status.ContainerImage != nil && *instance.Status.ContainerImage == operatorImage {
360+
return true
361+
}
362+
return false
363+
}
364+
357365
func isWebhookEndpoint(name string) bool {
358366
// NOTE: this is a static list for all operators with webhooks enabled
359367
endpointNames := []string{"openstack-operator-webhook-service", "infra-operator-webhook-service", "openstack-baremetal-operator-webhook-service"}
@@ -402,15 +410,19 @@ func (r *OpenStackReconciler) checkServiceEndpoints(ctx context.Context, instanc
402410
}
403411

404412
func (r *OpenStackReconciler) applyManifests(ctx context.Context, instance *operatorv1beta1.OpenStack) error {
405-
if err := r.applyCRDs(ctx, instance); err != nil {
406-
log.Log.Error(err, "failed applying CRD manifests")
407-
return err
408-
}
413+
// only apply CRDs and RBAC once per each containerImage change
414+
if !containerImageMatch(instance) {
415+
if err := r.applyCRDs(ctx, instance); err != nil {
416+
log.Log.Error(err, "failed applying CRD manifests")
417+
return err
418+
}
409419

410-
if err := r.applyRBAC(ctx, instance); err != nil {
411-
log.Log.Error(err, "failed applying RBAC manifests")
412-
return err
420+
if err := r.applyRBAC(ctx, instance); err != nil {
421+
log.Log.Error(err, "failed applying RBAC manifests")
422+
return err
423+
}
413424
}
425+
instance.Status.ContainerImage = &operatorImage
414426

415427
if err := r.applyOperator(ctx, instance); err != nil {
416428
log.Log.Error(err, "failed applying Operator manifests")

0 commit comments

Comments
 (0)