@@ -14,8 +14,108 @@ import (
1414 "github.com/cobaltcore-dev/cloud-profile-sync/cloudprofilesync"
1515)
1616
17- var _ = Describe ("ImageUpdater" , func () {
17+ var _ = Describe ("filterImages" , func () {
18+ // helper: run Update and return the versions written to spec.machineImages
19+ versions := func (ctx SpecContext , images []cloudprofilesync.SourceImage ) []gardencorev1beta1.MachineImageVersion {
20+ mockSource .images = images
21+ updater := cloudprofilesync.ImageUpdater {
22+ Log : GinkgoLogr ,
23+ Source : & mockSource ,
24+ ImageName : "test" ,
25+ EnableCapabilities : true ,
26+ }
27+ var cpSpec gardencorev1beta1.CloudProfileSpec
28+ Expect (updater .Update (ctx , & cpSpec )).To (Succeed ())
29+ if len (cpSpec .MachineImages ) == 0 {
30+ return nil
31+ }
32+ return cpSpec .MachineImages [0 ].Versions
33+ }
34+
35+ It ("invalid tag + no clean version: drops the image entirely" , func (ctx SpecContext ) {
36+ result := versions (ctx , []cloudprofilesync.SourceImage {
37+ {Version : "not-a-version" , Architectures : []string {"amd64" }},
38+ })
39+ Expect (result ).To (BeEmpty ())
40+ })
41+
42+ It ("invalid tag + invalid clean version: drops the image entirely" , func (ctx SpecContext ) {
43+ result := versions (ctx , []cloudprofilesync.SourceImage {
44+ {Version : "not-a-version" , CleanVersion : "also-not-a-version" , Architectures : []string {"amd64" }},
45+ })
46+ Expect (result ).To (BeEmpty ())
47+ })
48+
49+ It ("invalid tag + valid clean version: NEW format only (no legacy entry)" , func (ctx SpecContext ) {
50+ result := versions (ctx , []cloudprofilesync.SourceImage {
51+ {
52+ Version : "1877.9.2.0-metal-sci-pxe-amd64" ,
53+ CleanVersion : "1877.9.2" ,
54+ Architectures : []string {"amd64" },
55+ Capabilities : gardencorev1beta1.Capabilities {"architecture" : {"amd64" }, "feature" : {"sci" , "_pxe" }},
56+ },
57+ })
58+ Expect (result ).To (HaveLen (1 ))
59+ Expect (result [0 ].Version ).To (Equal ("1877.9.2" ))
60+ })
61+
62+ It ("valid tag + valid clean version: BOTH formats" , func (ctx SpecContext ) {
63+ result := versions (ctx , []cloudprofilesync.SourceImage {
64+ {
65+ Version : "2254.0.0-baremetal-sci-usi-amd64" ,
66+ CleanVersion : "2254.0.0" ,
67+ Architectures : []string {"amd64" },
68+ Capabilities : gardencorev1beta1.Capabilities {"architecture" : {"amd64" }, "feature" : {"sci" , "_usi" }},
69+ },
70+ })
71+ Expect (result ).To (HaveLen (2 ))
72+ versionStrings := []string {result [0 ].Version , result [1 ].Version }
73+ Expect (versionStrings ).To (ContainElements ("2254.0.0-baremetal-sci-usi-amd64" , "2254.0.0" ))
74+ })
75+
76+ It ("valid tag + no clean version: OLD format only" , func (ctx SpecContext ) {
77+ result := versions (ctx , []cloudprofilesync.SourceImage {
78+ {Version : "1921.0.0" , Architectures : []string {"amd64" }},
79+ })
80+ Expect (result ).To (HaveLen (1 ))
81+ Expect (result [0 ].Version ).To (Equal ("1921.0.0" ))
82+ })
83+
84+ It ("valid tag + invalid clean version: BOTH formats with clean version normalized" , func (ctx SpecContext ) {
85+ result := versions (ctx , []cloudprofilesync.SourceImage {
86+ {
87+ Version : "1921.0.0-metal-sci-usi-amd64" ,
88+ CleanVersion : "1921.0" ,
89+ Architectures : []string {"amd64" },
90+ Capabilities : gardencorev1beta1.Capabilities {"architecture" : {"amd64" }, "feature" : {"sci" , "_usi" }},
91+ },
92+ })
93+ Expect (result ).To (HaveLen (2 ))
94+ versionStrings := []string {result [0 ].Version , result [1 ].Version }
95+ Expect (versionStrings ).To (ContainElements ("1921.0.0-metal-sci-usi-amd64" , "1921.0.0" ))
96+ })
97+
98+ It ("valid tag + unparsable clean version: does not write clean version entry" , func (ctx SpecContext ) {
99+ result := versions (ctx , []cloudprofilesync.SourceImage {
100+ {
101+ Version : "1921.0.0-metal-sci-usi-amd64" ,
102+ CleanVersion : "not-a-version" ,
103+ Architectures : []string {"amd64" },
104+ },
105+ })
106+ Expect (result ).To (HaveLen (1 ))
107+ Expect (result [0 ].Version ).To (Equal ("1921.0.0-metal-sci-usi-amd64" ))
108+ })
18109
110+ It ("no architectures: drops the image entirely" , func (ctx SpecContext ) {
111+ result := versions (ctx , []cloudprofilesync.SourceImage {
112+ {Version : "1.0.0" },
113+ })
114+ Expect (result ).To (BeEmpty ())
115+ })
116+ })
117+
118+ var _ = Describe ("ImageUpdater" , func () {
19119 Describe ("flag OFF (default behavior)" , func () {
20120 It ("adds an image from the source to the CloudProfile spec" , func (ctx SpecContext ) {
21121 mockSource .images = []cloudprofilesync.SourceImage {{Version : "1.0.0" , Architectures : []string {"amd64" }}}
@@ -172,6 +272,37 @@ var _ = Describe("ImageUpdater", func() {
172272 Expect (cpSpec .MachineImages [0 ].Versions ).To (HaveLen (2 ))
173273 })
174274
275+ It ("skips legacy spec entry for non-semver raw tag but still passes image to provider" , func (ctx SpecContext ) {
276+ mockSource .images = []cloudprofilesync.SourceImage {
277+ {
278+ Version : "1877.9.2.0-metal-sci-pxe-amd64-1877-9-2-6bb2b442" ,
279+ CleanVersion : "1877.9.2" ,
280+ Architectures : []string {"amd64" },
281+ Capabilities : gardencorev1beta1.Capabilities {"architecture" : {"amd64" }, "feature" : {"sci" , "_pxe" }},
282+ },
283+ }
284+ updater := cloudprofilesync.ImageUpdater {
285+ Log : GinkgoLogr ,
286+ Source : & mockSource ,
287+ ImageName : "test" ,
288+ EnableCapabilities : true ,
289+ Provider : & MockProvider {},
290+ }
291+ var cpSpec gardencorev1beta1.CloudProfileSpec
292+ Expect (updater .Update (ctx , & cpSpec )).To (Succeed ())
293+
294+ // Non-semver raw tag must not appear in spec.machineImages — Gardener would reject it.
295+ // Only the clean version entry should be written.
296+ Expect (cpSpec .MachineImages [0 ].Versions ).To (HaveLen (1 ))
297+ Expect (cpSpec .MachineImages [0 ].Versions [0 ].Version ).To (Equal ("1877.9.2" ))
298+
299+ // The raw tag must still reach the provider (capabilityFlavors).
300+ var fromProvider []cloudprofilesync.SourceImage
301+ Expect (json .Unmarshal (cpSpec .ProviderConfig .Raw , & fromProvider )).To (Succeed ())
302+ Expect (fromProvider ).To (HaveLen (1 ))
303+ Expect (fromProvider [0 ].Version ).To (Equal ("1877.9.2.0-metal-sci-pxe-amd64-1877-9-2-6bb2b442" ))
304+ })
305+
175306 It ("writes only full tag when CleanVersion is absent" , func (ctx SpecContext ) {
176307 mockSource .images = []cloudprofilesync.SourceImage {
177308 {Version : "1877.0.0" , Architectures : []string {"amd64" }},
0 commit comments