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

Fix reconcile loop break when central is not changed #1251

Merged
merged 3 commits into from
Sep 12, 2023
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
11 changes: 7 additions & 4 deletions fleetshard/pkg/central/reconciler/reconciler.go
Original file line number Diff line number Diff line change
Expand Up @@ -817,15 +817,18 @@ func (r *CentralReconciler) collectReconciliationStatus(ctx context.Context, rem
}

func (r *CentralReconciler) areSecretsStored(secretsStored []string) bool {
secretsStoredSize := len(secretsStored)
expectedSecrets := k8s.GetWatchedSecrets()
if len(secretsStored) != len(expectedSecrets) {
if secretsStoredSize != len(expectedSecrets) {
return false
}

sort.Strings(secretsStored)
secretsStoredCopy := make([]string, secretsStoredSize)
copy(secretsStoredCopy, secretsStored)
sort.Strings(secretsStoredCopy)

for i := 0; i < len(secretsStored); i++ {
if secretsStored[i] != expectedSecrets[i] {
for i := 0; i < secretsStoredSize; i++ {
if secretsStoredCopy[i] != expectedSecrets[i] {
return false
}
}
Expand Down
30 changes: 30 additions & 0 deletions fleetshard/pkg/central/reconciler/reconciler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,36 @@ func TestReconcileLastHashSetOnSuccess(t *testing.T) {
assert.Equal(t, "4", central.Annotations[util.RevisionAnnotationKey])
}

func TestReconcileLastHashSecretsOrderIndependent(t *testing.T) {
_, _, r := getClientTrackerAndReconciler(
t,
defaultCentralConfig,
nil,
defaultReconcilerOptions,
&v1alpha1.Central{
ObjectMeta: metav1.ObjectMeta{
Name: centralName,
Namespace: centralNamespace,
Annotations: map[string]string{util.RevisionAnnotationKey: "3"},
},
},
centralDeploymentObject(),
centralTLSSecretObject(),
centralDBPasswordSecretObject(),
)

managedCentral := simpleManagedCentral
managedCentral.RequestStatus = centralConstants.CentralRequestStatusReady.String()
managedCentral.Metadata.SecretsStored = []string{"central-tls", "central-db-password"}

expectedHash, err := util.MD5SumFromJSONStruct(&managedCentral)
require.NoError(t, err)

_, err = r.Reconcile(context.TODO(), managedCentral)
require.NoError(t, err)
assert.Equal(t, expectedHash, r.lastCentralHash, "Order of stored secrets should not impact hash.")
}

func TestIgnoreCacheForCentralNotReady(t *testing.T) {
_, _, r := getClientTrackerAndReconciler(
t,
Expand Down
3 changes: 3 additions & 0 deletions internal/dinosaur/pkg/presenters/managedcentral.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package presenters
import (
"encoding/json"
"fmt"
"sort"
"time"

"github.com/golang/glog"
Expand Down Expand Up @@ -199,5 +200,7 @@ func getSecretNames(from *dbapi.CentralRequest) []string {
i++
}

sort.Strings(secretNames)

return secretNames
}