@@ -19,13 +19,17 @@ package component
19
19
import (
20
20
"context"
21
21
"fmt"
22
+ "io"
22
23
"os"
23
24
"time"
24
25
25
26
. "github.com/mandelsoft/goutils/testutils"
27
+ "github.com/mandelsoft/vfs/pkg/vfs"
26
28
. "github.com/onsi/ginkgo/v2"
27
29
. "github.com/onsi/gomega"
28
30
. "ocm.software/ocm/api/helper/builder"
31
+ "ocm.software/ocm/api/utils/accessobj"
32
+ "sigs.k8s.io/yaml"
29
33
30
34
"github.com/fluxcd/pkg/apis/meta"
31
35
"github.com/fluxcd/pkg/runtime/conditions"
@@ -37,9 +41,12 @@ import (
37
41
environment "ocm.software/ocm/api/helper/env"
38
42
"ocm.software/ocm/api/ocm/extensions/repositories/ctf"
39
43
"ocm.software/ocm/api/utils/accessio"
44
+ "sigs.k8s.io/controller-runtime/pkg/client"
40
45
"sigs.k8s.io/controller-runtime/pkg/envtest/komega"
41
46
42
47
"github.com/open-component-model/ocm-k8s-toolkit/api/v1alpha1"
48
+ "github.com/open-component-model/ocm-k8s-toolkit/pkg/ocm"
49
+ "github.com/open-component-model/ocm-k8s-toolkit/pkg/snapshot"
43
50
)
44
51
45
52
const (
@@ -133,20 +140,30 @@ var _ = Describe("Component Controller", func() {
133
140
Status : v1alpha1.ComponentStatus {},
134
141
}
135
142
Expect (k8sClient .Create (ctx , component )).To (Succeed ())
143
+ DeferCleanup (func (ctx SpecContext ) {
144
+ Expect (k8sClient .Delete (ctx , component , client .PropagationPolicy (metav1 .DeletePropagationForeground ))).To (Succeed ())
145
+ })
136
146
137
- By ("check that snapshot has been created successfully" )
147
+ By ("checking that the component has been reconciled successfully" )
148
+ Eventually (komega .Object (component ), "5m" ).Should (
149
+ HaveField ("Status.ObservedGeneration" , Equal (int64 (1 ))))
138
150
139
- Eventually (komega .Object (component ), "15s" ).Should (
140
- HaveField ("Status.SnapshotRef.Name" , Not (BeEmpty ())))
151
+ By ("checking that the snapshot has been created successfully" )
152
+ Expect (component ).To (HaveField ("Status.SnapshotRef.Name" , Not (BeEmpty ())))
153
+ snapshotComponent := Must (snapshot .GetSnapshotForOwner (ctx , k8sClient , component ))
141
154
142
- By ("checking if the snapshot can be received" )
143
- snapshot := & v1alpha1.Snapshot {
144
- ObjectMeta : metav1.ObjectMeta {
145
- Namespace : component .Namespace ,
146
- Name : component .Status .SnapshotRef .Name ,
147
- },
148
- }
149
- Eventually (komega .Get (snapshot )).Should (Succeed ())
155
+ By ("checking that the snapshot contains the correct content" )
156
+ snapshotRepository := Must (registry .NewRepository (ctx , snapshotComponent .Spec .Repository ))
157
+ snapshotComponentContentReader := Must (snapshotRepository .FetchSnapshot (ctx , snapshotComponent .GetDigest ()))
158
+ snapshotComponentContent := Must (io .ReadAll (snapshotComponentContentReader ))
159
+ snapshotDescriptors := & ocm.Descriptors {}
160
+ MustBeSuccessful (yaml .Unmarshal (snapshotComponentContent , snapshotDescriptors ))
161
+
162
+ repo := Must (ctf .Open (env , accessobj .ACC_WRITABLE , ctfpath , vfs .FileMode (vfs .O_RDWR ), env ))
163
+ cv := Must (repo .LookupComponentVersion (Component , Version1 ))
164
+ expectedDescriptors := Must (ocm .ListComponentDescriptors (ctx , cv , repo ))
165
+
166
+ Expect (snapshotDescriptors ).To (YAMLEqual (expectedDescriptors ))
150
167
})
151
168
152
169
It ("does not reconcile when the repository is not ready" , func () {
@@ -172,6 +189,9 @@ var _ = Describe("Component Controller", func() {
172
189
Status : v1alpha1.ComponentStatus {},
173
190
}
174
191
Expect (k8sClient .Create (ctx , component )).To (Succeed ())
192
+ DeferCleanup (func (ctx SpecContext ) {
193
+ Expect (k8sClient .Delete (ctx , component , client .PropagationPolicy (metav1 .DeletePropagationForeground ))).To (Succeed ())
194
+ })
175
195
176
196
By ("check that no snapshot has been created" )
177
197
Eventually (komega .Object (component ), "15s" ).Should (
@@ -197,11 +217,17 @@ var _ = Describe("Component Controller", func() {
197
217
Status : v1alpha1.ComponentStatus {},
198
218
}
199
219
Expect (k8sClient .Create (ctx , component )).To (Succeed ())
220
+ DeferCleanup (func (ctx SpecContext ) {
221
+ Expect (k8sClient .Delete (ctx , component , client .PropagationPolicy (metav1 .DeletePropagationForeground ))).To (Succeed ())
222
+ })
200
223
201
- By ("check that snapshot has been created successfully" )
224
+ By ("checking that the component has been reconciled successfully" )
225
+ Eventually (komega .Object (component ), "5m" ).Should (
226
+ HaveField ("Status.ObservedGeneration" , Equal (int64 (1 ))))
202
227
203
- Eventually (komega .Object (component ), "15s" ).Should (
204
- HaveField ("Status.SnapshotRef.Name" , Not (BeEmpty ())))
228
+ By ("checking that the snapshot has been created successfully" )
229
+ Expect (component ).To (HaveField ("Status.SnapshotRef.Name" , Not (BeEmpty ())))
230
+ Must (snapshot .GetSnapshotForOwner (ctx , k8sClient , component ))
205
231
206
232
Expect (k8sClient .Get (ctx , types.NamespacedName {Name : component .Name , Namespace : component .Namespace }, component )).To (Succeed ())
207
233
Expect (component .Status .Component .Version ).To (Equal (Version1 ))
@@ -254,10 +280,17 @@ var _ = Describe("Component Controller", func() {
254
280
Status : v1alpha1.ComponentStatus {},
255
281
}
256
282
Expect (k8sClient .Create (ctx , component )).To (Succeed ())
283
+ DeferCleanup (func (ctx SpecContext ) {
284
+ Expect (k8sClient .Delete (ctx , component , client .PropagationPolicy (metav1 .DeletePropagationForeground ))).To (Succeed ())
285
+ })
257
286
258
- By ("check that snapshot has been created successfully" )
287
+ By ("checking that the component has been reconciled successfully" )
288
+ Eventually (komega .Object (component ), "5m" ).Should (
289
+ HaveField ("Status.ObservedGeneration" , Equal (int64 (1 ))))
259
290
260
- Eventually (komega .Object (component ), "15s" ).Should (HaveField ("Status.SnapshotRef.Name" , Not (BeEmpty ())))
291
+ By ("checking that the snapshot has been created successfully" )
292
+ Expect (component ).To (HaveField ("Status.SnapshotRef.Name" , Not (BeEmpty ())))
293
+ Must (snapshot .GetSnapshotForOwner (ctx , k8sClient , component ))
261
294
262
295
Expect (k8sClient .Get (ctx , types.NamespacedName {Name : component .Name , Namespace : component .Namespace }, component )).To (Succeed ())
263
296
Expect (component .Status .Component .Version ).To (Equal ("0.0.3" ))
@@ -303,9 +336,17 @@ var _ = Describe("Component Controller", func() {
303
336
},
304
337
}
305
338
Expect (k8sClient .Create (ctx , component )).To (Succeed ())
339
+ DeferCleanup (func (ctx SpecContext ) {
340
+ Expect (k8sClient .Delete (ctx , component , client .PropagationPolicy (metav1 .DeletePropagationForeground ))).To (Succeed ())
341
+ })
306
342
307
- By ("check that snapshot has been created successfully" )
308
- Eventually (komega .Object (component ), "15s" ).Should (HaveField ("Status.SnapshotRef.Name" , Not (BeEmpty ())))
343
+ By ("checking that the component has been reconciled successfully" )
344
+ Eventually (komega .Object (component ), "5m" ).Should (
345
+ HaveField ("Status.ObservedGeneration" , Equal (int64 (1 ))))
346
+
347
+ By ("checking that the snapshot has been created successfully" )
348
+ Expect (component ).To (HaveField ("Status.SnapshotRef.Name" , Not (BeEmpty ())))
349
+ Must (snapshot .GetSnapshotForOwner (ctx , k8sClient , component ))
309
350
310
351
Expect (k8sClient .Get (ctx , types.NamespacedName {Name : component .Name , Namespace : component .Namespace }, component )).To (Succeed ())
311
352
Expect (component .Status .Component .Version ).To (Equal ("0.0.3" ))
@@ -349,11 +390,17 @@ var _ = Describe("Component Controller", func() {
349
390
Status : v1alpha1.ComponentStatus {},
350
391
}
351
392
Expect (k8sClient .Create (ctx , component )).To (Succeed ())
393
+ DeferCleanup (func (ctx SpecContext ) {
394
+ Expect (k8sClient .Delete (ctx , component , client .PropagationPolicy (metav1 .DeletePropagationForeground ))).To (Succeed ())
395
+ })
352
396
353
- By ("check that snapshot has been created successfully" )
397
+ By ("checking that the component has been reconciled successfully" )
398
+ Eventually (komega .Object (component ), "5m" ).Should (
399
+ HaveField ("Status.ObservedGeneration" , Equal (int64 (1 ))))
354
400
355
- Eventually (komega .Object (component ), "15s" ).Should (
356
- HaveField ("Status.SnapshotRef.Name" , Not (BeEmpty ())))
401
+ By ("checking that the snapshot has been created successfully" )
402
+ Expect (component ).To (HaveField ("Status.SnapshotRef.Name" , Not (BeEmpty ())))
403
+ Must (snapshot .GetSnapshotForOwner (ctx , k8sClient , component ))
357
404
358
405
Expect (k8sClient .Get (ctx , types.NamespacedName {Name : component .Name , Namespace : component .Namespace }, component )).To (Succeed ())
359
406
Expect (component .Status .Component .Version ).To (Equal ("0.0.3" ))
@@ -365,7 +412,7 @@ var _ = Describe("Component Controller", func() {
365
412
Expect (k8sClient .Get (ctx , types.NamespacedName {Name : component .Name , Namespace : component .Namespace }, component )).To (Succeed ())
366
413
367
414
return component .Status .Component .Version == "0.0.2"
368
- }).WithTimeout (15 * time .Second ).Should (BeTrue ())
415
+ }).WithTimeout (60 * time .Second ).Should (BeTrue ())
369
416
})
370
417
})
371
418
@@ -559,6 +606,14 @@ var _ = Describe("Component Controller", func() {
559
606
}
560
607
Expect (k8sClient .Create (ctx , component )).To (Succeed ())
561
608
609
+ By ("checking that the component has been reconciled successfully" )
610
+ Eventually (komega .Object (component ), "5m" ).Should (
611
+ HaveField ("Status.ObservedGeneration" , Equal (int64 (1 ))))
612
+
613
+ By ("checking that the snapshot has been created successfully" )
614
+ Expect (component ).To (HaveField ("Status.SnapshotRef.Name" , Not (BeEmpty ())))
615
+ Must (snapshot .GetSnapshotForOwner (ctx , k8sClient , component ))
616
+
562
617
Eventually (komega .Object (component ), "15s" ).Should (
563
618
HaveField ("Status.EffectiveOCMConfig" , ConsistOf (
564
619
v1alpha1.OCMConfiguration {
0 commit comments