eso.go 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. /*
  2. Licensed under the Apache License, Version 2.0 (the "License");
  3. you may not use this file except in compliance with the License.
  4. You may obtain a copy of the License at
  5. http://www.apache.org/licenses/LICENSE-2.0
  6. Unless required by applicable law or agreed to in writing, software
  7. distributed under the License is distributed on an "AS IS" BASIS,
  8. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  9. See the License for the specific language governing permissions and
  10. limitations under the License.
  11. */
  12. package framework
  13. import (
  14. "bytes"
  15. "context"
  16. "time"
  17. v1 "k8s.io/api/core/v1"
  18. apierrors "k8s.io/apimachinery/pkg/api/errors"
  19. "k8s.io/apimachinery/pkg/types"
  20. "k8s.io/apimachinery/pkg/util/wait"
  21. )
  22. // WaitForSecretValue waits until a secret comes into existence and compares the secret.Data
  23. // with the provided values.
  24. func (f *Framework) WaitForSecretValue(namespace, name string, values map[string][]byte) (*v1.Secret, error) {
  25. secret := &v1.Secret{}
  26. err := wait.PollImmediate(time.Second*2, time.Minute*2, func() (bool, error) {
  27. err := f.CRClient.Get(context.Background(), types.NamespacedName{
  28. Namespace: namespace,
  29. Name: name,
  30. }, secret)
  31. if apierrors.IsNotFound(err) {
  32. return false, nil
  33. }
  34. for k, exp := range values {
  35. if actual, ok := secret.Data[k]; ok && !bytes.Equal(actual, exp) {
  36. return false, nil
  37. }
  38. }
  39. return true, nil
  40. })
  41. return secret, err
  42. }