Skip to content

Commit ea020ed

Browse files
committed
remove olm.bundle.mediatype property and clusterextension support for plain+v0
Signed-off-by: Joe Lanford <[email protected]>
1 parent 5985cce commit ea020ed

File tree

10 files changed

+11
-457
lines changed

10 files changed

+11
-457
lines changed

Makefile

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,6 @@ e2e: $(SETUP_ENVTEST) #EXHELP Run the e2e tests.
123123
E2E_REGISTRY_NAME := docker-registry
124124
E2E_REGISTRY_NAMESPACE := operator-controller-e2e
125125
export REG_PKG_NAME := registry-operator
126-
export PLAIN_PKG_NAME := plain-operator
127126
export CATALOG_IMG := $(E2E_REGISTRY_NAME).$(E2E_REGISTRY_NAMESPACE).svc:5000/test-catalog:e2e
128127
.PHONY: test-ext-dev-e2e
129128
test-ext-dev-e2e: $(SETUP_ENVTEST) $(OPERATOR_SDK) $(KUSTOMIZE) $(KIND) #HELP Run extension create, upgrade and delete tests.
@@ -187,12 +186,10 @@ kind-load-test-artifacts: $(KIND) #EXHELP Load the e2e testdata container images
187186
$(CONTAINER_RUNTIME) tag localhost/testdata/bundles/registry-v1/prometheus-operator:v1.0.0 localhost/testdata/bundles/registry-v1/prometheus-operator:v1.0.1
188187
$(CONTAINER_RUNTIME) tag localhost/testdata/bundles/registry-v1/prometheus-operator:v1.0.0 localhost/testdata/bundles/registry-v1/prometheus-operator:v1.2.0
189188
$(CONTAINER_RUNTIME) tag localhost/testdata/bundles/registry-v1/prometheus-operator:v1.0.0 localhost/testdata/bundles/registry-v1/prometheus-operator:v2.0.0
190-
$(CONTAINER_RUNTIME) build testdata/bundles/plain-v0/plain.v0.1.0 -t localhost/testdata/bundles/plain-v0/plain:v0.1.0
191189
$(KIND) load docker-image localhost/testdata/bundles/registry-v1/prometheus-operator:v1.0.0 --name $(KIND_CLUSTER_NAME)
192190
$(KIND) load docker-image localhost/testdata/bundles/registry-v1/prometheus-operator:v1.0.1 --name $(KIND_CLUSTER_NAME)
193191
$(KIND) load docker-image localhost/testdata/bundles/registry-v1/prometheus-operator:v1.2.0 --name $(KIND_CLUSTER_NAME)
194192
$(KIND) load docker-image localhost/testdata/bundles/registry-v1/prometheus-operator:v2.0.0 --name $(KIND_CLUSTER_NAME)
195-
$(KIND) load docker-image localhost/testdata/bundles/plain-v0/plain:v0.1.0 --name $(KIND_CLUSTER_NAME)
196193

197194

198195
#SECTION Build

internal/catalogmetadata/types.go

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,6 @@ import (
1111
"github.com/operator-framework/operator-registry/alpha/property"
1212
)
1313

14-
const (
15-
MediaTypePlain = "plain+v0"
16-
MediaTypeRegistry = "registry+v1"
17-
PropertyBundleMediaType = "olm.bundle.mediatype"
18-
)
19-
2014
type Schemas interface {
2115
Package | Bundle | Channel | Deprecation
2216
}
@@ -50,7 +44,6 @@ type Bundle struct {
5044
bundlePackage *property.Package
5145
semVersion *bsemver.Version
5246
requiredPackages []PackageRequired
53-
mediaType *string
5447
}
5548

5649
func (b *Bundle) Version() (*bsemver.Version, error) {
@@ -67,14 +60,6 @@ func (b *Bundle) RequiredPackages() ([]PackageRequired, error) {
6760
return b.requiredPackages, nil
6861
}
6962

70-
func (b *Bundle) MediaType() (string, error) {
71-
if err := b.loadMediaType(); err != nil {
72-
return "", err
73-
}
74-
75-
return *b.mediaType, nil
76-
}
77-
7863
func (b *Bundle) loadPackage() error {
7964
b.mu.Lock()
8065
defer b.mu.Unlock()
@@ -120,19 +105,6 @@ func (b *Bundle) loadRequiredPackages() error {
120105
return nil
121106
}
122107

123-
func (b *Bundle) loadMediaType() error {
124-
b.mu.Lock()
125-
defer b.mu.Unlock()
126-
if b.mediaType == nil {
127-
mediaType, err := loadOneFromProps[string](b, PropertyBundleMediaType, false)
128-
if err != nil {
129-
return fmt.Errorf("error determining bundle mediatype for bundle %q: %s", b.Name, err)
130-
}
131-
b.mediaType = &mediaType
132-
}
133-
return nil
134-
}
135-
136108
func (b *Bundle) propertiesByType(propType string) []*property.Property {
137109
if b.propertiesMap == nil {
138110
b.propertiesMap = make(map[string][]*property.Property)

internal/catalogmetadata/types_test.go

Lines changed: 0 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ package catalogmetadata_test
22

33
import (
44
"encoding/json"
5-
"fmt"
65
"testing"
76

87
bsemver "github.com/blang/semver/v4"
@@ -147,61 +146,6 @@ func TestBundleRequiredPackages(t *testing.T) {
147146
}
148147
}
149148

150-
func TestBundleMediaType(t *testing.T) {
151-
for _, tt := range []struct {
152-
name string
153-
bundle *catalogmetadata.Bundle
154-
wantMediaType string
155-
wantErr string
156-
}{
157-
{
158-
name: "valid mediatype property",
159-
bundle: &catalogmetadata.Bundle{Bundle: declcfg.Bundle{
160-
Name: "fake-bundle.v1",
161-
Properties: []property.Property{
162-
{
163-
Type: catalogmetadata.PropertyBundleMediaType,
164-
Value: json.RawMessage(fmt.Sprintf(`"%s"`, catalogmetadata.MediaTypePlain)),
165-
},
166-
},
167-
}},
168-
wantMediaType: catalogmetadata.MediaTypePlain,
169-
},
170-
{
171-
name: "no media type provided",
172-
bundle: &catalogmetadata.Bundle{Bundle: declcfg.Bundle{
173-
Name: "fake-bundle.noMediaType",
174-
Properties: []property.Property{},
175-
}},
176-
wantMediaType: "",
177-
},
178-
{
179-
name: "malformed media type",
180-
bundle: &catalogmetadata.Bundle{Bundle: declcfg.Bundle{
181-
Name: "fake-bundle.badMediaType",
182-
Properties: []property.Property{
183-
{
184-
Type: catalogmetadata.PropertyBundleMediaType,
185-
Value: json.RawMessage("badtype"),
186-
},
187-
},
188-
}},
189-
wantMediaType: "",
190-
wantErr: `error determining bundle mediatype for bundle "fake-bundle.badMediaType": property "olm.bundle.mediatype" with value "badtype" could not be parsed: invalid character 'b' looking for beginning of value`,
191-
},
192-
} {
193-
t.Run(tt.name, func(t *testing.T) {
194-
mediaType, err := tt.bundle.MediaType()
195-
assert.Equal(t, tt.wantMediaType, mediaType)
196-
if tt.wantErr != "" {
197-
assert.EqualError(t, err, tt.wantErr)
198-
} else {
199-
assert.NoError(t, err)
200-
}
201-
})
202-
}
203-
}
204-
205149
func TestBundleHasDeprecation(t *testing.T) {
206150
for _, tt := range []struct {
207151
name string

internal/controllers/clusterextension_controller.go

Lines changed: 4 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -135,25 +135,16 @@ func (r *ClusterExtensionReconciler) reconcile(ctx context.Context, ext *ocv1alp
135135

136136
// TODO: Question - Should we set the deprecation statuses after we have successfully resolved instead of after a successful installation?
137137

138-
mediaType, err := bundle.MediaType()
139-
if err != nil {
140-
setInstalledStatusConditionFailed(&ext.Status.Conditions, err.Error(), ext.GetGeneration())
141-
setDeprecationStatusesUnknown(&ext.Status.Conditions, "deprecation checks have not been attempted as installation has failed", ext.GetGeneration())
142-
return ctrl.Result{}, err
143-
}
144-
145138
if err := r.validateBundle(bundle); err != nil {
146139
setInstalledStatusConditionFailed(&ext.Status.Conditions, err.Error(), ext.GetGeneration())
147140
setDeprecationStatusesUnknown(&ext.Status.Conditions, "deprecation checks have not been attempted as installation has failed", ext.GetGeneration())
148141
return ctrl.Result{}, err
149142
}
150143

151-
bundleProvisioner, err := mapBundleMediaTypeToBundleProvisioner(mediaType)
152-
if err != nil {
153-
setInstalledStatusConditionFailed(&ext.Status.Conditions, err.Error(), ext.GetGeneration())
154-
setDeprecationStatusesUnknown(&ext.Status.Conditions, "deprecation checks have not been attempted as installation has failed", ext.GetGeneration())
155-
return ctrl.Result{}, err
156-
}
144+
// Assume all bundles are registry+v1 for now, since that's all we support.
145+
// If the bundle is not a registry+v1 bundle, the conversion will fail.
146+
bundleProvisioner := "core-rukpak-io-registry"
147+
157148
// Ensure a BundleDeployment exists with its bundle source from the bundle
158149
// image we just looked up in the solution.
159150
dep := r.GenerateExpectedBundleDeployment(*ext, bundle.Image, bundleProvisioner)
@@ -523,23 +514,6 @@ func (r *ClusterExtensionReconciler) existingBundleDeploymentUnstructured(ctx co
523514
return &unstructured.Unstructured{Object: unstrExistingBundleDeploymentObj}, nil
524515
}
525516

526-
// mapBundleMediaTypeToBundleProvisioner maps an olm.bundle.mediatype property to a
527-
// rukpak bundle provisioner class name that is capable of unpacking the bundle type
528-
func mapBundleMediaTypeToBundleProvisioner(mediaType string) (string, error) {
529-
switch mediaType {
530-
case catalogmetadata.MediaTypePlain:
531-
return "core-rukpak-io-plain", nil
532-
// To ensure compatibility with bundles created with OLMv0 where the
533-
// olm.bundle.mediatype property doesn't exist, we assume that if the
534-
// property is empty (i.e doesn't exist) that the bundle is one created
535-
// with OLMv0 and therefore should use the registry provisioner
536-
case catalogmetadata.MediaTypeRegistry, "":
537-
return "core-rukpak-io-registry", nil
538-
default:
539-
return "", fmt.Errorf("unknown bundle mediatype: %s", mediaType)
540-
}
541-
}
542-
543517
// Generate reconcile requests for all cluster extensions affected by a catalog change
544518
func clusterExtensionRequestsForCatalog(c client.Reader, logger logr.Logger) handler.MapFunc {
545519
return func(ctx context.Context, _ client.Object) []reconcile.Request {

internal/controllers/clusterextension_controller_test.go

Lines changed: 0 additions & 144 deletions
Original file line numberDiff line numberDiff line change
@@ -909,116 +909,6 @@ func TestClusterExtensionNoVersion(t *testing.T) {
909909
require.NoError(t, cl.DeleteAllOf(ctx, &rukpakv1alpha2.BundleDeployment{}))
910910
}
911911

912-
func TestClusterExtensionPlainV0Bundle(t *testing.T) {
913-
cl, reconciler := newClientAndReconciler(t)
914-
ctx := context.Background()
915-
extKey := types.NamespacedName{Name: fmt.Sprintf("cluster-extension-test-%s", rand.String(8))}
916-
917-
t.Log("When the cluster extension specifies a package with a plain+v0 bundle")
918-
t.Log("By initializing cluster state")
919-
pkgName := "plain"
920-
pkgVer := "0.1.0"
921-
pkgChan := "beta"
922-
clusterExtension := &ocv1alpha1.ClusterExtension{
923-
ObjectMeta: metav1.ObjectMeta{Name: extKey.Name},
924-
Spec: ocv1alpha1.ClusterExtensionSpec{
925-
PackageName: pkgName,
926-
Version: pkgVer,
927-
Channel: pkgChan,
928-
InstallNamespace: "default",
929-
},
930-
}
931-
require.NoError(t, cl.Create(ctx, clusterExtension))
932-
933-
t.Log("It sets resolution success status")
934-
t.Log("By running reconcile")
935-
res, err := reconciler.Reconcile(ctx, ctrl.Request{NamespacedName: extKey})
936-
require.Equal(t, ctrl.Result{}, res)
937-
require.NoError(t, err)
938-
939-
t.Log("By fetching updated cluster extension after reconcile")
940-
require.NoError(t, cl.Get(ctx, extKey, clusterExtension))
941-
942-
t.Log("By checking the status fields")
943-
require.Equal(t, &ocv1alpha1.BundleMetadata{Name: "operatorhub/plain/0.1.0", Version: "0.1.0"}, clusterExtension.Status.ResolvedBundle)
944-
require.Empty(t, clusterExtension.Status.InstalledBundle)
945-
t.Log("By checking the expected conditions")
946-
cond := apimeta.FindStatusCondition(clusterExtension.Status.Conditions, ocv1alpha1.TypeResolved)
947-
require.NotNil(t, cond)
948-
require.Equal(t, metav1.ConditionTrue, cond.Status)
949-
require.Equal(t, ocv1alpha1.ReasonSuccess, cond.Reason)
950-
require.Equal(t, "resolved to \"quay.io/operatorhub/plain@sha256:plain\"", cond.Message)
951-
cond = apimeta.FindStatusCondition(clusterExtension.Status.Conditions, ocv1alpha1.TypeInstalled)
952-
require.NotNil(t, cond)
953-
require.Equal(t, metav1.ConditionUnknown, cond.Status)
954-
require.Equal(t, ocv1alpha1.ReasonInstallationStatusUnknown, cond.Reason)
955-
require.Equal(t, "bundledeployment status is unknown", cond.Message)
956-
957-
t.Log("By fetching the bundled deployment")
958-
bd := &rukpakv1alpha2.BundleDeployment{}
959-
require.NoError(t, cl.Get(ctx, types.NamespacedName{Name: extKey.Name}, bd))
960-
require.Equal(t, "core-rukpak-io-plain", bd.Spec.ProvisionerClassName)
961-
require.Equal(t, rukpakv1alpha2.SourceTypeImage, bd.Spec.Source.Type)
962-
require.NotNil(t, bd.Spec.Source.Image)
963-
require.Equal(t, "quay.io/operatorhub/plain@sha256:plain", bd.Spec.Source.Image.Ref)
964-
965-
verifyInvariants(ctx, t, reconciler.Client, clusterExtension)
966-
require.NoError(t, cl.DeleteAllOf(ctx, &ocv1alpha1.ClusterExtension{}))
967-
require.NoError(t, cl.DeleteAllOf(ctx, &rukpakv1alpha2.BundleDeployment{}))
968-
}
969-
970-
func TestClusterExtensionBadBundleMediaType(t *testing.T) {
971-
cl, reconciler := newClientAndReconciler(t)
972-
ctx := context.Background()
973-
extKey := types.NamespacedName{Name: fmt.Sprintf("cluster-extension-test-%s", rand.String(8))}
974-
975-
t.Log("When the cluster extension specifies a package with a bad bundle mediatype")
976-
t.Log("By initializing cluster state")
977-
pkgName := "badmedia"
978-
pkgVer := "0.1.0"
979-
pkgChan := "beta"
980-
clusterExtension := &ocv1alpha1.ClusterExtension{
981-
ObjectMeta: metav1.ObjectMeta{Name: extKey.Name},
982-
Spec: ocv1alpha1.ClusterExtensionSpec{
983-
PackageName: pkgName,
984-
Version: pkgVer,
985-
Channel: pkgChan,
986-
InstallNamespace: "default",
987-
},
988-
}
989-
require.NoError(t, cl.Create(ctx, clusterExtension))
990-
991-
t.Log("It sets resolution success status")
992-
t.Log("By running reconcile")
993-
res, err := reconciler.Reconcile(ctx, ctrl.Request{NamespacedName: extKey})
994-
require.Equal(t, ctrl.Result{}, res)
995-
require.Error(t, err)
996-
require.ErrorContains(t, err, "unknown bundle mediatype: badmedia+v1")
997-
998-
t.Log("By fetching updated cluster extension after reconcile")
999-
require.NoError(t, cl.Get(ctx, extKey, clusterExtension))
1000-
1001-
t.Log("By checking the status fields")
1002-
require.Equal(t, &ocv1alpha1.BundleMetadata{Name: "operatorhub/badmedia/0.1.0", Version: "0.1.0"}, clusterExtension.Status.ResolvedBundle)
1003-
require.Empty(t, clusterExtension.Status.InstalledBundle)
1004-
1005-
t.Log("By checking the expected conditions")
1006-
cond := apimeta.FindStatusCondition(clusterExtension.Status.Conditions, ocv1alpha1.TypeResolved)
1007-
require.NotNil(t, cond)
1008-
require.Equal(t, metav1.ConditionTrue, cond.Status)
1009-
require.Equal(t, ocv1alpha1.ReasonSuccess, cond.Reason)
1010-
require.Equal(t, "resolved to \"quay.io/operatorhub/badmedia@sha256:badmedia\"", cond.Message)
1011-
cond = apimeta.FindStatusCondition(clusterExtension.Status.Conditions, ocv1alpha1.TypeInstalled)
1012-
require.NotNil(t, cond)
1013-
require.Equal(t, metav1.ConditionFalse, cond.Status)
1014-
require.Equal(t, ocv1alpha1.ReasonInstallationFailed, cond.Reason)
1015-
require.Equal(t, "unknown bundle mediatype: badmedia+v1", cond.Message)
1016-
1017-
verifyInvariants(ctx, t, reconciler.Client, clusterExtension)
1018-
require.NoError(t, cl.DeleteAllOf(ctx, &ocv1alpha1.ClusterExtension{}))
1019-
require.NoError(t, cl.DeleteAllOf(ctx, &rukpakv1alpha2.BundleDeployment{}))
1020-
}
1021-
1022912
func verifyInvariants(ctx context.Context, t *testing.T, c client.Client, ext *ocv1alpha1.ClusterExtension) {
1023913
key := client.ObjectKeyFromObject(ext)
1024914
require.NoError(t, c.Get(ctx, key, ext))
@@ -2000,12 +1890,6 @@ var (
20001890
},
20011891
},
20021892
}
2003-
plainBetaChannel = catalogmetadata.Channel{
2004-
Channel: declcfg.Channel{
2005-
Name: "beta",
2006-
Package: "plain",
2007-
},
2008-
}
20091893
badmediaBetaChannel = catalogmetadata.Channel{
20101894
Channel: declcfg.Channel{
20111895
Name: "beta",
@@ -2080,32 +1964,4 @@ var testBundleList = []*catalogmetadata.Bundle{
20801964
CatalogName: "fake-catalog",
20811965
InChannels: []*catalogmetadata.Channel{&prometheusBetaChannel},
20821966
},
2083-
{
2084-
Bundle: declcfg.Bundle{
2085-
Name: "operatorhub/plain/0.1.0",
2086-
Package: "plain",
2087-
Image: "quay.io/operatorhub/plain@sha256:plain",
2088-
Properties: []property.Property{
2089-
{Type: property.TypePackage, Value: json.RawMessage(`{"packageName":"plain","version":"0.1.0"}`)},
2090-
{Type: property.TypeGVK, Value: json.RawMessage(`[]`)},
2091-
{Type: "olm.bundle.mediatype", Value: json.RawMessage(`"plain+v0"`)},
2092-
},
2093-
},
2094-
CatalogName: "fake-catalog",
2095-
InChannels: []*catalogmetadata.Channel{&plainBetaChannel},
2096-
},
2097-
{
2098-
Bundle: declcfg.Bundle{
2099-
Name: "operatorhub/badmedia/0.1.0",
2100-
Package: "badmedia",
2101-
Image: "quay.io/operatorhub/badmedia@sha256:badmedia",
2102-
Properties: []property.Property{
2103-
{Type: property.TypePackage, Value: json.RawMessage(`{"packageName":"badmedia","version":"0.1.0"}`)},
2104-
{Type: property.TypeGVK, Value: json.RawMessage(`[]`)},
2105-
{Type: "olm.bundle.mediatype", Value: json.RawMessage(`"badmedia+v1"`)},
2106-
},
2107-
},
2108-
CatalogName: "fake-catalog",
2109-
InChannels: []*catalogmetadata.Channel{&badmediaBetaChannel},
2110-
},
21111967
}

internal/controllers/extension_controller.go

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -164,31 +164,7 @@ func (r *ExtensionReconciler) reconcile(ctx context.Context, ext *ocv1alpha1.Ext
164164
ext.Status.ResolvedBundle = bundleMetadataFor(bundle)
165165
setResolvedStatusConditionSuccess(&ext.Status.Conditions, fmt.Sprintf("resolved to %q", bundle.Image), ext.GetGeneration())
166166

167-
mediaType, err := bundle.MediaType()
168-
if err != nil {
169-
if c := apimeta.FindStatusCondition(ext.Status.Conditions, ocv1alpha1.TypeInstalled); c == nil {
170-
ext.Status.InstalledBundle = nil
171-
setInstalledStatusConditionFailed(&ext.Status.Conditions, fmt.Sprintf("failed to read bundle mediaType: %v", err), ext.GetGeneration())
172-
setDeprecationStatusesUnknown(&ext.Status.Conditions, "deprecation checks have not been attempted as installation has failed", ext.GetGeneration())
173-
}
174-
setProgressingStatusConditionFailed(&ext.Status.Conditions, fmt.Sprintf("failed to read bundle mediaType: %v", err), ext.GetGeneration())
175-
return ctrl.Result{}, err
176-
}
177-
178-
// TODO: this needs to include the registryV1 bundle option. As of this PR, this only supports direct
179-
// installation of a set of manifests.
180-
if mediaType != catalogmetadata.MediaTypePlain {
181-
if c := apimeta.FindStatusCondition(ext.Status.Conditions, ocv1alpha1.TypeInstalled); c == nil {
182-
// Set the TypeInstalled condition to Failed to indicate that the resolution
183-
// hasn't been attempted yet, due to the spec being invalid.
184-
ext.Status.InstalledBundle = nil
185-
setInstalledStatusConditionFailed(&ext.Status.Conditions, fmt.Sprintf("bundle type %s not supported currently", mediaType), ext.GetGeneration())
186-
setDeprecationStatusesUnknown(&ext.Status.Conditions, "deprecation checks have not been attempted as installation has failed", ext.GetGeneration())
187-
}
188-
setProgressingStatusConditionFailed(&ext.Status.Conditions, fmt.Sprintf("bundle type %s not supported currently", mediaType), ext.GetGeneration())
189-
return ctrl.Result{}, nil
190-
}
191-
167+
// Right now, we just assume that the bundle is a plain+v0 bundle.
192168
app, err := r.GenerateExpectedApp(*ext, bundle)
193169
if err != nil {
194170
if c := apimeta.FindStatusCondition(ext.Status.Conditions, ocv1alpha1.TypeInstalled); c == nil {

0 commit comments

Comments
 (0)