eso_v2_mutators.go 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  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 addon
  14. import "os"
  15. const (
  16. v2HelmNamespace = "external-secrets-system"
  17. v2HelmReleaseName = "external-secrets"
  18. )
  19. func WithV2Namespace() MutationFunc {
  20. return func(eso *ESO) {
  21. eso.HelmChart.Namespace = v2HelmNamespace
  22. eso.HelmChart.ReleaseName = v2HelmReleaseName
  23. if !containsArg(eso.HelmChart.Args, "--create-namespace") {
  24. eso.HelmChart.Args = append(eso.HelmChart.Args, "--create-namespace")
  25. }
  26. }
  27. }
  28. func WithV2KubernetesProvider() MutationFunc {
  29. return func(eso *ESO) {
  30. version := os.Getenv("VERSION")
  31. vars := []StringTuple{
  32. {Key: "replicaCount", Value: "1"},
  33. {Key: "v2.enabled", Value: "true"},
  34. {Key: "crds.createProvider", Value: "true"},
  35. {Key: "crds.createClusterProvider", Value: "true"},
  36. {Key: "providers.enabled", Value: "true"},
  37. {Key: "providerDefaults.replicaCount", Value: "1"},
  38. {Key: "providers.list[0].name", Value: "kubernetes"},
  39. {Key: "providers.list[0].type", Value: "kubernetes"},
  40. {Key: "providers.list[0].enabled", Value: "true"},
  41. {Key: "providers.list[0].replicaCount", Value: "1"},
  42. {Key: "providers.list[0].image.repository", Value: "ghcr.io/external-secrets/provider-kubernetes"},
  43. {Key: "providers.list[0].image.tag", Value: version},
  44. {Key: "providers.list[0].image.pullPolicy", Value: "IfNotPresent"},
  45. }
  46. for _, variable := range vars {
  47. setOrAppendVar(eso.HelmChart, variable)
  48. }
  49. }
  50. }
  51. func setOrAppendVar(chart *HelmChart, variable StringTuple) {
  52. for i := range chart.Vars {
  53. if chart.Vars[i].Key == variable.Key {
  54. chart.Vars[i].Value = variable.Value
  55. return
  56. }
  57. }
  58. chart.Vars = append(chart.Vars, variable)
  59. }
  60. func containsArg(args []string, target string) bool {
  61. for _, arg := range args {
  62. if arg == target {
  63. return true
  64. }
  65. }
  66. return false
  67. }