@@ -113,17 +113,44 @@ func (c Client) DoCreate(ctx context.Context, objs ...client.Object) error {
113113 for _ , obj := range objs {
114114 kind := obj .GetObjectKind ().GroupVersionKind ().Kind
115115 log .Infof (" Creating %s %q" , kind , getName (obj .GetNamespace (), obj .GetName ()))
116- err := c .KubeClient .Create (ctx , obj )
117- if err != nil {
118- if ! apierrors .IsAlreadyExists (err ) {
116+
117+ for i := 0 ; i < 5 ; i ++ { // try to create 5 times before giving up
118+ retry , err := c .tryCreatingOneResource (ctx , obj , kind )
119+ if err != nil {
119120 return err
120121 }
121- log .Infof (" %s %q already exists" , kind , getName (obj .GetNamespace (), obj .GetName ()))
122+
123+ if retry {
124+ log .Infof (" the CRD for %s %q is not ready yet. Retrying in one second" , kind , getName (obj .GetNamespace (), obj .GetName ()))
125+ time .Sleep (time .Second )
126+ continue
127+ }
128+
129+ log .Infof (" %s %q created" , kind , getName (obj .GetNamespace (), obj .GetName ()))
130+ break
122131 }
123132 }
124133 return nil
125134}
126135
136+ func (c Client ) tryCreatingOneResource (ctx context.Context , obj client.Object , kind string ) (bool , error ) {
137+ err := c .KubeClient .Create (ctx , obj )
138+ if err != nil {
139+ if apierrors .IsAlreadyExists (err ) {
140+ log .Infof (" %s %q already exists" , kind , getName (obj .GetNamespace (), obj .GetName ()))
141+ return false , nil
142+ }
143+
144+ if meta .IsNoMatchError (err ) {
145+ return true , nil
146+ }
147+
148+ return false , err
149+ }
150+
151+ return false , nil
152+ }
153+
127154func (c Client ) DoDelete (ctx context.Context , objs ... client.Object ) error {
128155 for _ , obj := range objs {
129156 kind := obj .GetObjectKind ().GroupVersionKind ().Kind
0 commit comments