@@ -26,17 +26,16 @@ func NewLayeredNodeState(n *corev1.Node) *LayeredNodeState {
26
26
return & LayeredNodeState {node : n }
27
27
}
28
28
29
- // Checks if the node is done "working" and that the node is targeting is MachineConfig
30
- // determined by the pool. If in layered mode, the image annotations are also checked
31
- // checked against the OCL objects.
29
+ // Checks if the node is done "working." For a node in both layered and non-layered MCPs, the
30
+ // node's state annotation must be "Done" and it must be targeting the correct MachineConfig. For
31
+ // `layered` MCPs, the node's desired image annotation must match the image defined in the
32
+ // MachineOsConfig and the desired MachineConfig must match the config version defined in the
33
+ // MachineOSBuild. For non-layered MCPs, the node must not have a desired image annotation value.
32
34
func (l * LayeredNodeState ) IsDone (mcp * mcfgv1.MachineConfigPool , layered bool , mosc * mcfgv1.MachineOSConfig , mosb * mcfgv1.MachineOSBuild ) bool {
33
- // if layered {
34
- // klog.Errorf("in IsDone and layered")
35
- // return l.IsNodeDone() && l.IsDesiredMachineConfigEqualToPool(mcp) && l.IsDesiredEqualToBuild(mosc, mosb)
36
- // }
37
- // klog.Errorf("in IsDone and NOT layered")
38
- // return l.IsNodeDone() && l.IsDesiredMachineConfigEqualToPool(mcp)
39
- return l .IsNodeDone () && l .IsDesiredMachineConfigEqualToPool (mcp ) && l .IsDesiredEqualToBuild (mosc , mosb )
35
+ if layered {
36
+ return l .IsNodeDone () && l .IsDesiredMachineConfigEqualToPool (mcp ) && l .IsDesiredEqualToBuild (mosc , mosb )
37
+ }
38
+ return l .IsNodeDone () && l .IsDesiredMachineConfigEqualToPool (mcp ) && ! l .IsDesiredImageAnnotationPresentOnNode ()
40
39
}
41
40
42
41
// The original behavior of getUnavailableMachines is: getUnavailableMachines
@@ -70,28 +69,19 @@ func (l *LayeredNodeState) IsUnavailableForUpdate() bool {
70
69
// node's desired image annotation and compares the MachineConfig specified by the
71
70
// MachineOSBuild to the one specified by the node's desired MachineConfig annotation.
72
71
func (l * LayeredNodeState ) IsDesiredEqualToBuild (mosc * mcfgv1.MachineOSConfig , mosb * mcfgv1.MachineOSBuild ) bool {
73
- klog .Errorf ("in IsDesiredEqualToBuild" )
74
- return l .isDesiredImageEqualToMachineOSConfig (mosc ) && l .isDesiredMachineConfigEqualToBuild (mosb )
72
+ return (mosc != nil && l .isDesiredImageEqualToMachineOSConfig (mosc )) && (mosb != nil && l .isDesiredMachineConfigEqualToBuild (mosb ))
75
73
}
76
74
77
75
// Compares the desired image annotation on the node against the CurrentImagePullSpec
78
76
// specified by the MachineOSConfig object.
79
77
func (l * LayeredNodeState ) isDesiredImageEqualToMachineOSConfig (mosc * mcfgv1.MachineOSConfig ) bool {
80
- klog .Errorf ("in isDesiredImageEqualToMachineOSConfig" )
81
78
return l .isImageAnnotationEqualToMachineOSConfig (daemonconsts .DesiredImageAnnotationKey , mosc )
82
79
}
83
80
84
81
// Compares the MachineConfig specified by the MachineConfigPool to the MachineConfig
85
82
// specified by the node's desired MachineConfig annotation.
86
83
func (l * LayeredNodeState ) isDesiredMachineConfigEqualToBuild (mosb * mcfgv1.MachineOSBuild ) bool {
87
- mosbName := ""
88
- // Handle case when MOSB is nil (image mode is being disabled)
89
- if mosb != nil {
90
- // TODO: check if this comes back as nil or empty string
91
- mosbName = mosb .Spec .MachineConfig .Name
92
- }
93
-
94
- return l .node .Annotations [daemonconsts .DesiredMachineConfigAnnotationKey ] == mosbName
84
+ return l .node .Annotations [daemonconsts .DesiredMachineConfigAnnotationKey ] == mosb .Spec .MachineConfig .Name
95
85
96
86
}
97
87
@@ -104,9 +94,7 @@ func (l *LayeredNodeState) IsCurrentMachineConfigEqualToPool(mcp *mcfgv1.Machine
104
94
// Compares the MachineConfig specified by the MachineConfigPool to the one
105
95
// specified by the node's desired MachineConfig annotation.
106
96
func (l * LayeredNodeState ) IsDesiredMachineConfigEqualToPool (mcp * mcfgv1.MachineConfigPool ) bool {
107
- ret := l .node .Annotations [daemonconsts .DesiredMachineConfigAnnotationKey ] == mcp .Spec .Configuration .Name
108
- klog .Errorf ("in IsDesiredMachineConfigEqualToPool, returning %v" , ret )
109
- return ret
97
+ return l .node .Annotations [daemonconsts .DesiredMachineConfigAnnotationKey ] == mcp .Spec .Configuration .Name
110
98
}
111
99
112
100
// Checks if both the current and desired image annotation are present on the node.
@@ -127,42 +115,23 @@ func (l *LayeredNodeState) IsCurrentImageAnnotationPresentOnNode() bool {
127
115
// Compares the CurrentImagePullSpec specified by the MachineOSConfig object against the
128
116
// image specified by the annotation passed in.
129
117
func (l * LayeredNodeState ) isImageAnnotationEqualToMachineOSConfig (anno string , mosc * mcfgv1.MachineOSConfig ) bool {
130
- moscImage := ""
131
-
132
- // // Handle case when MOSC is nil (image mode is being disabled)
133
- // if mosc != nil {
134
- // // TOOD: check if this comes back as nil or empty string
135
- // return moscName =
136
- // }
118
+ moscs := NewMachineOSConfigState (mosc )
137
119
138
- // Get the image annotation from the node
139
120
val , ok := l .node .Annotations [anno ]
140
- klog .Errorf ("in isImageAnnotationEqualToMachineOSConfig, val: %v, ok: %v" , val , ok )
141
-
142
- // // Handle case when MOSC is nil (image mode is being disabled)
143
- // if mosc == nil {
144
- // // TOOD: check if this comes back as nil or empty string
145
- // return val == ""
146
- // }
147
121
148
122
// If a layered node does not have an image annotation and has a valid MOSC, then the image is being built
149
123
if val == "" || ! ok {
150
- klog .Errorf ("in isImageAnnotationEqualToMachineOSConfig returning false cause val == '' or !ok" )
151
124
return false
152
125
}
153
126
154
- // Get the MachineOSConfigState
155
- moscs := NewMachineOSConfigState (mosc )
156
- klog .Errorf ("in isImageAnnotationEqualToMachineOSConfig with moscs" )
157
-
158
127
if moscs .HasOSImage () {
159
128
// If the MOSC image has an image, the image annotation on the node can be directly compared.
160
- moscImage = moscs .GetOSImage ()
129
+ return moscs .GetOSImage () == val
161
130
}
162
131
163
132
// If the MOSC does not have an image, but the node has an older image annotation, the image is still likely
164
133
// being built.
165
- return moscImage == val
134
+ return false
166
135
}
167
136
168
137
// Sets the desired MachineConfig annotations from the MachineConfigPool.
@@ -208,26 +177,21 @@ func (l *LayeredNodeState) Node() *corev1.Node {
208
177
// isNodeDone returns true if the current == desired and the MCD has marked done.
209
178
func (l * LayeredNodeState ) IsNodeDone () bool {
210
179
if l .node .Annotations == nil {
211
- klog .Error ("in IsNodeDone, returning false, 1" )
212
180
return false
213
181
}
214
182
215
183
if ! l .isNodeConfigDone () {
216
- klog .Error ("in IsNodeDone, returning false, 2" )
217
184
return false
218
185
}
219
186
220
187
if ! l .isNodeImageDone () {
221
- klog .Error ("in IsNodeDone, returning false, 3" )
222
188
return false
223
189
}
224
190
225
191
if ! l .isNodeMCDState (daemonconsts .MachineConfigDaemonStateDone ) {
226
- klog .Error ("in IsNodeDone, returning false, 4" )
227
192
return false
228
193
}
229
194
230
- klog .Error ("in IsNodeDone, returning true" )
231
195
return true
232
196
}
233
197
0 commit comments