@@ -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+
3438const 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
3745func 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