@@ -2116,6 +2116,97 @@ var _ = Describe("Reconcile", func() {
21162116 }
21172117 })
21182118
2119+ It ("labels BMH and DataImage for backup" , func () {
2120+ bmh := bmhInState (bmh_v1alpha1 .StateAvailable )
2121+ bmh .Spec .Online = true
2122+ bmh .Spec .ExternallyProvisioned = false
2123+ Expect (c .Create (ctx , bmh )).To (Succeed ())
2124+
2125+ clusterInstall .Spec .BareMetalHostRef = & v1alpha1.BareMetalHostReference {
2126+ Name : bmh .Name ,
2127+ Namespace : bmh .Namespace ,
2128+ }
2129+ Expect (c .Create (ctx , clusterInstall )).To (Succeed ())
2130+ clusterDeployment .Spec .ClusterName = "test"
2131+ clusterDeployment .Spec .BaseDomain = "example.com"
2132+ Expect (c .Create (ctx , clusterDeployment )).To (Succeed ())
2133+
2134+ // Create DataImage beforehand so it exists when backup labeling happens
2135+ dataImage := & bmh_v1alpha1.DataImage {
2136+ ObjectMeta : metav1.ObjectMeta {
2137+ Name : bmh .Name ,
2138+ Namespace : bmh .Namespace ,
2139+ },
2140+ Spec : bmh_v1alpha1.DataImageSpec {
2141+ URL : imageURL (),
2142+ },
2143+ }
2144+ Expect (c .Create (ctx , dataImage )).To (Succeed ())
2145+
2146+ key := types.NamespacedName {
2147+ Namespace : clusterInstallNamespace ,
2148+ Name : clusterInstallName ,
2149+ }
2150+ installerSuccess ()
2151+ res , err := r .Reconcile (ctx , ctrl.Request {NamespacedName : key })
2152+ Expect (err ).NotTo (HaveOccurred ())
2153+ Expect (res ).To (Equal (ctrl.Result {}))
2154+
2155+ // Verify BMH has backup label
2156+ bmhKey := types.NamespacedName {
2157+ Namespace : bmh .Namespace ,
2158+ Name : bmh .Name ,
2159+ }
2160+ testBMH := & bmh_v1alpha1.BareMetalHost {}
2161+ Expect (c .Get (ctx , bmhKey , testBMH )).To (Succeed ())
2162+ Expect (testBMH .GetLabels ()).To (HaveKeyWithValue (backupLabel , backupLabelValue ), "BMH %s/%s missing backup label" , testBMH .Namespace , testBMH .Name )
2163+
2164+ // Verify DataImage has backup label
2165+ testDataImage := & bmh_v1alpha1.DataImage {}
2166+ Expect (c .Get (ctx , bmhKey , testDataImage )).To (Succeed ())
2167+ Expect (testDataImage .GetLabels ()).To (HaveKeyWithValue (backupLabel , backupLabelValue ), "DataImage %s/%s missing backup label" , testDataImage .Namespace , testDataImage .Name )
2168+ })
2169+
2170+ It ("labels newly created DataImage for backup" , func () {
2171+ bmh := bmhInState (bmh_v1alpha1 .StateAvailable )
2172+ bmh .Spec .Online = true
2173+ bmh .Spec .ExternallyProvisioned = false
2174+ Expect (c .Create (ctx , bmh )).To (Succeed ())
2175+
2176+ clusterInstall .Spec .BareMetalHostRef = & v1alpha1.BareMetalHostReference {
2177+ Name : bmh .Name ,
2178+ Namespace : bmh .Namespace ,
2179+ }
2180+ Expect (c .Create (ctx , clusterInstall )).To (Succeed ())
2181+ clusterDeployment .Spec .ClusterName = "test"
2182+ clusterDeployment .Spec .BaseDomain = "example.com"
2183+ Expect (c .Create (ctx , clusterDeployment )).To (Succeed ())
2184+
2185+ key := types.NamespacedName {
2186+ Namespace : clusterInstallNamespace ,
2187+ Name : clusterInstallName ,
2188+ }
2189+ installerSuccess ()
2190+ // First reconcile creates the DataImage
2191+ res , err := r .Reconcile (ctx , ctrl.Request {NamespacedName : key })
2192+ Expect (err ).NotTo (HaveOccurred ())
2193+ Expect (res ).To (Equal (ctrl.Result {}))
2194+
2195+ // Verify BMH has backup label
2196+ bmhKey := types.NamespacedName {
2197+ Namespace : bmh .Namespace ,
2198+ Name : bmh .Name ,
2199+ }
2200+ testBMH := & bmh_v1alpha1.BareMetalHost {}
2201+ Expect (c .Get (ctx , bmhKey , testBMH )).To (Succeed ())
2202+ Expect (testBMH .GetLabels ()).To (HaveKeyWithValue (backupLabel , backupLabelValue ), "BMH %s/%s missing backup label" , testBMH .Namespace , testBMH .Name )
2203+
2204+ // Verify newly created DataImage has backup label
2205+ testDataImage := & bmh_v1alpha1.DataImage {}
2206+ Expect (c .Get (ctx , bmhKey , testDataImage )).To (Succeed ())
2207+ Expect (testDataImage .GetLabels ()).To (HaveKeyWithValue (backupLabel , backupLabelValue ), "DataImage %s/%s missing backup label" , testDataImage .Namespace , testDataImage .Name )
2208+ })
2209+
21192210 Context ("when the cluster identity secrets exist" , func () {
21202211 createSecret := func (name string , data map [string ][]byte ) {
21212212 s := corev1.Secret {
0 commit comments