config.go 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. /*
  2. Copyright © The ESO Authors
  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 main provides the Kubernetes provider configuration and spec mapper implementation.
  14. package main
  15. import (
  16. "context"
  17. "sigs.k8s.io/controller-runtime/pkg/client"
  18. v1 "github.com/external-secrets/external-secrets/apis/externalsecrets/v1"
  19. k8sv2alpha1 "github.com/external-secrets/external-secrets/apis/provider/kubernetes/v2alpha1"
  20. pb "github.com/external-secrets/external-secrets/proto/provider"
  21. )
  22. // GetSpecMapper returns the spec mapper function for the Kubernetes provider.
  23. // This function converts v2 ProviderReference to v1 SecretStoreSpec.
  24. func GetSpecMapper(kubeClient client.Client) func(*pb.ProviderReference, string) (*v1.SecretStoreSpec, error) {
  25. return func(ref *pb.ProviderReference, sourceNamespace string) (*v1.SecretStoreSpec, error) {
  26. namespace := ref.Namespace
  27. if namespace == "" {
  28. namespace = sourceNamespace
  29. }
  30. var kubernetesProvider k8sv2alpha1.Kubernetes
  31. err := kubeClient.Get(context.Background(), client.ObjectKey{
  32. Namespace: namespace,
  33. Name: ref.Name,
  34. }, &kubernetesProvider)
  35. if err != nil {
  36. return nil, err
  37. }
  38. return &v1.SecretStoreSpec{
  39. Provider: &v1.SecretStoreProvider{
  40. Kubernetes: &kubernetesProvider.Spec,
  41. },
  42. }, nil
  43. }
  44. }