Skip to content

Commit 443874b

Browse files
author
Per G. da Silva
committed
Remove plain converter
Signed-off-by: Per G. da Silva <[email protected]>
1 parent 9b29cf4 commit 443874b

File tree

1 file changed

+28
-59
lines changed

1 file changed

+28
-59
lines changed

internal/operator-controller/rukpak/convert/registryv1.go

Lines changed: 28 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ import (
1212
apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1"
1313
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
1414
"k8s.io/apimachinery/pkg/runtime"
15-
"k8s.io/apimachinery/pkg/util/sets"
1615
"k8s.io/cli-runtime/pkg/resource"
1716
"sigs.k8s.io/controller-runtime/pkg/client"
1817
"sigs.k8s.io/yaml"
@@ -23,28 +22,47 @@ import (
2322
"github.com/operator-framework/operator-controller/internal/operator-controller/features"
2423
registry "github.com/operator-framework/operator-controller/internal/operator-controller/rukpak/operator-registry"
2524
"github.com/operator-framework/operator-controller/internal/operator-controller/rukpak/render"
26-
"github.com/operator-framework/operator-controller/internal/operator-controller/rukpak/render/certproviders"
27-
"github.com/operator-framework/operator-controller/internal/operator-controller/rukpak/render/registryv1"
2825
)
2926

3027
type Plain struct {
3128
Objects []client.Object
3229
}
3330

34-
func RegistryV1ToHelmChart(rv1 fs.FS, installNamespace string, watchNamespace string) (*chart.Chart, error) {
35-
reg, err := ParseFS(rv1)
31+
type RegistryV1Converter struct {
32+
BundleRenderer render.BundleRenderer
33+
CertificateProvider *render.CertificateProvider
34+
}
35+
36+
func (r *RegistryV1Converter) ToHelmChart(rv1fs fs.FS, installNamespace string, watchNamespace string) (*chart.Chart, error) {
37+
rv1, err := ParseFS(rv1fs)
3638
if err != nil {
3739
return nil, err
3840
}
3941

40-
plain, err := PlainConverter.Convert(reg, installNamespace, []string{watchNamespace})
41-
if err != nil {
42-
return nil, err
42+
if installNamespace == "" {
43+
installNamespace = rv1.CSV.Annotations["operatorframework.io/suggested-namespace"]
44+
}
45+
if installNamespace == "" {
46+
installNamespace = fmt.Sprintf("%s-system", rv1.PackageName)
47+
}
48+
49+
if len(rv1.CSV.Spec.APIServiceDefinitions.Owned) > 0 {
50+
return nil, fmt.Errorf("apiServiceDefintions are not supported")
51+
}
52+
53+
if r.CertificateProvider == nil && len(rv1.CSV.Spec.WebhookDefinitions) > 0 {
54+
return nil, fmt.Errorf("webhookDefinitions are not supported")
4355
}
4456

57+
objs, err := r.BundleRenderer.Render(
58+
rv1,
59+
installNamespace,
60+
render.WithTargetNamespaces(watchNamespace),
61+
render.WithCertificateProvider(r.CertificateProvider))
62+
4563
chrt := &chart.Chart{Metadata: &chart.Metadata{}}
46-
chrt.Metadata.Annotations = reg.CSV.GetAnnotations()
47-
for _, obj := range plain.Objects {
64+
chrt.Metadata.Annotations = rv1.CSV.GetAnnotations()
65+
for _, obj := range objs {
4866
jsonData, err := json.Marshal(obj)
4967
if err != nil {
5068
return nil, err
@@ -189,52 +207,3 @@ func copyMetadataPropertiesToCSV(csv *v1alpha1.ClusterServiceVersion, fsys fs.FS
189207
csv.Annotations["olm.properties"] = string(allPropertiesJSON)
190208
return nil
191209
}
192-
193-
var PlainConverter = Converter{
194-
BundleRenderer: registryv1.Renderer,
195-
}
196-
197-
type Converter struct {
198-
render.BundleRenderer
199-
}
200-
201-
func (c Converter) Convert(rv1 render.RegistryV1, installNamespace string, targetNamespaces []string) (*Plain, error) {
202-
if installNamespace == "" {
203-
installNamespace = rv1.CSV.Annotations["operatorframework.io/suggested-namespace"]
204-
}
205-
if installNamespace == "" {
206-
installNamespace = fmt.Sprintf("%s-system", rv1.PackageName)
207-
}
208-
supportedInstallModes := sets.New[string]()
209-
for _, im := range rv1.CSV.Spec.InstallModes {
210-
if im.Supported {
211-
supportedInstallModes.Insert(string(im.Type))
212-
}
213-
}
214-
if len(targetNamespaces) == 0 {
215-
if supportedInstallModes.Has(string(v1alpha1.InstallModeTypeAllNamespaces)) {
216-
targetNamespaces = []string{""}
217-
} else if supportedInstallModes.Has(string(v1alpha1.InstallModeTypeOwnNamespace)) {
218-
targetNamespaces = []string{installNamespace}
219-
}
220-
}
221-
222-
if len(rv1.CSV.Spec.APIServiceDefinitions.Owned) > 0 {
223-
return nil, fmt.Errorf("apiServiceDefintions are not supported")
224-
}
225-
226-
if !features.OperatorControllerFeatureGate.Enabled(features.WebhookProviderCertManager) && len(rv1.CSV.Spec.WebhookDefinitions) > 0 {
227-
return nil, fmt.Errorf("webhookDefinitions are not supported")
228-
}
229-
230-
objs, err := c.BundleRenderer.Render(
231-
rv1,
232-
installNamespace,
233-
render.WithTargetNamespaces(targetNamespaces...),
234-
render.WithCertificateProvider(certproviders.CertManagerCertificateProvider{}),
235-
)
236-
if err != nil {
237-
return nil, err
238-
}
239-
return &Plain{Objects: objs}, nil
240-
}

0 commit comments

Comments
 (0)