mirror of
https://github.com/mariadb-operator/mariadb-operator.git
synced 2025-08-19 16:24:15 +00:00
Triggering rolling update when my.cnf changes
This commit is contained in:
@ -2,6 +2,7 @@ package controller
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
|
"crypto/sha256"
|
||||||
"errors"
|
"errors"
|
||||||
"fmt"
|
"fmt"
|
||||||
"time"
|
"time"
|
||||||
@ -27,6 +28,7 @@ import (
|
|||||||
"github.com/mariadb-operator/mariadb-operator/pkg/discovery"
|
"github.com/mariadb-operator/mariadb-operator/pkg/discovery"
|
||||||
"github.com/mariadb-operator/mariadb-operator/pkg/environment"
|
"github.com/mariadb-operator/mariadb-operator/pkg/environment"
|
||||||
"github.com/mariadb-operator/mariadb-operator/pkg/health"
|
"github.com/mariadb-operator/mariadb-operator/pkg/health"
|
||||||
|
"github.com/mariadb-operator/mariadb-operator/pkg/metadata"
|
||||||
"github.com/mariadb-operator/mariadb-operator/pkg/refresolver"
|
"github.com/mariadb-operator/mariadb-operator/pkg/refresolver"
|
||||||
appsv1 "k8s.io/api/apps/v1"
|
appsv1 "k8s.io/api/apps/v1"
|
||||||
corev1 "k8s.io/api/core/v1"
|
corev1 "k8s.io/api/core/v1"
|
||||||
@ -309,7 +311,12 @@ func (r *MariaDBReconciler) reconcileInit(ctx context.Context, mariadb *mariadbv
|
|||||||
|
|
||||||
func (r *MariaDBReconciler) reconcileStatefulSet(ctx context.Context, mariadb *mariadbv1alpha1.MariaDB) (ctrl.Result, error) {
|
func (r *MariaDBReconciler) reconcileStatefulSet(ctx context.Context, mariadb *mariadbv1alpha1.MariaDB) (ctrl.Result, error) {
|
||||||
key := client.ObjectKeyFromObject(mariadb)
|
key := client.ObjectKeyFromObject(mariadb)
|
||||||
desiredSts, err := r.Builder.BuildMariadbStatefulSet(mariadb, key, nil)
|
podAnnotations, err := r.getPodAnnotations(ctx, mariadb)
|
||||||
|
if err != nil {
|
||||||
|
return ctrl.Result{}, fmt.Errorf("error getting Pod annotations: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
desiredSts, err := r.Builder.BuildMariadbStatefulSet(mariadb, key, podAnnotations)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return ctrl.Result{}, fmt.Errorf("error building StatefulSet: %v", err)
|
return ctrl.Result{}, fmt.Errorf("error building StatefulSet: %v", err)
|
||||||
}
|
}
|
||||||
@ -323,6 +330,20 @@ func (r *MariaDBReconciler) reconcileStatefulSet(ctx context.Context, mariadb *m
|
|||||||
return ctrl.Result{}, nil
|
return ctrl.Result{}, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (r *MariaDBReconciler) getPodAnnotations(ctx context.Context, mariadb *mariadbv1alpha1.MariaDB) (map[string]string, error) {
|
||||||
|
podAnnotations := make(map[string]string)
|
||||||
|
|
||||||
|
if mariadb.Spec.MyCnfConfigMapKeyRef != nil {
|
||||||
|
config, err := r.RefResolver.ConfigMapKeyRef(ctx, mariadb.Spec.MyCnfConfigMapKeyRef, mariadb.Namespace)
|
||||||
|
if err != nil {
|
||||||
|
return nil, fmt.Errorf("error getting my.cnf from ConfigMap: %v", err)
|
||||||
|
}
|
||||||
|
podAnnotations[metadata.ConfigAnnotation] = fmt.Sprintf("%x", sha256.Sum256([]byte(config)))
|
||||||
|
}
|
||||||
|
|
||||||
|
return podAnnotations, nil
|
||||||
|
}
|
||||||
|
|
||||||
func (r *MariaDBReconciler) reconcilePodDisruptionBudget(ctx context.Context, mariadb *mariadbv1alpha1.MariaDB) (ctrl.Result, error) {
|
func (r *MariaDBReconciler) reconcilePodDisruptionBudget(ctx context.Context, mariadb *mariadbv1alpha1.MariaDB) (ctrl.Result, error) {
|
||||||
if mariadb.IsHAEnabled() && mariadb.Spec.PodDisruptionBudget == nil {
|
if mariadb.IsHAEnabled() && mariadb.Spec.PodDisruptionBudget == nil {
|
||||||
return ctrl.Result{}, r.reconcileHighAvailabilityPDB(ctx, mariadb)
|
return ctrl.Result{}, r.reconcileHighAvailabilityPDB(ctx, mariadb)
|
||||||
|
@ -4,5 +4,6 @@ var (
|
|||||||
ReplicationAnnotation = "k8s.mariadb.com/replication"
|
ReplicationAnnotation = "k8s.mariadb.com/replication"
|
||||||
GaleraAnnotation = "k8s.mariadb.com/galera"
|
GaleraAnnotation = "k8s.mariadb.com/galera"
|
||||||
MariadbAnnotation = "k8s.mariadb.com/mariadb"
|
MariadbAnnotation = "k8s.mariadb.com/mariadb"
|
||||||
|
ConfigAnnotation = "k8s.mariadb.com/config"
|
||||||
WebhookConfigAnnotation = "k8s.mariadb.com/webhook"
|
WebhookConfigAnnotation = "k8s.mariadb.com/webhook"
|
||||||
)
|
)
|
||||||
|
@ -8,7 +8,6 @@ import (
|
|||||||
mariadbv1alpha1 "github.com/mariadb-operator/mariadb-operator/api/v1alpha1"
|
mariadbv1alpha1 "github.com/mariadb-operator/mariadb-operator/api/v1alpha1"
|
||||||
"github.com/mariadb-operator/mariadb-operator/pkg/metadata"
|
"github.com/mariadb-operator/mariadb-operator/pkg/metadata"
|
||||||
corev1 "k8s.io/api/core/v1"
|
corev1 "k8s.io/api/core/v1"
|
||||||
v1 "k8s.io/api/core/v1"
|
|
||||||
apierrors "k8s.io/apimachinery/pkg/api/errors"
|
apierrors "k8s.io/apimachinery/pkg/api/errors"
|
||||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||||
"k8s.io/apimachinery/pkg/types"
|
"k8s.io/apimachinery/pkg/types"
|
||||||
@ -119,19 +118,36 @@ func (r *RefResolver) SqlJob(ctx context.Context, ref *corev1.LocalObjectReferen
|
|||||||
|
|
||||||
func (r *RefResolver) SecretKeyRef(ctx context.Context, selector corev1.SecretKeySelector,
|
func (r *RefResolver) SecretKeyRef(ctx context.Context, selector corev1.SecretKeySelector,
|
||||||
namespace string) (string, error) {
|
namespace string) (string, error) {
|
||||||
nn := types.NamespacedName{
|
key := types.NamespacedName{
|
||||||
Name: selector.Name,
|
Name: selector.Name,
|
||||||
Namespace: namespace,
|
Namespace: namespace,
|
||||||
}
|
}
|
||||||
var secret v1.Secret
|
var secret corev1.Secret
|
||||||
if err := r.client.Get(ctx, nn, &secret); err != nil {
|
if err := r.client.Get(ctx, key, &secret); err != nil {
|
||||||
return "", fmt.Errorf("error getting secret: %v", err)
|
return "", fmt.Errorf("error getting Secret: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
data, ok := secret.Data[selector.Key]
|
data, ok := secret.Data[selector.Key]
|
||||||
if !ok {
|
if !ok {
|
||||||
return "", fmt.Errorf("secret key \"%s\" not found", selector.Key)
|
return "", fmt.Errorf("Secret key \"%s\" not found", selector.Key)
|
||||||
|
}
|
||||||
|
return string(data), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func (r *RefResolver) ConfigMapKeyRef(ctx context.Context, selector *corev1.ConfigMapKeySelector,
|
||||||
|
namespace string) (string, error) {
|
||||||
|
key := types.NamespacedName{
|
||||||
|
Name: selector.Name,
|
||||||
|
Namespace: namespace,
|
||||||
|
}
|
||||||
|
var configMap corev1.ConfigMap
|
||||||
|
if err := r.client.Get(ctx, key, &configMap); err != nil {
|
||||||
|
return "", fmt.Errorf("error getting ConfigMap: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
data, ok := configMap.Data[selector.Key]
|
||||||
|
if !ok {
|
||||||
|
return "", fmt.Errorf("ConfigMap key \"%s\" not found", selector.Key)
|
||||||
}
|
}
|
||||||
|
|
||||||
return string(data), nil
|
return string(data), nil
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user