Skip to content

Commit 7052e8e

Browse files
authored
cherry-pick: csv-gen bugfixes for #2015 #2017 (#2021)
* *: fix gen-csv to copy CRD manifests with any name (#2015) (cherry picked from commit 5d22a11) * internal/pkg/scaffold/olm-catalog/csv_updaters.go: fix applying owned CRDs (#2017) * internal/pkg/scaffold/olm-catalog/csv_updaters.go: fix applying owned CRDs * CHANGELOG.md: add line for #2017 (cherry picked from commit 5bfe311)
1 parent 8553e51 commit 7052e8e

File tree

4 files changed

+17
-9
lines changed

4 files changed

+17
-9
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010

1111
### Bug Fixes
1212

13+
- The command `operator-sdk olm-catalog gen-csv --csv-version=<version> --update-crds` would fail to copy over CRD manifests into `deploy/olm-catalog` for manifests whose name didn't end with a `_crd.yaml` suffix. This has been fixed so `gen-csv` now copies all CRD manifests specified by `deploy/olm-catalog/csv_config.yaml` by checking the type of the manifest rather than the filename suffix. ([#2015](https://github.com/operator-framework/operator-sdk/pull/2015))
14+
- Fixed an issue in `operator-sdk olm-catalog gen-csv` where the generated CSV is missing the expected set of owned CRDs. ([#2017](https://github.com/operator-framework/operator-sdk/pull/2017))
15+
1316
## v0.10.0
1417

1518
### Added

cmd/operator-sdk/olmcatalog/gen-csv.go

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,12 +18,12 @@ import (
1818
"fmt"
1919
"io/ioutil"
2020
"path/filepath"
21-
"strings"
2221

2322
"github.com/operator-framework/operator-sdk/internal/pkg/scaffold"
2423
"github.com/operator-framework/operator-sdk/internal/pkg/scaffold/input"
2524
catalog "github.com/operator-framework/operator-sdk/internal/pkg/scaffold/olm-catalog"
2625
"github.com/operator-framework/operator-sdk/internal/util/fileutil"
26+
"github.com/operator-framework/operator-sdk/internal/util/k8sutil"
2727
"github.com/operator-framework/operator-sdk/internal/util/projutil"
2828

2929
"github.com/coreos/go-semver/semver"
@@ -167,13 +167,18 @@ func verifyCSVVersion(version string) error {
167167

168168
func writeCRDsToDir(crdPaths []string, toDir string) error {
169169
for _, p := range crdPaths {
170-
if !strings.HasSuffix(p, "crd.yaml") {
171-
continue
172-
}
173170
b, err := ioutil.ReadFile(p)
174171
if err != nil {
175172
return err
176173
}
174+
typeMeta, err := k8sutil.GetTypeMetaFromBytes(b)
175+
if err != nil {
176+
return err
177+
}
178+
if typeMeta.Kind != "CustomResourceDefinition" {
179+
continue
180+
}
181+
177182
path := filepath.Join(toDir, filepath.Base(p))
178183
err = ioutil.WriteFile(path, b, fileutil.DefaultFileMode)
179184
if err != nil {

internal/pkg/scaffold/olm-catalog/csv_updaters.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -305,12 +305,12 @@ func getGVKID(g, v, k string) string {
305305
// the CRD key is not in spec.customresourcedefinitions.owned already.
306306
func (u *CustomResourceDefinitionsUpdate) Apply(csv *olmapiv1alpha1.ClusterServiceVersion) error {
307307
set := make(map[string]olmapiv1alpha1.CRDDescription)
308-
for _, uDesc := range u.Owned {
309-
set[crdDescID(uDesc)] = uDesc
308+
for _, csvDesc := range csv.Spec.CustomResourceDefinitions.Owned {
309+
set[crdDescID(csvDesc)] = csvDesc
310310
}
311311
newDescs := []olmapiv1alpha1.CRDDescription{}
312-
for _, csvDesc := range csv.Spec.CustomResourceDefinitions.Owned {
313-
if uDesc, ok := set[crdDescID(csvDesc)]; !ok {
312+
for _, uDesc := range u.Owned {
313+
if csvDesc, ok := set[crdDescID(uDesc)]; !ok {
314314
newDescs = append(newDescs, uDesc)
315315
} else {
316316
newDescs = append(newDescs, csvDesc)

internal/util/k8sutil/k8sutil.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ func GetTypeMetaFromBytes(b []byte) (t metav1.TypeMeta, err error) {
104104
// There is only one YAML doc if there are no more bytes to be read or EOF
105105
// is hit.
106106
if err := dec.Decode(&u); err == nil && r.Len() != 0 {
107-
return t, errors.New("error getting TypeMeta from bytes: more than one manifest in b")
107+
return t, errors.New("error getting TypeMeta from bytes: more than one manifest in file")
108108
} else if err != nil && err != io.EOF {
109109
return t, errors.Wrap(err, "error getting TypeMeta from bytes")
110110
}

0 commit comments

Comments
 (0)