Skip to content

Commit ffa71f1

Browse files
authored
Merge pull request #54 from simrandhaliw/singleton-operator-conversion-webhook-validation-check
Add installModes validation check for CRD conversion webhook support
2 parents cfd7b88 + 659673c commit ffa71f1

File tree

6 files changed

+677
-6
lines changed

6 files changed

+677
-6
lines changed

crds/zz_defs.go

+6-6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

go.sum

+3
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,9 @@ github.com/PuerkitoBio/urlesc v0.0.0-20160726150825-5bd2802263f2/go.mod h1:uGdko
2323
github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578 h1:d+Bc7a5rLufV/sSk/8dngufqelfh6jnri85riMAaF/M=
2424
github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578/go.mod h1:uGdkoq3SwY9Y+13GIhn11/XLaGBb4BfwItxLd5jeuXE=
2525
github.com/agnivade/levenshtein v1.0.1/go.mod h1:CURSv5d9Uaml+FovSIICkLbAUZ9S4RqaHDIsdSBg7lM=
26+
github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc h1:cAKDfWh5VpdgMhJosfJnn5/FoN2SRZ4p7fJNX58YPaU=
2627
github.com/alecthomas/template v0.0.0-20160405071501-a0175ee3bccc/go.mod h1:LOuyumcjzFXgccqObfd/Ljyb9UuFJ6TxHnclSeseNhc=
28+
github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf h1:qet1QNfXsQxTZqLG4oE62mJzwPIB8+Tee4RNCL9ulrY=
2729
github.com/alecthomas/units v0.0.0-20151022065526-2efee857e7cf/go.mod h1:ybxpYRFXyAe+OPACYpWeL0wqObRcbAqCMya13uyzqw0=
2830
github.com/andreyvit/diff v0.0.0-20170406064948-c7f18ee00883/go.mod h1:rCTlJbsFo29Kk6CurOXKm700vrz8f0KW0JNfpkRJY/8=
2931
github.com/armon/consul-api v0.0.0-20180202201655-eb2c6b5be1b6/go.mod h1:grANhF5doyWs3UAsr3K4I6qtAmlQcZDesFNEHPZAzj8=
@@ -539,6 +541,7 @@ google.golang.org/grpc v1.23.1 h1:q4XQuHFC6I28BKZpo6IYyb3mNO+l7lSOxRuYTCiDfXk=
539541
google.golang.org/grpc v1.23.1/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg=
540542
google.golang.org/grpc v1.26.0 h1:2dTRdpdFEEhJYQD8EMLB61nnrzSCTbG38PhqdhvOltg=
541543
google.golang.org/grpc v1.26.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk=
544+
gopkg.in/alecthomas/kingpin.v2 v2.2.6 h1:jMFz6MfLP0/4fUyZle81rXUoxOBFi19VUFKVDOQfozc=
542545
gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw=
543546
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
544547
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=

pkg/validation/internal/csv.go

+23
Original file line numberDiff line numberDiff line change
@@ -168,6 +168,29 @@ func validateInstallModes(csv *v1alpha1.ClusterServiceVersion) (errs []errors.Er
168168
}
169169
}
170170

171+
// validate installModes when conversionCRDs field is present in csv.Spec.Webhookdefinitions
172+
// check if WebhookDefinitions is present
173+
if len(csv.Spec.WebhookDefinitions) != 0 {
174+
for _, WebhookDefinition := range csv.Spec.WebhookDefinitions {
175+
// check if ConversionCRDs is present
176+
if len(WebhookDefinition.ConversionCRDs) != 0 {
177+
supportsOnlyAllNamespaces := true
178+
// check if AllNamespaces is supported and other install modes are not supported
179+
for _, installMode := range csv.Spec.InstallModes {
180+
if installMode.Type == "AllNamespaces" && !installMode.Supported {
181+
supportsOnlyAllNamespaces = false
182+
}
183+
if installMode.Type != "AllNamespaces" && installMode.Supported {
184+
supportsOnlyAllNamespaces = false
185+
}
186+
}
187+
if supportsOnlyAllNamespaces == false {
188+
errs = append(errs, errors.ErrInvalidCSV("only AllNamespaces InstallModeType is supported when conversionCRDs is present", csv.GetName()))
189+
}
190+
}
191+
}
192+
}
193+
171194
// all installModes should not be `false`
172195
if !anySupported {
173196
errs = append(errs, errors.ErrInvalidCSV("none of InstallModeTypes are supported", csv.GetName()))

pkg/validation/internal/csv_test.go

+17
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,23 @@ func TestValidateCSV(t *testing.T) {
3232
},
3333
filepath.Join("testdata", "noInstallMode.csv.yaml"),
3434
},
35+
{
36+
validatorFuncTest{
37+
description: "valid install modes when dealing with conversionCRDs",
38+
wantErr: false,
39+
},
40+
filepath.Join("testdata", "correct.csv.with.conversion.webhook.yaml"),
41+
},
42+
{
43+
validatorFuncTest{
44+
description: "invalid install modes when dealing with conversionCRDs",
45+
wantErr: true,
46+
errors: []errors.Error{
47+
errors.ErrInvalidCSV("only AllNamespaces InstallModeType is supported when conversionCRDs is present", "etcdoperator.v0.9.0"),
48+
},
49+
},
50+
filepath.Join("testdata", "incorrect.csv.with.conversion.webhook.yaml"),
51+
},
3552
}
3653
for _, c := range cases {
3754
b, err := ioutil.ReadFile(c.csvPath)

0 commit comments

Comments
 (0)