Skip to content

Commit 586f904

Browse files
authored
Add Nutanix CCM ignore node IPs list (#9068)
* BUGFIX Add Add Nutanix CCM ignore node IPs list * Fix comments and linter errors - fix kube-vip validation - fix kube-vip add to ignore node list - add unit-test * Fix comments
1 parent 7e4cf0e commit 586f904

File tree

70 files changed

+1233
-96
lines changed

Some content is hidden

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

70 files changed

+1233
-96
lines changed

config/crd/bases/anywhere.eks.amazonaws.com_nutanixdatacenterconfigs.yaml

+7
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,13 @@ spec:
4242
bundle for users that configured their Prism Central with certificates
4343
from non-publicly trusted CAs
4444
type: string
45+
ccmExcludeNodeIPs:
46+
description: CcmExcludeIPs is the optional list of IP addresses that
47+
should be excluded from the CCM IP pool for nodes. List should be
48+
valid IP addresses and IP address ranges.
49+
items:
50+
type: string
51+
type: array
4552
credentialRef:
4653
description: CredentialRef is the reference to the secret name that
4754
contains the credentials for the Nutanix Prism Central. The namespace

pkg/api/v1alpha1/nutanixdatacenterconfig_types.go

+5
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,11 @@ type NutanixDatacenterConfigSpec struct {
4747
// FailureDomains is the optional list of failure domains for the Nutanix Datacenter.
4848
// +optional
4949
FailureDomains []NutanixDatacenterFailureDomain `json:"failureDomains,omitempty"`
50+
51+
// CcmExcludeIPs is the optional list of IP addresses that should be excluded from the CCM IP pool for nodes.
52+
// List should be valid IP addresses and IP address ranges.
53+
// +optional
54+
CcmExcludeNodeIPs []string `json:"ccmExcludeNodeIPs,omitempty"`
5055
}
5156

5257
// NutanixDatacenterFailureDomain defines the failure domain for the Nutanix Datacenter.

pkg/api/v1alpha1/zz_generated.deepcopy.go

+5
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/providers/nutanix/config/cp-template.yaml

+2-1
Original file line numberDiff line numberDiff line change
@@ -647,7 +647,8 @@ data:
647647
"enableCustomLabeling": false,
648648
"topologyDiscovery": {
649649
"type": "Prism"
650-
}
650+
},
651+
"ignoredNodeIPs": [{{ range $i, $ip := .ccmIgnoredNodeIPs }}{{ if $i }}, {{ end }}"{{ $ip }}"{{ end }}]
651652
}
652653
---
653654
apiVersion: rbac.authorization.k8s.io/v1

pkg/providers/nutanix/template.go

+91
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import (
44
"encoding/base64"
55
"encoding/json"
66
"fmt"
7+
"net"
8+
"strings"
79

810
"sigs.k8s.io/yaml"
911

@@ -176,9 +178,12 @@ func buildTemplateMapCP(
176178

177179
failureDomains := generateNutanixFailureDomains(datacenterSpec.FailureDomains)
178180

181+
ccmIgnoredNodeIPs := generateCcmIgnoredNodeIPsList(clusterSpec)
182+
179183
values := map[string]interface{}{
180184
"auditPolicy": auditPolicy,
181185
"apiServerExtraArgs": apiServerExtraArgs.ToPartialYaml(),
186+
"ccmIgnoredNodeIPs": ccmIgnoredNodeIPs,
182187
"cloudProviderImage": versionsBundle.Nutanix.CloudProvider.VersionedImage(),
183188
"clusterName": clusterSpec.Cluster.Name,
184189
"controlPlaneEndpointIp": clusterSpec.Cluster.Spec.ControlPlaneConfiguration.Endpoint.Host,
@@ -568,3 +573,89 @@ func generateNutanixFailureDomains(eksNutanixFailureDomains []v1alpha1.NutanixDa
568573
}
569574
return failureDomains
570575
}
576+
577+
func incrementIP(ip net.IP) {
578+
for i := len(ip) - 1; i >= 0; i-- {
579+
ip[i]++
580+
if ip[i] > 0 {
581+
break
582+
}
583+
}
584+
}
585+
586+
func compareIP(ip1, ip2 net.IP) (int, error) {
587+
if len(ip1) != len(ip2) {
588+
return -1, fmt.Errorf("IP addresses are not the same protocol")
589+
}
590+
591+
for i := 0; i < len(ip1); i++ {
592+
if ip1[i] < ip2[i] {
593+
return -1, nil
594+
}
595+
if ip1[i] > ip2[i] {
596+
return 1, nil
597+
}
598+
}
599+
600+
return 0, nil
601+
}
602+
603+
func addCIDRToIgnoredNodeIPsList(cidr string, result []string) []string {
604+
ip, ipNet, _ := net.ParseCIDR(cidr)
605+
606+
// Add all ip addresses in the range to the list
607+
for ip := ip.Mask(ipNet.Mask); ipNet.Contains(ip); incrementIP(ip) {
608+
if ip != nil {
609+
result = append(result, ip.String())
610+
}
611+
}
612+
613+
return result
614+
}
615+
616+
func addIPRangeToIgnoredNodeIPsList(ipRangeStr string, result []string) []string {
617+
// Parse the range
618+
ipRange := strings.Split(ipRangeStr, "-")
619+
620+
// Parse the start and end of the range
621+
start := net.ParseIP(strings.TrimSpace(ipRange[0]))
622+
end := net.ParseIP(strings.TrimSpace(ipRange[1]))
623+
624+
cmp, _ := compareIP(start, end)
625+
if cmp >= 0 {
626+
// swap start and end if start is greater than end
627+
start, end = end, start
628+
}
629+
630+
// Add all ip addresses in the range to the list
631+
for ip := start; !ip.Equal(end); incrementIP(ip) {
632+
result = append(result, ip.String())
633+
}
634+
635+
result = append(result, end.String())
636+
637+
return result
638+
}
639+
640+
func addIPAddressToIgnoredNodeIPsList(ipAddrStr string, result []string) []string {
641+
result = append(result, ipAddrStr)
642+
return result
643+
}
644+
645+
func generateCcmIgnoredNodeIPsList(clusterSpec *cluster.Spec) []string {
646+
// Add the kube-vip IP address to the list
647+
result := []string{clusterSpec.Cluster.Spec.ControlPlaneConfiguration.Endpoint.Host}
648+
649+
for _, IPAddrOrRange := range clusterSpec.NutanixDatacenter.Spec.CcmExcludeNodeIPs {
650+
addrOrRange := strings.TrimSpace(IPAddrOrRange)
651+
if strings.Contains(addrOrRange, "/") {
652+
result = addCIDRToIgnoredNodeIPsList(addrOrRange, result)
653+
} else if strings.Contains(addrOrRange, "-") {
654+
result = addIPRangeToIgnoredNodeIPsList(addrOrRange, result)
655+
} else {
656+
result = addIPAddressToIgnoredNodeIPsList(addrOrRange, result)
657+
}
658+
}
659+
660+
return result
661+
}

pkg/providers/nutanix/template_test.go

+41
Original file line numberDiff line numberDiff line change
@@ -848,6 +848,47 @@ func TestTemplateBuilderGPUs(t *testing.T) {
848848
}
849849
}
850850

851+
func TestTemplateBuilderCcmExcludeNodeIPs(t *testing.T) {
852+
for _, tc := range []struct {
853+
Input string
854+
Output string
855+
ChangeFn func(clusterSpec *cluster.Spec) *cluster.Spec
856+
}{
857+
{
858+
Input: "testdata/eksa-cluster-ccm-exclude-node-ips.yaml",
859+
Output: "testdata/expected_cluster_ccm_exclude_node_ips.yaml",
860+
ChangeFn: func(clusterSpec *cluster.Spec) *cluster.Spec {
861+
excludeNodeIPs := []string{
862+
"127.100.200.101",
863+
"10.10.10.10-10.10.10.13",
864+
"10.123.0.0/29",
865+
}
866+
clusterSpec.NutanixDatacenter.Spec.CcmExcludeNodeIPs = excludeNodeIPs
867+
868+
return clusterSpec
869+
},
870+
},
871+
} {
872+
clusterSpec := test.NewFullClusterSpec(t, tc.Input)
873+
874+
machineCfg := clusterSpec.NutanixMachineConfig(clusterSpec.Cluster.Spec.ControlPlaneConfiguration.MachineGroupRef.Name)
875+
876+
t.Setenv(constants.EksaNutanixUsernameKey, "admin")
877+
t.Setenv(constants.EksaNutanixPasswordKey, "password")
878+
creds := GetCredsFromEnv()
879+
880+
clusterSpec = tc.ChangeFn(clusterSpec)
881+
882+
bldr := NewNutanixTemplateBuilder(&clusterSpec.NutanixDatacenter.Spec, &machineCfg.Spec, nil,
883+
map[string]anywherev1.NutanixMachineConfigSpec{}, creds, time.Now)
884+
885+
cpSpec, err := bldr.GenerateCAPISpecControlPlane(clusterSpec)
886+
assert.NoError(t, err)
887+
assert.NotNil(t, cpSpec)
888+
test.AssertContentToFile(t, string(cpSpec), tc.Output)
889+
}
890+
}
891+
851892
func minimalNutanixConfigSpec(t *testing.T) (*anywherev1.NutanixDatacenterConfig, *anywherev1.NutanixMachineConfig, map[string]anywherev1.NutanixMachineConfigSpec) {
852893
dcConf := &anywherev1.NutanixDatacenterConfig{}
853894
err := yaml.Unmarshal([]byte(nutanixDatacenterConfigSpec), dcConf)

pkg/providers/nutanix/testdata/cluster_api_server_cert_san_domain_name.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ spec:
99
name: test
1010
count: 1
1111
endpoint:
12-
host: test
12+
host: 10.199.199.1
1313
certSANs: ["foo.bar"]
1414
machineGroupRef:
1515
name: test

pkg/providers/nutanix/testdata/cluster_api_server_cert_san_ip.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ spec:
99
name: test
1010
count: 1
1111
endpoint:
12-
host: test
12+
host: 10.199.199.1
1313
certSANs: ["11.11.11.11"]
1414
machineGroupRef:
1515
name: test

pkg/providers/nutanix/testdata/cluster_nutanix_etcd_encryption.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ spec:
99
name: test
1010
count: 1
1111
endpoint:
12-
host: test
12+
host: 10.199.199.1
1313
machineGroupRef:
1414
name: test
1515
kind: NutanixMachineConfig

pkg/providers/nutanix/testdata/cluster_nutanix_etcd_encryption_1_29.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ spec:
99
name: test
1010
count: 1
1111
endpoint:
12-
host: test
12+
host: 10.199.199.1
1313
machineGroupRef:
1414
name: test
1515
kind: NutanixMachineConfig

pkg/providers/nutanix/testdata/cluster_nutanix_failure_domains.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ spec:
99
name: test
1010
count: 1
1111
endpoint:
12-
host: test
12+
host: 10.199.199.1
1313
machineGroupRef:
1414
name: test
1515
kind: NutanixMachineConfig

pkg/providers/nutanix/testdata/cluster_nutanix_with_invalid_trust_bundle.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ spec:
99
name: eksa-unit-test
1010
count: 3
1111
endpoint:
12-
host: test-ip
12+
host: 10.199.199.1
1313
machineGroupRef:
1414
name: eksa-unit-test
1515
kind: NutanixMachineConfig

pkg/providers/nutanix/testdata/cluster_nutanix_with_trust_bundle.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ spec:
99
name: eksa-unit-test
1010
count: 3
1111
endpoint:
12-
host: test-ip
12+
host: 10.199.199.1
1313
machineGroupRef:
1414
name: eksa-unit-test
1515
kind: NutanixMachineConfig

pkg/providers/nutanix/testdata/cluster_nutanix_with_upgrade_strategy_cp.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ spec:
99
name: eksa-unit-test
1010
count: 3
1111
endpoint:
12-
host: test-ip
12+
host: 10.199.199.1
1313
machineGroupRef:
1414
name: eksa-unit-test
1515
kind: NutanixMachineConfig

pkg/providers/nutanix/testdata/cluster_nutanix_with_upgrade_strategy_md.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ spec:
99
name: eksa-unit-test
1010
count: 3
1111
endpoint:
12-
host: test-ip
12+
host: 10.199.199.1
1313
machineGroupRef:
1414
name: eksa-unit-test
1515
kind: NutanixMachineConfig
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
apiVersion: anywhere.eks.amazonaws.com/v1alpha1
2+
kind: NutanixDatacenterConfig
3+
metadata:
4+
name: eksa-unit-test
5+
namespace: default
6+
spec:
7+
endpoint: "prism.nutanix.com"
8+
port: 9440
9+
credentialRef:
10+
kind: Secret
11+
name: "nutanix-credentials"
12+
ccmExcludeNodeIPs:
13+
- 10.0.0.1
14+
- 10.0.0.0/24
15+
- 10.0.0.10-10.0.0.30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
apiVersion: anywhere.eks.amazonaws.com/v1alpha1
2+
kind: NutanixDatacenterConfig
3+
metadata:
4+
name: eksa-unit-test
5+
namespace: default
6+
spec:
7+
endpoint: "prism.nutanix.com"
8+
port: 9440
9+
credentialRef:
10+
kind: Secret
11+
name: "nutanix-credentials"
12+
ccmExcludeNodeIPs:
13+
- 10.0.0.1
14+
- 10.0.0.0/24
15+
- 10.0.0.10-10.0.0.30
16+
- 10.100.0.0//16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
apiVersion: anywhere.eks.amazonaws.com/v1alpha1
2+
kind: NutanixDatacenterConfig
3+
metadata:
4+
name: eksa-unit-test
5+
namespace: default
6+
spec:
7+
endpoint: "prism.nutanix.com"
8+
port: 9440
9+
credentialRef:
10+
kind: Secret
11+
name: "nutanix-credentials"
12+
ccmExcludeNodeIPs:
13+
- 10.0.0.1
14+
- 10.0.0.0/24
15+
- 10.0.0.10-10.0.0.30
16+
- 244.244.01
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
apiVersion: anywhere.eks.amazonaws.com/v1alpha1
2+
kind: NutanixDatacenterConfig
3+
metadata:
4+
name: eksa-unit-test
5+
namespace: default
6+
spec:
7+
endpoint: "prism.nutanix.com"
8+
port: 9440
9+
credentialRef:
10+
kind: Secret
11+
name: "nutanix-credentials"
12+
ccmExcludeNodeIPs:
13+
- 10.0.0.1
14+
- 10.0.0.0/24
15+
- 10.0.0.10-10.0.0.30
16+
- 10.100.0.10-10.100.10.10-10.100.20.30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
apiVersion: anywhere.eks.amazonaws.com/v1alpha1
2+
kind: NutanixDatacenterConfig
3+
metadata:
4+
name: eksa-unit-test
5+
namespace: default
6+
spec:
7+
endpoint: "prism.nutanix.com"
8+
port: 9440
9+
credentialRef:
10+
kind: Secret
11+
name: "nutanix-credentials"
12+
ccmExcludeNodeIPs:
13+
- 10.0.0.1
14+
- 10.0.0.0/24
15+
- 10.0.0.10-10.0.0.30
16+
- 192.179.1.1-10.1.1.1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
apiVersion: anywhere.eks.amazonaws.com/v1alpha1
2+
kind: NutanixDatacenterConfig
3+
metadata:
4+
name: eksa-unit-test
5+
namespace: default
6+
spec:
7+
endpoint: "prism.nutanix.com"
8+
port: 9440
9+
credentialRef:
10+
kind: Secret
11+
name: "nutanix-credentials"
12+
ccmExcludeNodeIPs:
13+
- 10.0.0.1
14+
- 10.0.0.0/24
15+
- 10.0.0.10-10.0.0.30
16+
- 10.0.10.0-::1
17+

pkg/providers/nutanix/testdata/eksa-cluster-additional-categories.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ spec:
99
name: eksa-unit-test
1010
count: 3
1111
endpoint:
12-
host: test-ip
12+
host: 10.199.199.1
1313
machineGroupRef:
1414
name: eksa-unit-test
1515
kind: NutanixMachineConfig

0 commit comments

Comments
 (0)