Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions internal/operator-controller/applier/helm.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ 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"
"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"
Expand Down Expand Up @@ -57,7 +58,7 @@ type Preflight interface {
}

type BundleToHelmChartConverter interface {
ToHelmChart(bundle source.BundleSource, installNamespace string, watchNamespace string) (*chart.Chart, error)
ToHelmChart(bundle source.BundleSource, installNamespace string, config map[string]interface{}) (*chart.Chart, error)
}

type Helm struct {
Expand Down Expand Up @@ -222,7 +223,10 @@ func (h *Helm) buildHelmChart(bundleFS fs.FS, ext *ocv1.ClusterExtension) (*char
}
}

return h.BundleToHelmChartConverter.ToHelmChart(source.FromFS(bundleFS), ext.Spec.Namespace, watchNamespace)
bundleConfig := map[string]interface{}{
bundle.BundleConfigWatchNamespaceKey: watchNamespace,
}
return h.BundleToHelmChartConverter.ToHelmChart(source.FromFS(bundleFS), ext.Spec.Namespace, bundleConfig)
}

func (h *Helm) renderClientOnlyRelease(ctx context.Context, ext *ocv1.ClusterExtension, chrt *chart.Chart, values chartutil.Values, post postrender.PostRenderer) (*release.Release, error) {
Expand Down
19 changes: 10 additions & 9 deletions internal/operator-controller/applier/helm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import (
"github.com/operator-framework/operator-controller/internal/operator-controller/applier"
"github.com/operator-framework/operator-controller/internal/operator-controller/authorization"
"github.com/operator-framework/operator-controller/internal/operator-controller/features"
registryv1Bundle "github.com/operator-framework/operator-controller/internal/operator-controller/rukpak/bundle"
"github.com/operator-framework/operator-controller/internal/operator-controller/rukpak/bundle/source"
"github.com/operator-framework/operator-controller/internal/operator-controller/rukpak/convert"
)
Expand Down Expand Up @@ -559,8 +560,8 @@ func TestApply_InstallationWithSingleOwnNamespaceInstallSupportEnabled(t *testin
},
},
BundleToHelmChartConverter: &fakeBundleToHelmChartConverter{
fn: func(bundle source.BundleSource, installNamespace string, watchNamespace string) (*chart.Chart, error) {
require.Equal(t, expectedWatchNamespace, watchNamespace)
fn: func(bundle source.BundleSource, installNamespace string, config map[string]interface{}) (*chart.Chart, error) {
require.Equal(t, expectedWatchNamespace, config[registryv1Bundle.BundleConfigWatchNamespaceKey])
return nil, nil
},
},
Expand All @@ -574,7 +575,7 @@ func TestApply_InstallationWithSingleOwnNamespaceInstallSupportEnabled(t *testin
Config: &ocv1.ClusterExtensionConfig{
ConfigType: ocv1.ClusterExtensionConfigTypeInline,
Inline: &apiextensionsv1.JSON{
Raw: []byte(fmt.Sprintf(`{"watchNamespace":"%s"}`, expectedWatchNamespace)),
Raw: []byte(fmt.Sprintf(`{"%s":"%s"}`, registryv1Bundle.BundleConfigWatchNamespaceKey, expectedWatchNamespace)),
},
},
},
Expand All @@ -597,8 +598,8 @@ func TestApply_RegistryV1ToChartConverterIntegration(t *testing.T) {
},
},
BundleToHelmChartConverter: &fakeBundleToHelmChartConverter{
fn: func(bundle source.BundleSource, installNamespace string, watchNamespace string) (*chart.Chart, error) {
require.Equal(t, expectedWatchNamespace, watchNamespace)
fn: func(bundle source.BundleSource, installNamespace string, config map[string]interface{}) (*chart.Chart, error) {
require.Equal(t, expectedWatchNamespace, config[registryv1Bundle.BundleConfigWatchNamespaceKey])
return nil, nil
},
},
Expand All @@ -617,7 +618,7 @@ func TestApply_RegistryV1ToChartConverterIntegration(t *testing.T) {
},
},
BundleToHelmChartConverter: &fakeBundleToHelmChartConverter{
fn: func(bundle source.BundleSource, installNamespace string, watchNamespace string) (*chart.Chart, error) {
fn: func(bundle source.BundleSource, installNamespace string, config map[string]interface{}) (*chart.Chart, error) {
return nil, errors.New("some error")
},
},
Expand All @@ -629,9 +630,9 @@ func TestApply_RegistryV1ToChartConverterIntegration(t *testing.T) {
}

type fakeBundleToHelmChartConverter struct {
fn func(source.BundleSource, string, string) (*chart.Chart, error)
fn func(source.BundleSource, string, map[string]interface{}) (*chart.Chart, error)
}

func (f fakeBundleToHelmChartConverter) ToHelmChart(bundle source.BundleSource, installNamespace string, watchNamespace string) (*chart.Chart, error) {
return f.fn(bundle, installNamespace, watchNamespace)
func (f fakeBundleToHelmChartConverter) ToHelmChart(bundle source.BundleSource, installNamespace string, config map[string]interface{}) (*chart.Chart, error) {
return f.fn(bundle, installNamespace, config)
}
4 changes: 4 additions & 0 deletions internal/operator-controller/rukpak/bundle/registryv1.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@ import (
"github.com/operator-framework/api/pkg/operators/v1alpha1"
)

const (
BundleConfigWatchNamespaceKey = "watchNamespace"
)

type RegistryV1 struct {
PackageName string
CSV v1alpha1.ClusterServiceVersion
Expand Down
18 changes: 12 additions & 6 deletions internal/operator-controller/rukpak/convert/helm.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (

"helm.sh/helm/v3/pkg/chart"

bundlepkg "github.com/operator-framework/operator-controller/internal/operator-controller/rukpak/bundle"
"github.com/operator-framework/operator-controller/internal/operator-controller/rukpak/bundle/source"
"github.com/operator-framework/operator-controller/internal/operator-controller/rukpak/render"
)
Expand All @@ -17,12 +18,21 @@ type BundleToHelmChartConverter struct {
IsWebhookSupportEnabled bool
}

func (r *BundleToHelmChartConverter) ToHelmChart(bundle source.BundleSource, installNamespace string, watchNamespace string) (*chart.Chart, error) {
func (r *BundleToHelmChartConverter) ToHelmChart(bundle source.BundleSource, installNamespace string, config map[string]interface{}) (*chart.Chart, error) {
rv1, err := bundle.GetBundle()
if err != nil {
return nil, err
}

opts := []render.Option{
render.WithCertificateProvider(r.CertificateProvider),
}
if config != nil {
if watchNs, ok := config[bundlepkg.BundleConfigWatchNamespaceKey].(string); ok {
opts = append(opts, render.WithTargetNamespaces(watchNs))
}
}

if len(rv1.CSV.Spec.APIServiceDefinitions.Owned) > 0 {
return nil, fmt.Errorf("unsupported bundle: apiServiceDefintions are not supported")
}
Expand All @@ -39,11 +49,7 @@ func (r *BundleToHelmChartConverter) ToHelmChart(bundle source.BundleSource, ins
return nil, fmt.Errorf("unsupported bundle: webhookDefinitions are not supported")
}

objs, err := r.BundleRenderer.Render(
rv1, installNamespace,
render.WithTargetNamespaces(watchNamespace),
render.WithCertificateProvider(r.CertificateProvider),
)
objs, err := r.BundleRenderer.Render(rv1, installNamespace, opts...)

if err != nil {
return nil, fmt.Errorf("error rendering bundle: %w", err)
Expand Down
40 changes: 32 additions & 8 deletions internal/operator-controller/rukpak/convert/helm_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,10 @@ func Test_BundleToHelmChartConverter_ToHelmChart_ReturnsBundleSourceFailures(t *
var failingBundleSource FakeBundleSource = func() (bundle.RegistryV1, error) {
return bundle.RegistryV1{}, errors.New("some error")
}
_, err := converter.ToHelmChart(failingBundleSource, "install-namespace", "watch-namespace")
config := map[string]interface{}{
bundle.BundleConfigWatchNamespaceKey: "watch-namespace",
}
_, err := converter.ToHelmChart(failingBundleSource, "install-namespace", config)
require.Error(t, err)
require.Contains(t, err.Error(), "some error")
}
Expand All @@ -46,7 +49,10 @@ func Test_BundleToHelmChartConverter_ToHelmChart_ReturnsBundleRendererFailures(t
},
)

_, err := converter.ToHelmChart(b, "install-namespace", "")
config := map[string]interface{}{
bundle.BundleConfigWatchNamespaceKey: "",
}
_, err := converter.ToHelmChart(b, "install-namespace", config)
require.Error(t, err)
require.Contains(t, err.Error(), "some error")
}
Expand All @@ -60,7 +66,10 @@ func Test_BundleToHelmChartConverter_ToHelmChart_NoAPIServiceDefinitions(t *test
},
)

_, err := converter.ToHelmChart(b, "install-namespace", "")
config := map[string]interface{}{
bundle.BundleConfigWatchNamespaceKey: "",
}
_, err := converter.ToHelmChart(b, "install-namespace", config)
require.Error(t, err)
require.Contains(t, err.Error(), "unsupported bundle: apiServiceDefintions are not supported")
}
Expand All @@ -76,7 +85,10 @@ func Test_BundleToHelmChartConverter_ToHelmChart_NoWebhooksWithoutCertProvider(t
},
)

_, err := converter.ToHelmChart(b, "install-namespace", "")
config := map[string]interface{}{
bundle.BundleConfigWatchNamespaceKey: "",
}
_, err := converter.ToHelmChart(b, "install-namespace", config)
require.Error(t, err)
require.Contains(t, err.Error(), "webhookDefinitions are not supported")
}
Expand All @@ -92,7 +104,10 @@ func Test_BundleToHelmChartConverter_ToHelmChart_WebhooksSupportDisabled(t *test
},
)

_, err := converter.ToHelmChart(b, "install-namespace", "")
config := map[string]interface{}{
bundle.BundleConfigWatchNamespaceKey: "",
}
_, err := converter.ToHelmChart(b, "install-namespace", config)
require.Error(t, err)
require.Contains(t, err.Error(), "webhookDefinitions are not supported")
}
Expand All @@ -112,7 +127,10 @@ func Test_BundleToHelmChartConverter_ToHelmChart_WebhooksWithCertProvider(t *tes
},
)

_, err := converter.ToHelmChart(b, "install-namespace", "")
config := map[string]interface{}{
bundle.BundleConfigWatchNamespaceKey: "",
}
_, err := converter.ToHelmChart(b, "install-namespace", config)
require.NoError(t, err)
}

Expand Down Expand Up @@ -142,7 +160,10 @@ func Test_BundleToHelmChartConverter_ToHelmChart_BundleRendererIntegration(t *te
},
)

_, err := converter.ToHelmChart(b, expectedInstallNamespace, expectedWatchNamespace)
config := map[string]interface{}{
bundle.BundleConfigWatchNamespaceKey: expectedWatchNamespace,
}
_, err := converter.ToHelmChart(b, expectedInstallNamespace, config)
require.NoError(t, err)
}

Expand Down Expand Up @@ -181,7 +202,10 @@ func Test_BundleToHelmChartConverter_ToHelmChart_Success(t *testing.T) {
},
)

chart, err := converter.ToHelmChart(b, "install-namespace", "")
config := map[string]interface{}{
bundle.BundleConfigWatchNamespaceKey: "",
}
chart, err := converter.ToHelmChart(b, "install-namespace", config)
require.NoError(t, err)
require.NotNil(t, chart)
require.NotNil(t, chart.Metadata)
Expand Down
Loading