Skip to content

Commit

Permalink
Add credential secret for the machineClass (#35)
Browse files Browse the repository at this point in the history
Signed-off-by: Fynn Späker <[email protected]>
  • Loading branch information
fynluk authored Apr 28, 2023
1 parent 4f0ccb6 commit 9a5f4ec
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 12 deletions.
3 changes: 3 additions & 0 deletions charts/internal/machineclass/templates/machineclass.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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 }}
Expand Down
3 changes: 3 additions & 0 deletions charts/internal/machineclass/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down
6 changes: 5 additions & 1 deletion pkg/controller/worker/machines.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}

Expand All @@ -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,
Expand Down
23 changes: 12 additions & 11 deletions pkg/hcloud/apis/mock/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 9a5f4ec

Please sign in to comment.