Skip to content

Commit fb36b11

Browse files
author
Per Goncalves da Silva
committed
Add internal direct bundle install method
Signed-off-by: Per Goncalves da Silva <pegoncal@redhat.com>
1 parent 35da385 commit fb36b11

File tree

3 files changed

+41
-2
lines changed

3 files changed

+41
-2
lines changed

cmd/operator-controller/main.go

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,13 @@ import (
2424
"fmt"
2525
"net/http"
2626
"os"
27+
"path"
2728
"path/filepath"
2829
"strings"
2930
"time"
3031

32+
bsemver "github.com/blang/semver/v4"
33+
"github.com/distribution/reference"
3134
"github.com/spf13/cobra"
3235
"go.podman.io/image/v5/types"
3336
rbacv1 "k8s.io/api/rbac/v1"
@@ -58,6 +61,7 @@ import (
5861
"sigs.k8s.io/controller-runtime/pkg/metrics/server"
5962

6063
helmclient "github.com/operator-framework/helm-operator-plugins/pkg/client"
64+
"github.com/operator-framework/operator-registry/alpha/declcfg"
6165

6266
ocv1 "github.com/operator-framework/operator-controller/api/v1"
6367
"github.com/operator-framework/operator-controller/internal/operator-controller/action"
@@ -85,6 +89,11 @@ import (
8589
"github.com/operator-framework/operator-controller/internal/shared/version"
8690
)
8791

92+
const (
93+
directBundleInstallImageAnnotation = "olm.operatorframework.io/bundle-image"
94+
directBundleInstallVersionAnnotation = "olm.operatorframework.io/bundle-version"
95+
)
96+
8897
var (
8998
setupLog = ctrl.Log.WithName("setup")
9099
defaultSystemNamespace = "olmv1-system"
@@ -394,7 +403,7 @@ func run() error {
394403
return httputil.BuildHTTPClient(cpwCatalogd)
395404
})
396405

397-
resolver := &resolve.CatalogResolver{
406+
catalogResolver := &resolve.CatalogResolver{
398407
WalkCatalogsFunc: resolve.CatalogWalker(
399408
func(ctx context.Context, option ...client.ListOption) ([]ocv1.ClusterCatalog, error) {
400409
var catalogs ocv1.ClusterCatalogList
@@ -410,6 +419,28 @@ func run() error {
410419
},
411420
}
412421

422+
var resolver resolve.Func = func(ctx context.Context, ext *ocv1.ClusterExtension, installedBundle *ocv1.BundleMetadata) (*declcfg.Bundle, *bsemver.Version, *declcfg.Deprecation, error) {
423+
if features.OperatorControllerFeatureGate.Enabled(features.DirectBundleInstall) &&
424+
ext.Annotations != nil && ext.Annotations[directBundleInstallImageAnnotation] != "" &&
425+
ext.Annotations[directBundleInstallVersionAnnotation] != "" {
426+
bundleImageRef := ext.Annotations[directBundleInstallImageAnnotation]
427+
428+
ref, err := reference.ParseNamed(bundleImageRef)
429+
if err != nil {
430+
return nil, nil, nil, err
431+
}
432+
433+
packageName := path.Base(ref.Name())
434+
bundleVersion := bsemver.MustParse(ext.Annotations[directBundleInstallVersionAnnotation])
435+
return &declcfg.Bundle{
436+
Package: packageName,
437+
Image: bundleImageRef,
438+
}, &bundleVersion, nil, nil
439+
} else {
440+
return catalogResolver.Resolve(ctx, ext, installedBundle)
441+
}
442+
}
443+
413444
aeClient, err := apiextensionsv1client.NewForConfig(mgr.GetConfig())
414445
if err != nil {
415446
setupLog.Error(err, "unable to create apiextensions client")

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ require (
88
github.com/blang/semver/v4 v4.0.0
99
github.com/cert-manager/cert-manager v1.18.2
1010
github.com/containerd/containerd v1.7.28
11+
github.com/distribution/reference v0.6.0
1112
github.com/fsnotify/fsnotify v1.9.0
1213
github.com/go-logr/logr v1.4.3
1314
github.com/golang-jwt/jwt/v5 v5.3.0
@@ -87,7 +88,6 @@ require (
8788
github.com/cyberphone/json-canonicalization v0.0.0-20241213102144-19d51d7fe467 // indirect
8889
github.com/cyphar/filepath-securejoin v0.4.1 // indirect
8990
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect
90-
github.com/distribution/reference v0.6.0 // indirect
9191
github.com/docker/cli v28.4.0+incompatible // indirect
9292
github.com/docker/distribution v2.8.3+incompatible // indirect
9393
github.com/docker/docker v28.3.3+incompatible // indirect

internal/operator-controller/features/features.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ const (
1818
WebhookProviderOpenshiftServiceCA featuregate.Feature = "WebhookProviderOpenshiftServiceCA"
1919
HelmChartSupport featuregate.Feature = "HelmChartSupport"
2020
BoxcutterRuntime featuregate.Feature = "BoxcutterRuntime"
21+
DirectBundleInstall featuregate.Feature = "DirectBundleInstall"
2122
)
2223

2324
var operatorControllerFeatureGates = map[featuregate.Feature]featuregate.FeatureSpec{
@@ -80,6 +81,13 @@ var operatorControllerFeatureGates = map[featuregate.Feature]featuregate.Feature
8081
PreRelease: featuregate.Alpha,
8182
LockToDefault: false,
8283
},
84+
85+
// DirectBundleInstall allows for direct bundle installation via annotation
86+
DirectBundleInstall: {
87+
Default: false,
88+
PreRelease: featuregate.Alpha,
89+
LockToDefault: false,
90+
},
8391
}
8492

8593
var OperatorControllerFeatureGate featuregate.MutableFeatureGate = featuregate.NewFeatureGate()

0 commit comments

Comments
 (0)