Skip to content

Commit c9610b0

Browse files
Merge pull request #324 from Bowenislandsong/bug/understandsingBundles1827723
Bug 1827723: Adding error message for more than one CSV in bundle dir
2 parents d21c6e7 + 1d0a923 commit c9610b0

14 files changed

+1533
-20
lines changed

go.mod

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,34 +3,22 @@ module github.com/operator-framework/operator-registry
33
go 1.13
44

55
require (
6-
github.com/Microsoft/hcsshim v0.8.7 // indirect
76
github.com/antihax/optional v0.0.0-20180407024304-ca021399b1a6
87
github.com/blang/semver v3.5.0+incompatible
98
github.com/containerd/containerd v1.3.2
10-
github.com/containerd/continuity v0.0.0-20200228182428-0f16d7a0959c // indirect
119
github.com/docker/cli v0.0.0-20200130152716-5d0cf8839492
1210
github.com/docker/distribution v2.7.1+incompatible
1311
github.com/docker/docker v1.4.2-0.20200203170920-46ec8731fbce
14-
github.com/docker/docker-credential-helpers v0.6.3 // indirect
15-
github.com/docker/go-events v0.0.0-20190806004212-e31b211e4f1c // indirect
16-
github.com/docker/go-metrics v0.0.1 // indirect
17-
github.com/docker/libtrust v0.0.0-20160708172513-aabc10ec26b7 // indirect
1812
github.com/ghodss/yaml v1.0.0
1913
github.com/golang-migrate/migrate/v4 v4.6.2
2014
github.com/golang/mock v1.3.1
2115
github.com/golang/protobuf v1.3.2
22-
github.com/google/go-cmp v0.4.0 // indirect
23-
github.com/gorilla/mux v1.7.4 // indirect
2416
github.com/grpc-ecosystem/grpc-health-probe v0.2.1-0.20181220223928-2bf0a5b182db
25-
github.com/imdario/mergo v0.3.8 // indirect
2617
github.com/mattn/go-sqlite3 v1.10.0
2718
github.com/maxbrunsfeld/counterfeiter/v6 v6.2.2
28-
github.com/morikuni/aec v1.0.0 // indirect
2919
github.com/onsi/ginkgo v1.12.0
3020
github.com/onsi/gomega v1.9.0
3121
github.com/opencontainers/image-spec v1.0.2-0.20190823105129-775207bd45b6
32-
github.com/opencontainers/runc v1.0.0-rc9 // indirect
33-
github.com/opencontainers/runtime-spec v0.1.2-0.20190618234442-a950415649c7 // indirect
3422
github.com/operator-framework/api v0.3.4
3523
github.com/otiai10/copy v1.0.2
3624
github.com/phayes/freeport v0.0.0-20180830031419-95f893ade6f2
@@ -43,8 +31,8 @@ require (
4331
golang.org/x/net v0.0.0-20191028085509-fe3aa8a45271
4432
golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45
4533
google.golang.org/grpc v1.26.0
46-
gopkg.in/check.v1 v1.0.0-20190902080502-41f04d3bba15 // indirect
4734
gopkg.in/yaml.v2 v2.2.8
35+
gotest.tools/v3 v3.0.2 // indirect
4836
k8s.io/api v0.18.2
4937
k8s.io/apiextensions-apiserver v0.18.2
5038
k8s.io/apimachinery v0.18.2

go.sum

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,10 +90,6 @@ github.com/cockroachdb/datadriven v0.0.0-20190809214429-80d97fb3cbaa/go.mod h1:z
9090
github.com/containerd/cgroups v0.0.0-20190919134610-bf292b21730f h1:tSNMc+rJDfmYntojat8lljbt1mgKNpTxUZJsSzJ9Y1s=
9191
github.com/containerd/cgroups v0.0.0-20190919134610-bf292b21730f/go.mod h1:OApqhQ4XNSNC13gXIwDjhOQxjWa/NxkwZXJ1EvqT0ko=
9292
github.com/containerd/console v0.0.0-20180822173158-c12b1e7919c1/go.mod h1:Tj/on1eG8kiEhd0+fhSDzsPAFESxzBBvdyEgyryXffw=
93-
github.com/containerd/containerd v1.2.7/go.mod h1:bC6axHOhabU15QhwfG7w5PipXdVtMXFTttgp+kVtyUA=
94-
github.com/containerd/containerd v1.3.0-beta.2.0.20190828155532-0293cbd26c69/go.mod h1:bC6axHOhabU15QhwfG7w5PipXdVtMXFTttgp+kVtyUA=
95-
github.com/containerd/containerd v1.3.2 h1:ForxmXkA6tPIvffbrDAcPUIB32QgXkt2XFj+F0UxetA=
96-
github.com/containerd/containerd v1.3.2/go.mod h1:bC6axHOhabU15QhwfG7w5PipXdVtMXFTttgp+kVtyUA=
9793
github.com/containerd/continuity v0.0.0-20190426062206-aaeac12a7ffc/go.mod h1:GL3xCUCBDV3CZiTSEKksMWbLE66hEyuu9qyDOOqM47Y=
9894
github.com/containerd/continuity v0.0.0-20200228182428-0f16d7a0959c h1:8ahmSVELW1wghbjerVAyuEYD5+Dio66RYvSS0iGfL1M=
9995
github.com/containerd/continuity v0.0.0-20200228182428-0f16d7a0959c/go.mod h1:Dq467ZllaHgAtVp4p1xUQWBrFXR9s/wyoTpG8zOJGkY=
@@ -812,6 +808,7 @@ golang.org/x/tools v0.0.0-20190524140312-2c0ae7006135/go.mod h1:RgjU9mgBXZiqYHBn
812808
golang.org/x/tools v0.0.0-20190614205625-5aca471b1d59/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc=
813809
golang.org/x/tools v0.0.0-20190617190820-da514acc4774/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc=
814810
golang.org/x/tools v0.0.0-20190621195816-6e04913cbbac/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc=
811+
golang.org/x/tools v0.0.0-20190624222133-a101b041ded4/go.mod h1:/rFqwRUd4F7ZHNgwSSTFct+R/Kf4OFW1sUzUTQQTgfc=
815812
golang.org/x/tools v0.0.0-20190706070813-72ffa07ba3db h1:9hRk1xeL9LTT3yX/941DqeBz87XgHAQuj+TbimYJuiw=
816813
golang.org/x/tools v0.0.0-20190706070813-72ffa07ba3db/go.mod h1:jcCCGcm9btYwXyDqrUWc6MKQKKGJCWEQ3AfLSRIbEuI=
817814
golang.org/x/tools v0.0.0-20190920225731-5eefd052ad72 h1:bw9doJza/SFBEweII/rHQh338oozWyiFsBRHtrflcws=
@@ -890,6 +887,8 @@ gopkg.in/yaml.v2 v2.2.8/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
890887
gopkg.in/yaml.v3 v3.0.0-20190905181640-827449938966/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
891888
gotest.tools v2.2.0+incompatible h1:VsBPFP1AI068pPrMxtb/S8Zkgf9xEmTLJjfM+P5UIEo=
892889
gotest.tools v2.2.0+incompatible/go.mod h1:DsYFclhRJ6vuDpmuTbkuFWG+y2sxOXAzmJt81HFBacw=
890+
gotest.tools/v3 v3.0.2 h1:kG1BFyqVHuQoVQiR1bWGnfz/fmHvvuiSPIV7rvl360E=
891+
gotest.tools/v3 v3.0.2/go.mod h1:3SzNCllyD9/Y+b5r9JIKQ474KzkZyqLqEfYqMsX94Bk=
893892
honnef.co/go/tools v0.0.0-20180728063816-88497007e858/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
894893
honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
895894
honnef.co/go/tools v0.0.0-20190106161140-3f1c8253044a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=

pkg/registry/csv.go

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -65,8 +65,8 @@ type ClusterServiceVersion struct {
6565
Spec json.RawMessage `json:"spec"`
6666
}
6767

68-
// ReadCSVFromBundleDirectory tries to parse every YAML file in the directory and see if they are CSV.
69-
// According to the strict one CSV rule for every bundle, we return the first file that is considered a CSV type.
68+
// ReadCSVFromBundleDirectory tries to parse every YAML file in the directory without inspecting sub-directories and
69+
// returns a CSV. According to the strict one CSV per bundle rule, func returns an error if more than one CSV is found.
7070
func ReadCSVFromBundleDirectory(bundleDir string) (*ClusterServiceVersion, error) {
7171
dirContent, err := ioutil.ReadDir(bundleDir)
7272
if err != nil {
@@ -80,14 +80,15 @@ func ReadCSVFromBundleDirectory(bundleDir string) (*ClusterServiceVersion, error
8080
}
8181
}
8282

83+
csv := ClusterServiceVersion{}
84+
foundCSV := false
8385
for _, file := range files {
8486
yamlReader, err := os.Open(path.Join(bundleDir, file))
8587
if err != nil {
8688
continue
8789
}
8890

8991
unstructuredCSV := unstructured.Unstructured{}
90-
csv := ClusterServiceVersion{}
9192

9293
decoder := yaml.NewYAMLOrJSONDecoder(yamlReader, 30)
9394
if err = decoder.Decode(&unstructuredCSV); err != nil {
@@ -98,11 +99,18 @@ func ReadCSVFromBundleDirectory(bundleDir string) (*ClusterServiceVersion, error
9899
continue
99100
}
100101

102+
if foundCSV {
103+
return nil, fmt.Errorf("more than one ClusterServiceVersion is found in bundle")
104+
}
105+
101106
if err := runtime.DefaultUnstructuredConverter.FromUnstructured(unstructuredCSV.UnstructuredContent(),
102107
&csv); err != nil {
103108
return nil, err
104109
}
110+
foundCSV = true
111+
}
105112

113+
if foundCSV {
106114
return &csv, nil
107115
}
108116
return nil, fmt.Errorf("no ClusterServiceVersion object found in %s", bundleDir)

pkg/registry/csv_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -802,6 +802,10 @@ func TestLoadingCsvFromBundleDirectory(t *testing.T) {
802802
dir: "testdata/invalidPackges/3scale-community-operator/0.3.0",
803803
fail: true,
804804
},
805+
{
806+
dir: "testdata/invalidPackges/3scale-community-operator/0.4.0",
807+
fail: true,
808+
},
805809
}
806810

807811
for _, tt := range tests {

0 commit comments

Comments
 (0)