addon.go 1.8 KB

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