Skip to content

Commit 178862f

Browse files
Merge pull request #274 from dciabrin/adoption-cleanup
Clean up adoption configuration for galera CR
2 parents 1dde489 + 3d6a890 commit 178862f

File tree

7 files changed

+6
-153
lines changed

7 files changed

+6
-153
lines changed

api/bases/mariadb.openstack.org_galeras.yaml

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,6 @@ spec:
4444
spec:
4545
description: GaleraSpec defines the desired state of Galera
4646
properties:
47-
adoptionRedirect:
48-
description: Adoption configuration
49-
properties:
50-
host:
51-
description: MariaDB host to redirect to (IP or name)
52-
type: string
53-
type: object
5447
containerImage:
5548
description: Name of the galera container image to run (will be set
5649
to environmental default if empty)

api/v1beta1/galera_types.go

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,6 @@ const (
3838
CrMaxLengthCorrection = 17
3939
)
4040

41-
// AdoptionRedirectSpec defines redirection to a different DB instance during Adoption
42-
type AdoptionRedirectSpec struct {
43-
// MariaDB host to redirect to (IP or name)
44-
Host string `json:"host,omitempty"`
45-
}
46-
4741
// GaleraSpec defines the desired state of Galera
4842
type GaleraSpec struct {
4943
GaleraSpecCore `json:",inline"`
@@ -77,9 +71,6 @@ type GaleraSpecCore struct {
7771
// The content gets added to /etc/my.cnf.d/galera_custom.cnf
7872
CustomServiceConfig string `json:"customServiceConfig,omitempty"`
7973
// +kubebuilder:validation:Optional
80-
// Adoption configuration
81-
AdoptionRedirect AdoptionRedirectSpec `json:"adoptionRedirect"`
82-
// +kubebuilder:validation:Optional
8374
// +operator-sdk:csv:customresourcedefinitions:type=spec
8475
// TLS settings for MySQL service and internal Galera replication
8576
TLS tls.SimpleService `json:"tls,omitempty"`

api/v1beta1/zz_generated.deepcopy.go

Lines changed: 0 additions & 16 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

config/crd/bases/mariadb.openstack.org_galeras.yaml

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,6 @@ spec:
4444
spec:
4545
description: GaleraSpec defines the desired state of Galera
4646
properties:
47-
adoptionRedirect:
48-
description: Adoption configuration
49-
properties:
50-
host:
51-
description: MariaDB host to redirect to (IP or name)
52-
type: string
53-
type: object
5447
containerImage:
5548
description: Name of the galera container image to run (will be set
5649
to environmental default if empty)

controllers/galera_controller.go

Lines changed: 4 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -407,7 +407,7 @@ func (r *GaleraReconciler) Reconcile(ctx context.Context, req ctrl.Request) (res
407407
condition.UnknownCondition(condition.InputReadyCondition, condition.InitReason, condition.InputReadyInitMessage),
408408
// TLS cert secrets
409409
condition.UnknownCondition(condition.TLSInputReadyCondition, condition.InitReason, condition.InputReadyInitMessage),
410-
// endpoint for adoption redirect
410+
// service (expose database to pods) and headless service (between galera pods)
411411
condition.UnknownCondition(condition.ExposeServiceReadyCondition, condition.InitReason, condition.ExposeServiceReadyInitMessage),
412412
// configmap generation
413413
condition.UnknownCondition(condition.ServiceConfigReadyCondition, condition.InitReason, condition.ServiceConfigReadyInitMessage),
@@ -464,34 +464,6 @@ func (r *GaleraReconciler) Reconcile(ctx context.Context, req ctrl.Request) (res
464464
// Create/Update all the resources associated to this galera instance
465465
//
466466

467-
adoption := &instance.Spec.AdoptionRedirect
468-
469-
// Endpoints
470-
endpoints := mariadb.EndpointsForAdoption(instance, adoption)
471-
if endpoints != nil {
472-
op, err := controllerutil.CreateOrPatch(ctx, r.Client, endpoints, func() error {
473-
err := controllerutil.SetControllerReference(instance, endpoints, r.Scheme)
474-
if err != nil {
475-
return err
476-
}
477-
return nil
478-
})
479-
if err != nil {
480-
instance.Status.Conditions.Set(condition.FalseCondition(
481-
condition.ExposeServiceReadyCondition,
482-
condition.ErrorReason,
483-
condition.SeverityWarning,
484-
condition.ExposeServiceReadyErrorMessage,
485-
err.Error()))
486-
return ctrl.Result{}, err
487-
}
488-
if op != controllerutil.OperationResultNone {
489-
log.Info("", "Kind", instance.Kind, "Name", instance.Name, "database endpoints", endpoints.Name, "operation:", string(op))
490-
}
491-
}
492-
493-
instance.Status.Conditions.MarkTrue(condition.ExposeServiceReadyCondition, condition.ExposeServiceReadyMessage)
494-
495467
// the headless service provides DNS entries for pods
496468
// the name of the resource must match the name of the app selector
497469
pkghl := mariadb.HeadlessService(instance)
@@ -511,7 +483,7 @@ func (r *GaleraReconciler) Reconcile(ctx context.Context, req ctrl.Request) (res
511483
log.Info("", "Kind", instance.Kind, "Name", instance.Name, "database headless service", headless.Name, "operation", string(op))
512484
}
513485

514-
pkgsvc := mariadb.ServiceForAdoption(instance, "galera", adoption)
486+
pkgsvc := mariadb.Service(instance)
515487
service := &corev1.Service{ObjectMeta: pkgsvc.ObjectMeta}
516488
op, err = controllerutil.CreateOrPatch(ctx, r.Client, service, func() error {
517489
// 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
542514
log.Info("", "Kind", instance.Kind, "Name", instance.Name, "database service", service.Name, "operation", string(op))
543515
}
544516

517+
instance.Status.Conditions.MarkTrue(condition.ExposeServiceReadyCondition, condition.ExposeServiceReadyMessage)
518+
545519
// Map of all resources that may cause a rolling service restart
546520
inputHashEnv := make(map[string]env.Setter)
547521

pkg/mariadb/endpoints.go

Lines changed: 0 additions & 35 deletions
This file was deleted.

pkg/mariadb/service.go

Lines changed: 2 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,12 @@
11
package mariadb
22

33
import (
4-
"net"
5-
6-
databasev1beta1 "github.com/openstack-k8s-operators/mariadb-operator/api/v1beta1"
74
corev1 "k8s.io/api/core/v1"
85
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
96
)
107

11-
// ServiceForAdoption - create a service based on the adoption configuration
12-
func ServiceForAdoption(db metav1.Object, dbType string, adoption *databasev1beta1.AdoptionRedirectSpec) *corev1.Service {
13-
adoptionHost := adoption.Host
14-
adoptionHostIsIP := adoptionHost == "" || net.ParseIP(adoptionHost) != nil
15-
16-
if adoptionHost != "" {
17-
if adoptionHostIsIP {
18-
return externalServiceFromIP(db)
19-
}
20-
return externalServiceFromName(db, adoption)
21-
}
22-
return internalService(db, dbType)
23-
}
24-
25-
func internalService(db metav1.Object, dbType string) *corev1.Service {
26-
selectors := LabelSelectors(db, dbType)
8+
func Service(db metav1.Object) *corev1.Service {
9+
selectors := LabelSelectors(db, "galera")
2710
// NOTE(dciabrin) we currently deploy the Galera cluster as A/P,
2811
// by configuring the service's label selector to create
2912
// a single endpoint matching a single pod's name.
@@ -60,36 +43,6 @@ func internalService(db metav1.Object, dbType string) *corev1.Service {
6043
return svc
6144
}
6245

63-
func externalServiceFromIP(db metav1.Object) *corev1.Service {
64-
svc := &corev1.Service{
65-
ObjectMeta: metav1.ObjectMeta{
66-
Name: db.GetName(),
67-
Namespace: db.GetNamespace(),
68-
Labels: ServiceLabels(db),
69-
},
70-
Spec: corev1.ServiceSpec{
71-
ClusterIP: "None",
72-
Type: corev1.ServiceTypeClusterIP,
73-
},
74-
}
75-
return svc
76-
}
77-
78-
func externalServiceFromName(db metav1.Object, adoption *databasev1beta1.AdoptionRedirectSpec) *corev1.Service {
79-
svc := &corev1.Service{
80-
ObjectMeta: metav1.ObjectMeta{
81-
Name: db.GetName(),
82-
Namespace: db.GetNamespace(),
83-
Labels: ServiceLabels(db),
84-
},
85-
Spec: corev1.ServiceSpec{
86-
ExternalName: adoption.Host,
87-
Type: corev1.ServiceTypeExternalName,
88-
},
89-
}
90-
return svc
91-
}
92-
9346
// HeadlessService - service to give galera pods connectivity via DNS
9447
func HeadlessService(db metav1.Object) *corev1.Service {
9548
name := ResourceName(db.GetName())

0 commit comments

Comments
 (0)