Skip to content

Commit 4934838

Browse files
author
Eric Stroczynski
authored
generate kustomize manifests: skip parsing definitions on a non-existent API root dir (#4624)
Signed-off-by: Eric Stroczynski <[email protected]>
1 parent a07364f commit 4934838

File tree

3 files changed

+35
-6
lines changed

3 files changed

+35
-6
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
entries:
2+
- description: >
3+
Skip CSV definitions parsing in `generate kustomize manifests` if the APIs dir does not exist,
4+
as projects may use only required APIs.
5+
kind: bugfix

internal/generate/clusterserviceversion/bases/definitions/definitions.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,12 @@ type descriptionValues struct {
4141
// to populate csv spec fields. Go code with relevant markers and information is expected to be
4242
// in a package under apisRootDir and match a GVK in keys.
4343
func ApplyDefinitionsForKeysGo(csv *v1alpha1.ClusterServiceVersion, apisRootDir string, gvks []schema.GroupVersionKind) error {
44+
// Skip definitions parsing if dir doesn't exist, otherwise g.contextForRoots() will error.
45+
if _, err := os.Stat(apisRootDir); err != nil && errors.Is(err, os.ErrNotExist) {
46+
log.Warnf("Skipping definitions parsing: APIs root dir %q does not exist", apisRootDir)
47+
return nil
48+
}
49+
4450
wd, err := os.Getwd()
4551
if err != nil {
4652
return err
@@ -86,7 +92,7 @@ func ApplyDefinitionsForKeysGo(csv *v1alpha1.ClusterServiceVersion, apisRootDir
8692

8793
// Leftover GVKs are ignored because their types can't be found.
8894
for _, gvk := range gvkSet {
89-
log.Warnf("Skipping CSV annotation parsing for API %s: type not found", gvk)
95+
log.Warnf("Skipping definitions parsing for API %s: Go type not found", gvk)
9096
}
9197

9298
// Update csv with all values parsed.

internal/generate/clusterserviceversion/bases/definitions/definitions_test.go

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -241,13 +241,31 @@ func TestApplyDefinitionsForKeysGo(t *testing.T) {
241241
},
242242
},
243243
{
244-
description: "Return error for non-existent package dir",
244+
description: "Return the CSV unchanged for non-existent APIs dir",
245245
apisDir: filepath.Join("pkg", "notexist"),
246-
csv: &v1alpha1.ClusterServiceVersion{},
247-
gvks: []schema.GroupVersionKind{
248-
{Group: "cache.example.com", Version: "v1alpha2", Kind: "Dummy"},
246+
csv: &v1alpha1.ClusterServiceVersion{
247+
Spec: v1alpha1.ClusterServiceVersionSpec{
248+
CustomResourceDefinitions: v1alpha1.CustomResourceDefinitions{
249+
Owned: []v1alpha1.CRDDescription{
250+
{
251+
Name: "nokinds.cache.example.com", Version: "v1alpha2", Kind: "NoKind",
252+
DisplayName: "NoKind App",
253+
Description: "NoKind is the Schema for the other nokind API",
254+
},
255+
},
256+
},
257+
},
258+
},
259+
expectedCRDs: v1alpha1.CustomResourceDefinitions{
260+
Owned: []v1alpha1.CRDDescription{
261+
{
262+
Name: "nokinds.cache.example.com", Version: "v1alpha2", Kind: "NoKind",
263+
DisplayName: "NoKind App",
264+
Description: "NoKind is the Schema for the other nokind API",
265+
},
266+
},
249267
},
250-
wantErr: true,
268+
wantErr: false,
251269
},
252270
}
253271

0 commit comments

Comments
 (0)