uninstall_eso_crds.go 1.2 KB

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