Skip to content

Commit 3245561

Browse files
committed
*: fix gen-csv to copy CRD manifests with any name
1 parent dc713e4 commit 3245561

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
- Added new `--skip-generation` flag to the `operator-sdk add api` command to support skipping generation of deepcopy and OpenAPI code and OpenAPI CRD specs. ([#1890](https://github.com/operator-framework/operator-sdk/pull/1890))

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"
@@ -168,13 +168,18 @@ func verifyCSVVersion(version string) error {
168168

169169
func writeCRDsToDir(crdPaths []string, toDir string) error {
170170
for _, p := range crdPaths {
171-
if !strings.HasSuffix(p, "crd.yaml") {
172-
continue
173-
}
174171
b, err := ioutil.ReadFile(p)
175172
if err != nil {
176173
return err
177174
}
175+
typeMeta, err := k8sutil.GetTypeMetaFromBytes(b)
176+
if err != nil {
177+
return err
178+
}
179+
if typeMeta.Kind != "CustomResourceDefinition" {
180+
continue
181+
}
182+
178183
path := filepath.Join(toDir, filepath.Base(p))
179184
err = ioutil.WriteFile(path, b, fileutil.DefaultFileMode)
180185
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)