Skip to content

Commit 89adce8

Browse files
authored
🌱 Add SkipCreatingHetznerSecretInWorkloadCluster to HetznerCluster (#1637)
* 🌱 Add SkipCreatingHetznerSecretInWorkloadCluster to hetznercluster_controller SkipCreatingHetznerSecretInWorkloadCluster indicates whether the Hetzner secret should be created in the workload cluster. By default the secret gets created, so that the ccm (running in the wl-cluster) can use that secret. If you prefer to not reveal the secret in the workload cluster, you can set this to value to false, so that the secret is not created. Be sure to run the ccm outside of the workload cluster in that case, e.g. in the management cluster. Closes #1636
1 parent 58b042c commit 89adce8

File tree

6 files changed

+39
-1
lines changed

6 files changed

+39
-1
lines changed

Makefile

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -750,8 +750,15 @@ format: format-starlark format-golang format-yaml ## Format Codebase
750750

751751
.PHONY: generate-mocks
752752
generate-mocks: ## Generate Mocks
753+
ifeq ($(BUILD_IN_CONTAINER),true)
754+
docker run --rm -t -i \
755+
-v $(shell go env GOPATH)/pkg:/go/pkg$(MOUNT_FLAGS) \
756+
-v $(shell pwd):/src/cluster-api-provider-$(INFRA_PROVIDER)$(MOUNT_FLAGS) \
757+
$(BUILDER_IMAGE):$(BUILDER_IMAGE_VERSION) $@;
758+
else
753759
cd pkg/services/baremetal/client; go run github.com/vektra/mockery/[email protected]
754760
cd pkg/services/hcloud/client; go run github.com/vektra/mockery/[email protected] --all
761+
endif
755762

756763
.PHONY: generate
757764
generate: generate-manifests generate-go-deepcopy generate-boilerplate generate-modules generate-mocks ## Generate Files

api/v1beta1/hetznercluster_types.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
Copyright 2021 The Kubernetes Authors.
2+
Copyright 2025 The Kubernetes Authors.
33
44
Licensed under the Apache License, Version 2.0 (the "License");
55
you may not use this file except in compliance with the License.
@@ -64,6 +64,14 @@ type HetznerClusterSpec struct {
6464
// HetznerSecretRef is a reference to a token to be used when reconciling this cluster.
6565
// This is generated in the security section under API TOKENS. Read & write is necessary.
6666
HetznerSecret HetznerSecretRef `json:"hetznerSecretRef"`
67+
68+
// SkipCreatingHetznerSecretInWorkloadCluster indicates whether the Hetzner secret should be
69+
// created in the workload cluster. By default the secret gets created, so that the ccm (running
70+
// in the wl-cluster) can use that secret. If you prefer to not reveal the secret in the
71+
// wl-cluster, you can set this to value to false, so that the secret is not created. Be sure to
72+
// run the ccm outside of the wl-cluster in that case, e.g. in the management cluster.
73+
// +optional
74+
SkipCreatingHetznerSecretInWorkloadCluster bool `json:"skipCreatingHetznerSecretInWorkloadCluster,omitempty"`
6775
}
6876

6977
// HetznerClusterStatus defines the observed state of HetznerCluster.

config/crd/bases/infrastructure.cluster.x-k8s.io_hetznerclusters.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,14 @@ spec:
272272
- key
273273
- name
274274
type: object
275+
skipCreatingHetznerSecretInWorkloadCluster:
276+
description: |-
277+
SkipCreatingHetznerSecretInWorkloadCluster indicates whether the Hetzner secret should be
278+
created in the workload cluster. By default the secret gets created, so that the ccm (running
279+
in the wl-cluster) can use that secret. If you prefer to not reveal the secret in the
280+
wl-cluster, you can set this to value to false, so that the secret is not created. Be sure to
281+
run the ccm outside of the wl-cluster in that case, e.g. in the management cluster.
282+
type: boolean
275283
sshKeys:
276284
description: SSHKeys are cluster wide. Valid values are a valid SSH
277285
key name.

config/crd/bases/infrastructure.cluster.x-k8s.io_hetznerclustertemplates.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,14 @@ spec:
305305
- key
306306
- name
307307
type: object
308+
skipCreatingHetznerSecretInWorkloadCluster:
309+
description: |-
310+
SkipCreatingHetznerSecretInWorkloadCluster indicates whether the Hetzner secret should be
311+
created in the workload cluster. By default the secret gets created, so that the ccm (running
312+
in the wl-cluster) can use that secret. If you prefer to not reveal the secret in the
313+
wl-cluster, you can set this to value to false, so that the secret is not created. Be sure to
314+
run the ccm outside of the wl-cluster in that case, e.g. in the management cluster.
315+
type: boolean
308316
sshKeys:
309317
description: SSHKeys are cluster wide. Valid values are a
310318
valid SSH key name.

controllers/hetznercluster_controller.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -472,6 +472,12 @@ func hcloudTokenErrorResult(
472472
}
473473

474474
func reconcileTargetSecret(ctx context.Context, clusterScope *scope.ClusterScope) (res reconcile.Result, reterr error) {
475+
if clusterScope.HetznerCluster.Spec.SkipCreatingHetznerSecretInWorkloadCluster {
476+
// If the secret should not be created in the workload cluster, we just return.
477+
// This means the ccm is running outside of the workload cluster (or getting the secret differently).
478+
return reconcile.Result{}, nil
479+
}
480+
475481
// Checking if control plane is ready
476482
clientConfig, err := clusterScope.ClientConfig(ctx)
477483
if err != nil {

docs/caph/03-reference/02-hetzner-cluster.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,3 +70,4 @@ If you are using your own load balancer, you need to point towards it and config
7070
| `hetznerSecret.key.hcloudToken` | `string` | | no | Name of the key where the token for the Hetzner Cloud API is stored |
7171
| `hetznerSecret.key.hetznerRobotUser` | `string` | | no | Name of the key where the username for the Hetzner Robot API is stored |
7272
| `hetznerSecret.key.hetznerRobotPassword` | `string` | | no | Name of the key where the password for the Hetzner Robot API is stored |
73+
| `skipCreatingHetznerSecretInWorkloadCluster` | `bool` | `false` | no | Indicates whether the Hetzner secret should be created in the workload cluster. By default the secret gets created, so that the ccm (running in the wl-cluster) can use that secret. If you prefer to not reveal the secret in the wl-cluster, you can set this to value to false, so that the secret is not created. Be sure to run the ccm outside of the wl-cluster in that case, e.g. in the management cluster. |

0 commit comments

Comments
 (0)