mirror of https://github.com/kubernetes/kops.git
Add test for assigning ClusterCIDR and ClusterIPRange
This commit is contained in:
parent
424ed25f25
commit
64656bb911
|
@ -134,6 +134,8 @@ go_test(
|
|||
"//util/pkg/hashing:go_default_library",
|
||||
"//util/pkg/mirrors:go_default_library",
|
||||
"//util/pkg/vfs:go_default_library",
|
||||
"//vendor/github.com/stretchr/testify/assert:go_default_library",
|
||||
"//vendor/github.com/stretchr/testify/require:go_default_library",
|
||||
"//vendor/k8s.io/apimachinery/pkg/apis/meta/v1:go_default_library",
|
||||
"//vendor/k8s.io/klog/v2:go_default_library",
|
||||
"//vendor/sigs.k8s.io/yaml:go_default_library",
|
||||
|
|
|
@ -21,6 +21,8 @@ import (
|
|||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/stretchr/testify/assert"
|
||||
"github.com/stretchr/testify/require"
|
||||
"k8s.io/kops/pkg/testutils"
|
||||
|
||||
kopsapi "k8s.io/kops/pkg/apis/kops"
|
||||
|
@ -38,6 +40,7 @@ func buildMinimalCluster() (*awsup.MockAWSCloud, *kopsapi.Cluster) {
|
|||
|
||||
return cloud, c
|
||||
}
|
||||
|
||||
func TestPopulateCluster_Default_NoError(t *testing.T) {
|
||||
cloud, c := buildMinimalCluster()
|
||||
|
||||
|
@ -52,6 +55,40 @@ func TestPopulateCluster_Default_NoError(t *testing.T) {
|
|||
}
|
||||
}
|
||||
|
||||
func TestPopulateCluster_Subnets(t *testing.T) {
|
||||
tests := []struct {
|
||||
NonMasqueradeCIDR string
|
||||
ExpectedClusterCIDR string
|
||||
ExpectedServiceClusterIPRange string
|
||||
}{
|
||||
{
|
||||
NonMasqueradeCIDR: "100.64.0.0/10",
|
||||
ExpectedClusterCIDR: "100.96.0.0/11",
|
||||
ExpectedServiceClusterIPRange: "100.64.0.0/13",
|
||||
},
|
||||
{
|
||||
NonMasqueradeCIDR: "10.100.0.0/16",
|
||||
ExpectedClusterCIDR: "10.100.128.0/17",
|
||||
ExpectedServiceClusterIPRange: "10.100.0.0/19",
|
||||
},
|
||||
}
|
||||
for _, tc := range tests {
|
||||
t.Run(tc.NonMasqueradeCIDR, func(t *testing.T) {
|
||||
cloud, c := buildMinimalCluster()
|
||||
c.Spec.NonMasqueradeCIDR = tc.NonMasqueradeCIDR
|
||||
|
||||
err := PerformAssignments(c, cloud)
|
||||
require.NoError(t, err, "PerformAssignments")
|
||||
|
||||
full, err := mockedPopulateClusterSpec(c, cloud)
|
||||
require.NoError(t, err, "PopulateClusterSpec")
|
||||
|
||||
assert.Equal(t, tc.ExpectedClusterCIDR, full.Spec.KubeControllerManager.ClusterCIDR, "ClusterCIDR")
|
||||
assert.Equal(t, tc.ExpectedServiceClusterIPRange, full.Spec.ServiceClusterIPRange, "ServiceClusterIPRange")
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
func mockedPopulateClusterSpec(c *kopsapi.Cluster, cloud fi.Cloud) (*kopsapi.Cluster, error) {
|
||||
vfs.Context.ResetMemfsContext(true)
|
||||
|
||||
|
|
Loading…
Reference in New Issue