Browse Source

pdb

pull/14/head
Yaroslav Shishnev 1 month ago
parent
commit
7e474868c3

+ 0
- 4
deploy/deploy-operator-debug/service_account.yaml View File

@@ -1,4 +0,0 @@
apiVersion: v1
kind: ServiceAccount
metadata:
name: rabbitmq-operator

+ 10
- 21
pkg/controller/rabbitmq/rabbitmq_pdb.go View File

@@ -2,13 +2,13 @@ package rabbitmq

import (
"context"
"github.com/getsentry/raven-go"
"github.com/go-logr/logr"
v1beta1policy "k8s.io/api/policy/v1beta1"
apierrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/types"
"k8s.io/apimachinery/pkg/util/intstr"
"reflect"
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
"sigs.k8s.io/controller-runtime/pkg/reconcile"

@@ -32,7 +32,6 @@ func (r *ReconcileRabbitmq) reconcilePdb(reqLogger logr.Logger, cr *rabbitmqv1.R
if err != nil && apierrors.IsNotFound(err) {
reqLogger.Info("No PodDisruptionBudget found, creating new", "Pdb.Namespace", &newPdb.Namespace, "Pdb.Name", &newPdb.Name)
err = r.client.Create(context.TODO(), &newPdb)

foundPdb = &newPdb

if err != nil {
@@ -42,27 +41,17 @@ func (r *ReconcileRabbitmq) reconcilePdb(reqLogger logr.Logger, cr *rabbitmqv1.R
} else if err != nil {
reqLogger.Info("Error getting PodDisruptionBudget", "Pdb.Namespace", &newPdb.Namespace, "Pdb.Name", &newPdb.Name)
return reconcile.Result{}, err
} else {
if reconcileRequired, reconPdb := reconcilePdb(reqLogger, *foundPdb, newPdb); reconcileRequired {
reqLogger.Info("Updating PodDisruptionBudget", "Namespace", reconPdb.Namespace, "Name", reconPdb.Name)
if err = r.client.Update(context.TODO(), &reconPdb); err != nil {
reqLogger.Info("Reconcile PodDisruptionBudget error", "Namespace", foundPdb.Namespace, "Name", foundPdb.Name)
raven.CaptureErrorAndWait(err, nil)
return reconcile.Result{}, err
}
}
}

if !reflect.DeepEqual(foundPdb.Spec.Selector, &newPdb.Spec.Selector) {
reqLogger.Info("Selectors not deep equal", "Pdb.Namespace", &newPdb.Namespace, "Pdb.Name", &newPdb.Name)
foundPdb.Spec.Selector = newPdb.Spec.Selector
}

if !reflect.DeepEqual(foundPdb.Spec.MaxUnavailable, &newPdb.Spec.MaxUnavailable) {
reqLogger.Info("MaxUnavailable not deep equal", "Pdb.Namespace", &newPdb.Namespace, "Pdb.Name", &newPdb.Name)
foundPdb.Spec.MaxUnavailable = newPdb.Spec.MaxUnavailable
}

if !reflect.DeepEqual(foundPdb.Spec.MinAvailable, &newPdb.Spec.MinAvailable) {
reqLogger.Info("MinAvailable not deep equal", "Pdb.Namespace", &newPdb.Namespace, "Pdb.Name", &newPdb.Name)
foundPdb.Spec.MaxUnavailable = newPdb.Spec.MaxUnavailable
}

if err = r.client.Update(context.TODO(), foundPdb); err != nil {
reqLogger.Info("Error updating PodDisruptionBudget", "Pdb.Namespace", &newPdb.Namespace, "Pdb.Name", &newPdb.Name)
return reconcile.Result{}, err
}
return reconcile.Result{}, nil
}


+ 30
- 0
pkg/controller/rabbitmq/reconcile.go View File

@@ -0,0 +1,30 @@
package rabbitmq

import (
"github.com/go-logr/logr"
"k8s.io/api/policy/v1beta1"
"reflect"
)

func reconcilePdb(reqLogger logr.Logger, foundPdb v1beta1.PodDisruptionBudget, newPdb v1beta1.PodDisruptionBudget) (bool, v1beta1.PodDisruptionBudget) {

reconcileRequired := false
if !reflect.DeepEqual(foundPdb.Spec.Selector, newPdb.Spec.Selector) {
reqLogger.Info("Selectors not deep equal", "Pdb.Namespace", &newPdb.Namespace, "Pdb.Name", &newPdb.Name)
foundPdb.Spec.Selector = newPdb.Spec.Selector
reconcileRequired = true
}

if !reflect.DeepEqual(foundPdb.Spec.MaxUnavailable, newPdb.Spec.MaxUnavailable) {
reqLogger.Info("MaxUnavailable not deep equal", "Pdb.Namespace", &newPdb.Namespace, "Pdb.Name", &newPdb.Name)
foundPdb.Spec.MaxUnavailable = newPdb.Spec.MaxUnavailable
reconcileRequired = true
}

if !reflect.DeepEqual(foundPdb.Spec.MinAvailable, newPdb.Spec.MinAvailable) {
reqLogger.Info("MinAvailable not deep equal", "Pdb.Namespace", &newPdb.Namespace, "Pdb.Name", &newPdb.Name)
foundPdb.Spec.MinAvailable = newPdb.Spec.MinAvailable
reconcileRequired = true
}
return reconcileRequired, foundPdb
}

Loading…
Cancel
Save