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

chore: decouple webhook logic from cloud provider API #2079

Merged
merged 4 commits into from
Jul 11, 2022

Conversation

ellistarn
Copy link
Contributor

@ellistarn ellistarn commented Jul 7, 2022

Fixes #2052

Description

Separate aws specific webhook logic into a separate webhook that's hosted from the same webhook binary.

How was this change tested?

  • make test
  • make apply and manual verification
  • Tested Fresh Install
  • Tested Upgrade

Does this change impact docs?

  • Yes, PR includes docs updates
  • Yes, issue opened: #
  • No

Release Note

None

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@ellistarn ellistarn requested a review from a team July 7, 2022 23:41
@ellistarn ellistarn requested a review from a team as a code owner July 7, 2022 23:41
@ellistarn ellistarn requested a review from njtran July 7, 2022 23:41
@ellistarn ellistarn marked this pull request as draft July 7, 2022 23:41
@netlify
Copy link

netlify bot commented Jul 7, 2022

Deploy Preview for karpenter-docs-prod ready!

Name Link
🔨 Latest commit 36dc96f
🔍 Latest deploy log https://app.netlify.com/sites/karpenter-docs-prod/deploys/62cc5a3cf7c8ff0008a80e44
😎 Deploy Preview https://deploy-preview-2079--karpenter-docs-prod.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify site settings.

@ellistarn ellistarn marked this pull request as ready for review July 8, 2022 16:39
// Webhooks
{
certificates.NewController,
newCRDDefaultingWebhook,
Copy link
Contributor

@tzneal tzneal Jul 8, 2022

Choose a reason for hiding this comment

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

Aren't newCRDDefaultingWebhook and newAWSDefaultingWebhook both defaulting webhooks for v1alpha5.Provisioner. Do both get called, or are we lucky because of registration order?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

IIUC, they're called in a random ordering

You can use reinvocation to enforce ordering, but we don't have interdependence.
https://kubernetes.io/docs/reference/access-authn-authz/extensible-admission-controllers/#reinvocation-policy

cmd/webhook/main.go Outdated Show resolved Hide resolved
Comment on lines 41 to 54
hasLabel := false
if _, ok := p.Spec.Labels[key]; ok {
hasLabel = true
}
for _, requirement := range p.Spec.Requirements {
if requirement.Key == key {
hasLabel = true
}
}
if !hasLabel {
p.Spec.Requirements = append(p.Spec.Requirements, v1.NodeSelectorRequirement{
Key: key, Operator: v1.NodeSelectorOpIn, Values: []string{value},
})
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
hasLabel := false
if _, ok := p.Spec.Labels[key]; ok {
hasLabel = true
}
for _, requirement := range p.Spec.Requirements {
if requirement.Key == key {
hasLabel = true
}
}
if !hasLabel {
p.Spec.Requirements = append(p.Spec.Requirements, v1.NodeSelectorRequirement{
Key: key, Operator: v1.NodeSelectorOpIn, Values: []string{value},
})
}
_, hasLabel := p.Spec.Labels[key]
for _, requirement := range p.Spec.Requirements {
if requirement.Key == key || hasLabel {
hasLabel = true
break
}
}
if !hasLabel {
p.Spec.Requirements = append(p.Spec.Requirements, v1.NodeSelectorRequirement{
Key: key, Operator: v1.NodeSelectorOpIn, Values: []string{value},
})
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'm just coping this, but will check out this cleanup.

Comment on lines +27 to +28
- provisioners
- provisioners/status
Copy link
Contributor

Choose a reason for hiding this comment

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

what about AWSNodeTemplate?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I want to move this as part of a separate change. These APIs really need to be owned by pkg/cloudprovider/aws, but they're not currently.

Copy link
Contributor

@bwagner5 bwagner5 left a comment

Choose a reason for hiding this comment

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

lgtm

@ellistarn ellistarn merged commit 836f854 into aws:main Jul 11, 2022
@ellistarn ellistarn deleted the neutral branch July 11, 2022 18:00
ellistarn added a commit to ellistarn/karpenter-provider-aws that referenced this pull request Jul 19, 2022
ellistarn added a commit to ellistarn/karpenter-provider-aws that referenced this pull request Jul 19, 2022
ellistarn added a commit to ellistarn/karpenter-provider-aws that referenced this pull request Jul 19, 2022
njtran pushed a commit that referenced this pull request Jul 19, 2022
suket22 pushed a commit to suket22/karpenter that referenced this pull request Jul 21, 2022
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.

split webhoook default/validation methods out from cloudprovider
3 participants