Skip to content

Commit 04d9e5f

Browse files
committed
feat: add CiliumNetworkPolicies
Will be used if available, otherwise vanilla NetworkPolicies will be created. feat: switch konnectivity agent from DaemonSet to Deployment Also use leases for server counting, to account for dynamic changes chore: switch from envoy to nginx as a webhook mirror Envoy couldn't set the authentication header per mirror cluster.
1 parent 17964ca commit 04d9e5f

48 files changed

Lines changed: 1883 additions & 917 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Containerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
FROM cgr.dev/chainguard/static:latest-glibc
1+
FROM scratch
22
ARG manager
33
COPY $manager /manager
44
USER 1000:1000

api/v1alpha1/hostedcontrolplane_types.go

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -64,14 +64,14 @@ type HostedControlPlaneInlineSpec struct {
6464
//+kubebuilder:validation:Required
6565
Gateway GatewayReference `json:"gateway"`
6666

67-
//+kubebuilder:validation:Optional
68-
KonnectivityClient Container `json:"konnectivityClient,omitempty"`
67+
//+kubebuilder:default={}
68+
KonnectivityClient ScalablePod `json:"konnectivityClient,omitempty"`
6969
//+kubebuilder:validation:Optional
7070
KubeProxy KubeProxyComponent `json:"kubeProxy,omitempty"`
71-
//+kubebuilder:validation:Optional
72-
CoreDNS Container `json:"coredns,omitempty"`
7371
//+kubebuilder:default={}
74-
ETCD *ETCDComponent `json:"etcd,omitempty"`
72+
CoreDNS ScalablePod `json:"coredns,omitempty"`
73+
//+kubebuilder:default={}
74+
ETCD ETCDComponent `json:"etcd,omitempty"`
7575
}
7676

7777
type GatewayReference struct {
@@ -119,9 +119,8 @@ type Container struct {
119119

120120
type ScalablePod struct {
121121
Pod `json:",inline"`
122-
//+kubebuilder:validation:Optional
123-
//+kubebuilder:default=1
124-
Replicas *int32 `json:"replicas,omitempty"`
122+
//+kubebuilder:default=2
123+
Replicas int32 `json:"replicas,omitempty"`
125124
}
126125

127126
type KubeProxyComponent struct {
@@ -133,7 +132,7 @@ type KubeProxyComponent struct {
133132
type ETCDComponent struct {
134133
Container `json:",inline"`
135134
//+kubebuilder:validation:Optional
136-
VolumeSize resource.Quantity `json:"volumeSize,omitempty"`
135+
VolumeSize *resource.Quantity `json:"volumeSize,omitempty"`
137136
// AutoGrow will increase the volume size automatically when it is near full.
138137
//+kubebuilder:default=true
139138
AutoGrow bool `json:"autoGrow,omitempty"`
@@ -192,7 +191,6 @@ type AuditWebhook struct {
192191
Container `json:",inline"`
193192
//+kubebuilder:validation:Required
194193
//+kubebuilder:validation:MinItems=1
195-
//+kubebuilder:validation:UniqueItems=true
196194
Targets []AuditWebhookTarget `json:"targets"`
197195
}
198196

api/v1alpha1/hostedcontrolplane_webhook.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,15 +55,17 @@ func (w *hostedControlPlaneWebhook) ValidateCreate(
5555
fieldErrs = append(fieldErrs, fieldErr)
5656
}
5757

58-
if newHostedControlPlane.Spec.ETCD.AutoGrow && !newHostedControlPlane.Spec.ETCD.VolumeSize.IsZero() {
58+
if newHostedControlPlane.Spec.ETCD.AutoGrow && newHostedControlPlane.Spec.ETCD.VolumeSize != nil &&
59+
!newHostedControlPlane.Spec.ETCD.VolumeSize.IsZero() {
5960
fieldErrs = append(fieldErrs, field.Invalid(
6061
w.specPath.Child("etcd").Child("autoGrow"),
6162
newHostedControlPlane.Spec.ETCD.AutoGrow,
6263
"autoGrow cannot be true when volumeSize is set",
6364
))
6465
}
6566

66-
if !newHostedControlPlane.Spec.ETCD.AutoGrow && newHostedControlPlane.Spec.ETCD.VolumeSize.IsZero() {
67+
if !newHostedControlPlane.Spec.ETCD.AutoGrow &&
68+
(newHostedControlPlane.Spec.ETCD.VolumeSize == nil || newHostedControlPlane.Spec.ETCD.VolumeSize.IsZero()) {
6769
fieldErrs = append(fieldErrs, field.Invalid(
6870
w.specPath.Child("etcd").Child("autoGrow"),
6971
newHostedControlPlane.Spec.ETCD.AutoGrow,
@@ -136,7 +138,7 @@ func (w *hostedControlPlaneWebhook) ValidateUpdate(
136138
)})
137139
}
138140

139-
if !newHostedControlPlane.Spec.ETCD.AutoGrow {
141+
if !newHostedControlPlane.Spec.ETCD.AutoGrow && newHostedControlPlane.Spec.ETCD.VolumeSize != nil {
140142
if oldHostedControlPlane.Spec.ETCD.AutoGrow &&
141143
newHostedControlPlane.Spec.ETCD.VolumeSize.Cmp(
142144
oldHostedControlPlane.Status.ETCDVolumeSize) == -1 {
@@ -153,7 +155,7 @@ func (w *hostedControlPlaneWebhook) ValidateUpdate(
153155
),
154156
)},
155157
)
156-
} else if newHostedControlPlane.Spec.ETCD.VolumeSize.Cmp(oldHostedControlPlane.Spec.ETCD.VolumeSize) == -1 {
158+
} else if oldHostedControlPlane.Spec.ETCD.VolumeSize != nil && newHostedControlPlane.Spec.ETCD.VolumeSize.Cmp(*oldHostedControlPlane.Spec.ETCD.VolumeSize) == -1 {
157159
return warnings, apierrors.NewInvalid(w.groupKind, newHostedControlPlane.Name, field.ErrorList{field.Invalid(
158160
w.specPath.Child("etcd").Child("volumeSize"),
159161
newHostedControlPlane.Spec.ETCD.VolumeSize,

api/v1alpha1/hostedcontrolplane_webhook_test.go

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,6 @@ import (
1313

1414
func TestHostedControlPlaneWebhook_ValidateCreate(t *testing.T) {
1515
webhook := &hostedControlPlaneWebhook{}
16-
ctx := t.Context()
17-
g := NewWithT(t)
1816

1917
tests := []struct {
2018
name string
@@ -37,7 +35,7 @@ func TestHostedControlPlaneWebhook_ValidateCreate(t *testing.T) {
3735
Name: "test-gateway",
3836
Namespace: "default",
3937
},
40-
ETCD: &ETCDComponent{
38+
ETCD: ETCDComponent{
4139
AutoGrow: true,
4240
},
4341
},
@@ -60,9 +58,9 @@ func TestHostedControlPlaneWebhook_ValidateCreate(t *testing.T) {
6058
Name: "test-gateway",
6159
Namespace: "default",
6260
},
63-
ETCD: &ETCDComponent{
61+
ETCD: ETCDComponent{
6462
AutoGrow: false,
65-
VolumeSize: resource.MustParse("20Gi"),
63+
VolumeSize: ptr.To(resource.MustParse("20Gi")),
6664
},
6765
},
6866
},
@@ -83,7 +81,7 @@ func TestHostedControlPlaneWebhook_ValidateCreate(t *testing.T) {
8381
Name: "test-gateway",
8482
Namespace: "default",
8583
},
86-
ETCD: &ETCDComponent{
84+
ETCD: ETCDComponent{
8785
AutoGrow: true,
8886
},
8987
},
@@ -106,9 +104,9 @@ func TestHostedControlPlaneWebhook_ValidateCreate(t *testing.T) {
106104
Name: "test-gateway",
107105
Namespace: "default",
108106
},
109-
ETCD: &ETCDComponent{
107+
ETCD: ETCDComponent{
110108
AutoGrow: true,
111-
VolumeSize: resource.MustParse("20Gi"),
109+
VolumeSize: ptr.To(resource.MustParse("20Gi")),
112110
},
113111
},
114112
},
@@ -130,7 +128,7 @@ func TestHostedControlPlaneWebhook_ValidateCreate(t *testing.T) {
130128
Name: "test-gateway",
131129
Namespace: "default",
132130
},
133-
ETCD: &ETCDComponent{
131+
ETCD: ETCDComponent{
134132
AutoGrow: false,
135133
},
136134
},
@@ -143,7 +141,8 @@ func TestHostedControlPlaneWebhook_ValidateCreate(t *testing.T) {
143141

144142
for _, tt := range tests {
145143
t.Run(tt.name, func(t *testing.T) {
146-
_, err := webhook.ValidateCreate(ctx, tt.hcp)
144+
g := NewWithT(t)
145+
_, err := webhook.ValidateCreate(t.Context(), tt.hcp)
147146

148147
if tt.expectErr {
149148
g.Expect(err).To(MatchError(ContainSubstring(tt.errMsg)))
@@ -156,8 +155,6 @@ func TestHostedControlPlaneWebhook_ValidateCreate(t *testing.T) {
156155

157156
func TestHostedControlPlaneWebhook_ValidateUpdate(t *testing.T) {
158157
webhook := &hostedControlPlaneWebhook{}
159-
ctx := t.Context()
160-
g := NewWithT(t)
161158

162159
createValidHCP := func(version string, autoGrow bool, volumeSize string) *HostedControlPlane {
163160
hcp := &HostedControlPlane{
@@ -172,15 +169,15 @@ func TestHostedControlPlaneWebhook_ValidateUpdate(t *testing.T) {
172169
Name: "test-gateway",
173170
Namespace: "default",
174171
},
175-
ETCD: &ETCDComponent{
172+
ETCD: ETCDComponent{
176173
AutoGrow: autoGrow,
177174
},
178175
},
179176
},
180177
}
181178

182179
if volumeSize != "" {
183-
hcp.Spec.ETCD.VolumeSize = resource.MustParse(volumeSize)
180+
hcp.Spec.ETCD.VolumeSize = ptr.To(resource.MustParse(volumeSize))
184181
}
185182

186183
return hcp
@@ -276,7 +273,8 @@ func TestHostedControlPlaneWebhook_ValidateUpdate(t *testing.T) {
276273

277274
for _, tt := range tests {
278275
t.Run(tt.name, func(t *testing.T) {
279-
_, err := webhook.ValidateUpdate(ctx, tt.oldHCP, tt.newHCP)
276+
g := NewWithT(t)
277+
_, err := webhook.ValidateUpdate(t.Context(), tt.oldHCP, tt.newHCP)
280278

281279
if tt.expectErr {
282280
g.Expect(err).To(MatchError(ContainSubstring(tt.errMsg)))
@@ -289,7 +287,6 @@ func TestHostedControlPlaneWebhook_ValidateUpdate(t *testing.T) {
289287

290288
func TestHostedControlPlaneWebhook_ValidateDelete(t *testing.T) {
291289
webhook := &hostedControlPlaneWebhook{}
292-
ctx := t.Context()
293290
g := NewWithT(t)
294291

295292
hcp := &HostedControlPlane{
@@ -299,13 +296,12 @@ func TestHostedControlPlaneWebhook_ValidateDelete(t *testing.T) {
299296
},
300297
}
301298

302-
_, err := webhook.ValidateDelete(ctx, hcp)
299+
_, err := webhook.ValidateDelete(t.Context(), hcp)
303300
g.Expect(err).NotTo(HaveOccurred())
304301
}
305302

306303
func TestHostedControlPlaneWebhook_CastObjectToHostedControlPlane(t *testing.T) {
307304
webhook := &hostedControlPlaneWebhook{}
308-
g := NewWithT(t)
309305

310306
tests := []struct {
311307
name string
@@ -330,6 +326,7 @@ func TestHostedControlPlaneWebhook_CastObjectToHostedControlPlane(t *testing.T)
330326

331327
for _, tt := range tests {
332328
t.Run(tt.name, func(t *testing.T) {
329+
g := NewWithT(t)
333330
result, err := webhook.castObjectToHostedControlPlane(tt.obj)
334331

335332
if tt.expectErr {
@@ -345,7 +342,6 @@ func TestHostedControlPlaneWebhook_CastObjectToHostedControlPlane(t *testing.T)
345342

346343
func TestHostedControlPlaneWebhook_ParseVersion(t *testing.T) {
347344
webhook := &hostedControlPlaneWebhook{}
348-
g := NewWithT(t)
349345

350346
tests := []struct {
351347
name string
@@ -386,6 +382,7 @@ func TestHostedControlPlaneWebhook_ParseVersion(t *testing.T) {
386382

387383
for _, tt := range tests {
388384
t.Run(tt.name, func(t *testing.T) {
385+
g := NewWithT(t)
389386
hcp := &HostedControlPlane{
390387
Spec: HostedControlPlaneSpec{
391388
Version: tt.version,

api/v1alpha1/zz_generated.deepcopy.go

Lines changed: 6 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

config/deployment.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ apiVersion: apps/v1
22
kind: Deployment
33
metadata:
44
name: controller-manager
5+
namespace: system
56
labels:
67
control-plane: controller-manager
78
spec:

config/kustomization.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ namePrefix: capi-hosted-control-plane-
55
labels:
66
- includeSelectors: true
77
pairs:
8-
cluster.x-k8s.io/provider: control-plane-hosted
8+
cluster.x-k8s.io/provider: control-plane-hosted-control-plane
99

1010
resources:
1111
- ./deployment.yaml
@@ -121,6 +121,7 @@ replacements:
121121
options:
122122
create: true
123123
delimiter: .
124+
index: 1
124125
fieldPaths:
125126
- .spec.dnsNames.0
126127
- .spec.dnsNames.1

config/service.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ apiVersion: v1
22
kind: Service
33
metadata:
44
name: controller-manager
5+
namespace: system
56
spec:
67
ports:
78
- port: 443

0 commit comments

Comments
 (0)