-
Notifications
You must be signed in to change notification settings - Fork 1.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
✨deploy-image/v1-alpha: add finalizers for the Custom Resource created #2793
✨deploy-image/v1-alpha: add finalizers for the Custom Resource created #2793
Conversation
pkg/plugins/golang/deploy-image/v1alpha1/scaffolds/internal/templates/controllers/controller.go
Outdated
Show resolved
Hide resolved
pkg/plugins/golang/deploy-image/v1alpha1/scaffolds/internal/templates/controllers/controller.go
Outdated
Show resolved
Hide resolved
pkg/plugins/golang/deploy-image/v1alpha1/scaffolds/internal/templates/controllers/controller.go
Show resolved
Hide resolved
testdata/project-v3-with-deploy-image/controllers/busybox_controller.go
Outdated
Show resolved
Hide resolved
2f48f9d
to
96080da
Compare
testdata/project-v3-with-deploy-image/controllers/busybox_controller.go
Outdated
Show resolved
Hide resolved
1ac6046
to
86edad5
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
/hold
Until the fixes be made
pkg/plugins/golang/deploy-image/v1alpha1/scaffolds/internal/templates/controllers/controller.go
Outdated
Show resolved
Hide resolved
}, time.Minute, time.Second).Should(Succeed()) | ||
|
||
EventuallyWithOffset(1, func() error { | ||
events, err := kbc.Kubectl.Get(true, "events", "--field-selector", "type", "Warning", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"time" | ||
|
||
"github.com/go-logr/logr" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"github.com/go-logr/logr" |
@NikhilSharmaWe we need to use the log from the controller-runtime which is provided in the reconcile (see the log var) and not this one.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I was using that log only but I was using this for specifying the parameters of the finalize function but since now that parameter is not needed(due some changes in the finalize function), I am removing it.
pkg/plugins/golang/deploy-image/v1alpha1/scaffolds/internal/templates/controllers/controller.go
Outdated
Show resolved
Hide resolved
pkg/plugins/golang/deploy-image/v1alpha1/scaffolds/internal/templates/controllers/controller.go
Outdated
Show resolved
Hide resolved
pkg/plugins/golang/deploy-image/v1alpha1/scaffolds/internal/templates/controllers/controller.go
Outdated
Show resolved
Hide resolved
pkg/plugins/golang/deploy-image/v1alpha1/scaffolds/internal/templates/controllers/controller.go
Outdated
Show resolved
Hide resolved
pkg/plugins/golang/deploy-image/v1alpha1/scaffolds/internal/templates/controllers/controller.go
Show resolved
Hide resolved
pkg/plugins/golang/deploy-image/v1alpha1/scaffolds/internal/templates/controllers/controller.go
Outdated
Show resolved
Hide resolved
pkg/plugins/golang/deploy-image/v1alpha1/scaffolds/internal/templates/controllers/controller.go
Outdated
Show resolved
Hide resolved
86edad5
to
e57c24e
Compare
e57c24e
to
748178a
Compare
8b630f8
to
748178a
Compare
pkg/plugins/golang/deploy-image/v1alpha1/scaffolds/internal/templates/controllers/controller.go
Outdated
Show resolved
Hide resolved
1c40bd1
to
069ffa6
Compare
@@ -66,27 +66,33 @@ package {{ if and .MultiGroup .Resource.Group }}{{ .Resource.PackageName }}{{ el | |||
import ( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The new occurs because the recorder is empty and needs to be passed when we create the controller and pass it in the manager ( main.go ):
if err = (&controllers.FoorxobReconciler{
Client: mgr.GetClient(),
Scheme: mgr.GetScheme(),
Recorder: mgr.GetEventRecorderFor("mykind-controller"),
}).SetupWithManager(mgr); err != nil {
setupLog.Error(err, "unable to create controller", "controller", "Foorxob")
os.Exit(1)
}
//+kubebuilder:scaffold:builder
Also, in the controller, it needs to be changed to be Upper case: Recorder record.EventRecorder
Then, when we call the event use Eventf instead of Event since we want to format the message
See that this PR does not have the e2e check as well. It is missing can you come back that?
069ffa6
to
f604a6c
Compare
func (s *apiScaffolder) updateMainEventRecorder() error { | ||
defaultMainPath := "main.go" | ||
err := util.InsertCode(defaultMainPath, `Scheme: mgr.GetScheme(), | ||
`, | ||
fmt.Sprintf(recorderTemplate, strings.ToLower(s.resource.Kind))) | ||
if err != nil { | ||
return fmt.Errorf("error scaffolding event recorder while creating the controller in main.go: %v", err) | ||
} | ||
return nil | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Instead of use replace the best approach here would we create a MainUpdater like:
Then, in this updater we will have another template for the controller in the main: https://github.com/NikhilSharmaWe/kubebuilder/blob/f604a6cb2c4a3ba5425471ace96125630c9a50f3/pkg/plugins/golang/v3/scaffolds/internal/templates/main.go#L100-L106
Could you please add a TODO on top of the method at least such as
// TODO: replace this implementation by creating its own MainUpdater which will have its own controller template which set the recorder.
Also, could you please change the target so we ensure that you ONLY set the event.Recorder on the Controller code of the specific api instead of adding the code in all of them? If we have a project with an API that uses the plugin and another API that does not use the plugin only the API that uses the plugin should have this addition.
f604a6c
to
2bc1a66
Compare
@NikhilSharmaWe: The following test failed, say
Full PR test history. Your PR dashboard. Please help us cut down on flakes by linking to an open issue when you hit one in your PR. Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository. I understand the commands that are listed here. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The fix: https://github.com/kubernetes-sigs/kubebuilder/pull/2793/files#r915313169 is not a blocker for the PR. So, let's move forward and improve it in a follow up
/lgtm
/approved
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: camilamacedo86, NikhilSharmaWe The full list of commands accepted by this bot can be found here. The pull request process is described here
Needs approval from an approver in each of these files:
Approvers can indicate their approval by writing |
/test pull-kubebuilder-e2e-k8s-1-19-16 |
/hold cancel |
Description
Add finalizers for the Custom Resource created for deleting the deployment under before deleting the CR.
Motivation
Fixes part of #2765