eso.go 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146
  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 addon
  13. import (
  14. "os"
  15. // nolint
  16. . "github.com/onsi/ginkgo/v2"
  17. )
  18. type ESO struct {
  19. *HelmChart
  20. }
  21. func NewESO(mutators ...MutationFunc) *ESO {
  22. eso := &ESO{
  23. &HelmChart{
  24. Namespace: "default",
  25. ReleaseName: "eso",
  26. Chart: "/k8s/deploy/charts/external-secrets",
  27. Vars: []StringTuple{
  28. {
  29. Key: "image.repository",
  30. Value: os.Getenv("IMAGE_REGISTRY"),
  31. },
  32. {
  33. Key: "webhook.image.repository",
  34. Value: os.Getenv("IMAGE_REGISTRY"),
  35. },
  36. {
  37. Key: "certController.image.repository",
  38. Value: os.Getenv("IMAGE_REGISTRY"),
  39. },
  40. {
  41. Key: "webhook.image.tag",
  42. Value: os.Getenv("VERSION"),
  43. },
  44. {
  45. Key: "certController.image.tag",
  46. Value: os.Getenv("VERSION"),
  47. },
  48. {
  49. Key: "image.tag",
  50. Value: os.Getenv("VERSION"),
  51. },
  52. {
  53. Key: "installCRDs",
  54. Value: "false",
  55. },
  56. },
  57. },
  58. }
  59. for _, f := range mutators {
  60. f(eso)
  61. }
  62. return eso
  63. }
  64. type MutationFunc func(eso *ESO)
  65. func WithReleaseName(name string) MutationFunc {
  66. return func(eso *ESO) {
  67. eso.HelmChart.ReleaseName = name
  68. }
  69. }
  70. func WithNamespace(namespace string) MutationFunc {
  71. return func(eso *ESO) {
  72. eso.HelmChart.Namespace = namespace
  73. }
  74. }
  75. func WithNamespaceScope(namespace string) MutationFunc {
  76. return func(eso *ESO) {
  77. eso.HelmChart.Vars = append(eso.HelmChart.Vars, StringTuple{
  78. Key: "scopedNamespace",
  79. Value: namespace,
  80. })
  81. }
  82. }
  83. func WithoutWebhook() MutationFunc {
  84. return func(eso *ESO) {
  85. eso.HelmChart.Vars = append(eso.HelmChart.Vars, StringTuple{
  86. Key: "webhook.create",
  87. Value: "false",
  88. })
  89. }
  90. }
  91. func WithoutCertController() MutationFunc {
  92. return func(eso *ESO) {
  93. eso.HelmChart.Vars = append(eso.HelmChart.Vars, StringTuple{
  94. Key: "certController.create",
  95. Value: "false",
  96. })
  97. }
  98. }
  99. func WithServiceAccount(saName string) MutationFunc {
  100. return func(eso *ESO) {
  101. eso.HelmChart.Vars = append(eso.HelmChart.Vars, []StringTuple{
  102. {
  103. Key: "serviceAccount.create",
  104. Value: "false",
  105. },
  106. {
  107. Key: "serviceAccount.name",
  108. Value: saName,
  109. },
  110. }...)
  111. }
  112. }
  113. func WithControllerClass(class string) MutationFunc {
  114. return func(eso *ESO) {
  115. eso.HelmChart.Vars = append(eso.HelmChart.Vars, StringTuple{
  116. Key: "extraArgs.controller-class",
  117. Value: class,
  118. })
  119. }
  120. }
  121. func (l *ESO) Install() error {
  122. By("Installing eso\n")
  123. err := l.HelmChart.Install()
  124. if err != nil {
  125. return err
  126. }
  127. return nil
  128. }