diff --git a/pkg/scaffold/controller/controller.go b/pkg/scaffold/controller/controller.go index 760034390d2..2eb197b642c 100644 --- a/pkg/scaffold/controller/controller.go +++ b/pkg/scaffold/controller/controller.go @@ -248,23 +248,18 @@ func (r *Reconcile{{ .Resource.Kind }}) Reconcile(request reconcile.Request) (re // TODO(user): Change this for the object type created by your controller // Check if the Deployment already exists found := &appsv1.Deployment{} - created := false err = r.Get(context.TODO(), types.NamespacedName{Name: deploy.Name, Namespace: deploy.Namespace}, found) if err != nil && errors.IsNotFound(err) { log.Info("Creating Deployment", "namespace", deploy.Namespace, "name", deploy.Name) err = r.Create(context.TODO(), deploy) - if err != nil { - return reconcile.Result{}, err - } else { - created = true - } + return reconcile.Result{}, err } else if err != nil { return reconcile.Result{}, err } // TODO(user): Change this for the object type created by your controller // Update the found object and write the result back if there are any changes - if !created && !reflect.DeepEqual(deploy.Spec, found.Spec) { + if !reflect.DeepEqual(deploy.Spec, found.Spec) { found.Spec = deploy.Spec log.Info("Updating Deployment", "namespace", deploy.Namespace, "name", deploy.Name) err = r.Update(context.TODO(), found) diff --git a/test/project/pkg/controller/firstmate/firstmate_controller.go b/test/project/pkg/controller/firstmate/firstmate_controller.go index 085074b3e45..e3011779ea2 100644 --- a/test/project/pkg/controller/firstmate/firstmate_controller.go +++ b/test/project/pkg/controller/firstmate/firstmate_controller.go @@ -144,23 +144,18 @@ func (r *ReconcileFirstMate) Reconcile(request reconcile.Request) (reconcile.Res // TODO(user): Change this for the object type created by your controller // Check if the Deployment already exists found := &appsv1.Deployment{} - created := false err = r.Get(context.TODO(), types.NamespacedName{Name: deploy.Name, Namespace: deploy.Namespace}, found) if err != nil && errors.IsNotFound(err) { log.Info("Creating Deployment", "namespace", deploy.Namespace, "name", deploy.Name) err = r.Create(context.TODO(), deploy) - if err != nil { - return reconcile.Result{}, err - } else { - created = true - } + return reconcile.Result{}, err } else if err != nil { return reconcile.Result{}, err } // TODO(user): Change this for the object type created by your controller // Update the found object and write the result back if there are any changes - if !created && !reflect.DeepEqual(deploy.Spec, found.Spec) { + if !reflect.DeepEqual(deploy.Spec, found.Spec) { found.Spec = deploy.Spec log.Info("Updating Deployment", "namespace", deploy.Namespace, "name", deploy.Name) err = r.Update(context.TODO(), found)