Skip to content

Commit

Permalink
Change workerpool hash generation (#619)
Browse files Browse the repository at this point in the history
* change workpool hash generation

* Modify test case to pass additional data for workpool hash generation
  • Loading branch information
kasabe28 authored Aug 30, 2024
1 parent 360f607 commit 9c2e09b
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 10 deletions.
25 changes: 24 additions & 1 deletion pkg/controller/worker/machines.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"context"
"encoding/json"
"fmt"
"strconv"

"github.com/gardener/gardener/extensions/pkg/controller/worker"
genericworkeractuator "github.com/gardener/gardener/extensions/pkg/controller/worker/genericactuator"
Expand Down Expand Up @@ -190,5 +191,27 @@ func (w *workerDelegate) generateMachineClassAndSecrets() ([]*machinecontrollerv

func (w *workerDelegate) generateHashForWorkerPool(pool v1alpha1.WorkerPool) (string, error) {
// Generate the worker pool hash.
return worker.WorkerPoolHash(pool, w.cluster, nil, nil)
return worker.WorkerPoolHash(pool, w.cluster, computeAdditionalHashDataV1(pool), nil)
}

func computeAdditionalHashDataV1(pool v1alpha1.WorkerPool) []string {
var additionalData []string

if pool.Volume != nil && pool.Volume.Encrypted != nil {
additionalData = append(additionalData, strconv.FormatBool(*pool.Volume.Encrypted))
}

for _, dv := range pool.DataVolumes {
additionalData = append(additionalData, dv.Name, dv.Size)

if dv.Type != nil {
additionalData = append(additionalData, *dv.Type)
}

if dv.Encrypted != nil {
additionalData = append(additionalData, strconv.FormatBool(*dv.Encrypted))
}
}

return additionalData
}
8 changes: 5 additions & 3 deletions pkg/controller/worker/machines_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package worker
import (
"encoding/json"
"fmt"
"strconv"

"github.com/gardener/gardener/extensions/pkg/controller/worker"
genericworkeractuator "github.com/gardener/gardener/extensions/pkg/controller/worker/genericactuator"
Expand Down Expand Up @@ -53,8 +54,8 @@ var _ = Describe("Machines", func() {
err = workerDelegate.DeployMachineClasses(ctx)
Expect(err).NotTo(HaveOccurred())

// TODO: Fix machine pool hashing
workerPoolHash, err := worker.WorkerPoolHash(pool, testCluster, nil, nil)
additionalData := []string{strconv.FormatBool(volumeEncrypted), datVolumeName, volumeSize, volumeType, strconv.FormatBool(volumeEncrypted)}
workerPoolHash, err := worker.WorkerPoolHash(pool, testCluster, additionalData, nil)
Expect(err).NotTo(HaveOccurred())

By("ensuring that the machine class for each pool has been deployed")
Expand Down Expand Up @@ -120,7 +121,8 @@ var _ = Describe("Machines", func() {

It("should generate the machine deployments", func(ctx SpecContext) {
By("creating a worker delegate")
workerPoolHash, err := worker.WorkerPoolHash(pool, testCluster, nil, nil)
additionalData := []string{strconv.FormatBool(volumeEncrypted), datVolumeName, volumeSize, volumeType, strconv.FormatBool(volumeEncrypted)}
workerPoolHash, err := worker.WorkerPoolHash(pool, testCluster, additionalData, nil)
Expect(err).NotTo(HaveOccurred())
var (
deploymentName1 = fmt.Sprintf("%s-%s-z%d", w.Namespace, pool.Name, 1)
Expand Down
26 changes: 20 additions & 6 deletions pkg/controller/worker/suite_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,14 @@ var _ = BeforeSuite(func() {
komega.SetClient(k8sClient)
})

var (
volumeName = "test-volume"
volumeSize = "10Gi"
volumeType = "fast"
volumeEncrypted = true
datVolumeName = "volume-1"
)

func SetupTest() (*corev1.Namespace, *gardener.ChartApplier) {
var (
chartApplier gardener.ChartApplier
Expand All @@ -139,9 +147,6 @@ func SetupTest() (*corev1.Namespace, *gardener.ChartApplier) {
chartApplier, err = gardener.NewChartApplierForConfig(cfg)
Expect(err).NotTo(HaveOccurred())

volumeName := "test-volume"
volumeType := "fast"

// define test resources
pool = gardenerextensionv1alpha1.WorkerPool{
MachineType: "foo",
Expand All @@ -158,9 +163,18 @@ func SetupTest() (*corev1.Namespace, *gardener.ChartApplier) {
Name: "pool",
UserData: []byte("some-data"),
Volume: &gardenerextensionv1alpha1.Volume{
Name: &volumeName,
Type: &volumeType,
Size: "10Gi",
Name: &volumeName,
Type: &volumeType,
Size: volumeSize,
Encrypted: &volumeEncrypted,
},
DataVolumes: []gardenerextensionv1alpha1.DataVolume{
{
Name: datVolumeName,
Type: &volumeType,
Size: volumeSize,
Encrypted: &volumeEncrypted,
},
},
Zones: []string{"zone1", "zone2"},
Architecture: ptr.To[string]("amd64"),
Expand Down

0 comments on commit 9c2e09b

Please sign in to comment.