agones.dev/agones@v1.54.0/pkg/util/crd/crd.go (about) 1 // Copyright 2018 Google LLC All Rights Reserved. 2 // 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 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 // Package crd contains utilities for working with 16 // CustomResourceDefinitions. 17 package crd 18 19 import ( 20 "context" 21 "time" 22 23 "github.com/sirupsen/logrus" 24 apiextv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1" 25 apiextclientv1 "k8s.io/apiextensions-apiserver/pkg/client/clientset/clientset/typed/apiextensions/v1" 26 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" 27 "k8s.io/apimachinery/pkg/util/wait" 28 ) 29 30 // WaitForEstablishedCRD blocks until CRD comes to an Established state. 31 // Has a deadline of 60 seconds for this to occur. 32 func WaitForEstablishedCRD(_ context.Context, crdGetter apiextclientv1.CustomResourceDefinitionInterface, name string, logger *logrus.Entry) error { 33 return wait.PollUntilContextTimeout(context.Background(), time.Second, 60*time.Second, true, func(ctx context.Context) (done bool, err error) { 34 crd, err := crdGetter.Get(ctx, name, metav1.GetOptions{}) 35 if err != nil { 36 return false, err 37 } 38 39 for _, cond := range crd.Status.Conditions { 40 if cond.Type == apiextv1.Established { 41 if cond.Status == apiextv1.ConditionTrue { 42 logger.WithField("crd", crd.ObjectMeta.Name).Debug("custom resource definition established") 43 return true, err 44 } 45 } 46 } 47 48 return false, nil 49 }) 50 }