find_by_name.go 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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. "time"
  15. v1 "k8s.io/api/core/v1"
  16. metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
  17. esapi "github.com/external-secrets/external-secrets/apis/externalsecrets/v1beta1"
  18. "github.com/external-secrets/external-secrets/e2e/framework"
  19. )
  20. // This case creates multiple secrets with simple key/value pairs and syncs them using multiple .Spec.Data blocks.
  21. func FindByName(f *framework.Framework) (string, func(*framework.TestCase)) {
  22. return "[common] should find secrets by name using .DataFrom[]", func(tc *framework.TestCase) {
  23. const namePrefix = "e2e_find_name_%s_%s"
  24. secretKeyOne := fmt.Sprintf(namePrefix, f.Namespace.Name, "one")
  25. secretKeyTwo := fmt.Sprintf(namePrefix, f.Namespace.Name, "two")
  26. secretKeyThree := fmt.Sprintf(namePrefix, f.Namespace.Name, "three")
  27. secretValue := "{\"foo1\":\"foo1-val\"}"
  28. tc.Secrets = map[string]framework.SecretEntry{
  29. secretKeyOne: {Value: secretValue},
  30. secretKeyTwo: {Value: secretValue},
  31. secretKeyThree: {Value: secretValue},
  32. }
  33. tc.ExpectedSecret = &v1.Secret{
  34. Type: v1.SecretTypeOpaque,
  35. Data: map[string][]byte{
  36. secretKeyOne: []byte(secretValue),
  37. secretKeyTwo: []byte(secretValue),
  38. secretKeyThree: []byte(secretValue),
  39. },
  40. }
  41. // AWS Secrets Manager is eventually consistent
  42. // specifying a low refresh interval avoids flaky tests
  43. tc.ExternalSecret.Spec.RefreshInterval = &metav1.Duration{Duration: time.Second * 5}
  44. tc.ExternalSecret.Spec.DataFrom = []esapi.ExternalSecretDataFromRemoteRef{
  45. {
  46. Find: &esapi.ExternalSecretFind{
  47. Name: &esapi.FindName{
  48. RegExp: fmt.Sprintf("e2e_find_name_%s.+", f.Namespace.Name),
  49. },
  50. },
  51. },
  52. }
  53. }
  54. }
  55. func FindByNameWithPath(f *framework.Framework) (string, func(*framework.TestCase)) {
  56. return "[common] should find secrets by name with path", func(tc *framework.TestCase) {
  57. secretKeyOne := fmt.Sprintf("e2e-find-name-%s-one", f.Namespace.Name)
  58. secretKeyTwo := fmt.Sprintf("%s-two", f.Namespace.Name)
  59. secretKeythree := fmt.Sprintf("%s-three", f.Namespace.Name)
  60. secretValue := "{\"foo1\":\"foo1-val\"}"
  61. tc.Secrets = map[string]framework.SecretEntry{
  62. secretKeyOne: {Value: secretValue},
  63. secretKeyTwo: {Value: secretValue},
  64. secretKeythree: {Value: secretValue},
  65. }
  66. tc.ExpectedSecret = &v1.Secret{
  67. Type: v1.SecretTypeOpaque,
  68. Data: map[string][]byte{
  69. fmt.Sprintf("%s-two", f.Namespace.Name): []byte(secretValue),
  70. fmt.Sprintf("%s-three", f.Namespace.Name): []byte(secretValue),
  71. },
  72. }
  73. // AWS Secrets Manager is eventually consistent
  74. // specifying a low refresh interval avoids flaky tests
  75. tc.ExternalSecret.Spec.RefreshInterval = &metav1.Duration{Duration: time.Second * 5}
  76. tc.ExternalSecret.Spec.DataFrom = []esapi.ExternalSecretDataFromRemoteRef{
  77. {
  78. Find: &esapi.ExternalSecretFind{
  79. Path: &f.Namespace.Name,
  80. Name: &esapi.FindName{
  81. RegExp: ".+",
  82. },
  83. },
  84. },
  85. }
  86. }
  87. }