Skip to content
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

Closed
wants to merge 1 commit into from

Conversation

davidmogar
Copy link
Collaborator

The operator-toolkit has been already released and operator-goodies is deprecated.

@davidmogar
Copy link
Collaborator Author

/retest

1 similar comment
@davidmogar
Copy link
Collaborator Author

/retest

@kasemAlem
Copy link
Contributor

/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]>
@openshift-ci
Copy link

openshift-ci bot commented Jul 13, 2023

New changes are detected. LGTM label has been removed.

Copy link
Collaborator

@johnbieren johnbieren left a 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

Copy link
Collaborator

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"

Copy link
Collaborator Author

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.

Copy link
Collaborator

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"

Copy link
Collaborator Author

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.

Copy link
Collaborator

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

Copy link
Collaborator

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"
Copy link
Collaborator

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?

Copy link
Collaborator Author

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()
Copy link
Collaborator

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?

Copy link
Collaborator Author

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.

Copy link
Collaborator

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 {
Copy link
Collaborator

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?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consistency across webhooks.

Copy link
Collaborator

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)
Copy link
Collaborator

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?

Copy link
Collaborator Author

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 {
Copy link
Collaborator

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?

Copy link
Collaborator Author

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
Copy link
Collaborator

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?

Copy link
Collaborator Author

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 {
Copy link
Collaborator

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?

Copy link
Collaborator Author

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 {
Copy link
Collaborator

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?

Copy link
Collaborator Author

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.

@davidmogar davidmogar closed this Jul 14, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants