version_secret.go 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. /*
  2. Copyright © 2025 ESO Maintainer Team
  3. Licensed under the Apache License, Version 2.0 (the "License");
  4. you may not use this file except in compliance with the License.
  5. You may obtain a copy of the License at
  6. https://www.apache.org/licenses/LICENSE-2.0
  7. Unless required by applicable law or agreed to in writing, software
  8. distributed under the License is distributed on an "AS IS" BASIS,
  9. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  10. See the License for the specific language governing permissions and
  11. limitations under the License.
  12. */
  13. package aws
  14. import (
  15. "fmt"
  16. v1 "k8s.io/api/core/v1"
  17. "github.com/external-secrets/external-secrets-e2e/framework"
  18. esapi "github.com/external-secrets/external-secrets/apis/externalsecrets/v1"
  19. )
  20. // This case creates one secret secrets with multiple versions
  21. // the value contains the version number
  22. func VersionedParameter(prov *Provider) func(f *framework.Framework) (string, func(*framework.TestCase)) {
  23. return func(f *framework.Framework) (string, func(*framework.TestCase)) {
  24. return "[common] should read versioned secrets", func(tc *framework.TestCase) {
  25. const namePrefix = "/e2e/versioned/%s/%s"
  26. secretKeyOne := fmt.Sprintf(namePrefix, f.Namespace.Name, "one")
  27. versions := []int{1, 2, 3, 4, 5}
  28. valueStr := "value%d"
  29. tc.ExpectedSecret = &v1.Secret{
  30. Type: v1.SecretTypeOpaque,
  31. Data: map[string][]byte{}, // filled below
  32. }
  33. tc.ExternalSecret.Spec.Data = make([]esapi.ExternalSecretData, len(versions))
  34. // create many versions
  35. i := 0
  36. for _, v := range versions {
  37. secretKey := fmt.Sprintf("v%d", v)
  38. val := fmt.Sprintf(valueStr, v)
  39. prov.CreateSecret(secretKeyOne, framework.SecretEntry{
  40. Value: val,
  41. })
  42. tc.ExpectedSecret.Data[secretKey] = []byte(val)
  43. tc.ExternalSecret.Spec.Data[i] = esapi.ExternalSecretData{
  44. SecretKey: secretKey,
  45. RemoteRef: esapi.ExternalSecretDataRemoteRef{
  46. Key: secretKeyOne,
  47. Version: fmt.Sprintf("%d", v),
  48. },
  49. }
  50. i++
  51. }
  52. }
  53. }
  54. }