Skip to content

✨ Move webhook generator #136

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

Merged
merged 3 commits into from
Feb 27, 2019

Conversation

mengqiy
Copy link
Member

@mengqiy mengqiy commented Feb 1, 2019

This PR

  • add webhook subcommand as part of controller-gen all
  • move the generator code from controller-runtime to controller-tools and make some necessary changes.
  • move some file to make CT not depend on CR from dep perspective.

Updating the annotation will be done in a separate PR, since it requires more than just updating the annotation.
Annotation format is at https://github.com/jetstack/cert-manager/blob/ccd2dd853321c3ac568736b0d66ab9d3ad494d7b/pkg/controller/cainjector/controller.go#L40

@k8s-ci-robot k8s-ci-robot added do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. labels Feb 1, 2019
@k8s-ci-robot k8s-ci-robot added the size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. label Feb 1, 2019
@mengqiy mengqiy requested a review from DirectXMan12 February 1, 2019 18:57
@mengqiy mengqiy force-pushed the webhookgenerator branch 4 times, most recently from 7403182 to a019e3a Compare February 5, 2019 21:04
@mengqiy mengqiy changed the title [WIP] ✨ Move webhook generator ✨ Move webhook generator Feb 5, 2019
@k8s-ci-robot k8s-ci-robot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Feb 5, 2019
@mengqiy mengqiy force-pushed the webhookgenerator branch 3 times, most recently from d1faaf1 to 2970c77 Compare February 6, 2019 21:59
@mengqiy
Copy link
Member Author

mengqiy commented Feb 7, 2019

PTAL

Copy link
Contributor

@droot droot left a comment

Choose a reason for hiding this comment

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

I took a look and have a few comments. I will take another look sometime today, but want to send in the early feedback.

// name is the name of the webhook
name string
// t is the webhook type, i.e. mutating, validating
t webhookType
Copy link
Contributor

Choose a reason for hiding this comment

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

s/t/typ

Copy link
Member Author

Choose a reason for hiding this comment

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

Not sure if typ is better than using t or not.
It's a partial word which reads strange.

Why you think typ is better?

Copy link
Contributor

Choose a reason for hiding this comment

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

Oh.. just wanted it be more descriptive from readability perspective. Suggested typ because type is probably reserved word.

// This optional.
namespaceSelector *metav1.LabelSelector

once sync.Once
Copy link
Contributor

Choose a reason for hiding this comment

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

this can be taken out now.

ObjectMeta: metav1.ObjectMeta{
Name: o.mutatingWebhookConfigName,
Annotations: map[string]string{
"admissionwebhook.alpha.kubebuilder.io/ca-secret-name": "webhook-cert",
Copy link
Contributor

Choose a reason for hiding this comment

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

Two comments:

  • We should add a comment explaining (or linking to an issue/doc) why this annotation so readers understand it.
  • annotation name "alpha" needs to come before admissionwebhooks ? alpha.admissionwebhooks.kubebuilder.io/ca-secret-name
  • "webhook-cert" is hardcoded ?

Copy link
Member Author

Choose a reason for hiding this comment

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

I now uses alpha.admissionwebhook.kubebuilder.io/ca-secret-name.

"webhook-cert" is hardcoded ?

fixed.

- name: cert
secret:
defaultMode: 420
secretName: webhook-secret
Copy link
Contributor

Choose a reason for hiding this comment

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

Two concerns:

  • Looks like input for CA injections (secret-name, service name etc.) is split across the objects. It might make the cert controller implementation difficult. I am wondering if we can combine all these and apply it only on field. Annotation value could be then in JSON ?
  • webhook-secret is hardcoded. We should think of a way to override it (by default ?)

Copy link
Member Author

Choose a reason for hiding this comment

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

Looks like input for CA injections (secret-name, service name etc.) is split across the objects. It might make the cert controller implementation difficult.

For generating cert, everything it needs is in the service object.
For syncing CA, everything it needs is in the WebhookConfiguration object.
It should not make the controller hard to implement. Instead, it should be quite easy to implement it :)

webhook-secret is hardcoded.

This one is not.

Copy link
Contributor

Choose a reason for hiding this comment

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

Got it. You are right, those are decoupled annotations, so it should be simpler :)

return nil
}

func (o *WriterOptions) writeObjectsToDisk(objects ...runtime.Object) error {
Copy link
Contributor

Choose a reason for hiding this comment

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

This can probably go in a util pkg.

I wonder if we should have "k8s/ioutil" pkg which implements k8s object reader/writer :)

@mengqiy mengqiy added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Feb 8, 2019
@mengqiy mengqiy force-pushed the webhookgenerator branch 2 times, most recently from b57747a to 6a27543 Compare February 9, 2019 03:14
Copy link
Contributor

@droot droot left a comment

Choose a reason for hiding this comment

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

Looks good. I have one comment about how well it will work with kustomize ?

- name: cert
secret:
defaultMode: 420
secretName: webhook-secret
Copy link
Contributor

Choose a reason for hiding this comment

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

Got it. You are right, those are decoupled annotations, so it should be simpler :)

kind: MutatingWebhookConfiguration
metadata:
annotations:
alpha.admissionwebhook.kubebuilder.io/ca-secret-name: test-system/webhook-secret
Copy link
Contributor

Choose a reason for hiding this comment

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

I am wondering how will these value in these annotations will play with kustomization ?

@mengqiy
Copy link
Member Author

mengqiy commented Feb 12, 2019

how well it will work with kustomize ?

Kustomize by default doesn't know how to update the secret name in the annotation.
@droot we had a brief discussion last week. The outcome is that we don't use kustomize to manage the serving cert secret. We hand off this work to cert-manager. If the secret is not ready, let the pod wait for the secret.

@mengqiy
Copy link
Member Author

mengqiy commented Feb 13, 2019

Cherry-picker @DirectXMan12's commit which cleanup the vendor dir.
Resolved the conflicts caused by #142.

@droot
Copy link
Contributor

droot commented Feb 13, 2019

The outcome is that we don't use kustomize to manage the serving cert secret. We hand off this work to cert-manager. If the secret is not ready, let the pod wait for the secret.

Sounds good.

@mengqiy mengqiy force-pushed the webhookgenerator branch 3 times, most recently from 2a73501 to 54f2f6a Compare February 14, 2019 21:03
@mengqiy
Copy link
Member Author

mengqiy commented Feb 14, 2019

@droot @DirectXMan12 We need to decide what format the annotations should look like.

I'm currently using
alpha.admissionwebhook.cert-manager.io: "true"
and
alpha.service.cert-manager.io/serving-cert-secret-name: some-secret-name
in my code, since I don't remember what Solly were using in the PoC controller code.

Besides the annotation format, other code is ready for another round of review.

@mengqiy mengqiy force-pushed the webhookgenerator branch 3 times, most recently from 23c8932 to 5d22b6c Compare February 21, 2019 01:42
@mengqiy
Copy link
Member Author

mengqiy commented Feb 21, 2019

PTAL
No big changes.
Rebased to address merge conflicts.

Mengqi Yu and others added 3 commits February 27, 2019 13:44
This removes the dependency on CR by marking the testData directory as
ignored (it's moved so that we can make `go vet` ignore it).  It also
cleans up vendor by removing unecessary requires and adding prune-unused
(we only need to keep around the dependencies in KB and possibly CR).
@mengqiy
Copy link
Member Author

mengqiy commented Feb 27, 2019

Rebased.
Commit Clean up vendor, remove dep on CR cause merge conflicts, due to moving some packages around.

@mengqiy mengqiy removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Feb 27, 2019
@droot droot added lgtm "Looks good to me", indicates that a PR is ready to be merged. approved Indicates a PR has been approved by an approver from all required OWNERS files. labels Feb 27, 2019
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

Approval requirements bypassed by manually added approval.

This pull-request has been approved by: mengqiy

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 /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot merged commit 5752ac2 into kubernetes-sigs:master Feb 27, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants