new toggle to use internal ELB by default

This commit is contained in:
Felix Kunde
2020-05-22 16:37:32 +02:00
parent 3a49b485e5
commit 2484af436a
21 changed files with 131 additions and 11 deletions
+60
View File
@@ -403,6 +403,8 @@ func TestServiceAnnotations(t *testing.T) {
enableMasterLoadBalancerOC bool
enableReplicaLoadBalancerSpec *bool
enableReplicaLoadBalancerOC bool
enablePublicLoadBalancerSpec *bool
enablePublicLoadBalancerOC bool
operatorAnnotations map[string]string
clusterAnnotations map[string]string
expect map[string]string
@@ -427,6 +429,7 @@ func TestServiceAnnotations(t *testing.T) {
expect: map[string]string{
"external-dns.alpha.kubernetes.io/hostname": "test.acid.db.example.com",
"service.beta.kubernetes.io/aws-load-balancer-connection-idle-timeout": "3600",
"service.beta.kubernetes.io/aws-load-balancer-internal": "true",
},
},
{
@@ -447,6 +450,7 @@ func TestServiceAnnotations(t *testing.T) {
expect: map[string]string{
"external-dns.alpha.kubernetes.io/hostname": "test.acid.db.example.com",
"service.beta.kubernetes.io/aws-load-balancer-connection-idle-timeout": "3600",
"service.beta.kubernetes.io/aws-load-balancer-internal": "true",
},
},
{
@@ -458,6 +462,7 @@ func TestServiceAnnotations(t *testing.T) {
expect: map[string]string{
"external-dns.alpha.kubernetes.io/hostname": "test.acid.db.example.com",
"service.beta.kubernetes.io/aws-load-balancer-connection-idle-timeout": "3600",
"service.beta.kubernetes.io/aws-load-balancer-internal": "true",
"foo": "bar",
},
},
@@ -479,6 +484,7 @@ func TestServiceAnnotations(t *testing.T) {
expect: map[string]string{
"external-dns.alpha.kubernetes.io/hostname": "test.acid.db.example.com",
"service.beta.kubernetes.io/aws-load-balancer-connection-idle-timeout": "3600",
"service.beta.kubernetes.io/aws-load-balancer-internal": "true",
"foo": "bar",
},
},
@@ -493,6 +499,7 @@ func TestServiceAnnotations(t *testing.T) {
expect: map[string]string{
"external-dns.alpha.kubernetes.io/hostname": "test.acid.db.example.com",
"service.beta.kubernetes.io/aws-load-balancer-connection-idle-timeout": "1800",
"service.beta.kubernetes.io/aws-load-balancer-internal": "true",
},
},
{
@@ -506,6 +513,7 @@ func TestServiceAnnotations(t *testing.T) {
expect: map[string]string{
"external-dns.alpha.kubernetes.io/hostname": "test.acid.db.example.com",
"service.beta.kubernetes.io/aws-load-balancer-connection-idle-timeout": "1800",
"service.beta.kubernetes.io/aws-load-balancer-internal": "true",
},
},
{
@@ -519,6 +527,7 @@ func TestServiceAnnotations(t *testing.T) {
expect: map[string]string{
"external-dns.alpha.kubernetes.io/hostname": "test.acid.db.example.com",
"service.beta.kubernetes.io/aws-load-balancer-connection-idle-timeout": "3600",
"service.beta.kubernetes.io/aws-load-balancer-internal": "true",
},
},
{
@@ -532,6 +541,7 @@ func TestServiceAnnotations(t *testing.T) {
expect: map[string]string{
"external-dns.alpha.kubernetes.io/hostname": "test.acid.db.example.com",
"service.beta.kubernetes.io/aws-load-balancer-connection-idle-timeout": "3600",
"service.beta.kubernetes.io/aws-load-balancer-internal": "true",
},
},
// REPLICA
@@ -554,6 +564,7 @@ func TestServiceAnnotations(t *testing.T) {
expect: map[string]string{
"external-dns.alpha.kubernetes.io/hostname": "test-repl.acid.db.example.com",
"service.beta.kubernetes.io/aws-load-balancer-connection-idle-timeout": "3600",
"service.beta.kubernetes.io/aws-load-balancer-internal": "true",
},
},
{
@@ -574,6 +585,7 @@ func TestServiceAnnotations(t *testing.T) {
expect: map[string]string{
"external-dns.alpha.kubernetes.io/hostname": "test-repl.acid.db.example.com",
"service.beta.kubernetes.io/aws-load-balancer-connection-idle-timeout": "3600",
"service.beta.kubernetes.io/aws-load-balancer-internal": "true",
},
},
{
@@ -585,6 +597,7 @@ func TestServiceAnnotations(t *testing.T) {
expect: map[string]string{
"external-dns.alpha.kubernetes.io/hostname": "test-repl.acid.db.example.com",
"service.beta.kubernetes.io/aws-load-balancer-connection-idle-timeout": "3600",
"service.beta.kubernetes.io/aws-load-balancer-internal": "true",
"foo": "bar",
},
},
@@ -606,6 +619,7 @@ func TestServiceAnnotations(t *testing.T) {
expect: map[string]string{
"external-dns.alpha.kubernetes.io/hostname": "test-repl.acid.db.example.com",
"service.beta.kubernetes.io/aws-load-balancer-connection-idle-timeout": "3600",
"service.beta.kubernetes.io/aws-load-balancer-internal": "true",
"foo": "bar",
},
},
@@ -620,6 +634,7 @@ func TestServiceAnnotations(t *testing.T) {
expect: map[string]string{
"external-dns.alpha.kubernetes.io/hostname": "test-repl.acid.db.example.com",
"service.beta.kubernetes.io/aws-load-balancer-connection-idle-timeout": "1800",
"service.beta.kubernetes.io/aws-load-balancer-internal": "true",
},
},
{
@@ -633,6 +648,7 @@ func TestServiceAnnotations(t *testing.T) {
expect: map[string]string{
"external-dns.alpha.kubernetes.io/hostname": "test-repl.acid.db.example.com",
"service.beta.kubernetes.io/aws-load-balancer-connection-idle-timeout": "1800",
"service.beta.kubernetes.io/aws-load-balancer-internal": "true",
},
},
{
@@ -646,6 +662,7 @@ func TestServiceAnnotations(t *testing.T) {
expect: map[string]string{
"external-dns.alpha.kubernetes.io/hostname": "test-repl.acid.db.example.com",
"service.beta.kubernetes.io/aws-load-balancer-connection-idle-timeout": "3600",
"service.beta.kubernetes.io/aws-load-balancer-internal": "true",
},
},
{
@@ -659,6 +676,47 @@ func TestServiceAnnotations(t *testing.T) {
expect: map[string]string{
"external-dns.alpha.kubernetes.io/hostname": "test-repl.acid.db.example.com",
"service.beta.kubernetes.io/aws-load-balancer-connection-idle-timeout": "3600",
"service.beta.kubernetes.io/aws-load-balancer-internal": "true",
},
},
//PUBLIC
{
about: "Public ELB disabled in spec and OperatorConfig",
role: "master",
enableMasterLoadBalancerSpec: &enabled,
enablePublicLoadBalancerSpec: &disabled,
enablePublicLoadBalancerOC: false,
operatorAnnotations: make(map[string]string),
clusterAnnotations: make(map[string]string),
expect: map[string]string{
"external-dns.alpha.kubernetes.io/hostname": "test.acid.db.example.com",
"service.beta.kubernetes.io/aws-load-balancer-connection-idle-timeout": "3600",
"service.beta.kubernetes.io/aws-load-balancer-internal": "true",
},
},
{
about: "Enable public ELB with EnablePublicLoadBalancer in spec but disabled in OperatorConfig",
role: "master",
enableMasterLoadBalancerSpec: &enabled,
enablePublicLoadBalancerSpec: &enabled,
enablePublicLoadBalancerOC: false,
operatorAnnotations: make(map[string]string),
clusterAnnotations: make(map[string]string),
expect: map[string]string{
"external-dns.alpha.kubernetes.io/hostname": "test.acid.db.example.com",
"service.beta.kubernetes.io/aws-load-balancer-connection-idle-timeout": "3600",
},
},
{
about: "Enable public ELB with enable_public_load_balancer in OperatorConfig",
role: "master",
enableMasterLoadBalancerSpec: &enabled,
enablePublicLoadBalancerOC: true,
operatorAnnotations: make(map[string]string),
clusterAnnotations: make(map[string]string),
expect: map[string]string{
"external-dns.alpha.kubernetes.io/hostname": "test.acid.db.example.com",
"service.beta.kubernetes.io/aws-load-balancer-connection-idle-timeout": "3600",
},
},
// COMMON
@@ -685,6 +743,7 @@ func TestServiceAnnotations(t *testing.T) {
cl.OpConfig.CustomServiceAnnotations = tt.operatorAnnotations
cl.OpConfig.EnableMasterLoadBalancer = tt.enableMasterLoadBalancerOC
cl.OpConfig.EnableReplicaLoadBalancer = tt.enableReplicaLoadBalancerOC
cl.OpConfig.EnablePublicLoadBalancer = tt.enablePublicLoadBalancerOC
cl.OpConfig.MasterDNSNameFormat = "{cluster}.{team}.{hostedzone}"
cl.OpConfig.ReplicaDNSNameFormat = "{cluster}-repl.{team}.{hostedzone}"
cl.OpConfig.DbHostedZone = "db.example.com"
@@ -694,6 +753,7 @@ func TestServiceAnnotations(t *testing.T) {
cl.Postgresql.Spec.ServiceAnnotations = tt.clusterAnnotations
cl.Postgresql.Spec.EnableMasterLoadBalancer = tt.enableMasterLoadBalancerSpec
cl.Postgresql.Spec.EnableReplicaLoadBalancer = tt.enableReplicaLoadBalancerSpec
cl.Postgresql.Spec.EnablePublicLoadBalancer = tt.enablePublicLoadBalancerSpec
got := cl.generateServiceAnnotations(tt.role, &cl.Postgresql.Spec)
if len(tt.expect) != len(got) {
+15
View File
@@ -1525,6 +1525,17 @@ func (c *Cluster) shouldCreateLoadBalancerForService(role PostgresRole, spec *ac
}
func (c *Cluster) shouldUseInternalLoadBalancerForService(spec *acidv1.PostgresSpec) bool {
// if the value is explicitly set in a Postgresql manifest, follow this setting
if spec.EnablePublicLoadBalancer != nil {
return !(*spec.EnablePublicLoadBalancer)
}
// otherwise, follow the operator configuration
return !c.OpConfig.EnablePublicLoadBalancer
}
func (c *Cluster) generateService(role PostgresRole, spec *acidv1.PostgresSpec) *v1.Service {
serviceSpec := v1.ServiceSpec{
Ports: []v1.ServicePort{{Name: "postgresql", Port: 5432, TargetPort: intstr.IntOrString{IntVal: 5432}}},
@@ -1594,6 +1605,10 @@ func (c *Cluster) generateServiceAnnotations(role PostgresRole, spec *acidv1.Pos
}
// External DNS name annotation is not customizable
annotations[constants.ZalandoDNSNameAnnotation] = dnsName
if c.shouldUseInternalLoadBalancerForService(spec) {
annotations[constants.ElbInternal] = "true"
}
}
if len(annotations) == 0 {