mirror of https://github.com/kubernetes/kops.git
Merge pull request #12308 from olemarkus/lb-dns-no-precreate
Do not precreate dns record for api lbs
This commit is contained in:
commit
2645e8410a
|
|
@ -245,18 +245,17 @@ func precreateDNS(ctx context.Context, cluster *kops.Cluster, cloud fi.Cloud) er
|
||||||
|
|
||||||
// buildPrecreateDNSHostnames returns the hostnames we should precreate
|
// buildPrecreateDNSHostnames returns the hostnames we should precreate
|
||||||
func buildPrecreateDNSHostnames(cluster *kops.Cluster) []string {
|
func buildPrecreateDNSHostnames(cluster *kops.Cluster) []string {
|
||||||
var dnsHostnames []string
|
dnsHostnames := []string{}
|
||||||
|
|
||||||
if cluster.Spec.MasterPublicName != "" {
|
hasAPILoadbalancer := cluster.Spec.API != nil && cluster.Spec.API.LoadBalancer != nil
|
||||||
|
useLBForInternalAPI := hasAPILoadbalancer && cluster.Spec.API.LoadBalancer.UseForInternalApi
|
||||||
|
|
||||||
|
if cluster.Spec.MasterPublicName != "" && !hasAPILoadbalancer {
|
||||||
dnsHostnames = append(dnsHostnames, cluster.Spec.MasterPublicName)
|
dnsHostnames = append(dnsHostnames, cluster.Spec.MasterPublicName)
|
||||||
} else {
|
|
||||||
klog.Warningf("cannot pre-create MasterPublicName - not set")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if cluster.Spec.MasterInternalName != "" {
|
if cluster.Spec.MasterInternalName != "" && !useLBForInternalAPI {
|
||||||
dnsHostnames = append(dnsHostnames, cluster.Spec.MasterInternalName)
|
dnsHostnames = append(dnsHostnames, cluster.Spec.MasterInternalName)
|
||||||
} else {
|
|
||||||
klog.Warningf("cannot pre-create MasterInternalName - not set")
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if apimodel.UseKopsControllerForNodeBootstrap(cluster) {
|
if apimodel.UseKopsControllerForNodeBootstrap(cluster) {
|
||||||
|
|
|
||||||
|
|
@ -25,40 +25,77 @@ import (
|
||||||
)
|
)
|
||||||
|
|
||||||
func TestPrecreateDNSNames(t *testing.T) {
|
func TestPrecreateDNSNames(t *testing.T) {
|
||||||
cluster := &kops.Cluster{}
|
|
||||||
cluster.ObjectMeta.Name = "cluster1.example.com"
|
grid := []struct {
|
||||||
cluster.Spec.MasterPublicName = "api." + cluster.ObjectMeta.Name
|
cluster *kops.Cluster
|
||||||
cluster.Spec.MasterInternalName = "api.internal." + cluster.ObjectMeta.Name
|
expected []string
|
||||||
cluster.Spec.EtcdClusters = []kops.EtcdClusterSpec{
|
}{
|
||||||
{
|
{
|
||||||
Name: "main",
|
cluster: &kops.Cluster{},
|
||||||
Members: []kops.EtcdMemberSpec{
|
expected: []string{
|
||||||
{Name: "zone1"},
|
"api.cluster1.example.com",
|
||||||
{Name: "zone2"},
|
"api.internal.cluster1.example.com",
|
||||||
{Name: "zone3"},
|
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
Name: "events",
|
cluster: &kops.Cluster{
|
||||||
Members: []kops.EtcdMemberSpec{
|
Spec: kops.ClusterSpec{
|
||||||
{Name: "zonea"},
|
API: &kops.AccessSpec{
|
||||||
{Name: "zoneb"},
|
LoadBalancer: &kops.LoadBalancerAccessSpec{},
|
||||||
{Name: "zonec"},
|
},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
|
expected: []string{
|
||||||
|
"api.internal.cluster1.example.com",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
cluster: &kops.Cluster{
|
||||||
|
Spec: kops.ClusterSpec{
|
||||||
|
API: &kops.AccessSpec{
|
||||||
|
LoadBalancer: &kops.LoadBalancerAccessSpec{
|
||||||
|
UseForInternalApi: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
expected: []string{},
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
actual := buildPrecreateDNSHostnames(cluster)
|
for _, g := range grid {
|
||||||
|
cluster := g.cluster
|
||||||
|
|
||||||
expected := []string{
|
cluster.ObjectMeta.Name = "cluster1.example.com"
|
||||||
"api.cluster1.example.com",
|
cluster.Spec.MasterPublicName = "api." + cluster.ObjectMeta.Name
|
||||||
"api.internal.cluster1.example.com",
|
cluster.Spec.MasterInternalName = "api.internal." + cluster.ObjectMeta.Name
|
||||||
}
|
cluster.Spec.EtcdClusters = []kops.EtcdClusterSpec{
|
||||||
|
{
|
||||||
|
Name: "main",
|
||||||
|
Members: []kops.EtcdMemberSpec{
|
||||||
|
{Name: "zone1"},
|
||||||
|
{Name: "zone2"},
|
||||||
|
{Name: "zone3"},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
Name: "events",
|
||||||
|
Members: []kops.EtcdMemberSpec{
|
||||||
|
{Name: "zonea"},
|
||||||
|
{Name: "zoneb"},
|
||||||
|
{Name: "zonec"},
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
sort.Strings(actual)
|
actual := buildPrecreateDNSHostnames(cluster)
|
||||||
sort.Strings(expected)
|
|
||||||
|
|
||||||
if !reflect.DeepEqual(expected, actual) {
|
expected := g.expected
|
||||||
t.Fatalf("unexpected records. expected=%v actual=%v", expected, actual)
|
sort.Strings(actual)
|
||||||
|
sort.Strings(expected)
|
||||||
|
|
||||||
|
if !reflect.DeepEqual(expected, actual) {
|
||||||
|
t.Errorf("unexpected records. expected=%v actual=%v", expected, actual)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue