diff --git a/api/bases/mariadb.openstack.org_galeras.yaml b/api/bases/mariadb.openstack.org_galeras.yaml index 709dd51c..d745246f 100644 --- a/api/bases/mariadb.openstack.org_galeras.yaml +++ b/api/bases/mariadb.openstack.org_galeras.yaml @@ -44,13 +44,6 @@ spec: spec: description: GaleraSpec defines the desired state of Galera properties: - adoptionRedirect: - description: Adoption configuration - properties: - host: - description: MariaDB host to redirect to (IP or name) - type: string - type: object containerImage: description: Name of the galera container image to run (will be set to environmental default if empty) diff --git a/api/v1beta1/galera_types.go b/api/v1beta1/galera_types.go index 806003b7..c9becfc4 100644 --- a/api/v1beta1/galera_types.go +++ b/api/v1beta1/galera_types.go @@ -38,12 +38,6 @@ const ( CrMaxLengthCorrection = 17 ) -// AdoptionRedirectSpec defines redirection to a different DB instance during Adoption -type AdoptionRedirectSpec struct { - // MariaDB host to redirect to (IP or name) - Host string `json:"host,omitempty"` -} - // GaleraSpec defines the desired state of Galera type GaleraSpec struct { GaleraSpecCore `json:",inline"` @@ -77,9 +71,6 @@ type GaleraSpecCore struct { // The content gets added to /etc/my.cnf.d/galera_custom.cnf CustomServiceConfig string `json:"customServiceConfig,omitempty"` // +kubebuilder:validation:Optional - // Adoption configuration - AdoptionRedirect AdoptionRedirectSpec `json:"adoptionRedirect"` - // +kubebuilder:validation:Optional // +operator-sdk:csv:customresourcedefinitions:type=spec // TLS settings for MySQL service and internal Galera replication TLS tls.SimpleService `json:"tls,omitempty"` diff --git a/api/v1beta1/zz_generated.deepcopy.go b/api/v1beta1/zz_generated.deepcopy.go index 1d892d93..27746407 100644 --- a/api/v1beta1/zz_generated.deepcopy.go +++ b/api/v1beta1/zz_generated.deepcopy.go @@ -27,21 +27,6 @@ import ( "k8s.io/apimachinery/pkg/runtime" ) -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *AdoptionRedirectSpec) DeepCopyInto(out *AdoptionRedirectSpec) { - *out = *in -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new AdoptionRedirectSpec. -func (in *AdoptionRedirectSpec) DeepCopy() *AdoptionRedirectSpec { - if in == nil { - return nil - } - out := new(AdoptionRedirectSpec) - in.DeepCopyInto(out) - return out -} - // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *Database) DeepCopyInto(out *Database) { *out = *in @@ -199,7 +184,6 @@ func (in *GaleraSpecCore) DeepCopyInto(out *GaleraSpecCore) { (*out)[key] = val } } - out.AdoptionRedirect = in.AdoptionRedirect in.TLS.DeepCopyInto(&out.TLS) } diff --git a/config/crd/bases/mariadb.openstack.org_galeras.yaml b/config/crd/bases/mariadb.openstack.org_galeras.yaml index 709dd51c..d745246f 100644 --- a/config/crd/bases/mariadb.openstack.org_galeras.yaml +++ b/config/crd/bases/mariadb.openstack.org_galeras.yaml @@ -44,13 +44,6 @@ spec: spec: description: GaleraSpec defines the desired state of Galera properties: - adoptionRedirect: - description: Adoption configuration - properties: - host: - description: MariaDB host to redirect to (IP or name) - type: string - type: object containerImage: description: Name of the galera container image to run (will be set to environmental default if empty) diff --git a/controllers/galera_controller.go b/controllers/galera_controller.go index 4fd8b6b6..9d44875d 100644 --- a/controllers/galera_controller.go +++ b/controllers/galera_controller.go @@ -407,7 +407,7 @@ func (r *GaleraReconciler) Reconcile(ctx context.Context, req ctrl.Request) (res condition.UnknownCondition(condition.InputReadyCondition, condition.InitReason, condition.InputReadyInitMessage), // TLS cert secrets condition.UnknownCondition(condition.TLSInputReadyCondition, condition.InitReason, condition.InputReadyInitMessage), - // endpoint for adoption redirect + // service (expose database to pods) and headless service (between galera pods) condition.UnknownCondition(condition.ExposeServiceReadyCondition, condition.InitReason, condition.ExposeServiceReadyInitMessage), // configmap generation condition.UnknownCondition(condition.ServiceConfigReadyCondition, condition.InitReason, condition.ServiceConfigReadyInitMessage), @@ -464,34 +464,6 @@ func (r *GaleraReconciler) Reconcile(ctx context.Context, req ctrl.Request) (res // Create/Update all the resources associated to this galera instance // - adoption := &instance.Spec.AdoptionRedirect - - // Endpoints - endpoints := mariadb.EndpointsForAdoption(instance, adoption) - if endpoints != nil { - op, err := controllerutil.CreateOrPatch(ctx, r.Client, endpoints, func() error { - err := controllerutil.SetControllerReference(instance, endpoints, r.Scheme) - if err != nil { - return err - } - return nil - }) - if err != nil { - instance.Status.Conditions.Set(condition.FalseCondition( - condition.ExposeServiceReadyCondition, - condition.ErrorReason, - condition.SeverityWarning, - condition.ExposeServiceReadyErrorMessage, - err.Error())) - return ctrl.Result{}, err - } - if op != controllerutil.OperationResultNone { - log.Info("", "Kind", instance.Kind, "Name", instance.Name, "database endpoints", endpoints.Name, "operation:", string(op)) - } - } - - instance.Status.Conditions.MarkTrue(condition.ExposeServiceReadyCondition, condition.ExposeServiceReadyMessage) - // the headless service provides DNS entries for pods // the name of the resource must match the name of the app selector pkghl := mariadb.HeadlessService(instance) @@ -511,7 +483,7 @@ func (r *GaleraReconciler) Reconcile(ctx context.Context, req ctrl.Request) (res log.Info("", "Kind", instance.Kind, "Name", instance.Name, "database headless service", headless.Name, "operation", string(op)) } - pkgsvc := mariadb.ServiceForAdoption(instance, "galera", adoption) + pkgsvc := mariadb.Service(instance) service := &corev1.Service{ObjectMeta: pkgsvc.ObjectMeta} op, err = controllerutil.CreateOrPatch(ctx, r.Client, service, func() error { // Add finalizer to the svc to prevent deletion. If the svc gets deleted @@ -542,6 +514,8 @@ func (r *GaleraReconciler) Reconcile(ctx context.Context, req ctrl.Request) (res log.Info("", "Kind", instance.Kind, "Name", instance.Name, "database service", service.Name, "operation", string(op)) } + instance.Status.Conditions.MarkTrue(condition.ExposeServiceReadyCondition, condition.ExposeServiceReadyMessage) + // Map of all resources that may cause a rolling service restart inputHashEnv := make(map[string]env.Setter) diff --git a/pkg/mariadb/endpoints.go b/pkg/mariadb/endpoints.go deleted file mode 100644 index e9bf25f1..00000000 --- a/pkg/mariadb/endpoints.go +++ /dev/null @@ -1,35 +0,0 @@ -package mariadb - -import ( - "net" - - databasev1beta1 "github.com/openstack-k8s-operators/mariadb-operator/api/v1beta1" - corev1 "k8s.io/api/core/v1" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" -) - -// EndpointsForAdoption - create an endpoint based on the adoption configuration -func EndpointsForAdoption(db metav1.Object, adoption *databasev1beta1.AdoptionRedirectSpec) *corev1.Endpoints { - adoptionHost := adoption.Host - // We only create Endpoints directly if the adoption host is - // defined and it has an IP format (not FQDN format). - if adoptionHost == "" || net.ParseIP(adoptionHost) == nil { - return nil - } - - endpoints := &corev1.Endpoints{ - ObjectMeta: metav1.ObjectMeta{ - Name: db.GetName(), - Namespace: db.GetNamespace(), - Labels: GetLabels(db.GetName()), - }, - Subsets: []corev1.EndpointSubset{ - { - Addresses: []corev1.EndpointAddress{ - {IP: adoptionHost}, - }, - }, - }, - } - return endpoints -} diff --git a/pkg/mariadb/service.go b/pkg/mariadb/service.go index 563dd398..9204575c 100644 --- a/pkg/mariadb/service.go +++ b/pkg/mariadb/service.go @@ -1,29 +1,12 @@ package mariadb import ( - "net" - - databasev1beta1 "github.com/openstack-k8s-operators/mariadb-operator/api/v1beta1" corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) -// ServiceForAdoption - create a service based on the adoption configuration -func ServiceForAdoption(db metav1.Object, dbType string, adoption *databasev1beta1.AdoptionRedirectSpec) *corev1.Service { - adoptionHost := adoption.Host - adoptionHostIsIP := adoptionHost == "" || net.ParseIP(adoptionHost) != nil - - if adoptionHost != "" { - if adoptionHostIsIP { - return externalServiceFromIP(db) - } - return externalServiceFromName(db, adoption) - } - return internalService(db, dbType) -} - -func internalService(db metav1.Object, dbType string) *corev1.Service { - selectors := LabelSelectors(db, dbType) +func Service(db metav1.Object) *corev1.Service { + selectors := LabelSelectors(db, "galera") // NOTE(dciabrin) we currently deploy the Galera cluster as A/P, // by configuring the service's label selector to create // a single endpoint matching a single pod's name. @@ -60,36 +43,6 @@ func internalService(db metav1.Object, dbType string) *corev1.Service { return svc } -func externalServiceFromIP(db metav1.Object) *corev1.Service { - svc := &corev1.Service{ - ObjectMeta: metav1.ObjectMeta{ - Name: db.GetName(), - Namespace: db.GetNamespace(), - Labels: ServiceLabels(db), - }, - Spec: corev1.ServiceSpec{ - ClusterIP: "None", - Type: corev1.ServiceTypeClusterIP, - }, - } - return svc -} - -func externalServiceFromName(db metav1.Object, adoption *databasev1beta1.AdoptionRedirectSpec) *corev1.Service { - svc := &corev1.Service{ - ObjectMeta: metav1.ObjectMeta{ - Name: db.GetName(), - Namespace: db.GetNamespace(), - Labels: ServiceLabels(db), - }, - Spec: corev1.ServiceSpec{ - ExternalName: adoption.Host, - Type: corev1.ServiceTypeExternalName, - }, - } - return svc -} - // HeadlessService - service to give galera pods connectivity via DNS func HeadlessService(db metav1.Object) *corev1.Service { name := ResourceName(db.GetName())