diff --git a/controllers/upf/reconciler.go b/controllers/upf/reconciler.go index 09d0881..8b5e940 100644 --- a/controllers/upf/reconciler.go +++ b/controllers/upf/reconciler.go @@ -145,13 +145,13 @@ func (r *UPFDeploymentReconciler) Reconcile(ctx context.Context, req ctrl.Reques } if deployment, err := createDeployment(log, configMapVersion, upfDeployment); err == nil { + // Set the controller reference, specifying that UPFDeployment controls the underlying Deployment + if err := ctrl.SetControllerReference(upfDeployment, deployment, r.Scheme); err != nil { + log.Error(err, "Got error while setting Owner reference on Deployment", "Deployment.namespace", deployment.Name, "Deployment.name", deployment.Name) + } if !deploymentFound { // Only create Deployment in case all required NADs are present. Otherwise Requeue in 10 sec. if ok := controllers.ValidateNetworkAttachmentDefinitions(ctx, r.Client, log, upfDeployment.Kind, deployment); ok { - // Set the controller reference, specifying that UPFDeployment controls the underlying Deployment - if err := ctrl.SetControllerReference(upfDeployment, deployment, r.Scheme); err != nil { - log.Error(err, "Got error while setting Owner reference on Deployment", "Deployment.namespace", deployment.Name, "Deployment.name", deployment.Name) - } log.Info("Creating Deployment", "Deployment.namespace", deployment.Namespace, "Deployment.name", deployment.Name) if err := r.Client.Create(ctx, deployment); err != nil { @@ -164,6 +164,10 @@ func (r *UPFDeploymentReconciler) Reconcile(ctx context.Context, req ctrl.Reques log.Info("Not all NetworkAttachDefinitions available in current namespace, requeuing") return reconcile.Result{RequeueAfter: time.Duration(10) * time.Second}, nil } + } else { + if err = r.Client.Update(ctx, deployment); err != nil { + log.Error(err, "Failed to update Deployment", "Deployment.namespace", deployment.Namespace, "Deployment.name", deployment.Name) + } } } else { log.Error(err, "Failed to create Deployment")