Skip to content

Commit

Permalink
Fix taking a crd that is not yet installed
Browse files Browse the repository at this point in the history
Signed-off-by: dmitry.koba <dmitry.koba@flant.com>
  • Loading branch information
dmitry.koba committed Mar 18, 2024
1 parent 4641ea4 commit e810f7a
Showing 1 changed file with 9 additions and 14 deletions.
23 changes: 9 additions & 14 deletions pkg/webhook/conversion/crd_client_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,12 @@ package conversion

import (
"context"
"fmt"
"time"

log "github.com/sirupsen/logrus"
extv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/klog/v2"

klient "github.com/flant/kube-client/client"
)
Expand All @@ -24,23 +25,17 @@ type CrdClientConfig struct {
var SupportedConversionReviewVersions = []string{"v1", "v1beta1"}

func (c *CrdClientConfig) Update() error {
client := c.KubeClient
var retryTimeout = 15 * time.Second
var client = c.KubeClient

listOpts := metav1.ListOptions{
FieldSelector: "metadata.name=" + c.CrdName,
}

crdList, err := client.ApiExt().CustomResourceDefinitions().List(context.TODO(), listOpts)
tryToGetCRD:
crd, err := client.ApiExt().CustomResourceDefinitions().Get(context.TODO(), c.CrdName, metav1.GetOptions{})
if err != nil {
return err
klog.Errorf("crd getting error: %s. Retry will be executed after %s seconds.", err, retryTimeout)
time.Sleep(retryTimeout)
goto tryToGetCRD
}

if len(crdList.Items) == 0 {
return fmt.Errorf("crd/%s not found", c.CrdName)
}

crd := crdList.Items[0]

if crd.Spec.Conversion == nil {
crd.Spec.Conversion = new(extv1.CustomResourceConversion)
}
Expand Down

0 comments on commit e810f7a

Please sign in to comment.