Skip to content

Commit

Permalink
Merge pull request kubernetes#3 from jizh6311/add-warnings-not-found-crd
Browse files Browse the repository at this point in the history
Modify the informer generator to swallow notFound errors for Istio CRDs
  • Loading branch information
jizh6311 authored Mar 23, 2021
2 parents 08c2f8f + 0427d17 commit f5d4203
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 1 deletion.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
.idea/
17 changes: 16 additions & 1 deletion cmd/flexible-informer-gen/generators/informer.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ func (g *informerGenerator) GenerateType(c *generator.Context, t *types.Type, w
"v1ListOptions": c.Universe.Type(v1ListOptions),
"version": namer.IC(g.groupVersion.Version.String()),
"watchInterface": c.Universe.Type(watchInterface),
"isNotFound": c.Universe.Type(isNotFound),
"newFakeWatch": c.Universe.Type(newFakeWatch),
}

sw.Do(typeInformerInterface, m)
Expand Down Expand Up @@ -163,6 +165,12 @@ func NewFiltered$.type|public$Informer(client $.clientSetInterface|raw$$if .name
unstructuredResult := &unstructured.UnstructuredList{}
err := client.$.group$$.version$().RESTClient().Get().$if .namespaced$Namespace(namespace).$end$Resource($.toLower$("$.type|publicPlural$")).VersionedParams(&options, $.schemes|raw$).Timeout(timeout).Do(context.TODO()).Into(unstructuredResult)
if err != nil {
if $.isNotFound$(err) {
logs.warnf("The expected version of CRD for this kind was not found; it may be too old/new or not existing. All the resources for this kind will be ignored",
logs.String("expected type", "$.type|raw$"), logs.String("expected group", "$.group$"),
logs.String("expected version", "$.version$"), logs.ErrorField(err))
return result, nil
}
return nil, err
}
Expand All @@ -182,7 +190,14 @@ func NewFiltered$.type|public$Informer(client $.clientSetInterface|raw$$if .name
if tweakListOptions != nil {
tweakListOptions(&options)
}
return client.$.group$$.version$().$.type|publicPlural$($if .namespaced$namespace$end$).Watch(context.TODO(), options)
watchObj, err := client.$.group$$.version$().$.type|publicPlural$($if .namespaced$namespace$end$).Watch(context.TODO(), options)
if $.isNotFound$(err) {
logs.warnf("The expected version of CRD for this kind was not found; it may be too old/new or not existing. All the resources for this kind will be ignored",
logs.String("expected type", "$.type|raw$"), logs.String("expected group", "$.group$"),
logs.String("expected version", "$.version$"), logs.ErrorField(err))
return $.newFakeWatch$(), nil
}
return watchObj, err
},
},
&$.type|raw${},
Expand Down
2 changes: 2 additions & 0 deletions cmd/flexible-informer-gen/generators/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@ var (
metav1NamespaceAll = types.Name{Package: "k8s.io/apimachinery/pkg/apis/meta/v1", Name: "NamespaceAll"}
metav1Object = types.Name{Package: "k8s.io/apimachinery/pkg/apis/meta/v1", Name: "Object"}
watchInterface = types.Name{Package: "k8s.io/apimachinery/pkg/watch", Name: "Interface"}
newFakeWatch = types.Name{Package: "k8s.io/apimachinery/pkg/watch", Name: "NewFake"}
schemes = types.Name{Package: "istio.io/client-go/pkg/clientset/versioned/scheme", Name: "ParameterCodec"}
toLower = types.Name{Package: "strings", Name: "ToLower"}
isNotFound = types.Name{Package: "k8s.io/apimachinery/pkg/api/errors", Name: "IsNotFound"}
)

0 comments on commit f5d4203

Please sign in to comment.