@@ -2,6 +2,8 @@ package e2e_test
2
2
3
3
import (
4
4
"context"
5
+ "time"
6
+
5
7
osbuilder "github.com/kairos-io/osbuilder/api/v1alpha2"
6
8
. "github.com/onsi/ginkgo/v2"
7
9
. "github.com/onsi/gomega"
@@ -16,48 +18,54 @@ import (
16
18
"k8s.io/apimachinery/pkg/watch"
17
19
"k8s.io/client-go/dynamic"
18
20
ctrl "sigs.k8s.io/controller-runtime"
19
- "time"
20
21
)
21
22
22
23
var _ = Describe ("ISO build test" , func () {
23
- k8s := dynamic .NewForConfigOrDie (ctrl .GetConfigOrDie ())
24
- scheme := runtime .NewScheme ()
25
- _ = osbuilder .AddToScheme (scheme )
26
-
27
24
var artifactName string
28
- artifacts := k8s .Resource (schema.GroupVersionResource {Group : osbuilder .GroupVersion .Group , Version : osbuilder .GroupVersion .Version , Resource : "osartifacts" }).Namespace ("default" )
29
- pods := k8s .Resource (schema.GroupVersionResource {Group : corev1 .GroupName , Version : corev1 .SchemeGroupVersion .Version , Resource : "pods" }).Namespace ("default" )
30
- pvcs := k8s .Resource (schema.GroupVersionResource {Group : corev1 .GroupName , Version : corev1 .SchemeGroupVersion .Version , Resource : "persistentvolumeclaims" }).Namespace ("default" )
31
- jobs := k8s .Resource (schema.GroupVersionResource {Group : batchv1 .GroupName , Version : batchv1 .SchemeGroupVersion .Version , Resource : "jobs" }).Namespace ("default" )
32
-
33
- artifact := & osbuilder.OSArtifact {
34
- TypeMeta : metav1.TypeMeta {
35
- Kind : "OSArtifact" ,
36
- APIVersion : osbuilder .GroupVersion .String (),
37
- },
38
- ObjectMeta : metav1.ObjectMeta {
39
- GenerateName : "simple-" ,
40
- },
41
- Spec : osbuilder.OSArtifactSpec {
42
- ImageName : "quay.io/kairos/core-opensuse:latest" ,
43
- ISO : true ,
44
- DiskSize : "" ,
45
- Exporters : []batchv1.JobSpec {
46
- {
47
- Template : corev1.PodTemplateSpec {
48
- Spec : corev1.PodSpec {
49
- RestartPolicy : corev1 .RestartPolicyNever ,
50
- Containers : []corev1.Container {
51
- {
52
- Name : "test" ,
53
- Image : "debian:latest" ,
54
- Command : []string {"bash" },
55
- Args : []string {"-xec" , "[ -f /artifacts/*.iso ]" },
56
- VolumeMounts : []corev1.VolumeMount {
57
- {
58
- Name : "artifacts" ,
59
- ReadOnly : true ,
60
- MountPath : "/artifacts" ,
25
+ var artifacts , pods , pvcs , jobs dynamic.ResourceInterface
26
+ var scheme * runtime.Scheme
27
+ var artifactLabelSelector labels.Selector
28
+
29
+ BeforeEach (func () {
30
+ k8s := dynamic .NewForConfigOrDie (ctrl .GetConfigOrDie ())
31
+ scheme = runtime .NewScheme ()
32
+ err := osbuilder .AddToScheme (scheme )
33
+ Expect (err ).ToNot (HaveOccurred ())
34
+
35
+ artifacts = k8s .Resource (schema.GroupVersionResource {Group : osbuilder .GroupVersion .Group , Version : osbuilder .GroupVersion .Version , Resource : "osartifacts" }).Namespace ("default" )
36
+ pods = k8s .Resource (schema.GroupVersionResource {Group : corev1 .GroupName , Version : corev1 .SchemeGroupVersion .Version , Resource : "pods" }).Namespace ("default" )
37
+ pvcs = k8s .Resource (schema.GroupVersionResource {Group : corev1 .GroupName , Version : corev1 .SchemeGroupVersion .Version , Resource : "persistentvolumeclaims" }).Namespace ("default" )
38
+ jobs = k8s .Resource (schema.GroupVersionResource {Group : batchv1 .GroupName , Version : batchv1 .SchemeGroupVersion .Version , Resource : "jobs" }).Namespace ("default" )
39
+
40
+ artifact := & osbuilder.OSArtifact {
41
+ TypeMeta : metav1.TypeMeta {
42
+ Kind : "OSArtifact" ,
43
+ APIVersion : osbuilder .GroupVersion .String (),
44
+ },
45
+ ObjectMeta : metav1.ObjectMeta {
46
+ GenerateName : "simple-" ,
47
+ },
48
+ Spec : osbuilder.OSArtifactSpec {
49
+ ImageName : "quay.io/kairos/core-opensuse:latest" ,
50
+ ISO : true ,
51
+ DiskSize : "" ,
52
+ Exporters : []batchv1.JobSpec {
53
+ {
54
+ Template : corev1.PodTemplateSpec {
55
+ Spec : corev1.PodSpec {
56
+ RestartPolicy : corev1 .RestartPolicyNever ,
57
+ Containers : []corev1.Container {
58
+ {
59
+ Name : "test" ,
60
+ Image : "debian:latest" ,
61
+ Command : []string {"bash" },
62
+ Args : []string {"-xec" , "[ -f /artifacts/*.iso ]" },
63
+ VolumeMounts : []corev1.VolumeMount {
64
+ {
65
+ Name : "artifacts" ,
66
+ ReadOnly : true ,
67
+ MountPath : "/artifacts" ,
68
+ },
61
69
},
62
70
},
63
71
},
@@ -66,92 +74,89 @@ var _ = Describe("ISO build test", func() {
66
74
},
67
75
},
68
76
},
69
- },
70
- }
77
+ }
71
78
72
- uArtifact := unstructured.Unstructured {}
73
- uArtifact .Object , _ = runtime .DefaultUnstructuredConverter .ToUnstructured (artifact )
74
- resp , err := artifacts .Create (context .TODO (), & uArtifact , metav1.CreateOptions {})
75
- Expect (err ).ToNot (HaveOccurred ())
76
- artifactName = resp .GetName ()
79
+ uArtifact := unstructured.Unstructured {}
80
+ uArtifact .Object , _ = runtime .DefaultUnstructuredConverter .ToUnstructured (artifact )
81
+ resp , err := artifacts .Create (context .TODO (), & uArtifact , metav1.CreateOptions {})
82
+ Expect (err ).ToNot (HaveOccurred ())
83
+ artifactName = resp .GetName ()
77
84
78
- Context ("simple" , func () {
79
- artifactLabelSelectorReq , _ := labels .NewRequirement ("build.kairos.io/artifact" , selection .Equals , []string {artifactName })
80
- artifactLabelSelector := labels .NewSelector ().Add (* artifactLabelSelectorReq )
85
+ artifactLabelSelectorReq , err := labels .NewRequirement ("build.kairos.io/artifact" , selection .Equals , []string {artifactName })
86
+ Expect (err ).ToNot (HaveOccurred ())
87
+ artifactLabelSelector = labels .NewSelector ().Add (* artifactLabelSelectorReq )
88
+ })
81
89
82
- It ("starts the build" , func () {
83
- Eventually (func (g Gomega ) {
84
- w , err := pods .Watch (context .TODO (), metav1.ListOptions {LabelSelector : artifactLabelSelector .String ()})
85
- Expect (err ).ToNot (HaveOccurred ())
90
+ It ("works" , func () {
91
+ By ("starting the build" )
92
+ Eventually (func (g Gomega ) {
93
+ w , err := pods .Watch (context .TODO (), metav1.ListOptions {LabelSelector : artifactLabelSelector .String ()})
94
+ Expect (err ).ToNot (HaveOccurred ())
86
95
87
- var stopped bool
88
- for ! stopped {
89
- event , ok := <- w .ResultChan ()
96
+ var stopped bool
97
+ for ! stopped {
98
+ event , ok := <- w .ResultChan ()
90
99
91
- stopped = event .Type != watch .Deleted && event .Type != watch .Error || ! ok
92
- }
93
- }).WithTimeout (time .Hour ).Should (Succeed ())
94
- })
100
+ stopped = event .Type != watch .Deleted && event .Type != watch .Error || ! ok
101
+ }
102
+ }).WithTimeout (time .Hour ).Should (Succeed ())
103
+
104
+ By ("exporting the artifacts" )
105
+ Eventually (func (g Gomega ) {
106
+ w , err := jobs .Watch (context .TODO (), metav1.ListOptions {LabelSelector : artifactLabelSelector .String ()})
107
+ Expect (err ).ToNot (HaveOccurred ())
95
108
96
- It ("exports the artifacts" , func () {
97
- Eventually (func (g Gomega ) {
98
- w , err := jobs .Watch (context .TODO (), metav1.ListOptions {LabelSelector : artifactLabelSelector .String ()})
99
- Expect (err ).ToNot (HaveOccurred ())
109
+ var stopped bool
110
+ for ! stopped {
111
+ event , ok := <- w .ResultChan ()
100
112
101
- var stopped bool
102
- for ! stopped {
103
- event , ok := <- w . ResultChan ( )
113
+ stopped = event . Type != watch . Deleted && event . Type != watch . Error || ! ok
114
+ }
115
+ }). WithTimeout ( time . Hour ). Should ( Succeed () )
104
116
105
- stopped = event .Type != watch .Deleted && event .Type != watch .Error || ! ok
106
- }
107
- }).WithTimeout (time .Hour ).Should (Succeed ())
108
- })
109
-
110
- It ("artifact successfully builds" , func () {
111
- Eventually (func (g Gomega ) {
112
- w , err := artifacts .Watch (context .TODO (), metav1.ListOptions {})
113
- Expect (err ).ToNot (HaveOccurred ())
114
-
115
- var artifact osbuilder.OSArtifact
116
- var stopped bool
117
- for ! stopped {
118
- event , ok := <- w .ResultChan ()
119
- stopped = ! ok
120
-
121
- if event .Type == watch .Modified && event .Object .(* unstructured.Unstructured ).GetName () == artifactName {
122
- err := scheme .Convert (event .Object , & artifact , nil )
123
- Expect (err ).ToNot (HaveOccurred ())
124
- stopped = artifact .Status .Phase == osbuilder .Ready
125
- }
117
+ By ("building the artifacts successfully" )
118
+ Eventually (func (g Gomega ) {
119
+ w , err := artifacts .Watch (context .TODO (), metav1.ListOptions {})
120
+ Expect (err ).ToNot (HaveOccurred ())
126
121
122
+ var artifact osbuilder.OSArtifact
123
+ var stopped bool
124
+ for ! stopped {
125
+ event , ok := <- w .ResultChan ()
126
+ stopped = ! ok
127
+
128
+ if event .Type == watch .Modified && event .Object .(* unstructured.Unstructured ).GetName () == artifactName {
129
+ err := scheme .Convert (event .Object , & artifact , nil )
130
+ Expect (err ).ToNot (HaveOccurred ())
131
+ stopped = artifact .Status .Phase == osbuilder .Ready
127
132
}
128
- }).WithTimeout (time .Hour ).Should (Succeed ())
129
- })
130
133
131
- It ("cleans up resources on deleted" , func () {
132
- err := artifacts .Delete (context .TODO (), artifactName , metav1.DeleteOptions {})
133
- Expect (err ).ToNot (HaveOccurred ())
134
+ }
135
+ }).WithTimeout (time .Hour ).Should (Succeed ())
134
136
135
- Eventually (func (g Gomega ) int {
136
- res , err := artifacts .List (context .TODO (), metav1.ListOptions {})
137
- Expect (err ).ToNot (HaveOccurred ())
138
- return len (res .Items )
139
- }).WithTimeout (time .Minute ).Should (Equal (0 ))
140
- Eventually (func (g Gomega ) int {
141
- res , err := pods .List (context .TODO (), metav1.ListOptions {LabelSelector : artifactLabelSelector .String ()})
142
- Expect (err ).ToNot (HaveOccurred ())
143
- return len (res .Items )
144
- }).WithTimeout (time .Minute ).Should (Equal (0 ))
145
- Eventually (func (g Gomega ) int {
146
- res , err := pvcs .List (context .TODO (), metav1.ListOptions {LabelSelector : artifactLabelSelector .String ()})
147
- Expect (err ).ToNot (HaveOccurred ())
148
- return len (res .Items )
149
- }).WithTimeout (time .Minute ).Should (Equal (0 ))
150
- Eventually (func (g Gomega ) int {
151
- res , err := jobs .List (context .TODO (), metav1.ListOptions {LabelSelector : artifactLabelSelector .String ()})
152
- Expect (err ).ToNot (HaveOccurred ())
153
- return len (res .Items )
154
- }).WithTimeout (time .Minute ).Should (Equal (0 ))
155
- })
137
+ By ("cleaning up resources on deletion" )
138
+ err := artifacts .Delete (context .TODO (), artifactName , metav1.DeleteOptions {})
139
+ Expect (err ).ToNot (HaveOccurred ())
140
+
141
+ Eventually (func (g Gomega ) int {
142
+ res , err := artifacts .List (context .TODO (), metav1.ListOptions {})
143
+ Expect (err ).ToNot (HaveOccurred ())
144
+ return len (res .Items )
145
+ }).WithTimeout (time .Minute ).Should (Equal (0 ))
146
+ Eventually (func (g Gomega ) int {
147
+ res , err := pods .List (context .TODO (), metav1.ListOptions {LabelSelector : artifactLabelSelector .String ()})
148
+ Expect (err ).ToNot (HaveOccurred ())
149
+ return len (res .Items )
150
+ }).WithTimeout (time .Minute ).Should (Equal (0 ))
151
+ Eventually (func (g Gomega ) int {
152
+ res , err := pvcs .List (context .TODO (), metav1.ListOptions {LabelSelector : artifactLabelSelector .String ()})
153
+ Expect (err ).ToNot (HaveOccurred ())
154
+ return len (res .Items )
155
+ }).WithTimeout (time .Minute ).Should (Equal (0 ))
156
+ Eventually (func (g Gomega ) int {
157
+ res , err := jobs .List (context .TODO (), metav1.ListOptions {LabelSelector : artifactLabelSelector .String ()})
158
+ Expect (err ).ToNot (HaveOccurred ())
159
+ return len (res .Items )
160
+ }).WithTimeout (time .Minute ).Should (Equal (0 ))
156
161
})
157
162
})
0 commit comments