-
Notifications
You must be signed in to change notification settings - Fork 36
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
feat(HACBS-2381): update service to use operator-toolkit #212
Conversation
a71de3a
to
7b0d0e8
Compare
/retest |
1 similar comment
/retest |
/test release-service-e2e |
The operator-toolkit has been already released and operator-goodies is deprecated. Signed-off-by: David Moreno García <[email protected]>
New changes are detected. LGTM label has been removed. |
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.
Please remove the changes from this PR that are not related to switching to operator-toolkit. The PR says it is about using operator-toolkit. There should not be rewrites snuck into this
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.
I don't see how a single change in this file is related to "update service to use operator-toolkit"
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.
Using operator-toolkit comes with declaring webhooks in a different way. That is, moving webhooks into new directories. Those new directories need a suite for tests to run.
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.
I don't see how a single change in this file is related to "update service to use operator-toolkit"
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.
Using operator-toolkit comes with declaring webhooks in a different way. That is, moving webhooks into new directories. Those new directories need the webhook code using the toolkit functions.
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.
This should be added to operator-toolkit before being removed
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.
This should be added to operator-toolkit before being removed
@@ -29,35 +30,34 @@ import ( | |||
admissionv1 "k8s.io/api/admission/v1" | |||
ctrl "sigs.k8s.io/controller-runtime" | |||
"sigs.k8s.io/controller-runtime/pkg/client" | |||
"sigs.k8s.io/controller-runtime/pkg/webhook" | |||
ctrlWebhook "sigs.k8s.io/controller-runtime/pkg/webhook" |
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.
How is this change necessary for adding toolkit and not a rewrite?
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.
Because there's another webhook defined in the same package.
// +kubebuilder:webhook:path=/mutate-appstudio-redhat-com-v1alpha1-author,mutating=true,failurePolicy=fail,sideEffects=None,groups=appstudio.redhat.com,resources=releases;releaseplans,verbs=create;update,versions=v1alpha1,name=mauthor.kb.io,admissionReviewVersions=v1 | ||
// Register registers the webhook with the passed manager and log. | ||
func (w *Webhook) Register(mgr ctrl.Manager, log *logr.Logger) error { | ||
w.client = mgr.GetClient() |
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.
How is this change necessary for adding toolkit and not a rewrite?
Why can't we just do
mgr.GetWebhookServer().Register("/mutate-appstudio-redhat-com-v1alpha1-author", &webhook.Admission{
 Handler: &authorWebhook{
 client: mgr.GetClient(),
 log: log.WithName("author"),
 },
 })
and reduce the changeset?
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.
Consistency. The information to pass has to be carried into the webhook struct and given that it's received as a receiver, the new code is better.
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.
I do not think it is better, it is functionally the same and just increasing the diff for no benefit
"sigs.k8s.io/controller-runtime/pkg/webhook/admission" | ||
) | ||
|
||
// authorWebhook describes the data structure for the author webhook | ||
type authorWebhook struct { |
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.
How is this change necessary for adding toolkit and not a rewrite?
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.
Consistency across webhooks.
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.
Then make a new PR called "consistency across webhooks" and add the hundreds of lines of changes related to it. Don't sneak it in this PR
labels := make(map[string]string) | ||
if obj.GetLabels() != nil { | ||
labels = obj.GetLabels() | ||
} | ||
|
||
labels[metadata.AuthorLabel] = a.sanitizeLabelValue(username) | ||
labels[metadata.AuthorLabel] = w.sanitizeLabelValue(username) |
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.
How is this change necessary for adding toolkit and not a rewrite?
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.
Consistency.
obj.SetLabels(labels) | ||
} | ||
|
||
// sanitizeLabelValue takes a username and returns it in a form appropriate to use as a label value. | ||
func (a *authorWebhook) sanitizeLabelValue(username string) string { | ||
func (w *Webhook) sanitizeLabelValue(username string) string { |
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.
How is this change necessary for adding toolkit and not a rewrite?
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.
Consistency.
@@ -28,16 +28,16 @@ import ( | |||
type Syncer struct { | |||
client client.Client | |||
ctx context.Context | |||
logger logr.Logger | |||
logger *logr.Logger |
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.
How is this change necessary for adding toolkit and not a rewrite?
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.
Because this comes from the adapter and we are following how the new adapter should be defined.
} | ||
|
||
// NewSyncer creates a new Syncer with the given client and logger. | ||
func NewSyncer(client client.Client, logger logr.Logger) *Syncer { | ||
func NewSyncer(client client.Client, logger *logr.Logger) *Syncer { |
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.
How is this change necessary for adding toolkit and not a rewrite?
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.
Because this comes from the adapter and we are following how the new adapter should be defined.
return NewSyncerWithContext(client, logger, context.TODO()) | ||
} | ||
|
||
// NewSyncerWithContext creates a new Syncer with the given client, logger and context. | ||
func NewSyncerWithContext(client client.Client, logger logr.Logger, ctx context.Context) *Syncer { | ||
func NewSyncerWithContext(client client.Client, logger *logr.Logger, ctx context.Context) *Syncer { |
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.
How is this change necessary for adding toolkit and not a rewrite?
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.
Because this comes from the adapter and we are following how the new adapter should be defined.
The operator-toolkit has been already released and operator-goodies is deprecated.