Merge pull request #16342 from rifelpet/dns-topology

Move DNS topology setup earlier in cluster creation
This commit is contained in:
Kubernetes Prow Robot 2024-02-10 13:16:30 -08:00 committed by GitHub
commit e43e583d00
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
7 changed files with 102 additions and 15 deletions

View File

@ -122,8 +122,6 @@ spec:
type: Utility type: Utility
zone: us-test-1a zone: us-test-1a
topology: topology:
bastion:
bastionPublicName: bastion.complex.example.com
dns: dns:
type: None type: None

View File

@ -59,8 +59,6 @@ spec:
type: Utility type: Utility
zone: us-test-1a zone: us-test-1a
topology: topology:
bastion:
bastionPublicName: bastion.private.example.com
dns: dns:
type: None type: None

View File

@ -59,8 +59,6 @@ spec:
type: Utility type: Utility
zone: us-test-1a zone: us-test-1a
topology: topology:
bastion:
bastionPublicName: bastion.private.example.com
dns: dns:
type: None type: None

View File

@ -62,8 +62,6 @@ spec:
type: Utility type: Utility
zone: us-test-1a zone: us-test-1a
topology: topology:
bastion:
bastionPublicName: bastion.private.example.com
dns: dns:
type: None type: None

View File

@ -57,8 +57,6 @@ spec:
region: us-test1 region: us-test1
type: Private type: Private
topology: topology:
bastion:
bastionPublicName: bastion.private.example.com
dns: dns:
type: None type: None

View File

@ -1267,6 +1267,12 @@ func setupTopology(opt *NewClusterOptions, cluster *api.Cluster, allZones sets.S
} }
cluster.Spec.Networking.Topology = &api.TopologySpec{} cluster.Spec.Networking.Topology = &api.TopologySpec{}
err := setupDNSTopology(opt, cluster)
if err != nil {
return nil, err
}
switch opt.Topology { switch opt.Topology {
case api.TopologyPublic: case api.TopologyPublic:
@ -1405,10 +1411,6 @@ func setupTopology(opt *NewClusterOptions, cluster *api.Cluster, allZones sets.S
} }
} }
err := setupDNSTopology(opt, cluster)
if err != nil {
return nil, err
}
return bastions, nil return bastions, nil
} }

View File

@ -87,7 +87,6 @@ func TestCreateEtcdCluster(t *testing.T) {
func TestSetupNetworking(t *testing.T) { func TestSetupNetworking(t *testing.T) {
tests := []struct { tests := []struct {
options NewClusterOptions options NewClusterOptions
actual api.Cluster
expected api.Cluster expected api.Cluster
}{ }{
{ {
@ -337,6 +336,102 @@ func TestSetupNetworking(t *testing.T) {
} }
} }
func TestSetupTopology(t *testing.T) {
tests := []struct {
options NewClusterOptions
skeleton api.Cluster
expected api.Cluster
}{
{
options: NewClusterOptions{
Topology: api.TopologyPrivate,
Bastion: true,
},
skeleton: api.Cluster{
ObjectMeta: metav1.ObjectMeta{
Name: "test",
},
Spec: api.ClusterSpec{
KubernetesVersion: "v1.29.0",
Networking: api.NetworkingSpec{
Topology: &api.TopologySpec{
DNS: api.DNSTypeNone,
},
},
},
},
expected: api.Cluster{
ObjectMeta: metav1.ObjectMeta{
Name: "test",
},
Spec: api.ClusterSpec{
KubernetesVersion: "v1.29.0",
Networking: api.NetworkingSpec{
Topology: &api.TopologySpec{
DNS: api.DNSTypeNone,
},
},
},
},
},
{
options: NewClusterOptions{
Topology: api.TopologyPrivate,
DNSType: string(api.DNSTypePublic),
Bastion: true,
},
skeleton: api.Cluster{
ObjectMeta: metav1.ObjectMeta{
Name: "test",
},
Spec: api.ClusterSpec{
KubernetesVersion: "v1.29.0",
Networking: api.NetworkingSpec{
Topology: &api.TopologySpec{
DNS: api.DNSTypePublic,
},
},
},
},
expected: api.Cluster{
ObjectMeta: metav1.ObjectMeta{
Name: "test",
},
Spec: api.ClusterSpec{
KubernetesVersion: "v1.29.0",
Networking: api.NetworkingSpec{
Topology: &api.TopologySpec{
DNS: api.DNSTypePublic,
Bastion: &api.BastionSpec{
PublicName: "bastion.test",
},
},
},
},
},
},
}
for _, test := range tests {
_, err := setupTopology(&test.options, &test.skeleton, nil)
if err != nil {
t.Errorf("error during topology setup: %v", err)
}
expectedYaml, err := yaml.Marshal(test.expected)
if err != nil {
t.Errorf("error converting expected cluster spec to yaml: %v", err)
}
actualYaml, err := yaml.Marshal(&test.skeleton)
if err != nil {
t.Errorf("error converting actual cluster spec to yaml: %v", err)
}
if string(expectedYaml) != string(actualYaml) {
diffString := diff.FormatDiff(string(expectedYaml), string(actualYaml))
t.Errorf("unexpected cluster topology setup:\n%s", diffString)
}
}
}
func TestDefaultImage(t *testing.T) { func TestDefaultImage(t *testing.T) {
tests := []struct { tests := []struct {
cluster *api.Cluster cluster *api.Cluster