Skip to content

Commit a992498

Browse files
committed
wip: registry+v1 to helm chart
- handling for all install mode combinations is working - subscription.spec.config support
1 parent 87dfebe commit a992498

File tree

13 files changed

+17503
-9
lines changed

13 files changed

+17503
-9
lines changed

Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,9 +103,11 @@ tidy: #HELP Update dependencies.
103103
manifests: $(CONTROLLER_GEN) #EXHELP Generate WebhookConfiguration, ClusterRole and CustomResourceDefinition objects.
104104
$(CONTROLLER_GEN) rbac:roleName=manager-role crd webhook paths="./..." output:crd:artifacts:config=config/base/crd/bases output:rbac:artifacts:config=config/base/rbac
105105

106+
OPENAPI_VERSION := $(shell go list -m k8s.io/api | cut -d" " -f2 | sed 's/^v0/v1/')
106107
.PHONY: generate
107108
generate: $(CONTROLLER_GEN) #EXHELP Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations.
108109
$(CONTROLLER_GEN) object:headerFile="hack/boilerplate.go.txt" paths="./..."
110+
curl -sSL https://raw.githubusercontent.com/kubernetes/kubernetes/refs/tags/$(OPENAPI_VERSION)/api/openapi-spec/v3/apis__apps__v1_openapi.json > ./internal/rukpak/convert/v2/internal/apis__apps__v1_openapi.json
109111

110112
.PHONY: verify
111113
verify: tidy fmt vet generate manifests crd-ref-docs #HELP Verify all generated code is up-to-date.

cmd/registryv1-to-helm/main.go

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
"os"
6+
"path/filepath"
7+
8+
"github.com/spf13/cobra"
9+
"helm.sh/helm/v3/pkg/chartutil"
10+
11+
v2 "github.com/operator-framework/operator-controller/internal/rukpak/convert/v2"
12+
)
13+
14+
func main() {
15+
if err := rootCmd().Execute(); err != nil {
16+
os.Exit(1)
17+
}
18+
}
19+
20+
func rootCmd() *cobra.Command {
21+
cmd := &cobra.Command{
22+
Use: "registryv1-to-helm <registry+v1-directory-path> [output-path]",
23+
Args: cobra.RangeArgs(1, 2),
24+
Run: func(cmd *cobra.Command, args []string) {
25+
registryv1Path := args[0]
26+
27+
saveDir := "."
28+
if len(args) == 2 {
29+
saveDir = args[1]
30+
}
31+
32+
chrt, err := v2.RegistryV1ToHelmChart(cmd.Context(), os.DirFS(registryv1Path))
33+
if err != nil {
34+
cmd.PrintErr(err)
35+
os.Exit(1)
36+
}
37+
38+
if err := chartutil.SaveDir(chrt, saveDir); err != nil {
39+
cmd.PrintErr(err)
40+
os.Exit(1)
41+
}
42+
43+
origChartDir := filepath.Join(saveDir, chrt.Metadata.Name)
44+
desiredChartDir := filepath.Join(saveDir, fmt.Sprintf("%s-%s", chrt.Metadata.Name, chrt.Metadata.Version))
45+
if err := os.Rename(origChartDir, desiredChartDir); err != nil {
46+
cmd.PrintErr(err)
47+
os.Exit(1)
48+
}
49+
cmd.Printf("Chart saved to %s\n", desiredChartDir)
50+
},
51+
}
52+
return cmd
53+
}

cmd/registryv1-to-helm/values.yaml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
affinity:
2+
nodeAffinity:
3+
requiredDuringSchedulingIgnoredDuringExecution:
4+
nodeSelectorTerms:
5+
- matchExpressions:
6+
- key: node-role.kubernetes.io/master
7+
operator: Exists
8+
nodeSelector:
9+
overrideKey1: overrideValue1
10+
11+
selector:
12+
overrideKey2: overrideValue2
13+
14+
tolerations:
15+
- effect: NoSchedule
16+
key: node-role.kubernetes.io/master2
17+
18+
volumes:
19+
- name: argocd-operator-token-5z5z2
20+
emptyDir: {}
21+
22+
env:
23+
- name: WATCH_NAMESPACE
24+
value: BAR
25+
26+
envFrom:
27+
- configMapRef:
28+
name: my-configmap
29+
- secretRef:
30+
name: my-secret
31+
32+
resources:
33+
requests:
34+
cpu: 100m
35+
memory: 100Mi
36+
37+
volumeMounts:
38+
- name: tmp
39+
mountPath: override

go.mod

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,19 @@ require (
1111
github.com/containers/image/v5 v5.32.2
1212
github.com/fsnotify/fsnotify v1.7.0
1313
github.com/go-logr/logr v1.4.2
14+
github.com/go-openapi/loads v0.22.0
15+
github.com/go-openapi/spec v0.21.0
1416
github.com/google/go-cmp v0.6.0
1517
github.com/google/go-containerregistry v0.20.2
18+
github.com/joeycumines/go-dotnotation v0.0.0-20180131115956-2d3612e36c5d
1619
github.com/onsi/ginkgo/v2 v2.20.2
1720
github.com/onsi/gomega v1.34.2
1821
github.com/opencontainers/go-digest v1.0.0
1922
github.com/operator-framework/api v0.27.0
2023
github.com/operator-framework/catalogd v0.35.0
2124
github.com/operator-framework/helm-operator-plugins v0.7.0
2225
github.com/operator-framework/operator-registry v1.48.0
26+
github.com/spf13/cobra v1.8.1
2327
github.com/spf13/pflag v1.0.5
2428
github.com/stretchr/testify v1.9.0
2529
golang.org/x/exp v0.0.0-20240719175910-8a7402abbf56
@@ -101,9 +105,7 @@ require (
101105
github.com/go-openapi/errors v0.22.0 // indirect
102106
github.com/go-openapi/jsonpointer v0.21.0 // indirect
103107
github.com/go-openapi/jsonreference v0.21.0 // indirect
104-
github.com/go-openapi/loads v0.22.0 // indirect
105108
github.com/go-openapi/runtime v0.28.0 // indirect
106-
github.com/go-openapi/spec v0.21.0 // indirect
107109
github.com/go-openapi/strfmt v0.23.0 // indirect
108110
github.com/go-openapi/swag v0.23.0 // indirect
109111
github.com/go-openapi/validate v0.24.0 // indirect
@@ -193,7 +195,6 @@ require (
193195
github.com/sigstore/sigstore v1.8.4 // indirect
194196
github.com/sirupsen/logrus v1.9.3 // indirect
195197
github.com/spf13/cast v1.7.0 // indirect
196-
github.com/spf13/cobra v1.8.1 // indirect
197198
github.com/stefanberger/go-pkcs11uri v0.0.0-20230803200340-78284954bff6 // indirect
198199
github.com/stoewer/go-strcase v1.3.0 // indirect
199200
github.com/stretchr/objx v0.5.2 // indirect

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -392,6 +392,8 @@ github.com/jmoiron/sqlx v1.4.0 h1:1PLqN7S1UYp5t4SrVVnt4nUVNemrDAtxlulVe+Qgm3o=
392392
github.com/jmoiron/sqlx v1.4.0/go.mod h1:ZrZ7UsYB/weZdl2Bxg6jCRO9c3YHl8r3ahlKmRT4JLY=
393393
github.com/joelanford/ignore v0.1.0 h1:VawbTDeg5EL+PN7W8gxVzGerfGpVo3gFdR5ZAqnkYRk=
394394
github.com/joelanford/ignore v0.1.0/go.mod h1:Vb0PQMAQXK29fmiPjDukpO8I2NTcp1y8LbhFijD1/0o=
395+
github.com/joeycumines/go-dotnotation v0.0.0-20180131115956-2d3612e36c5d h1:ljoJyU5NEhe3LWXrRSHnYqWtQehQSJ+9d9tfIGNbpSw=
396+
github.com/joeycumines/go-dotnotation v0.0.0-20180131115956-2d3612e36c5d/go.mod h1:siHz7M0dAufA9aNRidkfckDSVB/S+Ld7allyOe5uxVg=
395397
github.com/jonboulle/clockwork v0.1.0/go.mod h1:Ii8DK3G1RaLaWxj9trq07+26W01tbo22gdxWY5EU2bo=
396398
github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8HmY=
397399
github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y=

internal/rukpak/convert/registryv1.go

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ type Plain struct {
3939
Objects []client.Object
4040
}
4141

42-
func RegistryV1ToHelmChart(ctx context.Context, rv1 fs.FS, installNamespace string, watchNamespaces []string) (*chart.Chart, error) {
42+
func LoadRegistryV1(ctx context.Context, rv1 fs.FS) (*RegistryV1, error) {
4343
l := log.FromContext(ctx)
4444

4545
reg := RegistryV1{}
@@ -100,8 +100,16 @@ func RegistryV1ToHelmChart(ctx context.Context, rv1 fs.FS, installNamespace stri
100100
}); err != nil {
101101
return nil, err
102102
}
103+
return &reg, nil
104+
}
105+
106+
func RegistryV1ToHelmChart(ctx context.Context, rv1 fs.FS, installNamespace string, watchNamespaces []string) (*chart.Chart, error) {
107+
reg, err := LoadRegistryV1(ctx, rv1)
108+
if err != nil {
109+
return nil, err
110+
}
103111

104-
return toChart(reg, installNamespace, watchNamespaces)
112+
return toChart(*reg, installNamespace, watchNamespaces)
105113
}
106114

107115
func toChart(in RegistryV1, installNamespace string, watchNamespaces []string) (*chart.Chart, error) {
@@ -195,17 +203,17 @@ func Convert(in RegistryV1, installNamespace string, targetNamespaces []string)
195203
for _, depSpec := range in.CSV.Spec.InstallStrategy.StrategySpec.DeploymentSpecs {
196204
annotations := util.MergeMaps(in.CSV.Annotations, depSpec.Spec.Template.Annotations)
197205
annotations["olm.targetNamespaces"] = strings.Join(targetNamespaces, ",")
206+
depSpec.Spec.Template.Annotations = annotations
198207
deployments = append(deployments, appsv1.Deployment{
199208
TypeMeta: metav1.TypeMeta{
200209
Kind: "Deployment",
201210
APIVersion: appsv1.SchemeGroupVersion.String(),
202211
},
203212

204213
ObjectMeta: metav1.ObjectMeta{
205-
Namespace: installNamespace,
206-
Name: depSpec.Name,
207-
Labels: depSpec.Label,
208-
Annotations: annotations,
214+
Namespace: installNamespace,
215+
Name: depSpec.Name,
216+
Labels: depSpec.Label,
209217
},
210218
Spec: depSpec.Spec,
211219
})

0 commit comments

Comments
 (0)