Skip to content

Commit 4462fdc

Browse files
committed
test(validation): add test to verify OLM can use bundles with CRDs with
min/max fields
1 parent f633e44 commit 4462fdc

File tree

5 files changed

+111
-7
lines changed

5 files changed

+111
-7
lines changed

go.mod

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ require (
2323
github.com/maxbrunsfeld/counterfeiter v0.0.0-20181017030959-1aadac120687
2424
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
2525
github.com/opencontainers/go-digest v1.0.0-rc1 // indirect
26-
github.com/operator-framework/operator-registry v1.0.3
26+
github.com/operator-framework/operator-registry v1.0.4
2727
github.com/peterbourgon/diskv v2.0.1+incompatible // indirect
2828
github.com/pkg/errors v0.8.0
2929
github.com/prometheus/client_golang v0.9.1
@@ -35,6 +35,7 @@ require (
3535
github.com/stretchr/testify v1.2.2
3636
github.com/tmc/grpc-websocket-proxy v0.0.0-20190109142713-0ad062ec5ee5 // indirect
3737
github.com/ugorji/go/codec v0.0.0-20181022190402-e5e69e061d4f // indirect
38+
github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2 // indirect
3839
go.uber.org/atomic v1.3.2 // indirect
3940
go.uber.org/multierr v1.1.0 // indirect
4041
go.uber.org/zap v1.9.1 // indirect

go.sum

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -156,10 +156,10 @@ github.com/onsi/gomega v1.4.2-0.20180831124310-ae19f1b56d53/go.mod h1:C1qb7wdrVG
156156
github.com/opencontainers/go-digest v1.0.0-rc1 h1:WzifXhOVOEOuFYOJAW6aQqW0TooG2iki3E3Ii+WN7gQ=
157157
github.com/opencontainers/go-digest v1.0.0-rc1/go.mod h1:cMLVZDEM3+U2I4VmLI6N8jQYUd2OVphdqWwCJHrFt2s=
158158
github.com/operator-framework/operator-lifecycle-manager v0.0.0-20181023032605-e838f7fb2186/go.mod h1:Ma5ZXd4S1vmMyewWlF7aO8CZiokR7Sd8dhSfkGkNU4U=
159-
github.com/operator-framework/operator-lifecycle-manager v0.0.0-20181218235825-c53c51a3572b/go.mod h1:c2QozxMttlmAql7kIIqCji72a1EMxmf6MmHEU2ppW/A=
159+
github.com/operator-framework/operator-lifecycle-manager v0.0.0-20190105193533-81104ffdc4fb/go.mod h1:XMyE4n2opUK4N6L45YGQkXXi8F9fD7XDYFv/CsS6V5I=
160160
github.com/operator-framework/operator-registry v1.0.1/go.mod h1:1xEdZjjUg2hPEd52LG3YQ0jtwiwEGdm98S1TH5P4RAA=
161-
github.com/operator-framework/operator-registry v1.0.3 h1:wy5LnO1NAS4Lg+mRmZKddiZr3xPU3Rp1w7Fu66pf8Uc=
162-
github.com/operator-framework/operator-registry v1.0.3/go.mod h1:GfGMdsMQkwS1DlXtYPVTdh2NV8aPUU22+1UXjm9SlW4=
161+
github.com/operator-framework/operator-registry v1.0.4 h1:/xOuw0AFrnV/zjZQeEGtX/xH/ZoLOrNZqWaYU5bRQwM=
162+
github.com/operator-framework/operator-registry v1.0.4/go.mod h1:hve6YwcjM2nGVlscLtNsp9sIIBkNZo6jlJgzWw7vP9s=
163163
github.com/pborman/uuid v1.2.0 h1:J7Q5mO4ysT1dv8hyrUGHb9+ooztCXu1D8MY8DZYsu3g=
164164
github.com/pborman/uuid v1.2.0/go.mod h1:X/NO0urCmaxf9VXbdlT7C2Yzkj2IKimNn4k+gtPdI/k=
165165
github.com/petar/GoLLRB v0.0.0-20130427215148-53be0d36a84c/go.mod h1:HUpKUBZnpzkdx0kD/+Yfuft+uD3zHGtXF/XJB14TUr4=
@@ -204,6 +204,8 @@ github.com/ugorji/go/codec v0.0.0-20181022190402-e5e69e061d4f h1:y3Vj7GoDdcBkxFa
204204
github.com/ugorji/go/codec v0.0.0-20181022190402-e5e69e061d4f/go.mod h1:VFNgLljTbGfSG7qAOspJ7OScBnGdDN/yBr0sguwnwf0=
205205
github.com/xiang90/probing v0.0.0-20160813154853-07dd2e8dfe18 h1:MPPkRncZLN9Kh4MEFmbnK4h3BD7AUmskWv2+EeZJCCs=
206206
github.com/xiang90/probing v0.0.0-20160813154853-07dd2e8dfe18/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU=
207+
github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2 h1:eY9dn8+vbi4tKz5Qo6v2eYzo7kUS51QINcR5jNpbZS8=
208+
github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU=
207209
go.uber.org/atomic v1.3.2 h1:2Oa65PReHzfn29GpvgsYwloV9AVFHPDk8tYxt2c2tr4=
208210
go.uber.org/atomic v1.3.2/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE=
209211
go.uber.org/multierr v1.1.0 h1:HoEmRHQPVSqub6w2z2d2EOVs2fjyFRGyofhKuyDq0QI=
@@ -289,6 +291,6 @@ k8s.io/kube-aggregator v0.0.0-20181204002017-122bac39d429 h1:wIDPKpRuwEfyt+ImBaP
289291
k8s.io/kube-aggregator v0.0.0-20181204002017-122bac39d429/go.mod h1:8sbzT4QQKDEmSCIbfqjV0sd97GpUT7A4W626sBiYJmU=
290292
k8s.io/kube-openapi v0.0.0-20181031203759-72693cb1fadd h1:ggv/Vfza0i5xuhUZyYyxcc25AmQvHY8Zi1C2m8WgBvA=
291293
k8s.io/kube-openapi v0.0.0-20181031203759-72693cb1fadd/go.mod h1:BXM9ceUBTj2QnfH2MK1odQs778ajze1RxcmP6S8RVVc=
292-
k8s.io/kubernetes v1.11.6-beta.0.0.20181212102158-c4240ecfddd7/go.mod h1:ocZa8+6APFNC2tX1DZASIbocyYT5jHzqFVsY5aoB7Jk=
294+
k8s.io/kubernetes v1.11.7-beta.0.0.20181219023948-b875d52ea96d/go.mod h1:ocZa8+6APFNC2tX1DZASIbocyYT5jHzqFVsY5aoB7Jk=
293295
k8s.io/kubernetes v1.11.7-beta.0.0.20190112090204-23cf8fe78f62 h1:BCNTASEARMUY8An3j4C7XN+wGAT257QTWW7zVf3LsVI=
294296
k8s.io/kubernetes v1.11.7-beta.0.0.20190112090204-23cf8fe78f62/go.mod h1:ocZa8+6APFNC2tX1DZASIbocyYT5jHzqFVsY5aoB7Jk=

test/e2e/installplan_e2e_test.go

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -714,3 +714,97 @@ func TestCreateInstallPlanWithPermissions(t *testing.T) {
714714
require.Equal(t, 0, len(expectedSteps), "Actual resource steps do not match expected")
715715

716716
}
717+
718+
func TestInstallPlanCRDValidation(t *testing.T) {
719+
// Tests if CRD validation works with the "minimum" property after being
720+
// pulled from a CatalogSource's operator-registry.
721+
defer cleaner.NotifyTestComplete(t, true)
722+
723+
crdPlural := genName("ins")
724+
crdName := crdPlural + ".cluster.com"
725+
var min float64 = 2
726+
var max float64 = 256
727+
728+
// Create CRD with offending property
729+
crd := apiextensions.CustomResourceDefinition{
730+
ObjectMeta: metav1.ObjectMeta{
731+
Name: crdName,
732+
},
733+
Spec: apiextensions.CustomResourceDefinitionSpec{
734+
Group: "cluster.com",
735+
Version: "v1alpha1",
736+
Names: apiextensions.CustomResourceDefinitionNames{
737+
Plural: crdPlural,
738+
Singular: crdPlural,
739+
Kind: crdPlural,
740+
ListKind: "list" + crdPlural,
741+
},
742+
Scope: "Namespaced",
743+
Validation: &apiextensions.CustomResourceValidation{
744+
OpenAPIV3Schema: &apiextensions.JSONSchemaProps{
745+
Properties: map[string]apiextensions.JSONSchemaProps{
746+
"spec": {
747+
Type: "object",
748+
Description: "Spec of a test object.",
749+
Properties: map[string]apiextensions.JSONSchemaProps{
750+
"scalar": {
751+
Type: "number",
752+
Description: "Scalar value that should have a min and max.",
753+
Minimum: &min,
754+
Maximum: &max,
755+
},
756+
},
757+
},
758+
},
759+
},
760+
},
761+
},
762+
}
763+
764+
// Create CSV
765+
packageName := genName("nginx-")
766+
stableChannel := "stable"
767+
packageNameStable := packageName + "-" + stableChannel
768+
namedStrategy := newNginxInstallStrategy(genName("dep-"), nil, nil)
769+
csv := newCSV(packageNameStable, testNamespace, "", *semver.New("0.1.0"), []apiextensions.CustomResourceDefinition{crd}, nil, namedStrategy)
770+
771+
// Create PackageManifests
772+
manifests := []registry.PackageManifest{
773+
{
774+
PackageName: packageName,
775+
Channels: []registry.PackageChannel{
776+
{Name: stableChannel, CurrentCSVName: packageNameStable},
777+
},
778+
DefaultChannelName: stableChannel,
779+
},
780+
}
781+
782+
// Create the CatalogSource
783+
c := newKubeClient(t)
784+
crc := newCRClient(t)
785+
catalogSourceName := genName("mock-nginx-")
786+
_, cleanupCatalogSource := createInternalCatalogSource(t, c, crc, catalogSourceName, testNamespace, manifests, []apiextensions.CustomResourceDefinition{crd}, []v1alpha1.ClusterServiceVersion{csv})
787+
defer cleanupCatalogSource()
788+
789+
// Attempt to get the catalog source before creating install plan
790+
_, err := fetchCatalogSource(t, crc, catalogSourceName, testNamespace, catalogSourceRegistryPodSynced)
791+
require.NoError(t, err)
792+
793+
subscriptionName := genName("sub-nginx-")
794+
cleanupSubscription := createSubscriptionForCatalog(t, crc, testNamespace, subscriptionName, catalogSourceName, packageName, stableChannel, v1alpha1.ApprovalAutomatic)
795+
defer cleanupSubscription()
796+
797+
subscription, err := fetchSubscription(t, crc, testNamespace, subscriptionName, subscriptionHasInstallPlanChecker)
798+
require.NoError(t, err)
799+
require.NotNil(t, subscription)
800+
801+
installPlanName := subscription.Status.Install.Name
802+
803+
// Wait for InstallPlan to be status: Complete before checking resource presence
804+
fetchedInstallPlan, err := fetchInstallPlan(t, crc, installPlanName, buildInstallPlanPhaseCheckFunc(v1alpha1.InstallPlanPhaseComplete, v1alpha1.InstallPlanPhaseFailed))
805+
require.NoError(t, err)
806+
t.Logf("Install plan %s fetched with status %s", fetchedInstallPlan.GetName(), fetchedInstallPlan.Status.Phase)
807+
808+
require.Equal(t, v1alpha1.InstallPlanPhaseComplete, fetchedInstallPlan.Status.Phase)
809+
810+
}

vendor/github.com/operator-framework/operator-registry/pkg/registry/bundle.go

Lines changed: 8 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/modules.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ github.com/mitchellh/mapstructure
125125
github.com/modern-go/concurrent
126126
# github.com/modern-go/reflect2 v1.0.1
127127
github.com/modern-go/reflect2
128-
# github.com/operator-framework/operator-registry v1.0.3
128+
# github.com/operator-framework/operator-registry v1.0.4
129129
github.com/operator-framework/operator-registry/pkg/client
130130
github.com/operator-framework/operator-registry/pkg/registry
131131
github.com/operator-framework/operator-registry/pkg/api

0 commit comments

Comments
 (0)