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
|
||||
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)
|
||||
} else {
|
||||
klog.Warningf("cannot pre-create MasterPublicName - not set")
|
||||
}
|
||||
|
||||
if cluster.Spec.MasterInternalName != "" {
|
||||
if cluster.Spec.MasterInternalName != "" && !useLBForInternalAPI {
|
||||
dnsHostnames = append(dnsHostnames, cluster.Spec.MasterInternalName)
|
||||
} else {
|
||||
klog.Warningf("cannot pre-create MasterInternalName - not set")
|
||||
}
|
||||
|
||||
if apimodel.UseKopsControllerForNodeBootstrap(cluster) {
|
||||
|
|
|
|||
|
|
@ -25,7 +25,47 @@ import (
|
|||
)
|
||||
|
||||
func TestPrecreateDNSNames(t *testing.T) {
|
||||
cluster := &kops.Cluster{}
|
||||
|
||||
grid := []struct {
|
||||
cluster *kops.Cluster
|
||||
expected []string
|
||||
}{
|
||||
{
|
||||
cluster: &kops.Cluster{},
|
||||
expected: []string{
|
||||
"api.cluster1.example.com",
|
||||
"api.internal.cluster1.example.com",
|
||||
},
|
||||
},
|
||||
{
|
||||
cluster: &kops.Cluster{
|
||||
Spec: kops.ClusterSpec{
|
||||
API: &kops.AccessSpec{
|
||||
LoadBalancer: &kops.LoadBalancerAccessSpec{},
|
||||
},
|
||||
},
|
||||
},
|
||||
expected: []string{
|
||||
"api.internal.cluster1.example.com",
|
||||
},
|
||||
},
|
||||
{
|
||||
cluster: &kops.Cluster{
|
||||
Spec: kops.ClusterSpec{
|
||||
API: &kops.AccessSpec{
|
||||
LoadBalancer: &kops.LoadBalancerAccessSpec{
|
||||
UseForInternalApi: true,
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
expected: []string{},
|
||||
},
|
||||
}
|
||||
|
||||
for _, g := range grid {
|
||||
cluster := g.cluster
|
||||
|
||||
cluster.ObjectMeta.Name = "cluster1.example.com"
|
||||
cluster.Spec.MasterPublicName = "api." + cluster.ObjectMeta.Name
|
||||
cluster.Spec.MasterInternalName = "api.internal." + cluster.ObjectMeta.Name
|
||||
|
|
@ -50,15 +90,12 @@ func TestPrecreateDNSNames(t *testing.T) {
|
|||
|
||||
actual := buildPrecreateDNSHostnames(cluster)
|
||||
|
||||
expected := []string{
|
||||
"api.cluster1.example.com",
|
||||
"api.internal.cluster1.example.com",
|
||||
}
|
||||
|
||||
expected := g.expected
|
||||
sort.Strings(actual)
|
||||
sort.Strings(expected)
|
||||
|
||||
if !reflect.DeepEqual(expected, actual) {
|
||||
t.Fatalf("unexpected records. expected=%v actual=%v", expected, actual)
|
||||
t.Errorf("unexpected records. expected=%v actual=%v", expected, actual)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue