kubernetes.go 4.4 KB

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