Skip to content

Commit

Permalink
Override pod and service subnet for kind cluster (#7654)
Browse files Browse the repository at this point in the history
  • Loading branch information
mitalipaygude authored Feb 21, 2024
1 parent dcb2e42 commit b63889f
Show file tree
Hide file tree
Showing 9 changed files with 66 additions and 0 deletions.
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

0 comments on commit b63889f

Please sign in to comment.