Skip to content
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

Fixes pre-deploy step having incorrect desired labels and adds a temp fix for race condition #835

Merged
merged 2 commits into from
Jul 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions controllers/custodian/reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (

druidv1alpha1 "github.com/gardener/etcd-druid/api/v1alpha1"

ctrlutils "github.com/gardener/etcd-druid/controllers/utils"
"github.com/gardener/etcd-druid/pkg/health/status"
"github.com/gardener/etcd-druid/pkg/utils"
kutil "github.com/gardener/gardener/pkg/utils/kubernetes"
Expand Down Expand Up @@ -74,6 +75,13 @@ func (r *Reconciler) Reconcile(ctx context.Context, req ctrl.Request) (ctrl.Resu

logger := r.logger.WithValues("etcd", kutil.Key(etcd.Namespace, etcd.Name).String())

if ctrlutils.HasOperationAnnotation(etcd) {
logger.Info("Skipping custodian-reconcile as etcd still has a reconcile annotation set on it. Will retry after 10s.")
return ctrl.Result{
RequeueAfter: 10 * time.Second,
}, nil
}

if etcd.Status.LastError != nil && *etcd.Status.LastError != "" {
logger.Info("Requeue item because of last error", "namespace", etcd.Namespace, "name", etcd.Name, "lastError", *etcd.Status.LastError)
return ctrl.Result{
Expand Down
15 changes: 6 additions & 9 deletions controllers/predicate/predicate.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ import (
"reflect"
"strings"

v1beta1constants "github.com/gardener/gardener/pkg/apis/core/v1beta1/constants"
"github.com/gardener/etcd-druid/controllers/utils"

appsv1 "k8s.io/api/apps/v1"
batchv1 "k8s.io/api/batch/v1"
coordinationv1 "k8s.io/api/coordination/v1"
Expand All @@ -31,21 +32,17 @@ import (
druidv1alpha1 "github.com/gardener/etcd-druid/api/v1alpha1"
)

func hasOperationAnnotation(obj client.Object) bool {
return obj.GetAnnotations()[v1beta1constants.GardenerOperation] == v1beta1constants.GardenerOperationReconcile
}

// HasOperationAnnotation is a predicate for the operation annotation.
func HasOperationAnnotation() predicate.Predicate {
return predicate.Funcs{
CreateFunc: func(event event.CreateEvent) bool {
return hasOperationAnnotation(event.Object)
return utils.HasOperationAnnotation(event.Object)
},
UpdateFunc: func(event event.UpdateEvent) bool {
return hasOperationAnnotation(event.ObjectNew)
return utils.HasOperationAnnotation(event.ObjectNew)
},
GenericFunc: func(event event.GenericEvent) bool {
return hasOperationAnnotation(event.Object)
return utils.HasOperationAnnotation(event.Object)
},
DeleteFunc: func(event event.DeleteEvent) bool {
return true
Expand Down Expand Up @@ -127,7 +124,7 @@ func EtcdReconciliationFinished(ignoreOperationAnnotation bool) predicate.Predic
condition := *etcd.Status.ObservedGeneration == etcd.Generation

if !ignoreOperationAnnotation {
condition = condition && !hasOperationAnnotation(etcd)
condition = condition && !utils.HasOperationAnnotation(etcd)
}

return condition
Expand Down
8 changes: 8 additions & 0 deletions controllers/utils/reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ package utils
import (
"path/filepath"

v1beta1constants "github.com/gardener/gardener/pkg/apis/core/v1beta1/constants"
"sigs.k8s.io/controller-runtime/pkg/client"

"github.com/gardener/etcd-druid/pkg/common"
"github.com/gardener/gardener/pkg/utils/imagevector"
)
Expand All @@ -41,3 +44,8 @@ func CreateImageVector() (imagevector.ImageVector, error) {
}
return imageVector, nil
}

// HasOperationAnnotation checks if the given object has the operation annotation and its value is set to Reconcile.
func HasOperationAnnotation(obj client.Object) bool {
return obj.GetAnnotations()[v1beta1constants.GardenerOperation] == v1beta1constants.GardenerOperationReconcile
}
2 changes: 1 addition & 1 deletion pkg/component/etcd/statefulset/statefulset.go
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ func (c *component) waitUntilPodsHaveDesiredLabels(ctx context.Context, etcd *dr
if err := c.client.Get(ctx, client.ObjectKey{Name: podName, Namespace: etcd.Namespace}, pod); err != nil {
return false, err
}
if !utils.ContainsAllDesiredLabels(pod.Labels, utils.MergeStringMaps(c.values.PodLabels, c.values.AdditionalPodLabels)) {
if !utils.ContainsAllDesiredLabels(pod.Labels, c.values.PodLabels) {
return false, nil
}
}
Expand Down