You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Allow karpenter to set arbitrary k8s labels on NodeClaim/Nodes
nodeClaim Labels are the source for core karpenter to sync Node Labels in a centralized fashion.
Some bootstrap userdata provider implementations also consume this labels and pass them through kubelet self setting.
That results in a coupling between a centralized and a kubelet self setting approach.
This coupling results in conflicting criteria for validations and degraded UX.
This PR removes the coupling.
As a consequence, Node Labels are not unncessarily restricted for the centralized sync anymore.
This better empowers administrators reducing the reliance on self setting kubelet and minimizing the risk of a Node steering privileged workloads to itself.
A subset of labels, excluding those disallowed by the node restriction admission, is now stored in json within the "karpenter.sh/node-restricted-labels" NodeClaim annotation.
This enables bootstrap userdata providers to continue utilizing the labels if needed.
Copy file name to clipboardexpand all lines: pkg/apis/v1/labels.go
+53-24
Original file line number
Diff line number
Diff line change
@@ -58,22 +58,17 @@ const (
58
58
)
59
59
60
60
var (
61
-
// RestrictedLabelDomains are either prohibited by the kubelet or reserved by karpenter
61
+
// RestrictedLabelDomains are reserved by karpenter
62
62
RestrictedLabelDomains=sets.New(
63
-
"kubernetes.io",
64
-
"k8s.io",
65
63
apis.Group,
66
64
)
67
65
68
-
// LabelDomainExceptions are sub-domains of the RestrictedLabelDomains but allowed because
69
-
// they are not used in a context where they may be passed as argument to kubelet.
70
-
LabelDomainExceptions=sets.New(
71
-
"kops.k8s.io",
72
-
v1.LabelNamespaceSuffixNode,
73
-
v1.LabelNamespaceNodeRestriction,
66
+
K8sLabelDomains=sets.New(
67
+
"kubernetes.io",
68
+
"k8s.io",
74
69
)
75
70
76
-
// WellKnownLabels are labels that belong to the RestrictedLabelDomains but allowed.
71
+
// WellKnownLabels are labels that belong to the RestrictedLabelDomains or K8sLabelDomains but allowed.
77
72
// Karpenter is aware of these labels, and they can be used to further narrow down
78
73
// the range of the corresponding values by either nodepool or pods.
79
74
WellKnownLabels=sets.New(
@@ -104,38 +99,72 @@ var (
104
99
}
105
100
)
106
101
107
-
// IsRestrictedLabel returns an error if the label is restricted.
102
+
// IsRestrictedLabel is used for runtime validation of requirements.
103
+
// Returns an error if the label is restricted. E.g. using .karpenter.sh suffix.
108
104
funcIsRestrictedLabel(keystring) error {
109
105
ifWellKnownLabels.Has(key) {
110
106
returnnil
111
107
}
112
-
ifIsRestrictedNodeLabel(key) {
113
-
returnfmt.Errorf("label %s is restricted; specify a well known label: %v, or a custom label that does not use a restricted domain: %v", key, sets.List(WellKnownLabels), sets.List(RestrictedLabelDomains))
returnfmt.Errorf("Using label %s is not allowed as it might interfere with the internal provisioning logic; specify a well known label: %v, or a custom label that does not use a restricted domain: %v", key, sets.List(WellKnownLabels), sets.List(RestrictedLabelDomains))
113
+
}
114
+
}
115
+
116
+
ifRestrictedLabels.Has(key) {
117
+
returnfmt.Errorf("Using label %s is not allowed as it might interfere with the internal provisioning logic; specify a well known label: %v, or a custom label that does not use a restricted domain: %v", key, sets.List(WellKnownLabels), sets.List(RestrictedLabelDomains))
114
118
}
119
+
115
120
returnnil
116
121
}
117
122
118
-
// IsRestrictedNodeLabel returns true if a node label should not be injected by Karpenter.
119
-
// They are either known labels that will be injected by cloud providers,
120
-
// or label domain managed by other software (e.g., kops.k8s.io managed by kOps).
121
-
funcIsRestrictedNodeLabel(keystring) bool {
123
+
// IsValidLabelToSync returns true if the label key is allowed to be synced to the Node object centrally by Karpenter.
124
+
funcIsValidToSyncCentrallyLabel(keystring) bool {
125
+
// TODO(enxebre): consider this to be configurable with runtime flag.
126
+
notValidToSyncLabel:=WellKnownLabels
127
+
128
+
return!notValidToSyncLabel.Has(key)
129
+
}
130
+
131
+
// IsKubeletLabel returns true if the label key is one that kubelets are allowed to set on their own Node object.
132
+
// This function is similar the one used by the node restriction admission https://github.com/kubernetes/kubernetes/blob/e319c541f144e9bee6160f1dd8671638a9029f4c/staging/src/k8s.io/kubelet/pkg/apis/well_known_labels.go#L67
133
+
// but karpenter also restricts the known labels to be passed to kubelet. Only the kubeletLabelNamespaces are allowed.
scheduling.NewNodeSelectorRequirementsWithMinValues(nodeClaim.Spec.Requirements...).Labels(), // Single-value requirement resolved labels that are synced to the Node object centrally by Karpenter.
0 commit comments