common.go 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  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 common
  13. import (
  14. "context"
  15. // nolint
  16. . "github.com/onsi/gomega"
  17. corev1 "k8s.io/api/core/v1"
  18. metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
  19. esv1alpha1 "github.com/external-secrets/external-secrets/apis/externalsecrets/v1alpha1"
  20. esmetav1 "github.com/external-secrets/external-secrets/apis/meta/v1"
  21. "github.com/external-secrets/external-secrets/e2e/framework"
  22. )
  23. const (
  24. WithReferencedIRSA = "with referenced IRSA"
  25. WithMountedIRSA = "with mounted IRSA"
  26. StaticCredentialsSecretName = "provider-secret"
  27. )
  28. func ReferencedIRSAStoreName(f *framework.Framework) string {
  29. return "irsa-ref-" + f.Namespace.Name
  30. }
  31. func MountedIRSAStoreName(f *framework.Framework) string {
  32. return "irsa-mounted-" + f.Namespace.Name
  33. }
  34. func UseClusterSecretStore(tc *framework.TestCase) {
  35. tc.ExternalSecret.Spec.SecretStoreRef.Kind = esv1alpha1.ClusterSecretStoreKind
  36. tc.ExternalSecret.Spec.SecretStoreRef.Name = ReferencedIRSAStoreName(tc.Framework)
  37. }
  38. func UseMountedIRSAStore(tc *framework.TestCase) {
  39. tc.ExternalSecret.Spec.SecretStoreRef.Kind = esv1alpha1.SecretStoreKind
  40. tc.ExternalSecret.Spec.SecretStoreRef.Name = MountedIRSAStoreName(tc.Framework)
  41. }
  42. // StaticStore is namespaced and references
  43. // static credentials from a secret.
  44. func SetupStaticStore(f *framework.Framework, kid, sak, region string, serviceType esv1alpha1.AWSServiceType) {
  45. awsCreds := &corev1.Secret{
  46. ObjectMeta: metav1.ObjectMeta{
  47. Name: StaticCredentialsSecretName,
  48. Namespace: f.Namespace.Name,
  49. },
  50. StringData: map[string]string{
  51. "kid": kid,
  52. "sak": sak,
  53. },
  54. }
  55. err := f.CRClient.Create(context.Background(), awsCreds)
  56. Expect(err).ToNot(HaveOccurred())
  57. secretStore := &esv1alpha1.SecretStore{
  58. ObjectMeta: metav1.ObjectMeta{
  59. Name: f.Namespace.Name,
  60. Namespace: f.Namespace.Name,
  61. },
  62. Spec: esv1alpha1.SecretStoreSpec{
  63. Provider: &esv1alpha1.SecretStoreProvider{
  64. AWS: &esv1alpha1.AWSProvider{
  65. Service: serviceType,
  66. Region: region,
  67. Auth: esv1alpha1.AWSAuth{
  68. SecretRef: &esv1alpha1.AWSAuthSecretRef{
  69. AccessKeyID: esmetav1.SecretKeySelector{
  70. Name: StaticCredentialsSecretName,
  71. Key: "kid",
  72. },
  73. SecretAccessKey: esmetav1.SecretKeySelector{
  74. Name: StaticCredentialsSecretName,
  75. Key: "sak",
  76. },
  77. },
  78. },
  79. },
  80. },
  81. },
  82. }
  83. err = f.CRClient.Create(context.Background(), secretStore)
  84. Expect(err).ToNot(HaveOccurred())
  85. }