diff --git a/charts/internal/machineclass/templates/machineclass.yaml b/charts/internal/machineclass/templates/machineclass.yaml index a00fb04b8..55cb7dc98 100644 --- a/charts/internal/machineclass/templates/machineclass.yaml +++ b/charts/internal/machineclass/templates/machineclass.yaml @@ -17,6 +17,9 @@ kind: MachineClass metadata: name: {{ $machineClass.name }} namespace: {{ $.Release.Namespace }} +credentialsSecretRef: + name: {{ $machineClass.credentialsSecretRef.name }} + namespace: {{ $machineClass.credentialsSecretRef.namespace }} providerSpec: cluster: {{ $machineClass.cluster }} zone: {{ $machineClass.zone }} diff --git a/charts/internal/machineclass/values.yaml b/charts/internal/machineclass/values.yaml index b4fde7a55..28a11631f 100644 --- a/charts/internal/machineclass/values.yaml +++ b/charts/internal/machineclass/values.yaml @@ -8,6 +8,9 @@ machineClasses: placementGroupID: "" networkName: test-namespace-workers floatingPoolName: MY-FLOATING-POOL + credentialsSecretRef: + name: cloudprovider + namespace: shoot-namespace secret: hcloudToken: base64token userData: IyEvYmluL2Jhc2gKCmVjaG8gImhlbGxvIHdvcmxkIgo= diff --git a/pkg/controller/worker/machines.go b/pkg/controller/worker/machines.go index c90e2e147..22e46485e 100644 --- a/pkg/controller/worker/machines.go +++ b/pkg/controller/worker/machines.go @@ -180,6 +180,10 @@ func (w *workerDelegate) generateMachineConfig(ctx context.Context) error { "mcm.gardener.cloud/cluster": w.worker.Namespace, "mcm.gardener.cloud/role": "node", }, + "credentialsSecretRef": map[string]interface{}{ + "name": w.worker.Spec.SecretRef.Name, + "namespace": w.worker.Spec.SecretRef.Namespace, + }, "secret": secretMap, } @@ -199,7 +203,7 @@ func (w *workerDelegate) generateMachineConfig(ctx context.Context) error { } deploymentName := fmt.Sprintf("%s-%s-%s", w.worker.Namespace, pool.Name, zone) - className := fmt.Sprintf("%s-%s", deploymentName, workerPoolHash) + className := fmt.Sprintf("%s-%s", deploymentName, workerPoolHash) machineDeployments = append(machineDeployments, worker.MachineDeployment{ Name: deploymentName, diff --git a/pkg/hcloud/apis/mock/worker.go b/pkg/hcloud/apis/mock/worker.go index bc5466067..07de06722 100644 --- a/pkg/hcloud/apis/mock/worker.go +++ b/pkg/hcloud/apis/mock/worker.go @@ -38,13 +38,14 @@ const ( "sshFingerprint": %q, "floatingPoolName": "MY-FLOATING-POOL" }` - TestWorkerMachineImageName = "ubuntu" - TestWorkerMachineImageVersion = "20.04" - TestWorkerMachineType = "cx11" - TestWorkerName = "hcloud" - TestWorkerPoolName = "hcloud-pool-1" - TestWorkerSecretName = "secret" - TestWorkerUserData = "IyEvYmluL2Jhc2gKCmVjaG8gImhlbGxvIHdvcmxkIgo=" + TestWorkerMachineImageName = "ubuntu" + TestWorkerMachineImageVersion = "20.04" + TestWorkerMachineType = "cx11" + TestWorkerName = "hcloud" + TestWorkerPoolName = "hcloud-pool-1" + TestWorkerSecretName = "secret" + TestWorkerCredentialsSecretName = "cloudprovider" + TestWorkerUserData = "IyEvYmluL2Jhc2gKCmVjaG8gImhlbGxvIHdvcmxkIgo=" ) // NewWorker generates a new provider specification for testing purposes. @@ -95,16 +96,16 @@ func ManipulateWorker(worker *v1alpha1.Worker, data map[string]interface{}) *v1a reSpecPools := regexp.MustCompile(`^Spec\.Pools\.(\d+)\.`) for key, value := range data { - if (strings.Index(key, "ObjectMeta") == 0) { + if strings.Index(key, "ObjectMeta") == 0 { manipulateStruct(&worker.ObjectMeta, key[11:], value) - } else if (reSpecPools.MatchString(key)) { + } else if reSpecPools.MatchString(key) { keyData := strings.SplitN(key, ".", 4) index, _ := strconv.Atoi(keyData[2]) manipulateStruct(&worker.Spec.Pools[index], keyData[3], value) - } else if (strings.Index(key, "Spec.Pools.") == 0) { + } else if strings.Index(key, "Spec.Pools.") == 0 { manipulateStruct(&worker.Spec, key[7:], value) - } else if (strings.Index(key, "Spec") == 0) { + } else if strings.Index(key, "Spec") == 0 { manipulateStruct(&worker.Spec, key[7:], value) } else { manipulateStruct(&worker, key, value)