mirror of https://github.com/k3s-io/k3s
Merge pull request #36463 from nikhiljindal/debugSecretTest
Automatic merge from submit-queue Fixing federation secret controller unit test flakiness Fixes https://github.com/kubernetes/kubernetes/issues/36422 Adding a wait for the secret to be updated in the store to fix flakiness. It was failing ~once in 3 to 5 runs before this change. I now have had 30 local runs without a failure. cc @kubernetes/sig-cluster-federation @mwielguspull/6/head
commit
5ccc8b1091
|
@ -127,6 +127,12 @@ func TestSecretController(t *testing.T) {
|
|||
assert.Equal(t, secret1.Namespace, updatedSecret.Namespace)
|
||||
assert.True(t, secretsEqual(secret1, *updatedSecret),
|
||||
fmt.Sprintf("expected: %v, actual: %v", secret1, *updatedSecret))
|
||||
// Wait for the secret to be updated in the informer store.
|
||||
err = WaitForSecretStoreUpdate(
|
||||
secretController.secretFederatedInformer.GetTargetStore(),
|
||||
cluster1.Name, types.NamespacedName{Namespace: secret1.Namespace, Name: secret1.Name}.String(),
|
||||
updatedSecret, wait.ForeverTestTimeout)
|
||||
assert.Nil(t, err, "secret should have been updated in the informer store")
|
||||
|
||||
// Test update federated secret.
|
||||
secret1.Data = map[string][]byte{
|
||||
|
@ -134,8 +140,8 @@ func TestSecretController(t *testing.T) {
|
|||
}
|
||||
secretWatch.Modify(&secret1)
|
||||
updatedSecret2 := GetSecretFromChan(cluster1UpdateChan)
|
||||
assert.NotNil(t, updatedSecret)
|
||||
assert.Equal(t, secret1.Name, updatedSecret.Name)
|
||||
assert.NotNil(t, updatedSecret2)
|
||||
assert.Equal(t, secret1.Name, updatedSecret2.Name)
|
||||
assert.Equal(t, secret1.Namespace, updatedSecret.Namespace)
|
||||
assert.True(t, secretsEqual(secret1, *updatedSecret2),
|
||||
fmt.Sprintf("expected: %v, actual: %v", secret1, *updatedSecret2))
|
||||
|
@ -171,3 +177,17 @@ func GetSecretFromChan(c chan runtime.Object) *api_v1.Secret {
|
|||
secret := GetObjectFromChan(c).(*api_v1.Secret)
|
||||
return secret
|
||||
}
|
||||
|
||||
// Wait till the store is updated with latest secret.
|
||||
func WaitForSecretStoreUpdate(store util.FederatedReadOnlyStore, clusterName, key string, desiredSecret *api_v1.Secret, timeout time.Duration) error {
|
||||
retryInterval := 100 * time.Millisecond
|
||||
err := wait.PollImmediate(retryInterval, timeout, func() (bool, error) {
|
||||
obj, found, err := store.GetByKey(clusterName, key)
|
||||
if !found || err != nil {
|
||||
return false, err
|
||||
}
|
||||
equal := secretsEqual(*obj.(*api_v1.Secret), *desiredSecret)
|
||||
return equal, err
|
||||
})
|
||||
return err
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue