Skip to content

Commit af4782b

Browse files
authored
Merge pull request #153 from richardcase/vip_fix
fix: incorrectly defaulting advertise address
2 parents 7d5bca2 + 6e2efbe commit af4782b

3 files changed

Lines changed: 162 additions & 15 deletions

File tree

controlplane/api/v1alpha1/rke2controlplane_webhook.go

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -47,16 +47,6 @@ var _ webhook.Defaulter = &RKE2ControlPlane{}
4747
// Default implements webhook.Defaulter so a webhook will be registered for the type.
4848
func (r *RKE2ControlPlane) Default() {
4949
bootstrapv1.DefaultRKE2ConfigSpec(&r.Spec.RKE2ConfigSpec)
50-
51-
if r.Spec.RegistrationMethod == RegistrationMethodAddress {
52-
if r.Spec.ServerConfig.AdvertiseAddress == "" {
53-
rke2controlplanelog.Info("setting advertise address from registration address",
54-
"rke2-control-plane", klog.KObj(r),
55-
"address", r.Spec.RegistrationAddress)
56-
57-
r.Spec.ServerConfig.AdvertiseAddress = r.Spec.RegistrationAddress
58-
}
59-
}
6050
}
6151

6252
//+kubebuilder:webhook:path=/validate-controlplane-cluster-x-k8s-io-v1alpha1-rke2controlplane,mutating=false,failurePolicy=fail,sideEffects=None,groups=controlplane.cluster.x-k8s.io,resources=rke2controlplanes,verbs=create;update,versions=v1alpha1,name=vrke2controlplane.kb.io,admissionReviewVersions=v1

pkg/registration/registration_test.go

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,7 @@ func TestInternalFirstMethod(t *testing.T) {
117117
actualAddresses, err := regMethod(tc.rcp, col)
118118
g.Expect(err).NotTo(HaveOccurred())
119119

120-
g.Expect(actualAddresses).To(BeComparableTo(tc.expectedAddresses))
121-
120+
g.Expect(actualAddresses).To(HaveExactElements(tc.expectedAddresses))
122121
})
123122
}
124123
}
@@ -170,7 +169,7 @@ func TestInternalOnlyMethod(t *testing.T) {
170169
actualAddresses, err := regMethod(tc.rcp, col)
171170
g.Expect(err).NotTo(HaveOccurred())
172171

173-
g.Expect(actualAddresses).To(BeComparableTo(tc.expectedAddresses))
172+
g.Expect(actualAddresses).To(HaveExactElements(tc.expectedAddresses))
174173

175174
})
176175
}
@@ -223,7 +222,7 @@ func TestExternalOnlyMethod(t *testing.T) {
223222
actualAddresses, err := regMethod(tc.rcp, col)
224223
g.Expect(err).NotTo(HaveOccurred())
225224

226-
g.Expect(actualAddresses).To(BeComparableTo(tc.expectedAddresses))
225+
g.Expect(actualAddresses).To(HaveExactElements(tc.expectedAddresses))
227226

228227
})
229228
}
@@ -274,7 +273,7 @@ func TestAddressMethod(t *testing.T) {
274273

275274
expectedAddresses := []string{"100.100.100.100"}
276275

277-
g.Expect(actualAddresses).To(BeComparableTo(expectedAddresses))
276+
g.Expect(actualAddresses).To(HaveExactElements(expectedAddresses))
278277

279278
})
280279
}
@@ -322,3 +321,15 @@ func createMachine(name string, internalIPs []string, externalIPs []string) *clu
322321

323322
return machine
324323
}
324+
325+
func strEquals(a, b []string) bool {
326+
if len(a) != len(b) {
327+
return false
328+
}
329+
for i, v := range a {
330+
if v != b[i] {
331+
return false
332+
}
333+
}
334+
return true
335+
}
Lines changed: 146 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,146 @@
1+
apiVersion: v1
2+
kind: Namespace
3+
metadata:
4+
name: ${CABPR_NAMESPACE}
5+
---
6+
apiVersion: cluster.x-k8s.io/v1beta1
7+
kind: Cluster
8+
metadata:
9+
namespace: ${CABPR_NAMESPACE}
10+
name: ${CLUSTER_NAME}
11+
spec:
12+
clusterNetwork:
13+
pods:
14+
cidrBlocks:
15+
- 10.45.0.0/16
16+
services:
17+
cidrBlocks:
18+
- 10.46.0.0/16
19+
serviceDomain: cluster.local
20+
controlPlaneRef:
21+
apiVersion: controlplane.cluster.x-k8s.io/v1alpha1
22+
kind: RKE2ControlPlane
23+
name: ${CLUSTER_NAME}-control-plane
24+
infrastructureRef:
25+
apiVersion: infrastructure.cluster.x-k8s.io/v1beta1
26+
kind: DockerCluster
27+
name: ${CLUSTER_NAME}
28+
---
29+
apiVersion: infrastructure.cluster.x-k8s.io/v1beta1
30+
kind: DockerCluster
31+
metadata:
32+
name: ${CLUSTER_NAME}
33+
namespace: ${CABPR_NAMESPACE}
34+
---
35+
apiVersion: controlplane.cluster.x-k8s.io/v1alpha1
36+
kind: RKE2ControlPlane
37+
metadata:
38+
name: ${CLUSTER_NAME}-control-plane
39+
namespace: ${CABPR_NAMESPACE}
40+
spec:
41+
replicas: ${CABPR_CP_REPLICAS}
42+
agentConfig:
43+
version: ${KUBERNETES_VERSION}+rke2r1
44+
serverConfig:
45+
cni: calico
46+
infrastructureRef:
47+
apiVersion: infrastructure.cluster.x-k8s.io/v1beta1
48+
kind: DockerMachineTemplate
49+
name: controlplane
50+
nodeDrainTimeout: 2m
51+
registrationMethod: "address"
52+
registrationAddress: "${REGISTRATION_VIP}"
53+
preRKE2Commands:
54+
- mkdir -p /var/lib/rancher/rke2/server/manifests/ && ctr images pull ghcr.io/kube-vip/kube-vip:v0.6.0 && ctr run --rm --net-host ghcr.io/kube-vip/kube-vip:v0.6.0 vip /kube-vip manifest daemonset --arp --interface $(ip -4 -j route list default | jq -r .[0].dev) --address ${REGISTRATION_VIP} --controlplane --leaderElection --taint --services --inCluster | tee /var/lib/rancher/rke2/server/manifests/kube-vip.yaml
55+
files:
56+
- path: /var/lib/rancher/rke2/server/manifests/kube-vip-rbac.yaml
57+
content: |
58+
apiVersion: v1
59+
kind: ServiceAccount
60+
metadata:
61+
name: kube-vip
62+
namespace: kube-system
63+
---
64+
apiVersion: rbac.authorization.k8s.io/v1
65+
kind: ClusterRole
66+
metadata:
67+
annotations:
68+
rbac.authorization.kubernetes.io/autoupdate: "true"
69+
name: system:kube-vip-role
70+
rules:
71+
- apiGroups: [""]
72+
resources: ["services", "services/status", "nodes", "endpoints"]
73+
verbs: ["list","get","watch", "update"]
74+
- apiGroups: ["coordination.k8s.io"]
75+
resources: ["leases"]
76+
verbs: ["list", "get", "watch", "update", "create"]
77+
---
78+
kind: ClusterRoleBinding
79+
apiVersion: rbac.authorization.k8s.io/v1
80+
metadata:
81+
name: system:kube-vip-binding
82+
roleRef:
83+
apiGroup: rbac.authorization.k8s.io
84+
kind: ClusterRole
85+
name: system:kube-vip-role
86+
subjects:
87+
- kind: ServiceAccount
88+
name: kube-vip
89+
namespace: kube-system
90+
owner: root:root
91+
---
92+
apiVersion: infrastructure.cluster.x-k8s.io/v1beta1
93+
kind: DockerMachineTemplate
94+
metadata:
95+
name: controlplane
96+
namespace: ${CABPR_NAMESPACE}
97+
spec:
98+
template:
99+
spec: {}
100+
---
101+
apiVersion: cluster.x-k8s.io/v1beta1
102+
kind: MachineDeployment
103+
metadata:
104+
name: worker-md-0
105+
namespace: ${CABPR_NAMESPACE}
106+
spec:
107+
clusterName: ${CLUSTER_NAME}
108+
replicas: ${CABPR_WK_REPLICAS}
109+
selector:
110+
matchLabels:
111+
cluster.x-k8s.io/cluster-name: ${CLUSTER_NAME}
112+
template:
113+
spec:
114+
version: ${KUBERNETES_VERSION}
115+
clusterName: ${CLUSTER_NAME}
116+
bootstrap:
117+
configRef:
118+
apiVersion: bootstrap.cluster.x-k8s.io/v1alpha1
119+
kind: RKE2ConfigTemplate
120+
name: ${CLUSTER_NAME}-agent
121+
namespace: ${CABPR_NAMESPACE}
122+
infrastructureRef:
123+
apiVersion: infrastructure.cluster.x-k8s.io/v1beta1
124+
kind: DockerMachineTemplate
125+
name: worker
126+
namespace: ${CABPR_NAMESPACE}
127+
---
128+
apiVersion: infrastructure.cluster.x-k8s.io/v1beta1
129+
kind: DockerMachineTemplate
130+
metadata:
131+
name: worker
132+
namespace: ${CABPR_NAMESPACE}
133+
spec:
134+
template:
135+
spec: {}
136+
---
137+
apiVersion: bootstrap.cluster.x-k8s.io/v1alpha1
138+
kind: RKE2ConfigTemplate
139+
metadata:
140+
namespace: ${CABPR_NAMESPACE}
141+
name: ${CLUSTER_NAME}-agent
142+
spec:
143+
template:
144+
spec:
145+
agentConfig:
146+
version: ${KUBERNETES_VERSION}+rke2r1

0 commit comments

Comments
 (0)