addon.go 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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 (
  15. "github.com/onsi/ginkgo/v2"
  16. "github.com/onsi/gomega"
  17. "k8s.io/client-go/kubernetes"
  18. "k8s.io/client-go/rest"
  19. crclient "sigs.k8s.io/controller-runtime/pkg/client"
  20. "github.com/external-secrets/external-secrets-e2e/framework/log"
  21. )
  22. var globalAddons []Addon
  23. func init() {
  24. globalAddons = make([]Addon, 0)
  25. }
  26. type Config struct {
  27. // KubeConfig which was used to create the connection.
  28. KubeConfig *rest.Config
  29. // Kubernetes API clientsets
  30. KubeClientSet kubernetes.Interface
  31. // controller-runtime client for newer controllers
  32. CRClient crclient.Client
  33. }
  34. type Addon interface {
  35. Setup(*Config) error
  36. Install() error
  37. Logs() error
  38. Uninstall() error
  39. }
  40. func InstallGlobalAddon(addon Addon, cfg *Config) {
  41. globalAddons = append(globalAddons, addon)
  42. ginkgo.By("installing global addon")
  43. err := addon.Setup(cfg)
  44. gomega.Expect(err).NotTo(gomega.HaveOccurred())
  45. err = addon.Install()
  46. gomega.Expect(err).NotTo(gomega.HaveOccurred())
  47. }
  48. func UninstallGlobalAddons() {
  49. for _, addon := range globalAddons {
  50. ginkgo.By("uninstalling addon")
  51. err := addon.Uninstall()
  52. gomega.Expect(err).NotTo(gomega.HaveOccurred())
  53. }
  54. }
  55. func PrintLogs() {
  56. for _, addon := range globalAddons {
  57. err := addon.Logs()
  58. if err != nil {
  59. log.Logf("error fetching logs: %s", err.Error())
  60. }
  61. }
  62. }