mirror of
https://github.com/zalando/postgres-operator.git
synced 2026-10-06 19:12:31 +02:00
new toggle to use internal ELB by default
This commit is contained in:
@@ -268,6 +268,9 @@ var PostgresCRDResourceValidation = apiextv1beta1.CustomResourceValidation{
|
||||
"enableMasterLoadBalancer": {
|
||||
Type: "boolean",
|
||||
},
|
||||
"enablePublicLoadBalancer": {
|
||||
Type: "boolean",
|
||||
},
|
||||
"enableReplicaLoadBalancer": {
|
||||
Type: "boolean",
|
||||
},
|
||||
@@ -1062,6 +1065,9 @@ var OperatorConfigCRDResourceValidation = apiextv1beta1.CustomResourceValidation
|
||||
"enable_master_load_balancer": {
|
||||
Type: "boolean",
|
||||
},
|
||||
"enable_public_load_balancer": {
|
||||
Type: "boolean",
|
||||
},
|
||||
"enable_replica_load_balancer": {
|
||||
Type: "boolean",
|
||||
},
|
||||
|
||||
@@ -100,6 +100,7 @@ type OperatorTimeouts struct {
|
||||
type LoadBalancerConfiguration struct {
|
||||
DbHostedZone string `json:"db_hosted_zone,omitempty"`
|
||||
EnableMasterLoadBalancer bool `json:"enable_master_load_balancer,omitempty"`
|
||||
EnablePublicLoadBalancer bool `json:"enable_public_load_balancer,omitempty"`
|
||||
EnableReplicaLoadBalancer bool `json:"enable_replica_load_balancer,omitempty"`
|
||||
CustomServiceAnnotations map[string]string `json:"custom_service_annotations,omitempty"`
|
||||
MasterDNSNameFormat config.StringTemplate `json:"master_dns_name_format,omitempty"`
|
||||
|
||||
@@ -40,6 +40,7 @@ type PostgresSpec struct {
|
||||
// vars that enable load balancers are pointers because it is important to know if any of them is omitted from the Postgres manifest
|
||||
// in that case the var evaluates to nil and the value is taken from the operator config
|
||||
EnableMasterLoadBalancer *bool `json:"enableMasterLoadBalancer,omitempty"`
|
||||
EnablePublicLoadBalancer *bool `json:"enablePublicLoadBalancer,omitempty"`
|
||||
EnableReplicaLoadBalancer *bool `json:"enableReplicaLoadBalancer,omitempty"`
|
||||
|
||||
// deprecated load balancer settings maintained for backward compatibility
|
||||
|
||||
@@ -525,6 +525,11 @@ func (in *PostgresSpec) DeepCopyInto(out *PostgresSpec) {
|
||||
*out = new(bool)
|
||||
**out = **in
|
||||
}
|
||||
if in.EnablePublicLoadBalancer != nil {
|
||||
in, out := &in.EnablePublicLoadBalancer, &out.EnablePublicLoadBalancer
|
||||
*out = new(bool)
|
||||
**out = **in
|
||||
}
|
||||
if in.EnableReplicaLoadBalancer != nil {
|
||||
in, out := &in.EnableReplicaLoadBalancer, &out.EnableReplicaLoadBalancer
|
||||
*out = new(bool)
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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 {
|
||||
|
||||
@@ -101,6 +101,7 @@ func (c *Controller) importConfigurationFromCRD(fromCRD *acidv1.OperatorConfigur
|
||||
// load balancer config
|
||||
result.DbHostedZone = fromCRD.LoadBalancer.DbHostedZone
|
||||
result.EnableMasterLoadBalancer = fromCRD.LoadBalancer.EnableMasterLoadBalancer
|
||||
result.EnablePublicLoadBalancer = fromCRD.LoadBalancer.EnablePublicLoadBalancer
|
||||
result.EnableReplicaLoadBalancer = fromCRD.LoadBalancer.EnableReplicaLoadBalancer
|
||||
result.CustomServiceAnnotations = fromCRD.LoadBalancer.CustomServiceAnnotations
|
||||
result.MasterDNSNameFormat = fromCRD.LoadBalancer.MasterDNSNameFormat
|
||||
|
||||
@@ -134,7 +134,8 @@ type Config struct {
|
||||
EnableTeamSuperuser bool `name:"enable_team_superuser" default:"false"`
|
||||
TeamAdminRole string `name:"team_admin_role" default:"admin"`
|
||||
EnableAdminRoleForUsers bool `name:"enable_admin_role_for_users" default:"true"`
|
||||
EnableMasterLoadBalancer bool `name:"enable_master_load_balancer" default:"true"`
|
||||
EnableMasterLoadBalancer bool `name:"enable_master_load_balancer" default:"false"`
|
||||
EnablePublicLoadBalancer bool `name:"enable_public_load_balancer" default:"false"`
|
||||
EnableReplicaLoadBalancer bool `name:"enable_replica_load_balancer" default:"false"`
|
||||
CustomServiceAnnotations map[string]string `name:"custom_service_annotations"`
|
||||
CustomPodAnnotations map[string]string `name:"custom_pod_annotations"`
|
||||
|
||||
@@ -5,6 +5,7 @@ const (
|
||||
ZalandoDNSNameAnnotation = "external-dns.alpha.kubernetes.io/hostname"
|
||||
ElbTimeoutAnnotationName = "service.beta.kubernetes.io/aws-load-balancer-connection-idle-timeout"
|
||||
ElbTimeoutAnnotationValue = "3600"
|
||||
ElbInternal = "service.beta.kubernetes.io/aws-load-balancer-internal"
|
||||
KubeIAmAnnotation = "iam.amazonaws.com/role"
|
||||
VolumeStorateProvisionerAnnotation = "pv.kubernetes.io/provisioned-by"
|
||||
PostgresqlControllerAnnotationKey = "acid.zalan.do/controller"
|
||||
|
||||
Reference in New Issue
Block a user