From 46957122d7a424b77e2abd0e8550a2601831bc22 Mon Sep 17 00:00:00 2001 From: Arsenii Pastushenko Date: Thu, 4 Nov 2021 21:19:42 +0200 Subject: [PATCH] Support loadBalancerSourceRanges configuration for master/replica services --- .../crd/bases/mysql.presslabs.org_mysqlclusters.yaml | 12 ++++++++++++ .../crds/mysql.presslabs.org_mysqlclusters.yaml | 10 ++++++++++ pkg/apis/mysql/v1alpha1/mysqlcluster_types.go | 4 ++++ pkg/apis/mysql/v1alpha1/zz_generated.deepcopy.go | 5 +++++ .../internal/syncer/healthy_replicas_service.go | 1 + .../mysqlcluster/internal/syncer/master_service.go | 1 + 6 files changed, 33 insertions(+) diff --git a/config/crd/bases/mysql.presslabs.org_mysqlclusters.yaml b/config/crd/bases/mysql.presslabs.org_mysqlclusters.yaml index 8c82057f1..0705c792e 100644 --- a/config/crd/bases/mysql.presslabs.org_mysqlclusters.yaml +++ b/config/crd/bases/mysql.presslabs.org_mysqlclusters.yaml @@ -54,6 +54,12 @@ spec: MasterServiceSpec: description: Master service extra specification properties: + allowedSourceRanges: + description: AllowedSourceRanges sets a list of CIDR blocks allowed + to access the cluster using LoadBalancer service. + items: + type: string + type: array annotations: additionalProperties: type: string @@ -6178,6 +6184,12 @@ spec: replicaServiceSpec: description: Healthy replica service extra specification properties: + allowedSourceRanges: + description: AllowedSourceRanges sets a list of CIDR blocks allowed + to access the cluster using LoadBalancer service. + items: + type: string + type: array annotations: additionalProperties: type: string diff --git a/deploy/charts/mysql-operator/crds/mysql.presslabs.org_mysqlclusters.yaml b/deploy/charts/mysql-operator/crds/mysql.presslabs.org_mysqlclusters.yaml index b14b74d50..829cc1d3c 100644 --- a/deploy/charts/mysql-operator/crds/mysql.presslabs.org_mysqlclusters.yaml +++ b/deploy/charts/mysql-operator/crds/mysql.presslabs.org_mysqlclusters.yaml @@ -49,6 +49,11 @@ spec: MasterServiceSpec: description: Master service extra specification properties: + allowedSourceRanges: + description: AllowedSourceRanges sets a list of CIDR blocks allowed to access the cluster using LoadBalancer service. + items: + type: string + type: array annotations: additionalProperties: type: string @@ -3774,6 +3779,11 @@ spec: replicaServiceSpec: description: Healthy replica service extra specification properties: + allowedSourceRanges: + description: AllowedSourceRanges sets a list of CIDR blocks allowed to access the cluster using LoadBalancer service. + items: + type: string + type: array annotations: additionalProperties: type: string diff --git a/pkg/apis/mysql/v1alpha1/mysqlcluster_types.go b/pkg/apis/mysql/v1alpha1/mysqlcluster_types.go index c12c5b511..f9a7a3e71 100644 --- a/pkg/apis/mysql/v1alpha1/mysqlcluster_types.go +++ b/pkg/apis/mysql/v1alpha1/mysqlcluster_types.go @@ -255,6 +255,10 @@ type ServiceSpec struct { // +optional LoadBalancer bool `json:"loadBalancer,omitempty"` + // AllowedSourceRanges sets a list of CIDR blocks allowed to access the cluster using LoadBalancer service. + // +optional + AllowedSourceRanges []string `json:"allowedSourceRanges,omitempty"` + // Annotations allow to specify annotations for MysqlCluster's services // +optional Annotations map[string]string `json:"annotations,omitempty"` diff --git a/pkg/apis/mysql/v1alpha1/zz_generated.deepcopy.go b/pkg/apis/mysql/v1alpha1/zz_generated.deepcopy.go index a11c06486..99267564b 100644 --- a/pkg/apis/mysql/v1alpha1/zz_generated.deepcopy.go +++ b/pkg/apis/mysql/v1alpha1/zz_generated.deepcopy.go @@ -836,6 +836,11 @@ func (in *QueryLimits) DeepCopy() *QueryLimits { // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *ServiceSpec) DeepCopyInto(out *ServiceSpec) { *out = *in + if in.AllowedSourceRanges != nil { + in, out := &in.AllowedSourceRanges, &out.AllowedSourceRanges + *out = make([]string, len(*in)) + copy(*out, *in) + } if in.Annotations != nil { in, out := &in.Annotations, &out.Annotations *out = make(map[string]string, len(*in)) diff --git a/pkg/controller/mysqlcluster/internal/syncer/healthy_replicas_service.go b/pkg/controller/mysqlcluster/internal/syncer/healthy_replicas_service.go index 0ee8ba64f..0261630e5 100644 --- a/pkg/controller/mysqlcluster/internal/syncer/healthy_replicas_service.go +++ b/pkg/controller/mysqlcluster/internal/syncer/healthy_replicas_service.go @@ -40,6 +40,7 @@ func NewHealthyReplicasSVCSyncer(c client.Client, scheme *runtime.Scheme, cluste // set service type if cluster.Spec.ReplicaServiceSpec.LoadBalancer { service.Spec.Type = core.ServiceTypeLoadBalancer + service.Spec.LoadBalancerSourceRanges = cluster.Spec.ReplicaServiceSpec.AllowedSourceRanges } // merge annotations diff --git a/pkg/controller/mysqlcluster/internal/syncer/master_service.go b/pkg/controller/mysqlcluster/internal/syncer/master_service.go index 156e83904..734745a81 100644 --- a/pkg/controller/mysqlcluster/internal/syncer/master_service.go +++ b/pkg/controller/mysqlcluster/internal/syncer/master_service.go @@ -40,6 +40,7 @@ func NewMasterSVCSyncer(c client.Client, scheme *runtime.Scheme, cluster *mysqlc // set service type if cluster.Spec.MasterServiceSpec.LoadBalancer { service.Spec.Type = core.ServiceTypeLoadBalancer + service.Spec.LoadBalancerSourceRanges = cluster.Spec.MasterServiceSpec.AllowedSourceRanges } // merge annotations