-
Notifications
You must be signed in to change notification settings - Fork 64
✨ Add support for deploying OCI helm charts in OLM v1 #1971
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,9 +26,11 @@ import ( | |
|
||
ocv1 "github.com/operator-framework/operator-controller/api/v1" | ||
"github.com/operator-framework/operator-controller/internal/operator-controller/authorization" | ||
"github.com/operator-framework/operator-controller/internal/operator-controller/features" | ||
"github.com/operator-framework/operator-controller/internal/operator-controller/rukpak/bundle/source" | ||
"github.com/operator-framework/operator-controller/internal/operator-controller/rukpak/preflights/crdupgradesafety" | ||
"github.com/operator-framework/operator-controller/internal/operator-controller/rukpak/util" | ||
imageutil "github.com/operator-framework/operator-controller/internal/shared/util/image" | ||
) | ||
|
||
const ( | ||
|
@@ -209,6 +211,17 @@ func (h *Helm) buildHelmChart(bundleFS fs.FS, ext *ocv1.ClusterExtension) (*char | |
if err != nil { | ||
return nil, err | ||
} | ||
if features.OperatorControllerFeatureGate.Enabled(features.HelmChartSupport) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We've been trying to put the feature checks in main. Wdyt about refactoring to have another implementation of the BundleToHelmChart converter that accepts chart bundles, or maybe that can route between different bundle types? Then if the feature gate is enabled, use that one? |
||
meta := new(chart.Metadata) | ||
if ok, _ := imageutil.IsBundleSourceChart(bundleFS, meta); ok { | ||
return imageutil.LoadChartFSWithOptions( | ||
bundleFS, | ||
fmt.Sprintf("%s-%s.tgz", meta.Name, meta.Version), | ||
imageutil.WithInstallNamespace(ext.Spec.Namespace), | ||
) | ||
} | ||
} | ||
OchiengEd marked this conversation as resolved.
Show resolved
Hide resolved
camilamacedo86 marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
return h.BundleToHelmChartConverter.ToHelmChart(source.FromFS(bundleFS), ext.Spec.Namespace, watchNamespace) | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change | ||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -16,16 +16,19 @@ import ( | |||||||||||
"github.com/containers/image/v5/docker/reference" | ||||||||||||
"github.com/opencontainers/go-digest" | ||||||||||||
ocispecv1 "github.com/opencontainers/image-spec/specs-go/v1" | ||||||||||||
"helm.sh/helm/v3/pkg/chart" | ||||||||||||
"helm.sh/helm/v3/pkg/registry" | ||||||||||||
"sigs.k8s.io/controller-runtime/pkg/log" | ||||||||||||
|
||||||||||||
errorutil "github.com/operator-framework/operator-controller/internal/shared/util/error" | ||||||||||||
fsutil "github.com/operator-framework/operator-controller/internal/shared/util/fs" | ||||||||||||
) | ||||||||||||
|
||||||||||||
type LayerData struct { | ||||||||||||
Reader io.Reader | ||||||||||||
Index int | ||||||||||||
Err error | ||||||||||||
MediaType string | ||||||||||||
Reader io.Reader | ||||||||||||
Index int | ||||||||||||
Err error | ||||||||||||
} | ||||||||||||
|
||||||||||||
type Cache interface { | ||||||||||||
|
@@ -128,8 +131,15 @@ func (a *diskCache) Store(ctx context.Context, ownerID string, srcRef reference. | |||||||||||
if layer.Err != nil { | ||||||||||||
return fmt.Errorf("error reading layer[%d]: %w", layer.Index, layer.Err) | ||||||||||||
} | ||||||||||||
if _, err := archive.Apply(ctx, dest, layer.Reader, applyOpts...); err != nil { | ||||||||||||
return fmt.Errorf("error applying layer[%d]: %w", layer.Index, err) | ||||||||||||
switch layer.MediaType { | ||||||||||||
case registry.ChartLayerMediaType: | ||||||||||||
if err := storeChartLayer(dest, layer); err != nil { | ||||||||||||
return err | ||||||||||||
} | ||||||||||||
default: | ||||||||||||
if _, err := archive.Apply(ctx, dest, layer.Reader, applyOpts...); err != nil { | ||||||||||||
return fmt.Errorf("error applying layer[%d]: %w", layer.Index, err) | ||||||||||||
} | ||||||||||||
Comment on lines
+134
to
+142
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Should it not be protected behind the feature flag as well? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The code will be unreachable as a result of the operator-controller/internal/shared/util/image/pull.go Lines 228 to 232 in 9b366d3
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I believe that all code should be categorised under a flag, allowing us to easily identify the purpose of each specific code for each alpha/beta feature. However, I think we can wait for others' input to see what they think about. My concern is: What happens if we decide not to use the alpha/beta feature and want to delete it? If we decide not to promote feature A or B. How hard will it be if not all related code is not under the feature flag condition? But others might think that is OK @perdasilva @tmshort WDYT? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Similarly to my comment above about moving the feature flag checks to main, should we refactor this in a way that make the cache configurable as to the different layer media types and how they are handled? |
||||||||||||
} | ||||||||||||
l.Info("applied layer", "layer", layer.Index) | ||||||||||||
} | ||||||||||||
|
@@ -147,6 +157,33 @@ func (a *diskCache) Store(ctx context.Context, ownerID string, srcRef reference. | |||||||||||
return os.DirFS(dest), modTime, nil | ||||||||||||
} | ||||||||||||
|
||||||||||||
func storeChartLayer(path string, layer LayerData) error { | ||||||||||||
if layer.Err != nil { | ||||||||||||
return fmt.Errorf("error found in layer data: %w", layer.Err) | ||||||||||||
} | ||||||||||||
data, err := io.ReadAll(layer.Reader) | ||||||||||||
if err != nil { | ||||||||||||
return fmt.Errorf("error reading layer[%d]: %w", layer.Index, err) | ||||||||||||
} | ||||||||||||
meta := new(chart.Metadata) | ||||||||||||
_, err = inspectChart(data, meta) | ||||||||||||
if err != nil { | ||||||||||||
return fmt.Errorf("inspecting chart layer: %w", err) | ||||||||||||
} | ||||||||||||
filename := filepath.Join(path, | ||||||||||||
fmt.Sprintf("%s-%s.tgz", meta.Name, meta.Version), | ||||||||||||
) | ||||||||||||
fmt.Println(filename) | ||||||||||||
chart, err := os.Create(filename) | ||||||||||||
if err != nil { | ||||||||||||
return fmt.Errorf("writing chart layer: %w", err) | ||||||||||||
} | ||||||||||||
defer chart.Close() | ||||||||||||
|
||||||||||||
_, err = chart.Write(data) | ||||||||||||
return err | ||||||||||||
} | ||||||||||||
|
||||||||||||
func (a *diskCache) Delete(_ context.Context, ownerID string) error { | ||||||||||||
return fsutil.DeleteReadOnlyRecursive(a.ownerIDPath(ownerID)) | ||||||||||||
} | ||||||||||||
|
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@OchiengEd
Here: https://github.com/operator-framework/operator-controller/pull/1724/files
@perdasilva added a demo and the doc under the docs/draft for another alpha feature
It would be very nice if we could do your demo within and add the doc for that. Such as it was done in this PR. However, I am okay with it being a follow-up.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would be for adding documentation and a demo as a follow up.