Skip to content

Commit

Permalink
Allow kOps to set labels required for cluster operations
Browse files Browse the repository at this point in the history
  • Loading branch information
Ole Markus With committed Dec 15, 2021
1 parent b405f79 commit cfcf6e5
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 0 deletions.
3 changes: 3 additions & 0 deletions pkg/apis/provisioning/v1alpha5/provisioner_validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,9 @@ func (c *Constraints) validateLabels() (errs *apis.FieldError) {

func IsRestrictedLabelDomain(key string) bool {
labelDomain := getLabelDomain(key)
if AllowedLabelDomains.Has(labelDomain) {
return false
}
for restrictedLabelDomain := range RestrictedLabelDomains {
if strings.HasSuffix(labelDomain, restrictedLabelDomain) {
return true
Expand Down
9 changes: 9 additions & 0 deletions pkg/apis/provisioning/v1alpha5/register.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,16 @@ var (
EmptinessTimestampAnnotationKey,
v1.LabelHostname,
)

// AllowedLabelDomains are domains that may be restricted, but that is allowed because
// they are not used in a context where they may be passed as argument to kubelet.
// AllowedLabelDomains are evaluated before RestrictedLabelDomains
AllowedLabelDomains = sets.NewString(
"kops.k8s.io",
)

// These are either prohibited by the kubelet or reserved by karpenter
// They are evaluated after AllowedLabelDomains
KarpenterLabelDomain = "karpenter.sh"
RestrictedLabelDomains = sets.NewString(
"kubernetes.io",
Expand Down
7 changes: 7 additions & 0 deletions pkg/apis/provisioning/v1alpha5/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,13 @@ var _ = Describe("Validation", func() {
Expect(provisioner.Validate(ctx)).ToNot(Succeed())
}
})
It("should allow labels kOps require", func() {
provisioner.Spec.Labels = map[string]string{
"kops.k8s.io/instancegroup": "karpenter-nodes",
"kops.k8s.io/gpu": "1",
}
Expect(provisioner.Validate(ctx)).To(Succeed())
})
})
Context("Taints", func() {
It("should succeed for valid taints", func() {
Expand Down

0 comments on commit cfcf6e5

Please sign in to comment.