Skip to content
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

✨ WIP: DO NOT MERGE: Shift Week Prototypes #1418

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open
Changes from 1 commit
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
Next Next commit
wip: registry+v1 to helm chart
- handling for all install mode combinations is working
- subscription.spec.config support
  • Loading branch information
joelanford committed Nov 26, 2024
commit f50a557022f9c4adb4e7d2e8b998bcedc9a55fd1
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -103,9 +103,11 @@ tidy: #HELP Update dependencies.
manifests: $(CONTROLLER_GEN) #EXHELP Generate WebhookConfiguration, ClusterRole and CustomResourceDefinition objects.
$(CONTROLLER_GEN) rbac:roleName=manager-role crd webhook paths="./..." output:crd:artifacts:config=config/base/crd/bases output:rbac:artifacts:config=config/base/rbac

OPENAPI_VERSION := $(shell go list -m k8s.io/api | cut -d" " -f2 | sed 's/^v0/v1/')
.PHONY: generate
generate: $(CONTROLLER_GEN) #EXHELP Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations.
$(CONTROLLER_GEN) object:headerFile="hack/boilerplate.go.txt" paths="./..."
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

.PHONY: verify
verify: tidy fmt vet generate manifests crd-ref-docs #HELP Verify all generated code is up-to-date.
53 changes: 53 additions & 0 deletions cmd/registryv1-to-helm/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package main

import (
"fmt"
"os"
"path/filepath"

"github.com/spf13/cobra"
"helm.sh/helm/v3/pkg/chartutil"

v2 "github.com/operator-framework/operator-controller/internal/rukpak/convert/v2"
)

func main() {
if err := rootCmd().Execute(); err != nil {
os.Exit(1)
}
}

func rootCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "registryv1-to-helm <registry+v1-directory-path> [output-path]",
Args: cobra.RangeArgs(1, 2),
Run: func(cmd *cobra.Command, args []string) {
registryv1Path := args[0]

saveDir := "."
if len(args) == 2 {
saveDir = args[1]
}

chrt, err := v2.RegistryV1ToHelmChart(cmd.Context(), os.DirFS(registryv1Path))
if err != nil {
cmd.PrintErr(err)
os.Exit(1)
}

if err := chartutil.SaveDir(chrt, saveDir); err != nil {
cmd.PrintErr(err)
os.Exit(1)
}

origChartDir := filepath.Join(saveDir, chrt.Metadata.Name)
desiredChartDir := filepath.Join(saveDir, fmt.Sprintf("%s-%s", chrt.Metadata.Name, chrt.Metadata.Version))
if err := os.Rename(origChartDir, desiredChartDir); err != nil {
cmd.PrintErr(err)
os.Exit(1)
}
cmd.Printf("Chart saved to %s\n", desiredChartDir)
},
}
return cmd
}
39 changes: 39 additions & 0 deletions cmd/registryv1-to-helm/values.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
affinity:
nodeAffinity:
requiredDuringSchedulingIgnoredDuringExecution:
nodeSelectorTerms:
- matchExpressions:
- key: node-role.kubernetes.io/master
operator: Exists
nodeSelector:
overrideKey1: overrideValue1

selector:
overrideKey2: overrideValue2

tolerations:
- effect: NoSchedule
key: node-role.kubernetes.io/master2

volumes:
- name: argocd-operator-token-5z5z2
emptyDir: {}

env:
- name: WATCH_NAMESPACE
value: BAR

envFrom:
- configMapRef:
name: my-configmap
- secretRef:
name: my-secret

resources:
requests:
cpu: 100m
memory: 100Mi

volumeMounts:
- name: tmp
mountPath: override
5 changes: 3 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
@@ -11,15 +11,18 @@ require (
github.com/containers/image/v5 v5.32.2
github.com/fsnotify/fsnotify v1.8.0
github.com/go-logr/logr v1.4.2
github.com/go-openapi/spec v0.21.0
github.com/google/go-cmp v0.6.0
github.com/google/go-containerregistry v0.20.2
github.com/joeycumines/go-dotnotation v0.0.0-20180131115956-2d3612e36c5d
github.com/onsi/ginkgo/v2 v2.21.0
github.com/onsi/gomega v1.35.1
github.com/opencontainers/go-digest v1.0.0
github.com/operator-framework/api v0.27.0
github.com/operator-framework/catalogd v1.0.0-rc2
github.com/operator-framework/helm-operator-plugins v0.7.0
github.com/operator-framework/operator-registry v1.48.0
github.com/spf13/cobra v1.8.1
github.com/spf13/pflag v1.0.5
github.com/stretchr/testify v1.9.0
golang.org/x/exp v0.0.0-20240719175910-8a7402abbf56
@@ -103,7 +106,6 @@ require (
github.com/go-openapi/jsonreference v0.21.0 // indirect
github.com/go-openapi/loads v0.22.0 // indirect
github.com/go-openapi/runtime v0.28.0 // indirect
github.com/go-openapi/spec v0.21.0 // indirect
github.com/go-openapi/strfmt v0.23.0 // indirect
github.com/go-openapi/swag v0.23.0 // indirect
github.com/go-openapi/validate v0.24.0 // indirect
@@ -193,7 +195,6 @@ require (
github.com/sigstore/sigstore v1.8.4 // indirect
github.com/sirupsen/logrus v1.9.3 // indirect
github.com/spf13/cast v1.7.0 // indirect
github.com/spf13/cobra v1.8.1 // indirect
github.com/stefanberger/go-pkcs11uri v0.0.0-20230803200340-78284954bff6 // indirect
github.com/stoewer/go-strcase v1.3.0 // indirect
github.com/stretchr/objx v0.5.2 // indirect
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -392,6 +392,8 @@ github.com/jmoiron/sqlx v1.4.0 h1:1PLqN7S1UYp5t4SrVVnt4nUVNemrDAtxlulVe+Qgm3o=
github.com/jmoiron/sqlx v1.4.0/go.mod h1:ZrZ7UsYB/weZdl2Bxg6jCRO9c3YHl8r3ahlKmRT4JLY=
github.com/joelanford/ignore v0.1.0 h1:VawbTDeg5EL+PN7W8gxVzGerfGpVo3gFdR5ZAqnkYRk=
github.com/joelanford/ignore v0.1.0/go.mod h1:Vb0PQMAQXK29fmiPjDukpO8I2NTcp1y8LbhFijD1/0o=
github.com/joeycumines/go-dotnotation v0.0.0-20180131115956-2d3612e36c5d h1:ljoJyU5NEhe3LWXrRSHnYqWtQehQSJ+9d9tfIGNbpSw=
github.com/joeycumines/go-dotnotation v0.0.0-20180131115956-2d3612e36c5d/go.mod h1:siHz7M0dAufA9aNRidkfckDSVB/S+Ld7allyOe5uxVg=
github.com/jonboulle/clockwork v0.1.0/go.mod h1:Ii8DK3G1RaLaWxj9trq07+26W01tbo22gdxWY5EU2bo=
github.com/josharian/intern v1.0.0 h1:vlS4z54oSdjm0bgjRigI+G1HpF+tI+9rE5LLzOg8HmY=
github.com/josharian/intern v1.0.0/go.mod h1:5DoeVV0s6jJacbCEi61lwdGj/aVlrQvzHFFd8Hwg//Y=
13 changes: 11 additions & 2 deletions internal/rukpak/convert/registryv1.go
Original file line number Diff line number Diff line change
@@ -41,7 +41,7 @@ type Plain struct {
Objects []client.Object
}

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

reg := RegistryV1{}
@@ -107,7 +107,16 @@ func RegistryV1ToHelmChart(ctx context.Context, rv1 fs.FS, installNamespace stri
return nil, err
}

return toChart(reg, installNamespace, watchNamespaces)
return &reg, nil
}

func RegistryV1ToHelmChart(ctx context.Context, rv1 fs.FS, installNamespace string, watchNamespaces []string) (*chart.Chart, error) {
reg, err := LoadRegistryV1(ctx, rv1)
if err != nil {
return nil, err
}

return toChart(*reg, installNamespace, watchNamespaces)
}

// copyMetadataPropertiesToCSV copies properties from `metadata/propeties.yaml` (in the filesystem fsys) into
Loading