Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Override pod and service subnet for kind cluster #7654

Merged
merged 1 commit into from
Feb 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions pkg/executables/config/kind.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
networking:
podSubnet: {{ .PodSubnet }}
serviceSubnet: {{ .ServiceSubnet }}
kubeadmConfigPatches:
- |
kind: ClusterConfiguration
Expand Down
13 changes: 13 additions & 0 deletions pkg/executables/kind.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ type kindExecConfig struct {
ExtraPortMappings []int
DockerExtraMounts bool
DisableDefaultCNI bool
PodSubnet string
ServiceSubnet string
}

func NewKind(executable Executable, writer filewriter.FileWriter) *Kind {
Expand All @@ -76,6 +78,17 @@ func (k *Kind) CreateBootstrapCluster(ctx context.Context, clusterSpec *cluster.
return "", err
}

serviceCidrs := clusterSpec.Cluster.Spec.ClusterNetwork.Services.CidrBlocks
podCidrs := clusterSpec.Cluster.Spec.ClusterNetwork.Pods.CidrBlocks

if len(serviceCidrs) != 0 {
k.execConfig.ServiceSubnet = serviceCidrs[0]
}

if len(podCidrs) != 0 {
k.execConfig.PodSubnet = podCidrs[0]
}

err = k.buildConfigFile()
if err != nil {
return "", err
Expand Down
32 changes: 32 additions & 0 deletions pkg/executables/kind_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,14 @@ func TestKindCreateBootstrapClusterSuccess(t *testing.T) {
clusterSpec := test.NewClusterSpec(func(s *cluster.Spec) {
s.Cluster.Name = clusterName
s.VersionsBundles["1.19"] = versionBundle
s.Cluster.Spec.ClusterNetwork = v1alpha1.ClusterNetwork{
Pods: v1alpha1.Pods{
CidrBlocks: []string{"1.1.1.1"},
},
Services: v1alpha1.Services{
CidrBlocks: []string{"2.2.2.2"},
},
}
})
eksClusterName := "test_cluster-eks-a-cluster"
kubeConfigFile := "test_cluster.kind.kubeconfig"
Expand Down Expand Up @@ -176,6 +184,14 @@ func TestKindCreateBootstrapClusterSuccessWithRegistryMirror(t *testing.T) {
},
},
}
s.Cluster.Spec.ClusterNetwork = v1alpha1.ClusterNetwork{
Pods: v1alpha1.Pods{
CidrBlocks: []string{"1.1.1.1"},
},
Services: v1alpha1.Services{
CidrBlocks: []string{"2.2.2.2"},
},
}
}),
env: map[string]string{},
wantKindConfig: "testdata/kind_config_registry_mirror_insecure.yaml",
Expand All @@ -191,6 +207,14 @@ func TestKindCreateBootstrapClusterSuccessWithRegistryMirror(t *testing.T) {
Port: constants.DefaultHttpsPort,
CACertContent: "test",
}
s.Cluster.Spec.ClusterNetwork = v1alpha1.ClusterNetwork{
Pods: v1alpha1.Pods{
CidrBlocks: []string{"1.1.1.1"},
},
Services: v1alpha1.Services{
CidrBlocks: []string{"2.2.2.2"},
},
}
}),
env: map[string]string{},
wantKindConfig: "testdata/kind_config_registry_mirror_with_ca.yaml",
Expand All @@ -216,6 +240,14 @@ func TestKindCreateBootstrapClusterSuccessWithRegistryMirror(t *testing.T) {
},
Authenticate: true,
}
s.Cluster.Spec.ClusterNetwork = v1alpha1.ClusterNetwork{
Pods: v1alpha1.Pods{
CidrBlocks: []string{"1.1.1.1"},
},
Services: v1alpha1.Services{
CidrBlocks: []string{"2.2.2.2"},
},
}
}),
env: map[string]string{},
wantKindConfig: "testdata/kind_config_registry_mirror_with_auth.yaml",
Expand Down
3 changes: 3 additions & 0 deletions pkg/executables/testdata/kind_config.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
networking:
podSubnet: 1.1.1.1
serviceSubnet: 2.2.2.2
kubeadmConfigPatches:
- |
kind: ClusterConfiguration
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
networking:
podSubnet: 1.1.1.1
serviceSubnet: 2.2.2.2
kubeadmConfigPatches:
- |
kind: ClusterConfiguration
Expand Down
3 changes: 3 additions & 0 deletions pkg/executables/testdata/kind_config_extra_port_mappings.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
networking:
podSubnet: 1.1.1.1
serviceSubnet: 2.2.2.2
kubeadmConfigPatches:
- |
kind: ClusterConfiguration
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
networking:
podSubnet: 1.1.1.1
serviceSubnet: 2.2.2.2
kubeadmConfigPatches:
- |
kind: ClusterConfiguration
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
networking:
podSubnet: 1.1.1.1
serviceSubnet: 2.2.2.2
kubeadmConfigPatches:
- |
kind: ClusterConfiguration
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
kind: Cluster
apiVersion: kind.x-k8s.io/v1alpha4
networking:
podSubnet: 1.1.1.1
serviceSubnet: 2.2.2.2
kubeadmConfigPatches:
- |
kind: ClusterConfiguration
Expand Down
Loading