Skip to content

Commit 151424a

Browse files
test fix
1 parent 7a56cf0 commit 151424a

File tree

2 files changed

+51
-10
lines changed

2 files changed

+51
-10
lines changed

pkg/controller/common/layered_node_state.go

Lines changed: 48 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,13 @@ func NewLayeredNodeState(n *corev1.Node) *LayeredNodeState {
3030
// determined by the pool. If in layered mode, the image annotations are also checked
3131
// checked against the OCL objects.
3232
func (l *LayeredNodeState) IsDone(mcp *mcfgv1.MachineConfigPool, layered bool, mosc *mcfgv1.MachineOSConfig, mosb *mcfgv1.MachineOSBuild) bool {
33-
if layered {
34-
return l.IsNodeDone() && l.IsDesiredMachineConfigEqualToPool(mcp) && l.IsDesiredEqualToBuild(mosc, mosb)
35-
}
36-
return l.IsNodeDone() && l.IsDesiredMachineConfigEqualToPool(mcp)
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)
3740
}
3841

3942
// The original behavior of getUnavailableMachines is: getUnavailableMachines
@@ -67,19 +70,28 @@ func (l *LayeredNodeState) IsUnavailableForUpdate() bool {
6770
// node's desired image annotation and compares the MachineConfig specified by the
6871
// MachineOSBuild to the one specified by the node's desired MachineConfig annotation.
6972
func (l *LayeredNodeState) IsDesiredEqualToBuild(mosc *mcfgv1.MachineOSConfig, mosb *mcfgv1.MachineOSBuild) bool {
70-
return (mosc != nil && l.isDesiredImageEqualToMachineOSConfig(mosc)) && (mosb != nil && l.isDesiredMachineConfigEqualToBuild(mosb))
73+
klog.Errorf("in IsDesiredEqualToBuild")
74+
return l.isDesiredImageEqualToMachineOSConfig(mosc) && l.isDesiredMachineConfigEqualToBuild(mosb)
7175
}
7276

7377
// Compares the desired image annotation on the node against the CurrentImagePullSpec
7478
// specified by the MachineOSConfig object.
7579
func (l *LayeredNodeState) isDesiredImageEqualToMachineOSConfig(mosc *mcfgv1.MachineOSConfig) bool {
80+
klog.Errorf("in isDesiredImageEqualToMachineOSConfig")
7681
return l.isImageAnnotationEqualToMachineOSConfig(daemonconsts.DesiredImageAnnotationKey, mosc)
7782
}
7883

7984
// Compares the MachineConfig specified by the MachineConfigPool to the MachineConfig
8085
// specified by the node's desired MachineConfig annotation.
8186
func (l *LayeredNodeState) isDesiredMachineConfigEqualToBuild(mosb *mcfgv1.MachineOSBuild) bool {
82-
return l.node.Annotations[daemonconsts.DesiredMachineConfigAnnotationKey] == mosb.Spec.MachineConfig.Name
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
8395

8496
}
8597

@@ -92,7 +104,9 @@ func (l *LayeredNodeState) IsCurrentMachineConfigEqualToPool(mcp *mcfgv1.Machine
92104
// Compares the MachineConfig specified by the MachineConfigPool to the one
93105
// specified by the node's desired MachineConfig annotation.
94106
func (l *LayeredNodeState) IsDesiredMachineConfigEqualToPool(mcp *mcfgv1.MachineConfigPool) bool {
95-
return l.node.Annotations[daemonconsts.DesiredMachineConfigAnnotationKey] == mcp.Spec.Configuration.Name
107+
ret := l.node.Annotations[daemonconsts.DesiredMachineConfigAnnotationKey] == mcp.Spec.Configuration.Name
108+
klog.Errorf("in IsDesiredMachineConfigEqualToPool, returning %v", ret)
109+
return ret
96110
}
97111

98112
// Checks if both the current and desired image annotation are present on the node.
@@ -113,23 +127,42 @@ func (l *LayeredNodeState) IsCurrentImageAnnotationPresentOnNode() bool {
113127
// Compares the CurrentImagePullSpec specified by the MachineOSConfig object against the
114128
// image specified by the annotation passed in.
115129
func (l *LayeredNodeState) isImageAnnotationEqualToMachineOSConfig(anno string, mosc *mcfgv1.MachineOSConfig) bool {
116-
moscs := NewMachineOSConfigState(mosc)
130+
moscImage := ""
117131

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+
// }
137+
138+
// Get the image annotation from the node
118139
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+
// }
119147

120148
// If a layered node does not have an image annotation and has a valid MOSC, then the image is being built
121149
if val == "" || !ok {
150+
klog.Errorf("in isImageAnnotationEqualToMachineOSConfig returning false cause val == '' or !ok")
122151
return false
123152
}
124153

154+
// Get the MachineOSConfigState
155+
moscs := NewMachineOSConfigState(mosc)
156+
klog.Errorf("in isImageAnnotationEqualToMachineOSConfig with moscs")
157+
125158
if moscs.HasOSImage() {
126159
// If the MOSC image has an image, the image annotation on the node can be directly compared.
127-
return moscs.GetOSImage() == val
160+
moscImage = moscs.GetOSImage()
128161
}
129162

130163
// If the MOSC does not have an image, but the node has an older image annotation, the image is still likely
131164
// being built.
132-
return false
165+
return moscImage == val
133166
}
134167

135168
// Sets the desired MachineConfig annotations from the MachineConfigPool.
@@ -175,21 +208,26 @@ func (l *LayeredNodeState) Node() *corev1.Node {
175208
// isNodeDone returns true if the current == desired and the MCD has marked done.
176209
func (l *LayeredNodeState) IsNodeDone() bool {
177210
if l.node.Annotations == nil {
211+
klog.Error("in IsNodeDone, returning false, 1")
178212
return false
179213
}
180214

181215
if !l.isNodeConfigDone() {
216+
klog.Error("in IsNodeDone, returning false, 2")
182217
return false
183218
}
184219

185220
if !l.isNodeImageDone() {
221+
klog.Error("in IsNodeDone, returning false, 3")
186222
return false
187223
}
188224

189225
if !l.isNodeMCDState(daemonconsts.MachineConfigDaemonStateDone) {
226+
klog.Error("in IsNodeDone, returning false, 4")
190227
return false
191228
}
192229

230+
klog.Error("in IsNodeDone, returning true")
193231
return true
194232
}
195233

pkg/controller/node/status.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,7 @@ func (ctrl *Controller) calculateStatus(mcs []*mcfgv1.MachineConfigNode, cconfig
206206

207207
// this is # 1 priority, get the upgrade states actually reporting
208208
if degradedMachineCount+readyMachineCount+unavailableMachineCount+updatingMachineCount != int32(len(nodes)) {
209+
klog.Errorf("In degraded + ready + unavailable + updating != nodes...")
209210

210211
updatedMachines = getUpdatedMachines(pool, nodes, mosc, mosb, isLayeredPool)
211212
updatedMachineCount = int32(len(updatedMachines))
@@ -218,6 +219,8 @@ func (ctrl *Controller) calculateStatus(mcs []*mcfgv1.MachineConfigNode, cconfig
218219

219220
degradedMachines = getDegradedMachines(nodes)
220221
degradedMachineCount = int32(len(degradedMachines))
222+
} else {
223+
klog.Errorf("In degraded + ready + unavailable + updating == nodes... Not where we want to be.")
221224
}
222225

223226
for _, n := range degradedMachines {

0 commit comments

Comments
 (0)