kubernetes.go 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  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 kubernetes
  14. import (
  15. "fmt"
  16. // nolint
  17. . "github.com/onsi/ginkgo/v2"
  18. v1 "k8s.io/api/core/v1"
  19. "github.com/external-secrets/external-secrets-e2e/framework"
  20. "github.com/external-secrets/external-secrets-e2e/suites/provider/cases/common"
  21. esapi "github.com/external-secrets/external-secrets/apis/externalsecrets/v1"
  22. )
  23. const referentAuth = "with referent auth"
  24. var _ = Describe("[kubernetes] ", Label("kubernetes"), func() {
  25. f := framework.New("eso-kubernetes")
  26. prov := NewProvider(f)
  27. DescribeTable("sync secrets",
  28. framework.TableFuncWithExternalSecret(f,
  29. prov),
  30. Entry(common.JSONDataWithProperty(f)),
  31. Entry(common.JSONDataWithoutTargetName(f)),
  32. Entry(common.JSONDataWithTemplate(f)),
  33. Entry(common.DataPropertyDockerconfigJSON(f)),
  34. Entry(common.SSHKeySyncDataProperty(f)),
  35. Entry(common.JSONDataFromSync(f)),
  36. Entry(common.JSONDataFromRewrite(f)),
  37. Entry(FindByTag(f)),
  38. Entry(FindByName(f)),
  39. framework.Compose(referentAuth, f, common.JSONDataWithProperty, withReferentStore),
  40. framework.Compose(referentAuth, f, common.JSONDataWithoutTargetName, withReferentStore),
  41. )
  42. })
  43. func withReferentStore(tc *framework.TestCase) {
  44. tc.ExternalSecret.Spec.SecretStoreRef.Name = referentStoreName(tc.Framework)
  45. tc.ExternalSecret.Spec.SecretStoreRef.Kind = esapi.ClusterSecretStoreKind
  46. }
  47. const (
  48. secretValue1 = "{\"foo1\":\"foo1-val\"}"
  49. )
  50. // This case creates multiple secrets with simple key/value pairs and syncs them using multiple .Spec.Data blocks.
  51. func FindByName(f *framework.Framework) (string, func(*framework.TestCase)) {
  52. return "[common] should find secrets by name using .DataFrom[]", func(tc *framework.TestCase) {
  53. const namePrefix = "e2e-find-name-%s-%s"
  54. secretKeyOne := fmt.Sprintf(namePrefix, f.Namespace.Name, "one")
  55. secretKeyTwo := fmt.Sprintf(namePrefix, f.Namespace.Name, "two")
  56. secretKeyThree := fmt.Sprintf(namePrefix, f.Namespace.Name, "three")
  57. secretValue := "{\"foo1\":\"foo1-val\"}"
  58. tc.Secrets = map[string]framework.SecretEntry{
  59. secretKeyOne: {Value: secretValue},
  60. secretKeyTwo: {Value: secretValue},
  61. secretKeyThree: {Value: secretValue},
  62. }
  63. tc.ExpectedSecret = &v1.Secret{
  64. Type: v1.SecretTypeOpaque,
  65. Data: map[string][]byte{
  66. secretKeyOne: []byte(secretValue),
  67. secretKeyTwo: []byte(secretValue),
  68. secretKeyThree: []byte(secretValue),
  69. },
  70. }
  71. tc.ExternalSecret.Spec.DataFrom = []esapi.ExternalSecretDataFromRemoteRef{
  72. {
  73. Find: &esapi.ExternalSecretFind{
  74. Name: &esapi.FindName{
  75. RegExp: fmt.Sprintf("e2e-find-name-%s.+", f.Namespace.Name),
  76. },
  77. },
  78. },
  79. }
  80. }
  81. }
  82. // This case creates multiple secrets with simple key/value pairs and syncs them using multiple .Spec.Data blocks.
  83. func FindByTag(f *framework.Framework) (string, func(*framework.TestCase)) {
  84. return "[common] should find secrets by tags using .DataFrom[]", func(tc *framework.TestCase) {
  85. const namePrefix = "e2e-find-name-%s-%s"
  86. secretKeyOne := fmt.Sprintf(namePrefix, f.Namespace.Name, "one")
  87. secretKeyTwo := fmt.Sprintf(namePrefix, f.Namespace.Name, "two")
  88. secretKeyThree := fmt.Sprintf(namePrefix, f.Namespace.Name, "three")
  89. tc.Secrets = map[string]framework.SecretEntry{
  90. secretKeyOne: {
  91. Value: secretValue1,
  92. Tags: map[string]string{
  93. "test": f.Namespace.Name,
  94. }},
  95. secretKeyTwo: {
  96. Value: secretValue1,
  97. Tags: map[string]string{
  98. "test": f.Namespace.Name,
  99. }},
  100. secretKeyThree: {
  101. Value: secretValue1,
  102. Tags: map[string]string{
  103. "noop": f.Namespace.Name,
  104. }},
  105. }
  106. tc.ExpectedSecret = &v1.Secret{
  107. Type: v1.SecretTypeOpaque,
  108. Data: map[string][]byte{
  109. fmt.Sprintf("e2e-find-name-%s-one", f.Namespace.Name): []byte(secretValue1),
  110. fmt.Sprintf("e2e-find-name-%s-two", f.Namespace.Name): []byte(secretValue1),
  111. },
  112. }
  113. tc.ExternalSecret.Spec.DataFrom = []esapi.ExternalSecretDataFromRemoteRef{
  114. {
  115. Find: &esapi.ExternalSecretFind{
  116. Tags: map[string]string{
  117. "test": f.Namespace.Name,
  118. },
  119. },
  120. },
  121. }
  122. }
  123. }