Skip to content

Commit

Permalink
Merge pull request #274 from dciabrin/adoption-cleanup
Browse files Browse the repository at this point in the history
Clean up adoption configuration for galera CR
  • Loading branch information
openshift-merge-bot[bot] authored Oct 3, 2024
2 parents 1dde489 + 3d6a890 commit 178862f
Show file tree
Hide file tree
Showing 7 changed files with 6 additions and 153 deletions.
7 changes: 0 additions & 7 deletions api/bases/mariadb.openstack.org_galeras.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
9 changes: 0 additions & 9 deletions api/v1beta1/galera_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down Expand Up @@ -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"`
Expand Down
16 changes: 0 additions & 16 deletions api/v1beta1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 0 additions & 7 deletions config/crd/bases/mariadb.openstack.org_galeras.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
34 changes: 4 additions & 30 deletions controllers/galera_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -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)
Expand All @@ -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
Expand Down Expand Up @@ -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)

Expand Down
35 changes: 0 additions & 35 deletions pkg/mariadb/endpoints.go

This file was deleted.

51 changes: 2 additions & 49 deletions pkg/mariadb/service.go
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -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())
Expand Down

0 comments on commit 178862f

Please sign in to comment.