Skip to content

Commit 2f9958f

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

File tree

15 files changed

+19043
-4
lines changed

15 files changed

+19043
-4
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: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,18 @@ require (
1111
github.com/containers/image/v5 v5.32.2
1212
github.com/fsnotify/fsnotify v1.8.0
1313
github.com/go-logr/logr v1.4.2
14+
github.com/go-openapi/spec v0.21.0
1415
github.com/google/go-cmp v0.6.0
1516
github.com/google/go-containerregistry v0.20.2
17+
github.com/joeycumines/go-dotnotation v0.0.0-20180131115956-2d3612e36c5d
1618
github.com/onsi/ginkgo/v2 v2.21.0
1719
github.com/onsi/gomega v1.35.1
1820
github.com/opencontainers/go-digest v1.0.0
1921
github.com/operator-framework/api v0.27.0
2022
github.com/operator-framework/catalogd v0.36.0
2123
github.com/operator-framework/helm-operator-plugins v0.7.0
2224
github.com/operator-framework/operator-registry v1.48.0
25+
github.com/spf13/cobra v1.8.1
2326
github.com/spf13/pflag v1.0.5
2427
github.com/stretchr/testify v1.9.0
2528
golang.org/x/exp v0.0.0-20240719175910-8a7402abbf56
@@ -103,7 +106,6 @@ require (
103106
github.com/go-openapi/jsonreference v0.21.0 // indirect
104107
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: 10 additions & 2 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) {

0 commit comments

Comments
 (0)