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

TAS: validate that kubernetes.io/hostname can only be at the lowest level #3714

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion apis/kueue/v1alpha1/tas_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,9 @@ type TopologySpec struct {
// +listType=atomic
// +kubebuilder:validation:MinItems=1
// +kubebuilder:validation:MaxItems=8
// +kubebuilder:validation:XValidation:rule="self == oldSelf",message="the levels field is immutable"
// +kubebuilder:validation:XValidation:rule="self == oldSelf",message="field is immutable"
// +kubebuilder:validation:XValidation:rule="size(self.filter(i, size(self.filter(j, j == i)) > 1)) == 0",message="must be unique"
// +kubebuilder:validation:XValidation:rule="size(self.filter(i, i.nodeLabel == 'kubernetes.io/hostname')) == 0 || self[size(self) - 1].nodeLabel == 'kubernetes.io/hostname'",message="the kubernetes.io/hostname label can only be used at the lowest level of topology"
Levels []TopologyLevel `json:"levels,omitempty"`
}

Expand Down
9 changes: 8 additions & 1 deletion charts/kueue/templates/crd/kueue.x-k8s.io_topologies.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -79,8 +79,15 @@ spec:
type: array
x-kubernetes-list-type: atomic
x-kubernetes-validations:
- message: the levels field is immutable
- message: field is immutable
rule: self == oldSelf
- message: must be unique
rule: size(self.filter(i, size(self.filter(j, j == i)) > 1)) ==
0
- message: the kubernetes.io/hostname label can only be used at the
lowest level of topology
rule: size(self.filter(i, i.nodeLabel == 'kubernetes.io/hostname'))
== 0 || self[size(self) - 1].nodeLabel == 'kubernetes.io/hostname'
required:
- levels
type: object
Expand Down
9 changes: 8 additions & 1 deletion config/components/crd/bases/kueue.x-k8s.io_topologies.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,15 @@ spec:
type: array
x-kubernetes-list-type: atomic
x-kubernetes-validations:
- message: the levels field is immutable
- message: field is immutable
rule: self == oldSelf
- message: must be unique
rule: size(self.filter(i, size(self.filter(j, j == i)) > 1)) ==
0
- message: the kubernetes.io/hostname label can only be used at the
lowest level of topology
rule: size(self.filter(i, i.nodeLabel == 'kubernetes.io/hostname'))
== 0 || self[size(self) - 1].nodeLabel == 'kubernetes.io/hostname'
required:
- levels
type: object
Expand Down
18 changes: 18 additions & 0 deletions test/integration/tas/tas_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -979,6 +979,18 @@ var _ = ginkgo.Describe("Topology validations", func() {
ginkgo.Entry("invalid levels",
testing.MakeTopology("invalid-level").Levels([]string{"@invalid"}).Obj(),
testing.BeInvalidError()),
ginkgo.Entry("non-unique levels",
testing.MakeTopology("default").Levels([]string{tasBlockLabel, tasBlockLabel}).Obj(),
testing.BeInvalidError()),
ginkgo.Entry("kubernetes.io/hostname first",
testing.MakeTopology("default").Levels([]string{corev1.LabelHostname, tasBlockLabel, tasRackLabel}).Obj(),
testing.BeInvalidError()),
ginkgo.Entry("kubernetes.io/hostname middle",
testing.MakeTopology("default").Levels([]string{tasBlockLabel, corev1.LabelHostname, tasRackLabel}).Obj(),
testing.BeInvalidError()),
ginkgo.Entry("kubernetes.io/hostname last",
testing.MakeTopology("default").Levels([]string{tasBlockLabel, tasRackLabel, corev1.LabelHostname}).Obj(),
gomega.Succeed()),
)
})

Expand Down Expand Up @@ -1011,6 +1023,12 @@ var _ = ginkgo.Describe("Topology validations", func() {
})
},
testing.BeInvalidError()),
ginkgo.Entry("updating levels order is prohibited",
testing.MakeTopology("default").Levels([]string{tasRackLabel, tasBlockLabel, corev1.LabelHostname}).Obj(),
func(topology *kueuealpha.Topology) {
topology.Spec.Levels[0], topology.Spec.Levels[1] = topology.Spec.Levels[1], topology.Spec.Levels[0]
},
testing.BeInvalidError()),
)
})
})