Skip to content

Commit 108ea56

Browse files
authored
ensure PodTemplateSpec has default values filled in (#131)
Call Scheme.Default() on the PodSpecTemplate before returning it to Kueue to ensure that Kueue's equality comparisons work as expected.
1 parent 7d8f6ea commit 108ea56

File tree

3 files changed

+26
-7
lines changed

3 files changed

+26
-7
lines changed

go.mod

+3
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ require (
99
k8s.io/api v0.29.2
1010
k8s.io/apimachinery v0.29.2
1111
k8s.io/client-go v0.29.2
12+
k8s.io/kubernetes v1.29.2
1213
k8s.io/utils v0.0.0-20230726121419-3b25d923346b
1314
sigs.k8s.io/controller-runtime v0.17.0
1415
sigs.k8s.io/kueue v0.6.2
@@ -20,6 +21,7 @@ require (
2021
github.com/blang/semver/v4 v4.0.0 // indirect
2122
github.com/cespare/xxhash/v2 v2.2.0 // indirect
2223
github.com/davecgh/go-spew v1.1.1 // indirect
24+
github.com/distribution/reference v0.5.0 // indirect
2325
github.com/emicklei/go-restful/v3 v3.11.0 // indirect
2426
github.com/evanphx/json-patch/v5 v5.8.0 // indirect
2527
github.com/fsnotify/fsnotify v1.7.0 // indirect
@@ -45,6 +47,7 @@ require (
4547
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
4648
github.com/modern-go/reflect2 v1.0.2 // indirect
4749
github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
50+
github.com/opencontainers/go-digest v1.0.0 // indirect
4851
github.com/pkg/errors v0.9.1 // indirect
4952
github.com/prometheus/client_golang v1.18.0 // indirect
5053
github.com/prometheus/client_model v0.5.0 // indirect

go.sum

+6
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ github.com/creack/pty v1.1.9/go.mod h1:oKZEueFk5CKHvIhNR5MUki03XCEU+Q6VDXinZuGJ3
88
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
99
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
1010
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
11+
github.com/distribution/reference v0.5.0 h1:/FUIFXtfc/x2gpa5/VGfiGLuOIdYa1t65IKK2OFGvA0=
12+
github.com/distribution/reference v0.5.0/go.mod h1:BbU0aIcezP1/5jX/8MP0YiH4SdvB5Y4f/wlDRiLyi3E=
1113
github.com/emicklei/go-restful/v3 v3.11.0 h1:rAQeMHw1c7zTmncogyy8VvRZwtkmkZ4FxERmMY4rD+g=
1214
github.com/emicklei/go-restful/v3 v3.11.0/go.mod h1:6n3XBCmQQb25CM2LCACGz8ukIrRry+4bhvbpWn3mrbc=
1315
github.com/evanphx/json-patch v5.6.0+incompatible h1:jBYDEEiFBPxA0v50tFdvOzQQTCvpL6mnFh5mB2/l16U=
@@ -92,6 +94,8 @@ github.com/open-policy-agent/cert-controller v0.10.1 h1:RXSYoyn8FdCenWecRP//UV5n
9294
github.com/open-policy-agent/cert-controller v0.10.1/go.mod h1:4uRbBLY5DsPOog+a9pqk3JLxuuhrWsbUedQW65HcLTI=
9395
github.com/open-policy-agent/frameworks/constraint v0.0.0-20230822235116-f0b62fe1e4c4 h1:5dum5SLEz+95JDLkMls7Z7IDPjvSq3UhJSFe4f5einQ=
9496
github.com/open-policy-agent/frameworks/constraint v0.0.0-20230822235116-f0b62fe1e4c4/go.mod h1:54/KzLMvA5ndBVpm7B1OjLeV0cUtTLTz2bZ2OtydLpU=
97+
github.com/opencontainers/go-digest v1.0.0 h1:apOUWs51W5PlhuyGyz9FCeeBIOUDA/6nW8Oi/yOhh5U=
98+
github.com/opencontainers/go-digest v1.0.0/go.mod h1:0JzlMkj0TRzQZfJkVvzbP0HBR3IKzErnv2BNG4W4MAM=
9599
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
96100
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
97101
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
@@ -225,6 +229,8 @@ k8s.io/kube-aggregator v0.28.1 h1:rvG4llYnQKHjj6YjjoBPEJxfD1uH0DJwkrJTNKGAaCs=
225229
k8s.io/kube-aggregator v0.28.1/go.mod h1:JaLizMe+AECSpO2OmrWVsvnG0V3dX1RpW+Wq/QHbu18=
226230
k8s.io/kube-openapi v0.0.0-20231010175941-2dd684a91f00 h1:aVUu9fTY98ivBPKR9Y5w/AuzbMm96cd3YHRTU83I780=
227231
k8s.io/kube-openapi v0.0.0-20231010175941-2dd684a91f00/go.mod h1:AsvuZPBlUDVuCdzJ87iajxtXuR9oktsTctW/R9wwouA=
232+
k8s.io/kubernetes v1.29.2 h1:8hh1cntqdulanjQt7wSSSsJfBgOyx6fUdFWslvGL5m0=
233+
k8s.io/kubernetes v1.29.2/go.mod h1:xZPKU0yO0CBbLTnbd+XGyRmmtmaVuJykDb8gNCkeeUE=
228234
k8s.io/utils v0.0.0-20230726121419-3b25d923346b h1:sgn3ZU783SCgtaSJjpcVVlRqd6GSnlTLKgpAAttJvpI=
229235
k8s.io/utils v0.0.0-20230726121419-3b25d923346b/go.mod h1:OLgZIPagt7ERELqWJFomSt595RzquPNLL48iOWgYOg0=
230236
sigs.k8s.io/controller-runtime v0.17.0 h1:fjJQf8Ukya+VjogLO6/bNX9HE6Y2xpsO5+fyS26ur/s=

pkg/utils/utils.go

+17-7
Original file line numberDiff line numberDiff line change
@@ -26,13 +26,21 @@ import (
2626
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
2727
"k8s.io/apimachinery/pkg/runtime"
2828
"k8s.io/apimachinery/pkg/runtime/schema"
29+
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
30+
pkgcorev1 "k8s.io/kubernetes/pkg/apis/core/v1"
2931
"k8s.io/utils/ptr"
3032

3133
workloadv1beta2 "github.com/project-codeflare/appwrapper/api/v1beta2"
3234
)
3335

36+
var scheme = runtime.NewScheme()
37+
3438
const templateString = "template"
3539

40+
func init() {
41+
utilruntime.Must(pkgcorev1.AddToScheme(scheme))
42+
}
43+
3644
// GetPodTemplateSpec extracts a Kueue-compatible PodTemplateSpec at the given path within obj
3745
func GetPodTemplateSpec(obj *unstructured.Unstructured, path string) (*v1.PodTemplateSpec, error) {
3846
candidatePTS, err := GetRawTemplate(obj.UnstructuredContent(), path)
@@ -41,27 +49,29 @@ func GetPodTemplateSpec(obj *unstructured.Unstructured, path string) (*v1.PodTem
4149
}
4250

4351
// Extract the PodSpec that should be at candidatePTS.spec
52+
podTemplate := &v1.PodTemplate{}
4453
spec, ok := candidatePTS["spec"].(map[string]interface{})
4554
if !ok {
4655
return nil, fmt.Errorf("content at %v does not contain a spec", path)
4756
}
48-
podSpec := &v1.PodSpec{}
49-
if err := runtime.DefaultUnstructuredConverter.FromUnstructuredWithValidation(spec, podSpec, true); err != nil {
57+
if err := runtime.DefaultUnstructuredConverter.FromUnstructuredWithValidation(spec, &podTemplate.Template.Spec, true); err != nil {
5058
return nil, fmt.Errorf("content at %v.spec not parseable as a v1.PodSpec: %w", path, err)
5159
}
5260

53-
// Construct the filtered PodTemplateSpec, copying only the metadata expected by Kueue
54-
template := &v1.PodTemplateSpec{Spec: *podSpec}
61+
// Set default values. Required for proper operation of Kueue's ComparePodSetSlices
62+
scheme.Default(podTemplate)
63+
64+
// Copy in the subset of the metadate expected by Kueye.
5565
if metadata, ok := candidatePTS["metadata"].(map[string]interface{}); ok {
5666
if labels, ok := metadata["labels"].(map[string]string); ok {
57-
template.ObjectMeta.Labels = labels
67+
podTemplate.Template.ObjectMeta.Labels = labels
5868
}
5969
if annotations, ok := metadata["annotations"].(map[string]string); ok {
60-
template.ObjectMeta.Annotations = annotations
70+
podTemplate.Template.ObjectMeta.Annotations = annotations
6171
}
6272
}
6373

64-
return template, nil
74+
return &podTemplate.Template, nil
6575
}
6676

6777
// GetReplicas parses the value at the given path within obj as an int

0 commit comments

Comments
 (0)