-
Notifications
You must be signed in to change notification settings - Fork 68
🌱 Add internal direct bundle install support #2252
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
perdasilva
wants to merge
1
commit into
operator-framework:main
Choose a base branch
from
perdasilva:direct-bundle-install
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+128
−12
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,84 @@ | ||
| package resolve | ||
|
|
||
| import ( | ||
| "context" | ||
| "fmt" | ||
| "io/fs" | ||
| "reflect" | ||
|
|
||
| bsemver "github.com/blang/semver/v4" | ||
|
|
||
| "github.com/operator-framework/operator-registry/alpha/action" | ||
| "github.com/operator-framework/operator-registry/alpha/declcfg" | ||
|
|
||
| ocv1 "github.com/operator-framework/operator-controller/api/v1" | ||
| "github.com/operator-framework/operator-controller/internal/operator-controller/bundleutil" | ||
| "github.com/operator-framework/operator-controller/internal/shared/util/image" | ||
| ) | ||
|
|
||
| const ( | ||
| directBundleInstallImageAnnotation = "alpha.olm.operatorframework.io/bundle-image-ref" | ||
| ) | ||
|
|
||
| type BundleImageRefResolver struct { | ||
| ImagePuller image.Puller | ||
| ImageCache image.Cache | ||
| } | ||
|
|
||
| func (r *BundleImageRefResolver) Resolve(ctx context.Context, ext *ocv1.ClusterExtension, _ *ocv1.BundleMetadata) (*declcfg.Bundle, *bsemver.Version, *declcfg.Deprecation, error) { | ||
| if ext.Annotations == nil || ext.Annotations[directBundleInstallImageAnnotation] == "" { | ||
| return nil, nil, nil, fmt.Errorf("ClusterExtension is missing required annotation %s", directBundleInstallImageAnnotation) | ||
| } | ||
| bundleFS, canonicalRef, _, err := r.ImagePuller.Pull(ctx, ext.Name, ext.Annotations[directBundleInstallImageAnnotation], r.ImageCache) | ||
| if err != nil { | ||
| return nil, nil, nil, err | ||
| } | ||
|
|
||
| // TODO: This is a temporary workaround to get the bundle from the filesystem | ||
| // until the operator-registry library is updated to support reading from a | ||
| // fs.FS. This will be removed once the library is updated. | ||
| bundlePath, err := getDirFSPath(bundleFS) | ||
perdasilva marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| if err != nil { | ||
| return nil, nil, nil, fmt.Errorf("expected to be able to recover bundle path from bundleFS: %v", err) | ||
| } | ||
|
|
||
| // Render the bundle | ||
| render := action.Render{ | ||
| Refs: []string{bundlePath}, | ||
| AllowedRefMask: action.RefBundleDir, | ||
| } | ||
| fbc, err := render.Run(ctx) | ||
| if err != nil { | ||
| return nil, nil, nil, err | ||
| } | ||
| if len(fbc.Bundles) != 1 { | ||
| return nil, nil, nil, fmt.Errorf("expected exactly one bundle but found %d", len(fbc.Bundles)) | ||
| } | ||
| bundle := fbc.Bundles[0] | ||
| bundle.Image = canonicalRef.String() | ||
| v, err := bundleutil.GetVersion(bundle) | ||
| if err != nil { | ||
| return nil, nil, nil, fmt.Errorf("error determining bundle version: %w", err) | ||
| } | ||
| return &bundle, v, nil, nil | ||
| } | ||
|
|
||
| // A function to recover the underlying path string from os.DirFS | ||
| func getDirFSPath(f fs.FS) (string, error) { | ||
| v := reflect.ValueOf(f) | ||
|
|
||
| // Check if the underlying type is a string (its kind) | ||
| if v.Kind() != reflect.String { | ||
| return "", fmt.Errorf("underlying type is not a string, it is %s", v.Kind()) | ||
| } | ||
|
|
||
| // The type itself (os.dirFS) is unexported, but its Kind is a string. | ||
| // We can convert the reflect.Value back to a regular string using .Interface() | ||
| // after converting it to a basic string type. | ||
| path, ok := v.Convert(reflect.TypeOf("")).Interface().(string) | ||
| if !ok { | ||
| return "", fmt.Errorf("could not convert reflected value to string") | ||
| } | ||
|
|
||
| return path, nil | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.