mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-08-03 01:06:27 +00:00
Enable update tests for federated secret controller
This commit is contained in:
parent
7d1a7eae50
commit
3e61baf3f0
@ -34,6 +34,7 @@ import (
|
|||||||
"k8s.io/kubernetes/pkg/types"
|
"k8s.io/kubernetes/pkg/types"
|
||||||
"k8s.io/kubernetes/pkg/util/wait"
|
"k8s.io/kubernetes/pkg/util/wait"
|
||||||
|
|
||||||
|
"github.com/golang/glog"
|
||||||
"github.com/stretchr/testify/assert"
|
"github.com/stretchr/testify/assert"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -52,7 +53,7 @@ func TestSecretController(t *testing.T) {
|
|||||||
cluster1Watch := RegisterFakeWatch("secrets", &cluster1Client.Fake)
|
cluster1Watch := RegisterFakeWatch("secrets", &cluster1Client.Fake)
|
||||||
RegisterFakeList("secrets", &cluster1Client.Fake, &apiv1.SecretList{Items: []apiv1.Secret{}})
|
RegisterFakeList("secrets", &cluster1Client.Fake, &apiv1.SecretList{Items: []apiv1.Secret{}})
|
||||||
cluster1CreateChan := RegisterFakeCopyOnCreate("secrets", &cluster1Client.Fake, cluster1Watch)
|
cluster1CreateChan := RegisterFakeCopyOnCreate("secrets", &cluster1Client.Fake, cluster1Watch)
|
||||||
// cluster1UpdateChan := RegisterFakeCopyOnUpdate("secrets", &cluster1Client.Fake, cluster1Watch)
|
cluster1UpdateChan := RegisterFakeCopyOnUpdate("secrets", &cluster1Client.Fake, cluster1Watch)
|
||||||
|
|
||||||
cluster2Client := &fakekubeclientset.Clientset{}
|
cluster2Client := &fakekubeclientset.Clientset{}
|
||||||
cluster2Watch := RegisterFakeWatch("secrets", &cluster2Client.Fake)
|
cluster2Watch := RegisterFakeWatch("secrets", &cluster2Client.Fake)
|
||||||
@ -116,38 +117,45 @@ func TestSecretController(t *testing.T) {
|
|||||||
cluster1.Name, types.NamespacedName{Namespace: secret1.Namespace, Name: secret1.Name}.String(), wait.ForeverTestTimeout)
|
cluster1.Name, types.NamespacedName{Namespace: secret1.Namespace, Name: secret1.Name}.String(), wait.ForeverTestTimeout)
|
||||||
assert.Nil(t, err, "secret should have appeared in the informer store")
|
assert.Nil(t, err, "secret should have appeared in the informer store")
|
||||||
|
|
||||||
/*
|
checkAll := func(expected apiv1.Secret) CheckingFunction {
|
||||||
// TODO: Uncomment this once we have figured out why this is flaky.
|
return func(obj runtime.Object) error {
|
||||||
// Test update federated secret.
|
glog.V(4).Infof("Checking %v", obj)
|
||||||
secret1.Annotations = map[string]string{
|
s := obj.(*apiv1.Secret)
|
||||||
"A": "B",
|
if err := CompareObjectMeta(expected.ObjectMeta, s.ObjectMeta); err != nil {
|
||||||
|
return err
|
||||||
}
|
}
|
||||||
secretWatch.Modify(&secret1)
|
if !reflect.DeepEqual(expected.Data, s.Data) {
|
||||||
updatedSecret = GetSecretFromChan(cluster1UpdateChan)
|
return fmt.Errorf("Data is different expected:%v actual:%v", expected.Data, s.Data)
|
||||||
assert.NotNil(t, updatedSecret)
|
}
|
||||||
assert.Equal(t, secret1.Name, updatedSecret.Name)
|
if expected.Type != s.Type {
|
||||||
assert.Equal(t, secret1.Namespace, updatedSecret.Namespace)
|
return fmt.Errorf("Type is different expected:%v actual:%v", expected.Type, s.Type)
|
||||||
assert.True(t, secretsEqual(secret1, *updatedSecret),
|
}
|
||||||
fmt.Sprintf("expected: %v, actual: %v", secret1, *updatedSecret))
|
return nil
|
||||||
// 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.
|
// Test update federated secret.
|
||||||
secret1.Data = map[string][]byte{
|
secret1.Annotations = map[string]string{
|
||||||
"config": []byte("myconfigurationfile"),
|
"A": "B",
|
||||||
}
|
}
|
||||||
secretWatch.Modify(&secret1)
|
secretWatch.Modify(&secret1)
|
||||||
updatedSecret2 := GetSecretFromChan(cluster1UpdateChan)
|
err = CheckObjectFromChan(cluster1UpdateChan, checkAll(secret1))
|
||||||
assert.NotNil(t, updatedSecret2)
|
assert.NoError(t, err)
|
||||||
assert.Equal(t, secret1.Name, updatedSecret2.Name)
|
|
||||||
assert.Equal(t, secret1.Namespace, updatedSecret.Namespace)
|
// Wait for the secret to be updated in the informer store.
|
||||||
assert.True(t, secretsEqual(secret1, *updatedSecret2),
|
err = WaitForSecretStoreUpdate(
|
||||||
fmt.Sprintf("expected: %v, actual: %v", secret1, *updatedSecret2))
|
secretController.secretFederatedInformer.GetTargetStore(),
|
||||||
*/
|
cluster1.Name, types.NamespacedName{Namespace: secret1.Namespace, Name: secret1.Name}.String(),
|
||||||
|
&secret1, wait.ForeverTestTimeout)
|
||||||
|
assert.NoError(t, err, "secret should have been updated in the informer store")
|
||||||
|
|
||||||
|
// Test update federated secret.
|
||||||
|
secret1.Data = map[string][]byte{
|
||||||
|
"config": []byte("myconfigurationfile"),
|
||||||
|
}
|
||||||
|
secretWatch.Modify(&secret1)
|
||||||
|
err = CheckObjectFromChan(cluster1UpdateChan, checkAll(secret1))
|
||||||
|
assert.NoError(t, err)
|
||||||
|
|
||||||
// Test add cluster
|
// Test add cluster
|
||||||
clusterWatch.Add(cluster2)
|
clusterWatch.Add(cluster2)
|
||||||
@ -183,13 +191,17 @@ func GetSecretFromChan(c chan runtime.Object) *apiv1.Secret {
|
|||||||
|
|
||||||
// Wait till the store is updated with latest secret.
|
// Wait till the store is updated with latest secret.
|
||||||
func WaitForSecretStoreUpdate(store util.FederatedReadOnlyStore, clusterName, key string, desiredSecret *apiv1.Secret, timeout time.Duration) error {
|
func WaitForSecretStoreUpdate(store util.FederatedReadOnlyStore, clusterName, key string, desiredSecret *apiv1.Secret, timeout time.Duration) error {
|
||||||
retryInterval := 100 * time.Millisecond
|
retryInterval := 200 * time.Millisecond
|
||||||
err := wait.PollImmediate(retryInterval, timeout, func() (bool, error) {
|
err := wait.PollImmediate(retryInterval, timeout, func() (bool, error) {
|
||||||
obj, found, err := store.GetByKey(clusterName, key)
|
obj, found, err := store.GetByKey(clusterName, key)
|
||||||
if !found || err != nil {
|
if !found || err != nil {
|
||||||
|
glog.Infof("%s is not in the store", key)
|
||||||
return false, err
|
return false, err
|
||||||
}
|
}
|
||||||
equal := secretsEqual(*obj.(*apiv1.Secret), *desiredSecret)
|
equal := secretsEqual(*obj.(*apiv1.Secret), *desiredSecret)
|
||||||
|
if !equal {
|
||||||
|
glog.Infof("wrong content in the store expected:\n%v\nactual:\n%v\n", *desiredSecret, *obj.(*apiv1.Secret))
|
||||||
|
}
|
||||||
return equal, err
|
return equal, err
|
||||||
})
|
})
|
||||||
return err
|
return err
|
||||||
|
@ -333,6 +333,6 @@ func MetaAndSpecCheckingFunction(expected runtime.Object) CheckingFunction {
|
|||||||
if util.ObjectMetaAndSpecEquivalent(obj, expected) {
|
if util.ObjectMetaAndSpecEquivalent(obj, expected) {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
return fmt.Errorf("Object different expected=%#v received=%#v", expected, obj)
|
return fmt.Errorf("Object different expected=%#v received=%#v", expected, obj)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user