Skip to content

Commit

Permalink
correction in the imports and function calls
Browse files Browse the repository at this point in the history
  • Loading branch information
NikhilSharmaWe committed Jul 5, 2022
1 parent ca6b7cb commit 86edad5
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ import (
"context"
"time"
"fmt"
"github.com/go-logr/logr"
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/client-go/tools/record"
Expand Down Expand Up @@ -152,21 +153,21 @@ func (r *{{ .Resource.Kind }}Reconciler) Reconcile(ctx context.Context, req ctrl
}
}
// Check if the Busybox instance is marked to be deleted, which is
// Check if the {{ .Resource.Kind }} instance is marked to be deleted, which is
// indicated by the deletion timestamp being set.
isBusyboxMarkedToBeDeleted := busybox.GetDeletionTimestamp() != nil
if isBusyboxMarkedToBeDeleted {
is{{ .Resource.Kind }}MarkedToBeDeleted := {{ lower .Resource.Kind }}.GetDeletionTimestamp() != nil
if is{{ .Resource.Kind }}MarkedToBeDeleted {
if controllerutil.ContainsFinalizer({{ lower .Resource.Kind }}, {{ lower .Resource.Kind }}Finalizer) {
// Run finalization logic for memcachedFinalizer. If the
// finalization logic fails, don't remove the finalizer so
// that we can retry during the next reconciliation.
if err := r.{{ lower .Resource.Kind }}Busybox(log, {{ lower .Resource.Kind }}); err != nil {
if err := r.finalize{{ .Resource.Kind }}(log, {{ lower .Resource.Kind }}); err != nil {
return ctrl.Result{}, err
}
// Remove memcachedFinalizer. Once all finalizers have been
// removed, the object will be deleted.
controllerutil.RemoveFinalizer(busybox, {{ lower .Resource.Kind }}Finalizer)
controllerutil.RemoveFinalizer({{ lower .Resource.Kind }}, {{ lower .Resource.Kind }}Finalizer)
err := r.Update(ctx, {{ lower .Resource.Kind }})
if err != nil {
return ctrl.Result{}, err
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ import (
"fmt"
"time"

"github.com/go-logr/logr"

"k8s.io/apimachinery/pkg/runtime"
"k8s.io/client-go/tools/record"
ctrl "sigs.k8s.io/controller-runtime"
Expand Down Expand Up @@ -112,7 +114,7 @@ func (r *BusyboxReconciler) Reconcile(ctx context.Context, req ctrl.Request) (ct
// Run finalization logic for memcachedFinalizer. If the
// finalization logic fails, don't remove the finalizer so
// that we can retry during the next reconciliation.
if err := r.busyboxBusybox(log, busybox); err != nil {
if err := r.finalizeBusybox(log, busybox); err != nil {
return ctrl.Result{}, err
}

Expand Down Expand Up @@ -175,7 +177,7 @@ func (r *BusyboxReconciler) finalizeBusybox(log logr.Logger, cr *examplecomv1alp
// of finalizers include performing backups and deleting
// resources that are not owned by this CR, like a PVC.
// The following implementation will raise an event
r.recorder.Event(cr, "Normal", "Deleting",
r.recorder.Event(cr, "Warning", "Deleting",
fmt.Sprintf("Custom Resource %s is being deleted from the namespace %s",
cr.Name,
cr.Namespace))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ import (
"fmt"
"time"

"github.com/go-logr/logr"

"k8s.io/apimachinery/pkg/runtime"
"k8s.io/client-go/tools/record"
ctrl "sigs.k8s.io/controller-runtime"
Expand Down Expand Up @@ -104,21 +106,21 @@ func (r *MemcachedReconciler) Reconcile(ctx context.Context, req ctrl.Request) (
}
}

// Check if the Busybox instance is marked to be deleted, which is
// Check if the Memcached instance is marked to be deleted, which is
// indicated by the deletion timestamp being set.
isBusyboxMarkedToBeDeleted := busybox.GetDeletionTimestamp() != nil
if isBusyboxMarkedToBeDeleted {
isMemcachedMarkedToBeDeleted := memcached.GetDeletionTimestamp() != nil
if isMemcachedMarkedToBeDeleted {
if controllerutil.ContainsFinalizer(memcached, memcachedFinalizer) {
// Run finalization logic for memcachedFinalizer. If the
// finalization logic fails, don't remove the finalizer so
// that we can retry during the next reconciliation.
if err := r.memcachedBusybox(log, memcached); err != nil {
if err := r.finalizeMemcached(log, memcached); err != nil {
return ctrl.Result{}, err
}

// Remove memcachedFinalizer. Once all finalizers have been
// removed, the object will be deleted.
controllerutil.RemoveFinalizer(busybox, memcachedFinalizer)
controllerutil.RemoveFinalizer(memcached, memcachedFinalizer)
err := r.Update(ctx, memcached)
if err != nil {
return ctrl.Result{}, err
Expand Down Expand Up @@ -175,7 +177,7 @@ func (r *MemcachedReconciler) finalizeMemcached(log logr.Logger, cr *examplecomv
// of finalizers include performing backups and deleting
// resources that are not owned by this CR, like a PVC.
// The following implementation will raise an event
r.recorder.Event(cr, "Normal", "Deleting",
r.recorder.Event(cr, "Warning", "Deleting",
fmt.Sprintf("Custom Resource %s is being deleted from the namespace %s",
cr.Name,
cr.Namespace))
Expand Down
2 changes: 1 addition & 1 deletion testdata/project-v3-with-deploy-image/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module sigs.k8s.io/kubebuilder/testdata/project-v3-with-deploy-image
go 1.18

require (
github.com/go-logr/logr v1.2.0
github.com/onsi/ginkgo v1.16.5
github.com/onsi/gomega v1.18.1
k8s.io/api v0.24.2
Expand All @@ -28,7 +29,6 @@ require (
github.com/evanphx/json-patch v4.12.0+incompatible // indirect
github.com/form3tech-oss/jwt-go v3.2.3+incompatible // indirect
github.com/fsnotify/fsnotify v1.5.1 // indirect
github.com/go-logr/logr v1.2.0 // indirect
github.com/go-logr/zapr v1.2.0 // indirect
github.com/go-openapi/jsonpointer v0.19.5 // indirect
github.com/go-openapi/jsonreference v0.19.5 // indirect
Expand Down

0 comments on commit 86edad5

Please sign in to comment.