Skip to content

Commit c22d4c0

Browse files
vknabelGerrit91
andauthored
use resource name as cluster id (#73)
Co-authored-by: Gerrit <[email protected]>
1 parent 666327b commit c22d4c0

File tree

6 files changed

+247
-8
lines changed

6 files changed

+247
-8
lines changed

README.md

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ export FIREWALL_MACHINE_SIZE=<machine-size>
7171
metalctl firewall create --description <description> --name <name> --hostname <hostname> --project $METAL_PROJECT_ID --partition $METAL_PARTITION --image $FIREWALL_MACHINE_IMAGE --size $FIREWALL_MACHINE_SIZE --firewall-rules-file=<rules.yaml> --networks internet,$METAL_NODE_NETWORK_ID
7272
```
7373

74-
For your first cluster, it is advised to start with our generated template.
74+
For your first cluster, it is advised to start with our generated template. Ensure that the namespaced cluster name is unique within the metal stack project.
7575

7676
```bash
7777
# display required environment variables
@@ -125,10 +125,12 @@ spec:
125125
EOF
126126
```
127127

128-
Additionally, the `metal-ccm` has to be deployed for the machines to reach `Running` phase. For this use the [template](capi-lab/metal-ccm.yaml) and fill in the required variables.
128+
Meanwhile, the `metal-ccm` has to be deployed for the machines to reach `Running` phase. For this use the [`config/target-cluster/metal-ccm.yaml` template](config/target-cluster/metal-ccm.yaml) and fill in the required variables.
129129

130130
```bash
131-
cat capi-lab/metal-ccm.yaml | envsubst | kubectl --kubeconfig capms-cluster.kubeconfig apply -f -
131+
export NAMESPACE=<namespace>
132+
export CLUSTER_NAME=<cluster name>
133+
cat config/target-cluster/metal-ccm.yaml | envsubst | kubectl --kubeconfig capms-cluster.kubeconfig apply -f -
132134
```
133135

134136
If you want to provide service's of type `LoadBalancer` through MetalLB by the `metal-ccm`, you need to deploy MetalLB:
@@ -137,8 +139,8 @@ If you want to provide service's of type `LoadBalancer` through MetalLB by the `
137139
kubectl --kubeconfig capms-cluster.kubeconfig apply --kustomize capi-lab/metallb
138140
```
139141

140-
For each worker node in your Kubernetes cluster, you need to create a BGP peer configuration. Replace the placeholders ({{
141-
NODE_ASN }}, {{ NODE_HOSTNAME }}, and {{ NODE_ROUTER_ID }}) with the appropriate values for each node.
142+
For each worker node in your Kubernetes cluster, you need to create a BGP peer configuration. Replace the placeholders (`{{
143+
NODE_ASN }}`, `{{ NODE_HOSTNAME }}`, and `{{ NODE_ROUTER_ID }}`) with the appropriate values for each node.
142144

143145
```bash
144146
# in metal-stack, list all machines of your cluster

api/v1alpha1/metalstackcluster_types.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ limitations under the License.
1717
package v1alpha1
1818

1919
import (
20+
"fmt"
21+
2022
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
2123

2224
clusterv1 "sigs.k8s.io/cluster-api/api/v1beta1"
@@ -138,3 +140,7 @@ func (c *MetalStackCluster) GetConditions() clusterv1.Conditions {
138140
func (c *MetalStackCluster) SetConditions(conditions clusterv1.Conditions) {
139141
c.Status.Conditions = conditions
140142
}
143+
144+
func (c *MetalStackCluster) GetClusterID() string {
145+
return fmt.Sprintf("%s/%s", c.GetNamespace(), c.GetName())
146+
}
Lines changed: 230 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,230 @@
1+
---
2+
apiVersion: v1
3+
kind: Secret
4+
metadata:
5+
name: cloud-controller-manager
6+
namespace: kube-system
7+
stringData:
8+
api-url: ${METAL_API_URL}
9+
api-hmac: ${METAL_API_HMAC}
10+
api-hmac-auth-type: ${METAL_API_HMAC_AUTH_TYPE}
11+
---
12+
apiVersion: v1
13+
kind: ServiceAccount
14+
metadata:
15+
name: cloud-controller-manager
16+
namespace: kube-system
17+
---
18+
apiVersion: rbac.authorization.k8s.io/v1
19+
kind: ClusterRole
20+
metadata:
21+
name: cloud-controller-manager
22+
rules:
23+
- apiGroups:
24+
- ""
25+
resources:
26+
- events
27+
verbs:
28+
- create
29+
- patch
30+
- update
31+
- apiGroups:
32+
- ""
33+
resources:
34+
- nodes
35+
verbs:
36+
- "*"
37+
- apiGroups:
38+
- ""
39+
resources:
40+
- nodes/status
41+
verbs:
42+
- patch
43+
- apiGroups:
44+
- ""
45+
resources:
46+
- services
47+
- services/status
48+
- endpoints
49+
verbs:
50+
- get
51+
- list
52+
- patch
53+
- update
54+
- watch
55+
- apiGroups:
56+
- ""
57+
resources:
58+
- serviceaccounts
59+
- serviceaccounts/token
60+
verbs:
61+
- create
62+
- get
63+
- list
64+
- watch
65+
- apiGroups:
66+
- ""
67+
resources:
68+
- secrets
69+
- configmaps
70+
verbs:
71+
- get
72+
- list
73+
- watch
74+
- update
75+
- create
76+
- patch
77+
- delete
78+
- apiGroups:
79+
- coordination.k8s.io
80+
resources:
81+
- leases
82+
verbs:
83+
- get
84+
- create
85+
- update
86+
- apiGroups:
87+
- metallb.io
88+
resources:
89+
- bgppeers
90+
verbs:
91+
- create
92+
- delete
93+
- get
94+
- list
95+
- patch
96+
- update
97+
- watch
98+
- apiGroups:
99+
- metallb.io
100+
resources:
101+
- ipaddresspools
102+
verbs:
103+
- create
104+
- delete
105+
- get
106+
- list
107+
- patch
108+
- update
109+
- watch
110+
- apiGroups:
111+
- metallb.io
112+
resources:
113+
- bgpadvertisements
114+
verbs:
115+
- create
116+
- delete
117+
- get
118+
- list
119+
- patch
120+
- update
121+
- watch
122+
---
123+
apiVersion: rbac.authorization.k8s.io/v1
124+
kind: ClusterRoleBinding
125+
metadata:
126+
name: cloud-controller-manager
127+
roleRef:
128+
apiGroup: rbac.authorization.k8s.io
129+
kind: ClusterRole
130+
name: cloud-controller-manager
131+
subjects:
132+
- kind: ServiceAccount
133+
name: cloud-controller-manager
134+
namespace: kube-system
135+
---
136+
apiVersion: apps/v1
137+
kind: Deployment
138+
metadata:
139+
labels:
140+
app: cloud-controller-manager
141+
name: cloud-controller-manager
142+
namespace: kube-system
143+
spec:
144+
replicas: 1
145+
selector:
146+
matchLabels:
147+
app: cloud-controller-manager
148+
strategy:
149+
type: RollingUpdate
150+
template:
151+
metadata:
152+
labels:
153+
app: cloud-controller-manager
154+
spec:
155+
containers:
156+
- command:
157+
- ./metal-cloud-controller-manager
158+
- --cluster-cidr=10.240.0.0/12
159+
- --cluster-name=
160+
- --concurrent-service-syncs=10
161+
- --leader-elect=true
162+
- --secure-port=10258
163+
- --use-service-account-credentials
164+
- --v=2
165+
env:
166+
- name: METAL_API_URL
167+
valueFrom:
168+
secretKeyRef:
169+
key: api-url
170+
name: cloud-controller-manager
171+
- name: METAL_AUTH_HMAC
172+
valueFrom:
173+
secretKeyRef:
174+
key: api-hmac
175+
name: cloud-controller-manager
176+
- name: METAL_AUTH_HMAC_AUTH_TYPE
177+
valueFrom:
178+
secretKeyRef:
179+
key: api-hmac-auth-type
180+
name: cloud-controller-manager
181+
- name: METAL_PROJECT_ID
182+
value: ${METAL_PROJECT_ID}
183+
- name: METAL_PARTITION_ID
184+
value: ${METAL_PARTITION}
185+
# associates service type load balancer ips with this cluster:
186+
- name: METAL_CLUSTER_ID
187+
value: ${NAMESPACE}/${CLUSTER_NAME}
188+
- name: METAL_DEFAULT_EXTERNAL_NETWORK_ID
189+
value: internet
190+
- name: METAL_ADDITIONAL_NETWORKS
191+
value: internet,${METAL_NODE_NETWORK_ID}
192+
- name: METAL_SSH_PUBLICKEY
193+
value: ""
194+
image: ghcr.io/metal-stack/metal-ccm:v0.9.4
195+
imagePullPolicy: IfNotPresent
196+
livenessProbe:
197+
failureThreshold: 2
198+
httpGet:
199+
path: /healthz
200+
port: 10258
201+
scheme: HTTPS
202+
initialDelaySeconds: 15
203+
periodSeconds: 10
204+
successThreshold: 1
205+
timeoutSeconds: 15
206+
name: cloud-controller-manager
207+
resources:
208+
limits:
209+
cpu: 250m
210+
memory: 256Mi
211+
requests:
212+
cpu: 100m
213+
memory: 64Mi
214+
nodeSelector:
215+
node-role.kubernetes.io/control-plane: ""
216+
hostNetwork: true
217+
serviceAccountName: cloud-controller-manager
218+
tolerations:
219+
- effect: NoSchedule
220+
operator: Exists
221+
key: node-role.kubernetes.io/control-plane
222+
- effect: NoSchedule
223+
key: node.cloudprovider.kubernetes.io/uninitialized
224+
value: "true"
225+
restartPolicy: Always
226+
volumes:
227+
- name: cloud-controller-manager
228+
secret:
229+
defaultMode: 420
230+
secretName: cloud-controller-manager

internal/controller/metalstackcluster_controller.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ func (r *clusterReconciler) ensureControlPlaneIP() (string, error) {
216216
Networkid: defaultNetwork.ID,
217217
Projectid: &r.infraCluster.Spec.ProjectID,
218218
Tags: []string{
219-
tag.New(tag.ClusterID, string(r.infraCluster.GetUID())),
219+
tag.New(tag.ClusterID, r.infraCluster.GetClusterID()),
220220
v1alpha1.TagControlPlanePurpose,
221221
},
222222
Type: ptr.To(models.V1IPBaseTypeEphemeral),

internal/controller/metalstackcluster_controller_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ var _ = Describe("MetalStackCluster Controller", func() {
271271
IP: func(m *mock.Mock) {
272272
m.On("AllocateIP", testcommon.MatchIgnoreContext(testingT, metalip.NewAllocateIPParams().WithBody(&models.V1IPAllocateRequest{
273273
Tags: []string{
274-
"cluster.metal-stack.io/id=" + string(resource.UID),
274+
"cluster.metal-stack.io/id=" + resource.GetClusterID(),
275275
"metal-stack.infrastructure.cluster.x-k8s.io/purpose=control-plane",
276276
},
277277
Name: resource.Name + "-control-plane",

internal/controller/metalstackmachine_controller.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ func (r *machineReconciler) create() (*models.V1MachineResponse, error) {
317317
resp, err := r.metalClient.Machine().AllocateMachine(metalmachine.NewAllocateMachineParamsWithContext(r.ctx).WithBody(&models.V1MachineAllocateRequest{
318318
Partitionid: &r.infraCluster.Spec.Partition,
319319
Projectid: &r.infraCluster.Spec.ProjectID,
320-
PlacementTags: []string{tag.New(tag.ClusterID, string(r.infraCluster.GetUID()))},
320+
PlacementTags: []string{tag.New(tag.ClusterID, r.infraCluster.GetClusterID())},
321321
Tags: append(r.machineTags(), r.additionalMachineTags()...),
322322
Name: r.infraMachine.Name,
323323
Hostname: r.infraMachine.Name,
@@ -437,6 +437,7 @@ func (r *machineReconciler) patchMachineLabels(m *models.V1MachineResponse) {
437437

438438
func (r *machineReconciler) machineTags() []string {
439439
tags := []string{
440+
tag.New(tag.ClusterID, r.infraCluster.Spec.NodeNetworkID),
440441
tag.New(v1alpha1.TagInfraClusterResource, fmt.Sprintf("%s/%s", r.infraCluster.Namespace, r.infraCluster.Name)),
441442
tag.New(v1alpha1.TagInfraMachineResource, fmt.Sprintf("%s/%s", r.infraMachine.Namespace, r.infraMachine.Name)),
442443
}

0 commit comments

Comments
 (0)