Skip to content

Commit

Permalink
Remove k8s.io/kubernetes dependency
Browse files Browse the repository at this point in the history
According to
golang/go#32776 (comment), it's
not supposed to be used as a dependency.

Additionally, I think this code might end up being removed if we agree
with eksctl-io#2197 (comment).

Closes eksctl-io#1537
  • Loading branch information
michaelbeaumont committed Jun 10, 2020
1 parent 8da038f commit 38826ff
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 4 deletions.
1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@ require (
k8s.io/code-generator v0.16.8
k8s.io/kops v1.15.2
k8s.io/kubelet v0.16.8
k8s.io/kubernetes v1.16.8
k8s.io/legacy-cloud-providers v0.16.8
sigs.k8s.io/aws-iam-authenticator v0.5.0
sigs.k8s.io/yaml v1.2.0
Expand Down
1 change: 0 additions & 1 deletion go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1290,7 +1290,6 @@ k8s.io/kube-scheduler v0.16.8/go.mod h1:Yq1uX8tvuzb/dxjx0nKQE88XBRDRyhW75drSDHLT
k8s.io/kubectl v0.16.8/go.mod h1:s6lhPwTkZjHBVHH6BRVRUA1SAqqZF8osaWSYTvR1H1U=
k8s.io/kubelet v0.16.8 h1:737GeCz3Bu4NxGivTj910vPaL6UYkxaXoOGuMarzCI0=
k8s.io/kubelet v0.16.8/go.mod h1:mzDpnryQg2dlB6V3/WAgb1baIamiICtWpXMFrPOFh6I=
k8s.io/kubernetes v1.16.8 h1:AQb20svioSN1foO9LOdZiUOM8zRmNua2PnYB8bvO48w=
k8s.io/kubernetes v1.16.8/go.mod h1:bpUsy1qP0W6EtkxrPluP02p2+wyVN+95lkjPKnLQZtc=
k8s.io/legacy-cloud-providers v0.16.8 h1:CtBX+VIKHfijcJzvNaIZJ/oRYQJCsZ5y57aN8cb8Xqs=
k8s.io/legacy-cloud-providers v0.16.8/go.mod h1:8g5j8qDmqXvj1mQjyYOvSBv15CWbzV3D/CsRFrTGCJY=
Expand Down
50 changes: 48 additions & 2 deletions pkg/apis/eksctl.io/v1alpha5/validation.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,9 @@ import (
"github.com/aws/aws-sdk-go/aws/arn"
"github.com/pkg/errors"

v1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/util/validation"
kubeletapis "k8s.io/kubernetes/pkg/kubelet/apis"
"k8s.io/apimachinery/pkg/util/sets"
)

var (
Expand Down Expand Up @@ -239,6 +240,51 @@ func ValidateNodeGroup(i int, ng *NodeGroup) error {
return nil
}

// isKubeletLabel returns true if the label key is one that kubelets are allowed to set on their own Node object.
// This checks if the key is in the KubeletLabels() list, or has a namespace in the KubeletLabelNamespaces() list.
func isKubeletLabel(key string) bool {
var LabelOS = "beta.kubernetes.io/os"
var LabelArch = "beta.kubernetes.io/arch"

var labelZoneFailureDomainGA = "failure-domain.kubernetes.io/zone"
var labelZoneRegionGA = "failure-domain.kubernetes.io/region"
var labelInstanceTypeGA = "kubernetes.io/instance-type"
var kubeletLabels = sets.NewString(
v1.LabelHostname,
v1.LabelZoneFailureDomain,
v1.LabelZoneRegion,
v1.LabelInstanceType,
v1.LabelOSStable,
v1.LabelArchStable,

LabelOS,
LabelArch,

labelZoneFailureDomainGA,
labelZoneRegionGA,
labelInstanceTypeGA,
)
if kubeletLabels.Has(key) {
return true
}

var namespace string
if parts := strings.SplitN(key, "/", 2); len(parts) == 2 {
namespace = parts[0]
}
var kubeletLabelNamespaces = sets.NewString(
v1.LabelNamespaceSuffixKubelet,
v1.LabelNamespaceSuffixNode,
)
for allowedNamespace := range kubeletLabelNamespaces {
if namespace == allowedNamespace || strings.HasSuffix(namespace, "."+allowedNamespace) {
return true
}
}

return false
}

// ValidateNodeGroupLabels uses proper Kubernetes label validation,
// it's designed to make sure users don't pass weird labels to the
// nodes, which would prevent kubelets to startup properly
Expand Down Expand Up @@ -266,7 +312,7 @@ func ValidateNodeGroupLabels(labels map[string]string) error {

if len(labelParts) == 2 {
namespace := labelParts[0]
if isKubernetesLabel(namespace) && !kubeletapis.IsKubeletLabel(label) {
if isKubernetesLabel(namespace) && !isKubeletLabel(label) {
unknownKubernetesLabels = append(unknownKubernetesLabels, label)
}
}
Expand Down

0 comments on commit 38826ff

Please sign in to comment.