Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change workerpool hash generation #619

Merged
merged 2 commits into from
Aug 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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