pkg/operator: consistently check MC fragments version
@@ -222,31 +222,30 @@ func isMachineConfigPoolConfigurationValid(pool *mcfgv1.MachineConfigPool, versi
if len(pool.Status.Configuration.Source) == 0 {
return fmt.Errorf("list of MachineConfigs that were used to generate configuration for pool %s is empty", pool.GetName())
}
-
- type configValidationTask struct {
- name string
- versionCheckRequired bool
- }
- // we check that all the machineconfigs (generated, and those that were used to create generated) were generated by correct version of the controller.
- tasks := []configValidationTask{{
- name: pool.Status.Configuration.Name,
- versionCheckRequired: true,
- }}
- for _, ref := range pool.Status.Configuration.Source {
- tasks = append(tasks, configValidationTask{name: ref.Name, versionCheckRequired: false})
- }
- for _, t := range tasks {
- mc, err := machineConfigGetter(t.name)
+ mcs := []string{pool.Status.Configuration.Name}
+ for _, fragment := range pool.Status.Configuration.Source {
+ mcs = append(mcs, fragment.Name)
+ }
+ for _, mcName := range mcs {
+ mc, err := machineConfigGetter(mcName)
if err != nil {
return err
}
+ // We check that all the machineconfigs (generated, and those that were used to create generated,
+ // not the user provided ones that do not have a version) were generated by correct version of the controller.
v, ok := mc.Annotations[ctrlcommon.GeneratedByControllerVersionAnnotationKey]
- if t.versionCheckRequired && !ok {
- return fmt.Errorf("%s must be created by controller version %s", t.name, version)
- }
+ // The generated machineconfig from fragments for the pool MUST have a version and the annotation.
+ // The bootstrapped MCs fragments do have this annotation but we don't fail (???) if they don't have
+ // the annotation for some reason.
+ if !ok && pool.Status.Configuration.Name == mcName {
+ return fmt.Errorf("%s must be created by controller version %s", mcName, version)
+ }
+ // user provided MC fragments do not have the annotation, so we just skip version check there
+ // The check below is just for: 1) the generated MC for the pool, 2) the bootstrapped fragments
+ // that do have this annotation with a version.
if ok && v != version {
- return fmt.Errorf("controller version mismatch for %s expected %s has %s", t.name, version, v)
+ return fmt.Errorf("controller version mismatch for %s expected %s has %s", mcName, version, v)
}
}
return nil
