find_by_name.go 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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. limitations under the License.
  10. */
  11. package common
  12. import (
  13. "fmt"
  14. v1 "k8s.io/api/core/v1"
  15. esapi "github.com/external-secrets/external-secrets/apis/externalsecrets/v1beta1"
  16. "github.com/external-secrets/external-secrets/e2e/framework"
  17. )
  18. // This case creates multiple secrets with simple key/value pairs and syncs them using multiple .Spec.Data blocks.
  19. // Not supported by: vault.
  20. func FindByName(f *framework.Framework) (string, func(*framework.TestCase)) {
  21. return "[common] should find secrets by name using .DataFrom[]", func(tc *framework.TestCase) {
  22. secretKeyOne := fmt.Sprintf("e2e-find-name-%s-%s", f.Namespace.Name, "one")
  23. secretKeyTwo := fmt.Sprintf("e2e-find-name-%s-%s", f.Namespace.Name, "two")
  24. secretKeyThree := fmt.Sprintf("e2e-find-name-%s-%s", f.Namespace.Name, "three")
  25. secretValue := "something"
  26. tc.Secrets = map[string]string{
  27. secretKeyOne: secretValue,
  28. secretKeyTwo: secretValue,
  29. secretKeyThree: secretValue,
  30. }
  31. tc.ExpectedSecret = &v1.Secret{
  32. Type: v1.SecretTypeOpaque,
  33. Data: map[string][]byte{
  34. fmt.Sprintf("e2e-find-name-%s-one", f.Namespace.Name): []byte(secretValue),
  35. fmt.Sprintf("e2e-find-name-%s-two", f.Namespace.Name): []byte(secretValue),
  36. fmt.Sprintf("e2e-find-name-%s-three", f.Namespace.Name): []byte(secretValue),
  37. },
  38. }
  39. tc.ExternalSecret = nil
  40. tc.BetaExternalSecret = framework.DefaultBetaExternalSecret(f)
  41. tc.BetaExternalSecret.Spec.DataFrom = []esapi.ExternalSecretDataFromRemoteRef{
  42. {
  43. Find: &esapi.ExternalSecretFind{
  44. Name: &esapi.FindName{
  45. RegExp: fmt.Sprintf("e2e-find-name-%s.+", f.Namespace.Name),
  46. },
  47. },
  48. },
  49. }
  50. }
  51. }