Skip to content

Commit

Permalink
fix machine image maintenance for shoots with multiple worker pools
Browse files Browse the repository at this point in the history
```improvement operator
Fixes a bug in the maintenance controller that could lead to machine images to not be updated if the Shoot has multiple worker pools.
```
  • Loading branch information
danielfoehrKn authored and vpnachev committed Jul 31, 2020
1 parent 3bf0b03 commit 715e5da
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 3 deletions.
Expand Up @@ -318,8 +318,10 @@ func hasMaintainNowAnnotation(shoot *gardencorev1beta1.Shoot) bool {

// MaintainMachineImages determines if a shoots machine images have to be maintained and in case returns the target images
func MaintainMachineImages(logger *logrus.Entry, shoot *gardencorev1beta1.Shoot, cloudProfile *gardencorev1beta1.CloudProfile) (updatedMachineImages []*gardencorev1beta1.ShootMachineImage, reasons []string, error error) {
var shootMachineImagesForUpdate []*gardencorev1beta1.ShootMachineImage
var reasonsForUpdate []string
var (
shootMachineImagesForUpdate []*gardencorev1beta1.ShootMachineImage
reasonsForUpdate []string
)
for _, worker := range shoot.Spec.Provider.Workers {
workerImage := worker.Machine.Image
machineImageFromCloudProfile, err := determineMachineImage(cloudProfile, workerImage)
Expand All @@ -333,14 +335,17 @@ func MaintainMachineImages(logger *logrus.Entry, shoot *gardencorev1beta1.Shoot,
}

if !shouldBeUpdated {
return nil, nil, nil
continue
}

message := fmt.Sprintf("image of worker-pool '%s' from '%s' version '%s' to version '%s'. Reason: %s", worker.Name, workerImage.Name, *workerImage.Version, *updatedMachineImage.Version, *reason)
reasonsForUpdate = append(reasonsForUpdate, message)
logger.Debugf("[SHOOT MAINTENANCE] Updating %s", message)
shootMachineImagesForUpdate = append(shootMachineImagesForUpdate, updatedMachineImage)
}
if len(shootMachineImagesForUpdate) == 0 {
return nil, nil, nil
}
return shootMachineImagesForUpdate, reasonsForUpdate, nil
}

Expand Down
Expand Up @@ -172,6 +172,31 @@ var _ = Describe("Shoot Maintenance", func() {
Expect(workerImages[0].Version).To(PointTo(Equal(cloudProfile.Spec.MachineImages[0].Versions[1].Version)))
})

It("should determine that the shoot worker machine images must be maintained - multiple worker pools", func() {
cloudProfile.Spec.MachineImages = append(cloudProfile.Spec.MachineImages, gardencorev1beta1.MachineImage{
Name: "gardenlinux",
Versions: []gardencorev1beta1.ExpirableVersion{
{Version: "1.0.0"},
},
})

otherWorker := gardencorev1beta1.Worker{
Name: "cpu-glinux",
Machine: gardencorev1beta1.Machine{Image: &gardencorev1beta1.ShootMachineImage{
Name: "gardenlinux",
Version: pointer.StringPtr("1.0.0"),
}},
}

shoot.Spec.Provider.Workers = append(shoot.Spec.Provider.Workers, otherWorker)
workerImages, _, err := MaintainMachineImages(testlogger, shoot, cloudProfile)

Expect(err).NotTo(HaveOccurred())
Expect(len(workerImages)).NotTo(Equal(0))
Expect(workerImages[0].Name).To(Equal(cloudProfile.Spec.MachineImages[0].Name))
Expect(workerImages[0].Version).To(PointTo(Equal(cloudProfile.Spec.MachineImages[0].Versions[1].Version)))
})

It("should update to latest non-preview version - MaintenanceAutoUpdate set to true", func() {
highestPreviewVersion := gardencorev1beta1.ExpirableVersion{
Version: "1.1.2",
Expand Down

0 comments on commit 715e5da

Please sign in to comment.