Skip to content

Commit cd0711c

Browse files
committed
*: fix gen-csv to copy CRD manifests with any name (operator-framework#2015)
(cherry picked from commit 5d22a11)
1 parent e5ae768 commit cd0711c

File tree

3 files changed

+14
-5
lines changed

3 files changed

+14
-5
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
## Unreleased
22

3+
### Bug Fixes
4+
5+
- 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))
6+
37
### Added
48

59
### Changed

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/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)