uninstall_eso_crds.go 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. /*
  2. Copyright © The ESO Authors
  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. "strings"
  16. . "github.com/onsi/ginkgo/v2"
  17. apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
  18. apierrors "k8s.io/apimachinery/pkg/api/errors"
  19. "sigs.k8s.io/controller-runtime/pkg/client"
  20. )
  21. func uninstallCRDs(cfg *Config) error {
  22. By("Uninstalling eso CRDs")
  23. var crdList apiextensionsv1.CustomResourceDefinitionList
  24. if err := cfg.CRClient.List(GinkgoT().Context(), &crdList); err != nil {
  25. return err
  26. }
  27. for _, crd := range crdList.Items {
  28. if !strings.Contains(crd.Spec.Group, "external-secrets.io") {
  29. continue
  30. }
  31. err := cfg.CRClient.Delete(GinkgoT().Context(), &crd, &client.DeleteOptions{})
  32. if err != nil && !apierrors.IsNotFound(err) {
  33. return err
  34. }
  35. }
  36. return nil
  37. }