eso.go 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185
  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. const installCRDsVar = "installCRDs"
  22. func NewESO(mutators ...MutationFunc) *ESO {
  23. eso := &ESO{
  24. &HelmChart{
  25. Namespace: "default",
  26. ReleaseName: "eso",
  27. Chart: "/k8s/deploy/charts/external-secrets",
  28. Vars: []StringTuple{
  29. {
  30. Key: "webhook.port",
  31. Value: "9443",
  32. },
  33. {
  34. Key: "webhook.image.tag",
  35. Value: os.Getenv("VERSION"),
  36. },
  37. {
  38. Key: "certController.image.tag",
  39. Value: os.Getenv("VERSION"),
  40. },
  41. {
  42. Key: "image.tag",
  43. Value: os.Getenv("VERSION"),
  44. },
  45. {
  46. Key: "extraArgs.loglevel",
  47. Value: "debug",
  48. },
  49. {
  50. Key: installCRDsVar,
  51. Value: "false",
  52. },
  53. {
  54. Key: "concurrent",
  55. Value: "100",
  56. },
  57. {
  58. Key: "extraArgs.experimental-enable-vault-token-cache",
  59. Value: "true",
  60. },
  61. {
  62. Key: "extraArgs.experimental-enable-aws-session-cache",
  63. Value: "true",
  64. },
  65. {
  66. Key: "extraArgs.experimental-vault-token-cache-size",
  67. Value: "10",
  68. },
  69. },
  70. },
  71. }
  72. for _, f := range mutators {
  73. f(eso)
  74. }
  75. return eso
  76. }
  77. type MutationFunc func(eso *ESO)
  78. func WithReleaseName(name string) MutationFunc {
  79. return func(eso *ESO) {
  80. eso.HelmChart.ReleaseName = name
  81. }
  82. }
  83. func WithNamespace(namespace string) MutationFunc {
  84. return func(eso *ESO) {
  85. eso.HelmChart.Namespace = namespace
  86. }
  87. }
  88. func WithNamespaceScope(namespace string) MutationFunc {
  89. return func(eso *ESO) {
  90. eso.HelmChart.Vars = append(eso.HelmChart.Vars, StringTuple{
  91. Key: "scopedNamespace",
  92. Value: namespace,
  93. })
  94. }
  95. }
  96. func WithoutWebhook() MutationFunc {
  97. return func(eso *ESO) {
  98. eso.HelmChart.Vars = append(eso.HelmChart.Vars, StringTuple{
  99. Key: "webhook.create",
  100. Value: "false",
  101. })
  102. }
  103. }
  104. func WithoutCertController() MutationFunc {
  105. return func(eso *ESO) {
  106. eso.HelmChart.Vars = append(eso.HelmChart.Vars, StringTuple{
  107. Key: "certController.create",
  108. Value: "false",
  109. })
  110. }
  111. }
  112. func WithServiceAccount(saName string) MutationFunc {
  113. return func(eso *ESO) {
  114. eso.HelmChart.Vars = append(eso.HelmChart.Vars, []StringTuple{
  115. {
  116. Key: "serviceAccount.create",
  117. Value: "false",
  118. },
  119. {
  120. Key: "serviceAccount.name",
  121. Value: saName,
  122. },
  123. }...)
  124. }
  125. }
  126. func WithControllerClass(class string) MutationFunc {
  127. return func(eso *ESO) {
  128. eso.HelmChart.Vars = append(eso.HelmChart.Vars, StringTuple{
  129. Key: "extraArgs.controller-class",
  130. Value: class,
  131. })
  132. }
  133. }
  134. // By default ESO is installed without CRDs
  135. // when using WithCRDs() the CRDs will be installed before
  136. // and uninstalled after use.
  137. func WithCRDs() MutationFunc {
  138. return func(eso *ESO) {
  139. for i, v := range eso.HelmChart.Vars {
  140. if v.Key == installCRDsVar {
  141. eso.HelmChart.Vars[i].Value = "true"
  142. }
  143. }
  144. }
  145. }
  146. func (l *ESO) Install() error {
  147. By("Installing eso\n")
  148. err := l.HelmChart.Install()
  149. if err != nil {
  150. return err
  151. }
  152. return nil
  153. }
  154. func (l *ESO) Uninstall() error {
  155. By("Uninstalling eso")
  156. err := l.HelmChart.Uninstall()
  157. if err != nil {
  158. return err
  159. }
  160. if l.HelmChart.HasVar(installCRDsVar, "true") {
  161. return uninstallCRDs(l.config)
  162. }
  163. return nil
  164. }