Skip to content

Commit 04bc0af

Browse files
Revert "change logic"
This reverts commit db878ed.
1 parent 8160058 commit 04bc0af

2 files changed

Lines changed: 65 additions & 94 deletions

File tree

controllers/managedcloudprofile_controller.go

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -79,12 +79,8 @@ func (r *Reconciler) reconcileCloudProfile(ctx context.Context, log logr.Logger,
7979
return err
8080
}
8181
log.V(1).Info("controller reference set")
82-
totalVersionsBefore := 0
83-
for _, img := range cloudProfile.Spec.MachineImages {
84-
totalVersionsBefore += len(img.Versions)
85-
log.Info("before update - machine image summary", "image", img.Name, "versions_count", len(img.Versions))
86-
}
87-
log.Info("total machine image versions before update", "total_versions_before", totalVersionsBefore)
82+
cloudProfile.Spec = CloudProfileSpecToGardener(&mcp.Spec.CloudProfile)
83+
log.V(1).Info("converted ManagedCloudProfile spec to CloudProfileSpec", "machineImages", len(cloudProfile.Spec.MachineImages))
8884
errs := make([]error, 0)
8985
for _, updates := range mcp.Spec.MachineImageUpdates {
9086
log.V(1).Info("updating machine images from source", "imageName", updates.ImageName)
@@ -93,14 +89,6 @@ func (r *Reconciler) reconcileCloudProfile(ctx context.Context, log logr.Logger,
9389
errs = append(errs, updateErr)
9490
}
9591
}
96-
cloudProfile.Spec = CloudProfileSpecToGardener(&mcp.Spec.CloudProfile)
97-
totalVersionsAfter := 0
98-
for _, img := range cloudProfile.Spec.MachineImages {
99-
totalVersionsAfter += len(img.Versions)
100-
log.Info("after update - machine image summary", "image", img.Name, "versions_count", len(img.Versions))
101-
}
102-
log.Info("total machine image versions after update", "total_versions_after", totalVersionsAfter)
103-
10492
gardenerv1beta1.SetObjectDefaults_CloudProfile(&cloudProfile)
10593
log.V(1).Info("set CloudProfile defaults")
10694
return errors.Join(errs...)

controllers/managedcloudprofile_controller_test.go

Lines changed: 63 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -164,63 +164,63 @@ var _ = Describe("The ManagedCloudProfile reconciler", func() {
164164
Expect(k8sClient.Delete(ctx, &mcp)).To(Succeed())
165165
})
166166

167-
// It("invokes the image updater based on an image source", func(ctx SpecContext) {
168-
// var mcp v1alpha1.ManagedCloudProfile
169-
// mcp.Name = "test-oci"
170-
// usable := true
171-
// mcp.Spec.CloudProfile = v1alpha1.CloudProfileSpec{
172-
// Regions: []gardenerv1beta1.Region{{Name: "foo"}},
173-
// MachineTypes: []gardenerv1beta1.MachineType{
174-
// {
175-
// Name: "baz",
176-
// Architecture: &amd64,
177-
// Usable: &usable,
178-
// },
179-
// },
180-
// }
181-
// mcp.Spec.MachineImageUpdates = []v1alpha1.MachineImageUpdate{
182-
// {
183-
// Source: v1alpha1.MachineImageUpdateSource{
184-
// OCI: &v1alpha1.MachineImageUpdateSourceOCI{
185-
// Registry: registryAddr,
186-
// Repository: "repo",
187-
// Insecure: true,
188-
// },
189-
// },
190-
// ImageName: "the-image",
191-
// },
192-
// }
193-
// Expect(k8sClient.Create(ctx, &mcp)).To(Succeed())
194-
195-
// Eventually(func(g Gomega) v1alpha1.ReconcileStatus {
196-
// g.Expect(k8sClient.Get(ctx, client.ObjectKeyFromObject(&mcp), &mcp)).To(Succeed())
197-
// return mcp.Status.Status
198-
// }).Should(Equal(v1alpha1.SucceededReconcileStatus))
199-
// Expect(mcp.Status.Conditions).To(ContainElement(SatisfyAll(
200-
// HaveField("Type", controllers.CloudProfileAppliedConditionType),
201-
// HaveField("Status", metav1.ConditionTrue),
202-
// )))
203-
// var cloudProfile gardenerv1beta1.CloudProfile
204-
// cloudProfile.Name = mcp.Name
205-
// Eventually(func() error {
206-
// return k8sClient.Get(ctx, client.ObjectKeyFromObject(&cloudProfile), &cloudProfile)
207-
// }).Should(Succeed())
208-
209-
// Expect(cloudProfile.Spec.Regions).To(Equal(mcp.Spec.CloudProfile.Regions))
210-
// Expect(cloudProfile.Spec.MachineTypes).To(Equal(mcp.Spec.CloudProfile.MachineTypes))
211-
// mi := cloudProfile.Spec.MachineImages
212-
// Expect(mi).To(HaveLen(1))
213-
// Expect(mi[0].Name).To(Equal("the-image"))
214-
// vers := mi[0].Versions
215-
// Expect(vers).To(ContainElement(gardenerv1beta1.MachineImageVersion{ExpirableVersion: gardenerv1beta1.ExpirableVersion{Version: "1.0.0"}, Architectures: []string{"amd64"}, CRI: []gardenerv1beta1.CRI{{Name: "containerd"}}}))
216-
// Expect(vers).To(ContainElement(gardenerv1beta1.MachineImageVersion{ExpirableVersion: gardenerv1beta1.ExpirableVersion{Version: "1.0.1+abc"}, Architectures: []string{"amd64"}, CRI: []gardenerv1beta1.CRI{{Name: "containerd"}}}))
217-
218-
// Expect(k8sClient.Get(ctx, client.ObjectKeyFromObject(&mcp), &mcp)).To(Succeed())
219-
// Expect(mcp.Status.Status).To(Equal(v1alpha1.SucceededReconcileStatus))
220-
221-
// Expect(k8sClient.Delete(ctx, &mcp)).To(Succeed())
222-
// Expect(k8sClient.Delete(ctx, &cloudProfile)).To(Succeed())
223-
// })
167+
It("invokes the image updater based on an image source", func(ctx SpecContext) {
168+
var mcp v1alpha1.ManagedCloudProfile
169+
mcp.Name = "test-oci"
170+
usable := true
171+
mcp.Spec.CloudProfile = v1alpha1.CloudProfileSpec{
172+
Regions: []gardenerv1beta1.Region{{Name: "foo"}},
173+
MachineTypes: []gardenerv1beta1.MachineType{
174+
{
175+
Name: "baz",
176+
Architecture: &amd64,
177+
Usable: &usable,
178+
},
179+
},
180+
}
181+
mcp.Spec.MachineImageUpdates = []v1alpha1.MachineImageUpdate{
182+
{
183+
Source: v1alpha1.MachineImageUpdateSource{
184+
OCI: &v1alpha1.MachineImageUpdateSourceOCI{
185+
Registry: registryAddr,
186+
Repository: "repo",
187+
Insecure: true,
188+
},
189+
},
190+
ImageName: "the-image",
191+
},
192+
}
193+
Expect(k8sClient.Create(ctx, &mcp)).To(Succeed())
194+
195+
Eventually(func(g Gomega) v1alpha1.ReconcileStatus {
196+
g.Expect(k8sClient.Get(ctx, client.ObjectKeyFromObject(&mcp), &mcp)).To(Succeed())
197+
return mcp.Status.Status
198+
}).Should(Equal(v1alpha1.SucceededReconcileStatus))
199+
Expect(mcp.Status.Conditions).To(ContainElement(SatisfyAll(
200+
HaveField("Type", controllers.CloudProfileAppliedConditionType),
201+
HaveField("Status", metav1.ConditionTrue),
202+
)))
203+
var cloudProfile gardenerv1beta1.CloudProfile
204+
cloudProfile.Name = mcp.Name
205+
Eventually(func() error {
206+
return k8sClient.Get(ctx, client.ObjectKeyFromObject(&cloudProfile), &cloudProfile)
207+
}).Should(Succeed())
208+
209+
Expect(cloudProfile.Spec.Regions).To(Equal(mcp.Spec.CloudProfile.Regions))
210+
Expect(cloudProfile.Spec.MachineTypes).To(Equal(mcp.Spec.CloudProfile.MachineTypes))
211+
mi := cloudProfile.Spec.MachineImages
212+
Expect(mi).To(HaveLen(1))
213+
Expect(mi[0].Name).To(Equal("the-image"))
214+
vers := mi[0].Versions
215+
Expect(vers).To(ContainElement(gardenerv1beta1.MachineImageVersion{ExpirableVersion: gardenerv1beta1.ExpirableVersion{Version: "1.0.0"}, Architectures: []string{"amd64"}, CRI: []gardenerv1beta1.CRI{{Name: "containerd"}}}))
216+
Expect(vers).To(ContainElement(gardenerv1beta1.MachineImageVersion{ExpirableVersion: gardenerv1beta1.ExpirableVersion{Version: "1.0.1+abc"}, Architectures: []string{"amd64"}, CRI: []gardenerv1beta1.CRI{{Name: "containerd"}}}))
217+
218+
Expect(k8sClient.Get(ctx, client.ObjectKeyFromObject(&mcp), &mcp)).To(Succeed())
219+
Expect(mcp.Status.Status).To(Equal(v1alpha1.SucceededReconcileStatus))
220+
221+
Expect(k8sClient.Delete(ctx, &mcp)).To(Succeed())
222+
Expect(k8sClient.Delete(ctx, &cloudProfile)).To(Succeed())
223+
})
224224

225225
It("fetches a secret for the OCI source", func(ctx SpecContext) {
226226
var secret corev1.Secret
@@ -232,16 +232,9 @@ var _ = Describe("The ManagedCloudProfile reconciler", func() {
232232
var mcp v1alpha1.ManagedCloudProfile
233233
mcp.Name = "test-secret"
234234
mcp.Spec.CloudProfile = v1alpha1.CloudProfileSpec{
235-
Regions: []gardenerv1beta1.Region{{Name: "foo"}},
236-
MachineTypes: []gardenerv1beta1.MachineType{
237-
{Name: "baz"},
238-
},
239-
MachineImages: []gardenerv1beta1.MachineImage{{
240-
Name: "the-image",
241-
Versions: []gardenerv1beta1.MachineImageVersion{},
242-
}},
235+
Regions: []gardenerv1beta1.Region{{Name: "foo"}},
236+
MachineTypes: []gardenerv1beta1.MachineType{{Name: "baz"}},
243237
}
244-
245238
mcp.Spec.MachineImageUpdates = []v1alpha1.MachineImageUpdate{
246239
{
247240
Source: v1alpha1.MachineImageUpdateSource{
@@ -260,25 +253,21 @@ var _ = Describe("The ManagedCloudProfile reconciler", func() {
260253
ImageName: "the-image",
261254
},
262255
}
263-
264256
Expect(k8sClient.Create(ctx, &mcp)).To(Succeed())
265257

266258
Eventually(func(g Gomega) v1alpha1.ReconcileStatus {
267259
g.Expect(k8sClient.Get(ctx, client.ObjectKeyFromObject(&mcp), &mcp)).To(Succeed())
268260
return mcp.Status.Status
269-
}, "10s").Should(Equal(v1alpha1.SucceededReconcileStatus))
270-
261+
}).Should(Equal(v1alpha1.SucceededReconcileStatus))
271262
Expect(mcp.Status.Conditions).To(ContainElement(SatisfyAll(
272263
HaveField("Type", controllers.CloudProfileAppliedConditionType),
273264
HaveField("Status", metav1.ConditionTrue),
274265
)))
275-
276266
var cloudProfile gardenerv1beta1.CloudProfile
277267
cloudProfile.Name = mcp.Name
278268
Eventually(func() error {
279269
return k8sClient.Get(ctx, client.ObjectKeyFromObject(&cloudProfile), &cloudProfile)
280-
}, "10s").Should(Succeed())
281-
270+
}).Should(Succeed())
282271
Expect(cloudProfile.Spec.MachineImages).To(HaveLen(1))
283272

284273
Expect(k8sClient.Delete(ctx, &mcp)).To(Succeed())
@@ -292,12 +281,6 @@ var _ = Describe("The ManagedCloudProfile reconciler", func() {
292281
mcp.Spec.CloudProfile = v1alpha1.CloudProfileSpec{
293282
Regions: []gardenerv1beta1.Region{{Name: "foo"}},
294283
MachineTypes: []gardenerv1beta1.MachineType{{Name: "baz"}},
295-
MachineImages: []gardenerv1beta1.MachineImage{
296-
{
297-
Name: "gc-image",
298-
Versions: []gardenerv1beta1.MachineImageVersion{},
299-
},
300-
},
301284
}
302285
mcp.Spec.MachineImageUpdates = []v1alpha1.MachineImageUpdate{
303286
{
@@ -321,7 +304,7 @@ var _ = Describe("The ManagedCloudProfile reconciler", func() {
321304
Eventually(func(g Gomega) v1alpha1.ReconcileStatus {
322305
g.Expect(k8sClient.Get(ctx, client.ObjectKeyFromObject(&mcp), &mcp)).To(Succeed())
323306
return mcp.Status.Status
324-
}, "30s", "1s").Should(Equal(v1alpha1.SucceededReconcileStatus))
307+
}).Should(Equal(v1alpha1.SucceededReconcileStatus))
325308

326309
var cloudProfile gardenerv1beta1.CloudProfile
327310
cloudProfile.Name = mcp.Name
@@ -339,7 +322,7 @@ var _ = Describe("The ManagedCloudProfile reconciler", func() {
339322
}
340323
}
341324
return 0
342-
}, "60s", "2s").Should(Equal(0))
325+
}, "10s").Should(Equal(0))
343326

344327
Expect(k8sClient.Delete(ctx, &mcp)).To(Succeed())
345328
})

0 commit comments

Comments
 (0)