Skip to content

Commit 0ac1530

Browse files
committed
refactor: new disabled kube-proxy mode
1 parent 1827939 commit 0ac1530

18 files changed

+132
-136
lines changed

api/v1alpha1/clusterconfig_types.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -437,14 +437,17 @@ const (
437437
// KubeProxyModeNFTables indicates that kube-proxy should be installed in nftables
438438
// mode.
439439
KubeProxyModeNFTables KubeProxyMode = "nftables"
440+
// KubeProxyModeDisabled indicates that kube-proxy should be disabled.
441+
KubeProxyModeDisabled KubeProxyMode = "disabled"
440442
)
441443

442444
type KubeProxy struct {
443445
// Mode specifies the mode for kube-proxy:
444446
// - iptables means that kube-proxy is installed in iptables mode.
445447
// - nftables means that kube-proxy is installed in nftables mode.
448+
// - disabled means that kube-proxy is disabled.
446449
// +kubebuilder:validation:Optional
447-
// +kubebuilder:validation:Enum=iptables;nftables
450+
// +kubebuilder:validation:Enum=iptables;nftables;disabled
448451
// +kubebuilder:validation:XValidation:rule="self == oldSelf",message="Value cannot be changed after cluster creation"
449452
Mode KubeProxyMode `json:"mode,omitempty"`
450453
}

api/v1alpha1/crds/caren.nutanix.com_awsclusterconfigs.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -716,9 +716,11 @@ spec:
716716
Mode specifies the mode for kube-proxy:
717717
- iptables means that kube-proxy is installed in iptables mode.
718718
- nftables means that kube-proxy is installed in nftables mode.
719+
- disabled means that kube-proxy is disabled.
719720
enum:
720721
- iptables
721722
- nftables
723+
- disabled
722724
type: string
723725
x-kubernetes-validations:
724726
- message: Value cannot be changed after cluster creation

api/v1alpha1/crds/caren.nutanix.com_dockerclusterconfigs.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -531,9 +531,11 @@ spec:
531531
Mode specifies the mode for kube-proxy:
532532
- iptables means that kube-proxy is installed in iptables mode.
533533
- nftables means that kube-proxy is installed in nftables mode.
534+
- disabled means that kube-proxy is disabled.
534535
enum:
535536
- iptables
536537
- nftables
538+
- disabled
537539
type: string
538540
x-kubernetes-validations:
539541
- message: Value cannot be changed after cluster creation

api/v1alpha1/crds/caren.nutanix.com_eksclusterconfigs.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -443,9 +443,11 @@ spec:
443443
Mode specifies the mode for kube-proxy:
444444
- iptables means that kube-proxy is installed in iptables mode.
445445
- nftables means that kube-proxy is installed in nftables mode.
446+
- disabled means that kube-proxy is disabled.
446447
enum:
447448
- iptables
448449
- nftables
450+
- disabled
449451
type: string
450452
x-kubernetes-validations:
451453
- message: Value cannot be changed after cluster creation

api/v1alpha1/crds/caren.nutanix.com_nutanixclusterconfigs.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -719,9 +719,11 @@ spec:
719719
Mode specifies the mode for kube-proxy:
720720
- iptables means that kube-proxy is installed in iptables mode.
721721
- nftables means that kube-proxy is installed in nftables mode.
722+
- disabled means that kube-proxy is disabled.
722723
enum:
723724
- iptables
724725
- nftables
726+
- disabled
725727
type: string
726728
x-kubernetes-validations:
727729
- message: Value cannot be changed after cluster creation

api/variables/getters.go

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,29 @@ func RegistryAddon(cluster *clusterv1.Cluster) (*carenv1.RegistryAddon, error) {
2727

2828
return spec.Addons.Registry, nil
2929
}
30+
31+
// KubeProxyMode retrieves the kube-proxy mode from the cluster's topology variables.
32+
// Returns nil if the kube-proxy mode is not defined.
33+
func KubeProxyMode(cluster *clusterv1.Cluster) (*carenv1.KubeProxyMode, error) {
34+
spec, err := UnmarshalClusterConfigVariable(cluster.Spec.Topology.Variables)
35+
if err != nil {
36+
return nil, fmt.Errorf("failed to unmarshal cluster variable: %w", err)
37+
}
38+
if spec == nil {
39+
return nil, nil
40+
}
41+
if spec.KubeProxy == nil {
42+
return nil, nil
43+
}
44+
45+
return &spec.KubeProxy.Mode, nil
46+
}
47+
48+
// KubeProxyIsDisabled returns true if kube-proxy mode from the cluster's topology variables is disabled.
49+
func KubeProxyIsDisabled(cluster *clusterv1.Cluster) (bool, error) {
50+
mode, err := KubeProxyMode(cluster)
51+
if err != nil {
52+
return false, err
53+
}
54+
return mode != nil && *mode == carenv1.KubeProxyModeDisabled, nil
55+
}

common/pkg/capi/utils/annotations.go

Lines changed: 0 additions & 18 deletions
This file was deleted.

docs/content/customization/generic/kube-proxy-mode.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,11 @@ metadata:
6060
name: <NAME>
6161
spec:
6262
topology:
63-
controlPlane:
64-
metadata:
65-
annotations:
66-
controlplane.cluster.x-k8s.io/skip-kube-proxy: ""
63+
variables:
64+
- name: clusterConfig
65+
value:
66+
kubeProxy:
67+
mode: disabled
6768
```
6869

6970
Applying this configuration will result in the following configuration being applied:

examples/capi-quick-start/aws-cluster-cilium-helm-addon.yaml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,6 @@ spec:
1616
topology:
1717
class: aws-quick-start
1818
controlPlane:
19-
metadata:
20-
annotations:
21-
controlplane.cluster.x-k8s.io/skip-kube-proxy: ""
2219
replicas: ${CONTROL_PLANE_MACHINE_COUNT}
2320
variables:
2421
- name: clusterConfig
@@ -52,6 +49,8 @@ spec:
5249
encryptionAtRest:
5350
providers:
5451
- aescbc: {}
52+
kubeProxy:
53+
mode: disabled
5554
- name: workerConfig
5655
value:
5756
aws:

examples/capi-quick-start/eks-cluster.yaml

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,7 @@ metadata:
6262
spec:
6363
topology:
6464
class: eks-quick-start
65-
controlPlane:
66-
metadata:
67-
annotations:
68-
controlplane.cluster.x-k8s.io/skip-kube-proxy: ""
65+
controlPlane: {}
6966
variables:
7067
- name: clusterConfig
7168
value:
@@ -89,6 +86,8 @@ spec:
8986
nfd: {}
9087
eks:
9188
region: us-west-2
89+
kubeProxy:
90+
mode: disabled
9291
version: ${KUBERNETES_VERSION}
9392
workers:
9493
machineDeployments:

0 commit comments

Comments
 (0)