Skip to content

Commit c905130

Browse files
authored
Merge pull request kubernetes#95179 from stevenshuang/master
Replace AreLabelsInWhiteList with IsSubset
2 parents 0ef3707 + f0ea540 commit c905130

File tree

2 files changed

+18
-20
lines changed

2 files changed

+18
-20
lines changed

plugin/pkg/admission/podnodeselector/admission.go

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ func (p *Plugin) Validate(ctx context.Context, a admission.Attributes, o admissi
148148
if err != nil {
149149
return err
150150
}
151-
if !labels.AreLabelsInWhiteList(pod.Spec.NodeSelector, whitelist) {
151+
if !isSubset(pod.Spec.NodeSelector, whitelist) {
152152
return errors.NewForbidden(resource, pod.Name, fmt.Errorf("pod node label selector labels conflict with its namespace whitelist"))
153153
}
154154

@@ -259,3 +259,20 @@ func (p *Plugin) getNodeSelectorMap(namespace *corev1.Namespace) (labels.Set, er
259259
}
260260
return selector, nil
261261
}
262+
263+
func isSubset(subSet, superSet labels.Set) bool {
264+
if len(superSet) == 0 {
265+
return true
266+
}
267+
268+
for k, v := range subSet {
269+
value, ok := superSet[k]
270+
if !ok {
271+
return false
272+
}
273+
if value != v {
274+
return false
275+
}
276+
}
277+
return true
278+
}

staging/src/k8s.io/apimachinery/pkg/labels/labels.go

Lines changed: 0 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -141,25 +141,6 @@ func Equals(labels1, labels2 Set) bool {
141141
return true
142142
}
143143

144-
// AreLabelsInWhiteList verifies if the provided label list
145-
// is in the provided whitelist and returns true, otherwise false.
146-
func AreLabelsInWhiteList(labels, whitelist Set) bool {
147-
if len(whitelist) == 0 {
148-
return true
149-
}
150-
151-
for k, v := range labels {
152-
value, ok := whitelist[k]
153-
if !ok {
154-
return false
155-
}
156-
if value != v {
157-
return false
158-
}
159-
}
160-
return true
161-
}
162-
163144
// ConvertSelectorToLabelsMap converts selector string to labels map
164145
// and validates keys and values
165146
func ConvertSelectorToLabelsMap(selector string) (Set, error) {

0 commit comments

Comments
 (0)