install_eso_crds.go 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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. "context"
  16. "fmt"
  17. "os/exec"
  18. "path/filepath"
  19. "time"
  20. apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
  21. apierrors "k8s.io/apimachinery/pkg/api/errors"
  22. "k8s.io/apimachinery/pkg/types"
  23. "k8s.io/apimachinery/pkg/util/wait"
  24. . "github.com/onsi/ginkgo/v2"
  25. )
  26. const clusterProviderClassCRDName = "clusterproviderclasses.external-secrets.io"
  27. var (
  28. externalSecretsCRDInstallPollInterval = time.Second
  29. externalSecretsCRDInstallTimeout = 5 * time.Minute
  30. )
  31. func installCRDs(cfg *Config) error {
  32. bundlePath := filepath.Join(AssetDir(), "deploy/crds/bundle.yaml")
  33. cmd := exec.Command("kubectl", "apply", "--server-side", "--force-conflicts", "-f", bundlePath)
  34. output, err := cmd.CombinedOutput()
  35. if err != nil {
  36. return fmt.Errorf("unable to install eso CRDs from %s: %w: %s", bundlePath, err, string(output))
  37. }
  38. return wait.PollUntilContextTimeout(GinkgoT().Context(), externalSecretsCRDInstallPollInterval, externalSecretsCRDInstallTimeout, true, func(ctx context.Context) (bool, error) {
  39. var crd apiextensionsv1.CustomResourceDefinition
  40. err := cfg.CRClient.Get(ctx, types.NamespacedName{Name: clusterProviderClassCRDName}, &crd)
  41. if apierrors.IsNotFound(err) {
  42. return false, nil
  43. }
  44. if err != nil {
  45. return false, err
  46. }
  47. for _, condition := range crd.Status.Conditions {
  48. if condition.Type == apiextensionsv1.Established && condition.Status == apiextensionsv1.ConditionTrue {
  49. return true, nil
  50. }
  51. }
  52. return false, nil
  53. })
  54. }