@@ -91,28 +91,31 @@ type imagePullSecret struct {
9191}
9292
9393const (
94- detachedAnnotation = "baremetalhost.metal3.io/detached"
95- detachedAnnotationValue = "imageclusterinstall-controller"
96- inspectAnnotation = "inspect.metal3.io"
97- rebootAnnotation = "reboot.metal3.io"
98- rebootAnnotationValue = ""
99- ibioManagedBMH = "image-based-install-managed"
100- ClusterConfigDir = "cluster-configuration"
101- extraManifestsDir = "extra-manifests"
102- nmstateSecretKey = "nmstate"
103- clusterInstallFinalizerName = "imageclusterinstall." + v1alpha1 .Group + "/deprovision"
104- caBundleFileName = "tls-ca-bundle.pem"
105- imageBasedInstallInvoker = "image-based-install"
106- invokerCMFileName = "invoker-cm.yaml"
107- installTimeoutAnnotation = "imageclusterinstall." + v1alpha1 .Group + "/install-timeout"
108- backupLabel = "cluster.open-cluster-management.io/backup"
109- backupLabelValue = "true"
110- imageBasedConfigFilename = "image-based-config.yaml"
111- installConfigFilename = "install-config.yaml"
112- authDir = "auth"
113- kubeAdminFile = "kubeadmin-password"
114- FilesDir = "files"
115- IsoName = "imagebasedconfig.iso"
94+ detachedAnnotation = "baremetalhost.metal3.io/detached"
95+ detachedAnnotationValue = "imageclusterinstall-controller"
96+ inspectAnnotation = "inspect.metal3.io"
97+ rebootAnnotation = "reboot.metal3.io"
98+ rebootAnnotationValue = ""
99+ ibioManagedBMH = "image-based-install-managed"
100+ ClusterConfigDir = "cluster-configuration"
101+ extraManifestsDir = "extra-manifests"
102+ nmstateSecretKey = "nmstate"
103+ clusterInstallFinalizerName = "imageclusterinstall." + v1alpha1 .Group + "/deprovision"
104+ caBundleFileName = "tls-ca-bundle.pem"
105+ imageBasedInstallInvoker = "image-based-install"
106+ invokerCMFileName = "invoker-cm.yaml"
107+ installTimeoutAnnotation = "imageclusterinstall." + v1alpha1 .Group + "/install-timeout"
108+ backupLabel = "cluster.open-cluster-management.io/backup"
109+ backupLabelValue = "true"
110+ imageBasedConfigFilename = "image-based-config.yaml"
111+ installConfigFilename = "install-config.yaml"
112+ authDir = "auth"
113+ kubeAdminFile = "kubeadmin-password"
114+ FilesDir = "files"
115+ IsoName = "imagebasedconfig.iso"
116+ restoreStatusAnnotation = "velero.io/restore-status"
117+ restoreStatusAnnotationValue = "true"
118+ restoreSourceLabel = "velero.io/restore-name"
116119)
117120
118121//+kubebuilder:rbac:groups="",resources=secrets,verbs=get;list;watch;create;update;patch;delete
@@ -164,6 +167,16 @@ func (r *ImageClusterInstallReconciler) Reconcile(ctx context.Context, req ctrl.
164167 log .Info ("Running reconcile for ici with bootTime set" )
165168 }
166169
170+ if iciIsBeingRestored (ici ) {
171+ log .Info ("Waiting for status restore" )
172+ return ctrl.Result {}, nil
173+ }
174+
175+ if err := r .ensureRestoreStatusAnnotation (ctx , ici ); err != nil {
176+ log .Errorf ("Failed to ensure restore status annotation: %s" , err )
177+ return ctrl.Result {}, err
178+ }
179+
167180 if err := r .initializeConditions (ctx , ici ); err != nil {
168181 log .Errorf ("Failed to initialize conditions: %s" , err )
169182 return ctrl.Result {}, err
@@ -1457,3 +1470,21 @@ func verifyIsoAndAuthExists(clusterConfigPath string) bool {
14571470
14581471 return true
14591472}
1473+
1474+ // iciIsBeingRestored returns true if the status is completely empty and the velero restore source label is present
1475+ func iciIsBeingRestored (ici * v1alpha1.ImageClusterInstall ) bool {
1476+ _ , hasLabel := ici .ObjectMeta .Labels [restoreSourceLabel ]
1477+ return hasLabel &&
1478+ len (ici .Status .Conditions ) == 0 &&
1479+ ici .Status .InstallRestarts == 0 &&
1480+ ici .Status .BareMetalHostRef == nil &&
1481+ ici .Status .BootTime .IsZero ()
1482+ }
1483+
1484+ func (r * ImageClusterInstallReconciler ) ensureRestoreStatusAnnotation (ctx context.Context , ici * v1alpha1.ImageClusterInstall ) error {
1485+ patch := client .MergeFrom (ici .DeepCopy ())
1486+ if ! setAnnotationIfNotExists (& ici .ObjectMeta , restoreStatusAnnotation , restoreStatusAnnotationValue ) {
1487+ return nil
1488+ }
1489+ return r .Patch (ctx , ici , patch )
1490+ }
0 commit comments