@@ -26,13 +26,21 @@ import (
26
26
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
27
27
"k8s.io/apimachinery/pkg/runtime"
28
28
"k8s.io/apimachinery/pkg/runtime/schema"
29
+ utilruntime "k8s.io/apimachinery/pkg/util/runtime"
30
+ pkgcorev1 "k8s.io/kubernetes/pkg/apis/core/v1"
29
31
"k8s.io/utils/ptr"
30
32
31
33
workloadv1beta2 "github.com/project-codeflare/appwrapper/api/v1beta2"
32
34
)
33
35
36
+ var scheme = runtime .NewScheme ()
37
+
34
38
const templateString = "template"
35
39
40
+ func init () {
41
+ utilruntime .Must (pkgcorev1 .AddToScheme (scheme ))
42
+ }
43
+
36
44
// GetPodTemplateSpec extracts a Kueue-compatible PodTemplateSpec at the given path within obj
37
45
func GetPodTemplateSpec (obj * unstructured.Unstructured , path string ) (* v1.PodTemplateSpec , error ) {
38
46
candidatePTS , err := GetRawTemplate (obj .UnstructuredContent (), path )
@@ -41,27 +49,29 @@ func GetPodTemplateSpec(obj *unstructured.Unstructured, path string) (*v1.PodTem
41
49
}
42
50
43
51
// Extract the PodSpec that should be at candidatePTS.spec
52
+ podTemplate := & v1.PodTemplate {}
44
53
spec , ok := candidatePTS ["spec" ].(map [string ]interface {})
45
54
if ! ok {
46
55
return nil , fmt .Errorf ("content at %v does not contain a spec" , path )
47
56
}
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 {
50
58
return nil , fmt .Errorf ("content at %v.spec not parseable as a v1.PodSpec: %w" , path , err )
51
59
}
52
60
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.
55
65
if metadata , ok := candidatePTS ["metadata" ].(map [string ]interface {}); ok {
56
66
if labels , ok := metadata ["labels" ].(map [string ]string ); ok {
57
- template .ObjectMeta .Labels = labels
67
+ podTemplate . Template .ObjectMeta .Labels = labels
58
68
}
59
69
if annotations , ok := metadata ["annotations" ].(map [string ]string ); ok {
60
- template .ObjectMeta .Annotations = annotations
70
+ podTemplate . Template .ObjectMeta .Annotations = annotations
61
71
}
62
72
}
63
73
64
- return template , nil
74
+ return & podTemplate . Template , nil
65
75
}
66
76
67
77
// GetReplicas parses the value at the given path within obj as an int
0 commit comments