diff --git a/go.mod b/go.mod index 9d35ae39c15..d577dce65c0 100644 --- a/go.mod +++ b/go.mod @@ -23,7 +23,7 @@ require ( github.com/maxbrunsfeld/counterfeiter v0.0.0-20181017030959-1aadac120687 github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect github.com/opencontainers/go-digest v1.0.0-rc1 // indirect - github.com/operator-framework/operator-registry v1.0.3 + github.com/operator-framework/operator-registry v1.0.4 github.com/peterbourgon/diskv v2.0.1+incompatible // indirect github.com/pkg/errors v0.8.0 github.com/prometheus/client_golang v0.9.1 @@ -35,6 +35,7 @@ require ( github.com/stretchr/testify v1.2.2 github.com/tmc/grpc-websocket-proxy v0.0.0-20190109142713-0ad062ec5ee5 // indirect github.com/ugorji/go/codec v0.0.0-20181022190402-e5e69e061d4f // indirect + github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2 // indirect go.uber.org/atomic v1.3.2 // indirect go.uber.org/multierr v1.1.0 // indirect go.uber.org/zap v1.9.1 // indirect diff --git a/go.sum b/go.sum index d84accfb8ef..0a8e2358e45 100644 --- a/go.sum +++ b/go.sum @@ -156,10 +156,10 @@ github.com/onsi/gomega v1.4.2-0.20180831124310-ae19f1b56d53/go.mod h1:C1qb7wdrVG github.com/opencontainers/go-digest v1.0.0-rc1 h1:WzifXhOVOEOuFYOJAW6aQqW0TooG2iki3E3Ii+WN7gQ= github.com/opencontainers/go-digest v1.0.0-rc1/go.mod h1:cMLVZDEM3+U2I4VmLI6N8jQYUd2OVphdqWwCJHrFt2s= github.com/operator-framework/operator-lifecycle-manager v0.0.0-20181023032605-e838f7fb2186/go.mod h1:Ma5ZXd4S1vmMyewWlF7aO8CZiokR7Sd8dhSfkGkNU4U= -github.com/operator-framework/operator-lifecycle-manager v0.0.0-20181218235825-c53c51a3572b/go.mod h1:c2QozxMttlmAql7kIIqCji72a1EMxmf6MmHEU2ppW/A= +github.com/operator-framework/operator-lifecycle-manager v0.0.0-20190105193533-81104ffdc4fb/go.mod h1:XMyE4n2opUK4N6L45YGQkXXi8F9fD7XDYFv/CsS6V5I= github.com/operator-framework/operator-registry v1.0.1/go.mod h1:1xEdZjjUg2hPEd52LG3YQ0jtwiwEGdm98S1TH5P4RAA= -github.com/operator-framework/operator-registry v1.0.3 h1:wy5LnO1NAS4Lg+mRmZKddiZr3xPU3Rp1w7Fu66pf8Uc= -github.com/operator-framework/operator-registry v1.0.3/go.mod h1:GfGMdsMQkwS1DlXtYPVTdh2NV8aPUU22+1UXjm9SlW4= +github.com/operator-framework/operator-registry v1.0.4 h1:/xOuw0AFrnV/zjZQeEGtX/xH/ZoLOrNZqWaYU5bRQwM= +github.com/operator-framework/operator-registry v1.0.4/go.mod h1:hve6YwcjM2nGVlscLtNsp9sIIBkNZo6jlJgzWw7vP9s= github.com/pborman/uuid v1.2.0 h1:J7Q5mO4ysT1dv8hyrUGHb9+ooztCXu1D8MY8DZYsu3g= github.com/pborman/uuid v1.2.0/go.mod h1:X/NO0urCmaxf9VXbdlT7C2Yzkj2IKimNn4k+gtPdI/k= 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 github.com/ugorji/go/codec v0.0.0-20181022190402-e5e69e061d4f/go.mod h1:VFNgLljTbGfSG7qAOspJ7OScBnGdDN/yBr0sguwnwf0= github.com/xiang90/probing v0.0.0-20160813154853-07dd2e8dfe18 h1:MPPkRncZLN9Kh4MEFmbnK4h3BD7AUmskWv2+EeZJCCs= github.com/xiang90/probing v0.0.0-20160813154853-07dd2e8dfe18/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU= +github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2 h1:eY9dn8+vbi4tKz5Qo6v2eYzo7kUS51QINcR5jNpbZS8= +github.com/xiang90/probing v0.0.0-20190116061207-43a291ad63a2/go.mod h1:UETIi67q53MR2AWcXfiuqkDkRtnGDLqkBTpCHuJHxtU= go.uber.org/atomic v1.3.2 h1:2Oa65PReHzfn29GpvgsYwloV9AVFHPDk8tYxt2c2tr4= go.uber.org/atomic v1.3.2/go.mod h1:gD2HeocX3+yG+ygLZcrzQJaqmWj9AIm7n08wl/qW/PE= 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 k8s.io/kube-aggregator v0.0.0-20181204002017-122bac39d429/go.mod h1:8sbzT4QQKDEmSCIbfqjV0sd97GpUT7A4W626sBiYJmU= k8s.io/kube-openapi v0.0.0-20181031203759-72693cb1fadd h1:ggv/Vfza0i5xuhUZyYyxcc25AmQvHY8Zi1C2m8WgBvA= k8s.io/kube-openapi v0.0.0-20181031203759-72693cb1fadd/go.mod h1:BXM9ceUBTj2QnfH2MK1odQs778ajze1RxcmP6S8RVVc= -k8s.io/kubernetes v1.11.6-beta.0.0.20181212102158-c4240ecfddd7/go.mod h1:ocZa8+6APFNC2tX1DZASIbocyYT5jHzqFVsY5aoB7Jk= +k8s.io/kubernetes v1.11.7-beta.0.0.20181219023948-b875d52ea96d/go.mod h1:ocZa8+6APFNC2tX1DZASIbocyYT5jHzqFVsY5aoB7Jk= k8s.io/kubernetes v1.11.7-beta.0.0.20190112090204-23cf8fe78f62 h1:BCNTASEARMUY8An3j4C7XN+wGAT257QTWW7zVf3LsVI= k8s.io/kubernetes v1.11.7-beta.0.0.20190112090204-23cf8fe78f62/go.mod h1:ocZa8+6APFNC2tX1DZASIbocyYT5jHzqFVsY5aoB7Jk= diff --git a/test/e2e/installplan_e2e_test.go b/test/e2e/installplan_e2e_test.go index e7186164317..c00f2230e01 100644 --- a/test/e2e/installplan_e2e_test.go +++ b/test/e2e/installplan_e2e_test.go @@ -714,3 +714,97 @@ func TestCreateInstallPlanWithPermissions(t *testing.T) { require.Equal(t, 0, len(expectedSteps), "Actual resource steps do not match expected") } + +func TestInstallPlanCRDValidation(t *testing.T) { + // Tests if CRD validation works with the "minimum" property after being + // pulled from a CatalogSource's operator-registry. + defer cleaner.NotifyTestComplete(t, true) + + crdPlural := genName("ins") + crdName := crdPlural + ".cluster.com" + var min float64 = 2 + var max float64 = 256 + + // Create CRD with offending property + crd := apiextensions.CustomResourceDefinition{ + ObjectMeta: metav1.ObjectMeta{ + Name: crdName, + }, + Spec: apiextensions.CustomResourceDefinitionSpec{ + Group: "cluster.com", + Version: "v1alpha1", + Names: apiextensions.CustomResourceDefinitionNames{ + Plural: crdPlural, + Singular: crdPlural, + Kind: crdPlural, + ListKind: "list" + crdPlural, + }, + Scope: "Namespaced", + Validation: &apiextensions.CustomResourceValidation{ + OpenAPIV3Schema: &apiextensions.JSONSchemaProps{ + Properties: map[string]apiextensions.JSONSchemaProps{ + "spec": { + Type: "object", + Description: "Spec of a test object.", + Properties: map[string]apiextensions.JSONSchemaProps{ + "scalar": { + Type: "number", + Description: "Scalar value that should have a min and max.", + Minimum: &min, + Maximum: &max, + }, + }, + }, + }, + }, + }, + }, + } + + // Create CSV + packageName := genName("nginx-") + stableChannel := "stable" + packageNameStable := packageName + "-" + stableChannel + namedStrategy := newNginxInstallStrategy(genName("dep-"), nil, nil) + csv := newCSV(packageNameStable, testNamespace, "", *semver.New("0.1.0"), []apiextensions.CustomResourceDefinition{crd}, nil, namedStrategy) + + // Create PackageManifests + manifests := []registry.PackageManifest{ + { + PackageName: packageName, + Channels: []registry.PackageChannel{ + {Name: stableChannel, CurrentCSVName: packageNameStable}, + }, + DefaultChannelName: stableChannel, + }, + } + + // Create the CatalogSource + c := newKubeClient(t) + crc := newCRClient(t) + catalogSourceName := genName("mock-nginx-") + _, cleanupCatalogSource := createInternalCatalogSource(t, c, crc, catalogSourceName, testNamespace, manifests, []apiextensions.CustomResourceDefinition{crd}, []v1alpha1.ClusterServiceVersion{csv}) + defer cleanupCatalogSource() + + // Attempt to get the catalog source before creating install plan + _, err := fetchCatalogSource(t, crc, catalogSourceName, testNamespace, catalogSourceRegistryPodSynced) + require.NoError(t, err) + + subscriptionName := genName("sub-nginx-") + cleanupSubscription := createSubscriptionForCatalog(t, crc, testNamespace, subscriptionName, catalogSourceName, packageName, stableChannel, v1alpha1.ApprovalAutomatic) + defer cleanupSubscription() + + subscription, err := fetchSubscription(t, crc, testNamespace, subscriptionName, subscriptionHasInstallPlanChecker) + require.NoError(t, err) + require.NotNil(t, subscription) + + installPlanName := subscription.Status.Install.Name + + // Wait for InstallPlan to be status: Complete before checking resource presence + fetchedInstallPlan, err := fetchInstallPlan(t, crc, installPlanName, buildInstallPlanPhaseCheckFunc(v1alpha1.InstallPlanPhaseComplete, v1alpha1.InstallPlanPhaseFailed)) + require.NoError(t, err) + t.Logf("Install plan %s fetched with status %s", fetchedInstallPlan.GetName(), fetchedInstallPlan.Status.Phase) + + require.Equal(t, v1alpha1.InstallPlanPhaseComplete, fetchedInstallPlan.Status.Phase) + +} diff --git a/vendor/github.com/operator-framework/operator-registry/pkg/registry/bundle.go b/vendor/github.com/operator-framework/operator-registry/pkg/registry/bundle.go index 4fcfb268dd6..d9a203143f7 100644 --- a/vendor/github.com/operator-framework/operator-registry/pkg/registry/bundle.go +++ b/vendor/github.com/operator-framework/operator-registry/pkg/registry/bundle.go @@ -3,6 +3,7 @@ package registry import ( "fmt" "k8s.io/apimachinery/pkg/util/yaml" + "encoding/json" "strings" "github.com/operator-framework/operator-lifecycle-manager/pkg/api/apis/operators/v1alpha1" @@ -205,7 +206,13 @@ func (b *Bundle) cache() error { for _, o := range b.Objects { if o.GetObjectKind().GroupVersionKind().Kind == "CustomResourceDefinition" { crd := &apiextensions.CustomResourceDefinition{} - if err := runtime.DefaultUnstructuredConverter.FromUnstructured(o.UnstructuredContent(), crd); err != nil { + // Marshal Unstructured and Unmarshal as CustomResourceDefinition. FromUnstructured has issues + // converting JSON numbers to float64 for CRD minimum/maximum validation. + bytes, err := o.MarshalJSON() + if err != nil { + return err + } + if err := json.Unmarshal(bytes, &crd); err != nil { return err } b.crds = append(b.crds, crd) diff --git a/vendor/modules.txt b/vendor/modules.txt index 7d417ce7eaa..c7c94dca711 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -125,7 +125,7 @@ github.com/mitchellh/mapstructure github.com/modern-go/concurrent # github.com/modern-go/reflect2 v1.0.1 github.com/modern-go/reflect2 -# github.com/operator-framework/operator-registry v1.0.3 +# github.com/operator-framework/operator-registry v1.0.4 github.com/operator-framework/operator-registry/pkg/client github.com/operator-framework/operator-registry/pkg/registry github.com/operator-framework/operator-registry/pkg/api