-
Notifications
You must be signed in to change notification settings - Fork 34
add multi-master option to galera #260
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -27,6 +27,8 @@ import ( | |
ctrl "sigs.k8s.io/controller-runtime" | ||
"sigs.k8s.io/controller-runtime/pkg/client" | ||
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil" | ||
"sigs.k8s.io/controller-runtime/pkg/handler" | ||
"sigs.k8s.io/controller-runtime/pkg/reconcile" | ||
|
||
condition "github.com/openstack-k8s-operators/lib-common/modules/common/condition" | ||
helper "github.com/openstack-k8s-operators/lib-common/modules/common/helper" | ||
|
@@ -145,7 +147,7 @@ func (r *MariaDBDatabaseReconciler) Reconcile(ctx context.Context, req ctrl.Requ | |
|
||
// here we know that Galera exists so add a finalizer to ourselves and to the db CR. Before this point there is no reason to have a finalizer on ourselves as nothing to cleanup. | ||
if instance.DeletionTimestamp.IsZero() || isNewInstance { // this condition can be removed if you wish as it is always true at this point otherwise we would returned earlier. | ||
if controllerutil.AddFinalizer(dbGalera, fmt.Sprintf("%s-%s", helper.GetFinalizer(), instance.Name)) { | ||
if dbGalera.DeletionTimestamp.IsZero() && controllerutil.AddFinalizer(dbGalera, fmt.Sprintf("%s-%s", helper.GetFinalizer(), instance.Name)) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @dciabrin can you review this line, without this the kuttl tests would run into a stack trace as trying to reconcile the mariadbdatabase after galera were deleted would raise here (this happens more frequently due to the Watch I added in this PR). note that by checking this, we do continue on to add a finalizer to the mariadbdatabase itself if one was not there already, but I think that would have been there anyway |
||
err := r.Update(ctx, dbGalera) | ||
if err != nil { | ||
return ctrl.Result{}, err | ||
|
@@ -200,6 +202,9 @@ func (r *MariaDBDatabaseReconciler) Reconcile(ctx context.Context, req ctrl.Requ | |
return ctrl.Result{}, err | ||
} | ||
|
||
// DB instances setup for multi master | ||
instance.Status.EnableMultiMaster = dbGalera.Spec.EnableMultiMaster | ||
|
||
dbCreateHash := instance.Status.Hash[databasev1beta1.DbCreateHash] | ||
dbCreateJob := job.NewJob( | ||
jobDef, | ||
|
@@ -245,8 +250,43 @@ func (r *MariaDBDatabaseReconciler) Reconcile(ctx context.Context, req ctrl.Requ | |
|
||
// SetupWithManager - | ||
func (r *MariaDBDatabaseReconciler) SetupWithManager(mgr ctrl.Manager) error { | ||
|
||
updateStatusFn := func(ctx context.Context, o client.Object) []reconcile.Request { | ||
log := GetLog(ctx, "MariaDBDatabase") | ||
|
||
result := []reconcile.Request{} | ||
|
||
mariaDBDatabases := &databasev1beta1.MariaDBDatabaseList{} | ||
|
||
listOpts := []client.ListOption{ | ||
client.InNamespace(o.GetNamespace()), | ||
} | ||
if err := r.Client.List(ctx, mariaDBDatabases, listOpts...); err != nil { | ||
log.Error(err, "Unable to retrieve MariaDBDatabase CRs %w") | ||
return nil | ||
} | ||
|
||
for _, cr := range mariaDBDatabases.Items { | ||
|
||
if o.GetName() == cr.GetLabels()["dbName"] { | ||
name := client.ObjectKey{ | ||
Namespace: o.GetNamespace(), | ||
Name: cr.Name, | ||
} | ||
log.Info(fmt.Sprintf("Galera %s is used by MariaDBDatabase CR %s", o.GetName(), cr.Name)) | ||
result = append(result, reconcile.Request{NamespacedName: name}) | ||
} | ||
} | ||
|
||
if len(result) > 0 { | ||
return result | ||
} | ||
return nil | ||
} | ||
|
||
return ctrl.NewControllerManagedBy(mgr). | ||
For(&databasev1beta1.MariaDBDatabase{}). | ||
Watches(&databasev1beta1.Galera{}, handler.EnqueueRequestsFromMapFunc(updateStatusFn)). | ||
Complete(r) | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
apiVersion: kuttl.dev/v1beta | ||
kind: TestStep | ||
delete: | ||
- apiVersion: mariadb.openstack.org/v1beta1 | ||
kind: Galera | ||
name: openstack | ||
commands: | ||
- script: | | ||
oc delete -n $NAMESPACE pvc mysql-db-openstack-galera-0 mysql-db-openstack-galera-1 mysql-db-openstack-galera-2 | ||
for i in `oc get pv | awk '/mysql-db.*galera/ {print $1}'`; do oc patch pv $i -p '{"spec":{"claimRef": null}}'; done |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
apiVersion: kuttl.dev/v1beta | ||
kind: TestStep | ||
delete: | ||
- apiVersion: mariadb.openstack.org/v1beta1 | ||
kind: Galera | ||
name: openstack | ||
commands: | ||
- script: | | ||
oc delete -n $NAMESPACE pvc mysql-db-openstack-galera-0 mysql-db-openstack-galera-1 mysql-db-openstack-galera-2 | ||
for i in `oc get pv | awk '/mysql-db.*galera/ {print $1}'`; do oc patch pv $i -p '{"spec":{"claimRef": null}}'; done |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
apiVersion: mariadb.openstack.org/v1beta1 | ||
kind: Galera | ||
metadata: | ||
name: openstack | ||
spec: | ||
secret: osp-secret | ||
storageClass: local-storage | ||
storageRequest: 500M | ||
replicas: 3 | ||
enableMultiMaster: false | ||
--- | ||
apiVersion: mariadb.openstack.org/v1beta1 | ||
kind: MariaDBDatabase | ||
metadata: | ||
name: mydatabase | ||
labels: | ||
dbName: openstack | ||
spec: | ||
name: mydatabase |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
# | ||
# Check for: | ||
# | ||
# - 1 MariaDB CR | ||
# - 1 Pod for MariaDB CR | ||
# | ||
|
||
apiVersion: mariadb.openstack.org/v1beta1 | ||
kind: Galera | ||
metadata: | ||
name: openstack | ||
spec: | ||
replicas: 3 | ||
secret: osp-secret | ||
storageRequest: 500M | ||
status: | ||
bootstrapped: true | ||
conditions: | ||
- message: Setup complete | ||
reason: Ready | ||
status: "True" | ||
type: Ready | ||
- message: Deployment completed | ||
reason: Ready | ||
status: "True" | ||
type: DeploymentReady | ||
- message: Exposing service completed | ||
reason: Ready | ||
status: "True" | ||
type: ExposeServiceReady | ||
- message: Input data complete | ||
reason: Ready | ||
status: "True" | ||
type: InputReady | ||
- message: RoleBinding created | ||
reason: Ready | ||
status: "True" | ||
type: RoleBindingReady | ||
- message: Role created | ||
reason: Ready | ||
status: "True" | ||
type: RoleReady | ||
- message: ServiceAccount created | ||
reason: Ready | ||
status: "True" | ||
type: ServiceAccountReady | ||
- message: Service config create completed | ||
reason: Ready | ||
status: "True" | ||
type: ServiceConfigReady | ||
- message: Input data complete | ||
reason: Ready | ||
status: "True" | ||
type: TLSInputReady | ||
--- | ||
apiVersion: apps/v1 | ||
kind: StatefulSet | ||
metadata: | ||
name: openstack-galera | ||
spec: | ||
replicas: 3 | ||
selector: | ||
matchLabels: | ||
app: galera | ||
cr: galera-openstack | ||
galera/name: openstack | ||
serviceName: openstack-galera | ||
template: | ||
metadata: | ||
labels: | ||
app: galera | ||
cr: galera-openstack | ||
galera/name: openstack | ||
spec: | ||
containers: | ||
- command: | ||
- /usr/bin/dumb-init | ||
- -- | ||
- /usr/local/bin/kolla_start | ||
name: galera | ||
ports: | ||
- containerPort: 3306 | ||
name: mysql | ||
protocol: TCP | ||
- containerPort: 4567 | ||
name: galera | ||
protocol: TCP | ||
serviceAccount: galera-openstack | ||
serviceAccountName: galera-openstack | ||
status: | ||
availableReplicas: 3 | ||
readyReplicas: 3 | ||
replicas: 3 | ||
--- | ||
apiVersion: v1 | ||
kind: Pod | ||
metadata: | ||
name: openstack-galera-0 | ||
--- | ||
apiVersion: v1 | ||
kind: Pod | ||
metadata: | ||
name: openstack-galera-1 | ||
--- | ||
apiVersion: v1 | ||
kind: Pod | ||
metadata: | ||
name: openstack-galera-2 | ||
--- | ||
apiVersion: v1 | ||
kind: Service | ||
metadata: | ||
name: openstack-galera | ||
spec: | ||
ports: | ||
- name: mysql | ||
port: 3306 | ||
protocol: TCP | ||
targetPort: 3306 | ||
selector: | ||
app: galera | ||
cr: galera-openstack | ||
--- | ||
apiVersion: mariadb.openstack.org/v1beta1 | ||
kind: MariaDBDatabase | ||
metadata: | ||
labels: | ||
dbName: openstack | ||
name: mydatabase | ||
spec: | ||
name: mydatabase |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
--- | ||
apiVersion: kuttl.dev/v1beta1 | ||
kind: TestAssert | ||
commands: | ||
- script: | | ||
# ensure kubernetes pod key present | ||
oc get -n ${NAMESPACE} service openstack -o yaml | grep "statefulset.kubernetes.io/pod-name: openstack-galera-" |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
apiVersion: mariadb.openstack.org/v1beta1 | ||
kind: Galera | ||
metadata: | ||
name: openstack | ||
spec: | ||
secret: osp-secret | ||
storageClass: local-storage | ||
storageRequest: 500M | ||
replicas: 3 | ||
enableMultiMaster: true |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
apiVersion: kuttl.dev/v1beta1 | ||
kind: TestAssert | ||
commands: | ||
- script: | | ||
# ensure kubernetes pod key *not* present | ||
! oc get -n ${NAMESPACE} service openstack -o yaml | grep "statefulset.kubernetes.io/pod-name: openstack-galera-" |
Uh oh!
There was an error while loading. Please reload this page.