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 c8f2f90
Showing 1 changed file with 10 additions and 3 deletions.
13 changes: 10 additions & 3 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,8 +25,12 @@ type CrdClientConfig struct {
var SupportedConversionReviewVersions = []string{"v1", "v1beta1"}

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

tryToGetCRD:
listOpts := metav1.ListOptions{
FieldSelector: "metadata.name=" + c.CrdName,
}
Expand All @@ -36,7 +41,9 @@ func (c *CrdClientConfig) Update() error {
}

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

crd := crdList.Items[0]
Expand Down

0 comments on commit c8f2f90

Please sign in to comment.