-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Merge feature/run-bundle into master: Add FBC support to run bundle
and run bundle-upgrade
commands
#5809
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
Merged
Merged
Merge feature/run-bundle into master: Add FBC support to run bundle
and run bundle-upgrade
commands
#5809
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
718b194
Implement File-Based Catalog support for run bundle command in SDK
rashmigottipati 9b63280
Implement File-Based Catalog (FBC) support for run bundle-upgrade (#5…
VenkatRamaraju 74011aa
Refactor FBC-related functions and structs into a utility module
rashmigottipati 6f6909c
Add changelog fragment
rashmigottipati 2885f88
Address review feedback
rashmigottipati 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
entries: | ||
- description: > | ||
Add support for File-Based Catalog to the subcommands [operator-sdk run bundle](https://sdk.operatorframework.io/docs/cli/operator-sdk_run_bundle/#m-docsclioperator-sdk_run_bundle) | ||
and [run bundle-upgrade](https://sdk.operatorframework.io/docs/cli/operator-sdk_run_bundle-upgrade/) so that | ||
new indexes created by these subcommands are using the new format. | ||
Users are able to pass in an index catalog with FBC format via the flag option `--index-image`. | ||
|
||
# kind is one of: | ||
# - addition | ||
# - change | ||
# - deprecation | ||
# - removal | ||
# - bugfix | ||
kind: change | ||
|
||
# Is this a breaking change? | ||
breaking: false |
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,151 @@ | ||
// Copyright 2022 The Operator-SDK Authors | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
package fbcutil | ||
|
||
import ( | ||
"bytes" | ||
"context" | ||
"errors" | ||
"fmt" | ||
"io/ioutil" | ||
"os" | ||
|
||
"github.com/operator-framework/operator-registry/alpha/action" | ||
"github.com/operator-framework/operator-registry/alpha/declcfg" | ||
declarativeconfig "github.com/operator-framework/operator-registry/alpha/declcfg" | ||
"github.com/operator-framework/operator-registry/pkg/containertools" | ||
registryutil "github.com/operator-framework/operator-sdk/internal/registry" | ||
log "github.com/sirupsen/logrus" | ||
) | ||
|
||
const ( | ||
SchemaChannel = "olm.channel" | ||
SchemaPackage = "olm.package" | ||
DefaultChannel = "operator-sdk-run" | ||
) | ||
|
||
const ( | ||
// defaultIndexImageBase is the base for defaultIndexImage. It is necessary to separate | ||
// them for string comparison when defaulting bundle add mode. | ||
DefaultIndexImageBase = "quay.io/operator-framework/opm:" | ||
// DefaultIndexImage is the index base image used if none is specified. It contains no bundles. | ||
// TODO(v2.0.0): pin this image tag to a specific version. | ||
DefaultIndexImage = DefaultIndexImageBase + "latest" | ||
) | ||
|
||
// BundleDeclcfg represents a minimal File-Based Catalog. | ||
// This struct only consists of one Package, Bundle, and Channel blob. It is used to | ||
// represent the bundle image in the File-Based Catalog format. | ||
type BundleDeclcfg struct { | ||
Package declcfg.Package | ||
Channel declcfg.Channel | ||
Bundle declcfg.Bundle | ||
} | ||
|
||
// FBCContext is a struct that stores all the required information while constructing | ||
// a new File-Based Catalog on the fly. The fields from this struct are passed as | ||
// parameters to Operator Registry API calls to generate declarative config objects. | ||
type FBCContext struct { | ||
Package string | ||
ChannelName string | ||
Refs []string | ||
ChannelEntry declarativeconfig.ChannelEntry | ||
} | ||
|
||
// CreateFBC generates an FBC by creating bundle, package and channel blobs. | ||
func (f *FBCContext) CreateFBC(ctx context.Context) (BundleDeclcfg, error) { | ||
var bundleDC BundleDeclcfg | ||
// Rendering the bundle image into a declarative config format. | ||
declcfg, err := RenderRefs(ctx, f.Refs) | ||
if err != nil { | ||
return BundleDeclcfg{}, err | ||
} | ||
|
||
// Ensuring a valid bundle size. | ||
if len(declcfg.Bundles) != 1 { | ||
return BundleDeclcfg{}, fmt.Errorf("bundle image should contain exactly one bundle blob") | ||
} | ||
|
||
bundleDC.Bundle = declcfg.Bundles[0] | ||
|
||
// generate package. | ||
bundleDC.Package = declarativeconfig.Package{ | ||
Schema: SchemaPackage, | ||
Name: f.Package, | ||
DefaultChannel: f.ChannelName, | ||
} | ||
|
||
// generate channel. | ||
bundleDC.Channel = declarativeconfig.Channel{ | ||
Schema: SchemaChannel, | ||
Name: f.ChannelName, | ||
Package: f.Package, | ||
Entries: []declarativeconfig.ChannelEntry{f.ChannelEntry}, | ||
} | ||
|
||
return bundleDC, nil | ||
} | ||
|
||
// ValidateAndStringify first converts the generated declarative config to a model and validates it. | ||
// If the declarative config model is valid, it will convert the declarative config to a YAML string and return it. | ||
func ValidateAndStringify(declcfg *declarativeconfig.DeclarativeConfig) (string, error) { | ||
// validates and converts declarative config to model | ||
_, err := declarativeconfig.ConvertToModel(*declcfg) | ||
if err != nil { | ||
return "", fmt.Errorf("error converting the declarative config to model: %v", err) | ||
} | ||
|
||
var buf bytes.Buffer | ||
err = declarativeconfig.WriteYAML(*declcfg, &buf) | ||
if err != nil { | ||
return "", fmt.Errorf("error writing generated declarative config to JSON encoder: %v", err) | ||
} | ||
|
||
if buf.String() == "" { | ||
return "", errors.New("file-based catalog contents cannot be empty") | ||
} | ||
|
||
return buf.String(), nil | ||
} | ||
|
||
// RenderRefs will invoke Operator Registry APIs and return a declarative config object representation | ||
// of the references that are passed in as a string array. | ||
func RenderRefs(ctx context.Context, refs []string) (*declarativeconfig.DeclarativeConfig, error) { | ||
render := action.Render{ | ||
Refs: refs, | ||
} | ||
|
||
log.SetOutput(ioutil.Discard) | ||
declcfg, err := render.Run(ctx) | ||
log.SetOutput(os.Stdout) | ||
if err != nil { | ||
return nil, fmt.Errorf("error in rendering the bundle and index image: %v", err) | ||
} | ||
|
||
return declcfg, nil | ||
} | ||
|
||
// IsFBC will determine if an index image uses the File-Based Catalog or SQLite index image format. | ||
// The default index image will adopt the File-Based Catalog format. | ||
func IsFBC(ctx context.Context, indexImage string) (bool, error) { | ||
// adding updates to the IndexImageCatalogCreator if it is an FBC image | ||
catalogLabels, err := registryutil.GetImageLabels(ctx, nil, indexImage, false) | ||
if err != nil { | ||
return false, fmt.Errorf("get index image labels: %v", err) | ||
} | ||
_, hasFBCLabel := catalogLabels[containertools.ConfigsLocationLabel] | ||
|
||
return hasFBCLabel || indexImage == DefaultIndexImage, 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.