@@ -13,8 +13,9 @@ import (
13
13
e2e "k8s.io/kubernetes/test/e2e/framework"
14
14
15
15
mcfgv1 "github.com/openshift/api/machineconfiguration/v1"
16
- // mcfgv1alpha1 "github.com/openshift/api/machineconfiguration/v1alpha1"
16
+ mcfgv1alpha1 "github.com/openshift/api/machineconfiguration/v1alpha1"
17
17
commonstate "github.com/openshift/machine-config-operator/pkg/controller/common/state"
18
+ ctrlnode "github.com/openshift/machine-config-operator/pkg/controller/node"
18
19
corev1 "k8s.io/api/core/v1"
19
20
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
20
21
@@ -105,7 +106,10 @@ func AllNodePoolOptInTest(oc *exutil.CLI, moscFixture string, mcpFixture string)
105
106
106
107
mcp , err := getMCPFromFixture (mcpFixture )
107
108
o .Expect (err ).NotTo (o .HaveOccurred ())
108
-
109
+
110
+ mosc , err := getMOSCFromFixture (moscFixture )
111
+ o .Expect (err ).NotTo (o .HaveOccurred ())
112
+
109
113
waitTime := time .Minute * 20
110
114
ctx , cancel := context .WithTimeout (context .Background (), waitTime )
111
115
defer cancel ()
@@ -114,7 +118,9 @@ func AllNodePoolOptInTest(oc *exutil.CLI, moscFixture string, mcpFixture string)
114
118
err = waitForBuild (ctx , machineConfigClient , mcp )
115
119
o .Expect (err ).NotTo (o .HaveOccurred (), "Waiting for MOSB to be created and builder pod to Succeed" )
116
120
117
- // Wait for the build Image to be applied to all nodes
121
+ // Wait for the build Image to be applied to mcp successfully
122
+ err = waitForRollout (ctx , machineConfigClient , oc , mcp , mosc )
123
+ o .Expect (err ).NotTo (o .HaveOccurred (), "Waiting for MCP to have desired config as the new built image" )
118
124
}
119
125
120
126
func getMCPFromFixture (path string ) (* mcfgv1.MachineConfigPool , error ) {
@@ -132,6 +138,84 @@ func getMCPFromFixture(path string) (*mcfgv1.MachineConfigPool, error) {
132
138
return mcp , err
133
139
}
134
140
141
+ func getMOSCFromFixture (path string ) (* mcfgv1alpha1.MachineOSConfig , error ) {
142
+ data , err := ioutil .ReadFile (path )
143
+ if err != nil {
144
+ return nil , err
145
+ }
146
+
147
+ mosc := new (mcfgv1alpha1.MachineOSConfig )
148
+ err = yaml .Unmarshal (data , mosc )
149
+ if err != nil {
150
+ return nil , err
151
+ }
152
+
153
+ return mosc , err
154
+ }
155
+
156
+ func getNodesForPool (ctx context.Context , oc * exutil.CLI , pool * mcfgv1.MachineConfigPool ) (* corev1.NodeList , error ) {
157
+ selector , err := metav1 .LabelSelectorAsSelector (pool .Spec .NodeSelector )
158
+ if err != nil {
159
+ return nil , fmt .Errorf ("invalid label selector: %w" , err )
160
+ }
161
+ nodes , err := oc .KubeClient ().CoreV1 ().Nodes ().List (ctx , metav1.ListOptions {LabelSelector : selector .String (),})
162
+ if err != nil {
163
+ return nil , fmt .Errorf ("couldnt get nodes for mcp: %w" , err )
164
+ }
165
+ return nodes , nil
166
+ }
167
+
168
+ func waitForRollout (ctx context.Context , clientset * mcClient.Clientset , oc * exutil.CLI , mcpG * mcfgv1.MachineConfigPool , moscG * mcfgv1alpha1.MachineOSConfig ) error {
169
+ return wait .PollUntilContextCancel (ctx , time .Second , true , func (ctx context.Context ) (done bool , err error ) {
170
+
171
+ //Get mosb
172
+ var mosb mcfgv1alpha1.MachineOSBuild
173
+ var mosbFound bool
174
+ mosbList , err := clientset .MachineconfigurationV1alpha1 ().MachineOSBuilds ().List (ctx , metav1.ListOptions {})
175
+ if err != nil {
176
+ return false , err
177
+ }
178
+ for _ , m := range mosbList .Items {
179
+ if m .Spec .DesiredConfig .Name == mcpG .Spec .Configuration .Name {
180
+ mosb = m
181
+ mosbFound = true
182
+ break
183
+ }
184
+ }
185
+ if ! mosbFound {
186
+ return false , fmt .Errorf ("could not find mosb" )
187
+ }
188
+
189
+ // Get mosc
190
+ mosc , err := clientset .MachineconfigurationV1alpha1 ().MachineOSConfigs ().Get (ctx , moscG .ObjectMeta .Name , metav1.GetOptions {})
191
+ if err != nil {
192
+ return false , fmt .Errorf ("couldnt get mosc: %w" , err )
193
+ }
194
+
195
+ // Get Pool
196
+ pool , err := clientset .MachineconfigurationV1 ().MachineConfigPools ().Get (ctx , mcpG .ObjectMeta .Name , metav1.GetOptions {})
197
+ if err != nil {
198
+ return false , fmt .Errorf ("couldnt get pool: %w" , err )
199
+ }
200
+
201
+ // Get nodes
202
+ nodes , err := getNodesForPool (ctx , oc , pool )
203
+
204
+ // Ensure rollout
205
+ doneNodes := 0
206
+ for _ , node := range nodes .Items {
207
+ lns := commonstate .NewLayeredNodeState (& node )
208
+ if mosb .Spec .DesiredConfig .Name == pool .Spec .Configuration .Name && ctrlnode .IsNodeDoneAt (& node , pool , true ) && lns .IsCurrentImageEqualToBuild (mosc ){
209
+ doneNodes += 1
210
+ }
211
+ }
212
+ if doneNodes == len (nodes .Items ){
213
+ return true , nil
214
+ }
215
+ return false , nil
216
+ })
217
+ }
218
+
135
219
func waitForBuild (ctx context.Context , clientset * mcClient.Clientset , mcp * mcfgv1.MachineConfigPool ) error {
136
220
return wait .PollUntilContextCancel (ctx , time .Second , true , func (ctx context.Context ) (done bool , err error ) {
137
221
@@ -164,6 +248,7 @@ func waitForBuild(ctx context.Context, clientset *mcClient.Clientset, mcp *mcfgv
164
248
if state .IsBuildFailure () {
165
249
return false , fmt .Errorf ("build %s failed after %s" , mosb .Name , time .Since (start ))
166
250
}
251
+ break
167
252
}
168
253
}
169
254
return false , nil
0 commit comments