-
Notifications
You must be signed in to change notification settings - Fork 767
Add "cyctl helm migrate" command to batch-migrate Helm releases to Cyclops Modules #864
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
Open
0XSIKIPON
wants to merge
7
commits into
cyclops-ui:main
Choose a base branch
from
0XSIKIPON:feat/batch-helm-migration
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 4 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
e356877
feat: fetch and validate templates existence passed in the cyctl cli …
0XSIKIPON 980d50d
feat: Implement the functionality of retrieving values from the given…
0XSIKIPON 5c6540c
Add list-release functionality within given namesapce
0XSIKIPON e0582ca
Directly directly constructs and submits a MOdule CR via Cyclops client
0XSIKIPON ebebf3b
Refactor: Reuse the k8s client from /cyclops-ctrl/pkg, add cleanup re…
0XSIKIPON 3e241c5
Fix: fix k8sclient call with required parameters
0XSIKIPON 39722be
Refactor: revert to go 1.22.0 and toolchain go1.22.2 and to helm v3
0XSIKIPON File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,21 @@ | ||
| package cmd | ||
|
|
||
| import ( | ||
| "github.com/spf13/cobra" | ||
| ) | ||
|
|
||
| var ( | ||
| helmExample = ` # Migrate Helm releases to Cyclops modules | ||
| cyctl helm migrate --namespace mynamespace --repo https://charts.bitnami.com/bitnami --path postgresql --version 12.5.6` | ||
| ) | ||
|
|
||
| var helmCmd = &cobra.Command{ | ||
| Use: "helm", | ||
| Short: "Helm release related operations", | ||
| Long: "Helm release related operations like migrating releases to Cyclops modules", | ||
| Example: helmExample, | ||
| } | ||
|
|
||
| func init() { | ||
| RootCmd.AddCommand(helmCmd) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,140 @@ | ||
| package cmd | ||
|
|
||
| import ( | ||
| "encoding/json" | ||
| "log" | ||
|
|
||
| "github.com/spf13/cobra" | ||
|
|
||
| "github.com/cyclops-ui/cyclops/cyclops-ctrl/api/v1alpha1" | ||
| cyclopsclient "github.com/cyclops-ui/cyclops/cyclops-ctrl/api/v1alpha1/client" | ||
| "github.com/cyclops-ui/cycops-cyctl/utility" | ||
|
|
||
| apiextensionsv1 "k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1" | ||
| metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
| "k8s.io/client-go/tools/clientcmd" | ||
| ) | ||
|
|
||
| var ( | ||
| namespace string | ||
| repo string | ||
| path string | ||
| version string | ||
|
|
||
| migrateExample = ` # Migrate all Helm releases in 'myns' to Cyclops Modules | ||
| cyctl helm migrate --namespace myns --repo https://charts.bitnami.com/bitnami --path postgresql --version 12.5.6` | ||
| ) | ||
|
|
||
| var migrateCmd = &cobra.Command{ | ||
| Use: "migrate", | ||
| Short: "Migrate Helm releases to Cyclops Modules", | ||
| Long: "Batch‑migrate all Helm releases in a namespace to Cyclops Module CRs", | ||
| Example: migrateExample, | ||
| Run: runMigrate, | ||
| } | ||
|
|
||
| func init() { | ||
| migrateCmd.Flags().StringVarP(&namespace, "namespace", "n", "", "namespace containing the Helm releases to migrate") | ||
| migrateCmd.Flags().StringVarP(&repo, "repo", "r", "", "repository URL containing the template") | ||
| migrateCmd.Flags().StringVarP(&path, "path", "p", "", "path to the template in the repository") | ||
| migrateCmd.Flags().StringVarP(&version, "version", "v", "", "version of the template") | ||
|
|
||
| migrateCmd.MarkFlagRequired("namespace") | ||
| migrateCmd.MarkFlagRequired("repo") | ||
| migrateCmd.MarkFlagRequired("path") | ||
| migrateCmd.MarkFlagRequired("version") | ||
|
|
||
| helmCmd.AddCommand(migrateCmd) | ||
| } | ||
|
|
||
| func runMigrate(cmd *cobra.Command, args []string) { | ||
| // 1. Validate template existence | ||
| log.Printf("[1/4] Validating template %s/%s:%s …", repo, path, version) | ||
| if err := utility.ValidateTemplate(repo, path, version); err != nil { | ||
| log.Fatalf("Error validating template: %v", err) | ||
| } | ||
| log.Printf("✓ Template validated successfully") | ||
|
|
||
| // 2. Build k8s config & Cyclops client | ||
| log.Printf("[2/4] Loading Kubernetes config …") | ||
| loadingRules := clientcmd.NewDefaultClientConfigLoadingRules() | ||
| configOverrides := &clientcmd.ConfigOverrides{} | ||
| kubeConfig := clientcmd.NewNonInteractiveDeferredLoadingClientConfig(loadingRules, configOverrides) | ||
| cfg, err := kubeConfig.ClientConfig() | ||
| if err != nil { | ||
| log.Fatalf("Error loading kubeconfig: %v", err) | ||
| } | ||
| log.Printf("✓ Kubernetes config loaded") | ||
|
|
||
| log.Printf("Creating Cyclops client …") | ||
| cyclopsClient, err := cyclopsclient.NewForConfig(cfg) | ||
| if err != nil { | ||
| log.Fatalf("Error creating Cyclops client: %v", err) | ||
| } | ||
| log.Printf("✓ Cyclops client ready") | ||
|
|
||
| // 3. List all Helm releases in the namespace | ||
| log.Printf("[3/4] Listing Helm releases in namespace %q …", namespace) | ||
| releases, err := utility.ListHelmReleases(namespace) | ||
| if err != nil { | ||
| log.Fatalf("Error listing Helm releases: %v", err) | ||
| } | ||
| if len(releases) == 0 { | ||
| log.Printf("⚠ No Helm releases found in namespace %q", namespace) | ||
| return | ||
| } | ||
| log.Printf("✓ Found %d release(s) in namespace %q", len(releases), namespace) | ||
|
|
||
| // 4. For each release: fetch values → marshal → create Module | ||
| log.Printf("[4/4] Migrating releases …") | ||
| for _, relName := range releases { | ||
| log.Printf("→ Starting migration for release %q", relName) | ||
|
|
||
| // a) fetch values | ||
| vals, err := utility.GetReleaseValues(relName, namespace) | ||
| if err != nil { | ||
| log.Printf(" • [ERROR] failed to get values for %q: %v", relName, err) | ||
| continue | ||
| } | ||
| log.Printf(" • Retrieved values for %q", relName) | ||
|
|
||
| // b) marshal into JSON | ||
| rawJSON, err := json.Marshal(vals) | ||
| if err != nil { | ||
| log.Printf(" • [ERROR] failed to marshal values for %q: %v", relName, err) | ||
| continue | ||
| } | ||
| log.Printf(" • Marshalled values for %q", relName) | ||
|
|
||
| // c) build Module CR | ||
| mod := &v1alpha1.Module{ | ||
| TypeMeta: metav1.TypeMeta{ | ||
| Kind: "Module", | ||
| APIVersion: "cyclops-ui.com/v1alpha1", | ||
| }, | ||
| ObjectMeta: metav1.ObjectMeta{ | ||
| Name: relName, | ||
| Namespace: "cyclops", // could be a flag | ||
| }, | ||
| Spec: v1alpha1.ModuleSpec{ | ||
| TargetNamespace: namespace, | ||
| TemplateRef: v1alpha1.TemplateRef{ | ||
| URL: repo, | ||
| Path: path, | ||
| Version: version, | ||
| }, | ||
| Values: apiextensionsv1.JSON{Raw: rawJSON}, | ||
| }, | ||
| } | ||
|
|
||
| // d) submit to Cyclops API | ||
| _, err = cyclopsClient.Modules("cyclops").Create(mod) | ||
| if err != nil { | ||
| log.Printf(" • [ERROR] failed to create Module for %q: %v", relName, err) | ||
| continue | ||
| } | ||
| log.Printf(" ✔ Successfully migrated %q → Module/%s", relName, relName) | ||
| } | ||
|
|
||
| log.Printf("All done.") | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,74 +1,127 @@ | ||
| module github.com/cyclops-ui/cycops-cyctl | ||
|
|
||
| go 1.22.0 | ||
| go 1.24.0 | ||
|
||
|
|
||
| toolchain go1.22.2 | ||
| toolchain go1.24.2 | ||
|
|
||
| require ( | ||
| github.com/cyclops-ui/cyclops/cyclops-ctrl v0.0.0-20240917130002-9f787d2ad567 | ||
| github.com/manifoldco/promptui v0.9.0 | ||
| github.com/spf13/cobra v1.8.0 | ||
| k8s.io/api v0.30.1 | ||
| k8s.io/apiextensions-apiserver v0.30.1 | ||
| k8s.io/apimachinery v0.30.1 | ||
| k8s.io/client-go v0.30.1 | ||
| github.com/spf13/cobra v1.9.1 | ||
| helm.sh/helm/v4 v4.0.0-20250425235407-31e22b9866af | ||
| k8s.io/api v0.33.0 | ||
| k8s.io/apiextensions-apiserver v0.33.0 | ||
| k8s.io/apimachinery v0.33.0 | ||
| k8s.io/cli-runtime v0.33.0 | ||
| k8s.io/client-go v0.33.0 | ||
| sigs.k8s.io/yaml v1.4.0 | ||
| ) | ||
|
|
||
| require ( | ||
| dario.cat/mergo v1.0.1 // indirect | ||
| github.com/Azure/go-ansiterm v0.0.0-20250102033503-faa5f7b0171c // indirect | ||
| github.com/BurntSushi/toml v1.5.0 // indirect | ||
| github.com/MakeNowJust/heredoc v1.0.0 // indirect | ||
| github.com/Masterminds/goutils v1.1.1 // indirect | ||
| github.com/Masterminds/semver/v3 v3.3.0 // indirect | ||
| github.com/Masterminds/sprig/v3 v3.3.0 // indirect | ||
| github.com/Masterminds/squirrel v1.5.4 // indirect | ||
| github.com/asaskevich/govalidator v0.0.0-20230301143203-a9d515a09cc2 // indirect | ||
| github.com/beorn7/perks v1.0.1 // indirect | ||
| github.com/cespare/xxhash/v2 v2.2.0 // indirect | ||
| github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e // indirect | ||
| github.com/davecgh/go-spew v1.1.1 // indirect | ||
| github.com/emicklei/go-restful/v3 v3.11.0 // indirect | ||
| github.com/evanphx/json-patch/v5 v5.9.0 // indirect | ||
| github.com/fsnotify/fsnotify v1.7.0 // indirect | ||
| github.com/go-logr/logr v1.4.1 // indirect | ||
| github.com/go-openapi/jsonpointer v0.19.6 // indirect | ||
| github.com/go-openapi/jsonreference v0.20.2 // indirect | ||
| github.com/go-openapi/swag v0.22.3 // indirect | ||
| github.com/blang/semver/v4 v4.0.0 // indirect | ||
| github.com/cespare/xxhash/v2 v2.3.0 // indirect | ||
| github.com/chai2010/gettext-go v1.0.2 // indirect | ||
| github.com/chzyer/readline v1.5.1 // indirect | ||
| github.com/cyphar/filepath-securejoin v0.4.1 // indirect | ||
| github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc // indirect | ||
| github.com/emicklei/go-restful/v3 v3.12.1 // indirect | ||
| github.com/evanphx/json-patch v5.9.11+incompatible // indirect | ||
| github.com/evanphx/json-patch/v5 v5.9.11 // indirect | ||
| github.com/exponent-io/jsonpath v0.0.0-20210407135951-1de76d718b3f // indirect | ||
| github.com/fatih/color v1.13.0 // indirect | ||
| github.com/fluxcd/cli-utils v0.36.0-flux.13 // indirect | ||
| github.com/fsnotify/fsnotify v1.8.0 // indirect | ||
| github.com/fxamacker/cbor/v2 v2.7.0 // indirect | ||
| github.com/go-errors/errors v1.5.1 // indirect | ||
| github.com/go-gorp/gorp/v3 v3.1.0 // indirect | ||
| github.com/go-logr/logr v1.4.2 // indirect | ||
| github.com/go-openapi/jsonpointer v0.21.0 // indirect | ||
| github.com/go-openapi/jsonreference v0.21.0 // indirect | ||
| github.com/go-openapi/swag v0.23.0 // indirect | ||
| github.com/gobwas/glob v0.2.3 // indirect | ||
| github.com/gogo/protobuf v1.3.2 // indirect | ||
| github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect | ||
| github.com/golang/protobuf v1.5.4 // indirect | ||
| github.com/google/gnostic-models v0.6.8 // indirect | ||
| github.com/google/go-cmp v0.6.0 // indirect | ||
| github.com/google/gofuzz v1.2.0 // indirect | ||
| github.com/google/btree v1.1.3 // indirect | ||
| github.com/google/gnostic-models v0.6.9 // indirect | ||
| github.com/google/go-cmp v0.7.0 // indirect | ||
| github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 // indirect | ||
| github.com/google/uuid v1.6.0 // indirect | ||
| github.com/gorilla/websocket v1.5.0 // indirect | ||
| github.com/imdario/mergo v0.3.13 // indirect | ||
| github.com/gorilla/websocket v1.5.4-0.20250319132907-e064f32e3674 // indirect | ||
| github.com/gosuri/uitable v0.0.4 // indirect | ||
| github.com/gregjones/httpcache v0.0.0-20190611155906-901d90724c79 // indirect | ||
| github.com/huandu/xstrings v1.5.0 // indirect | ||
| github.com/inconshreveable/mousetrap v1.1.0 // indirect | ||
| github.com/jmoiron/sqlx v1.4.0 // indirect | ||
| github.com/josharian/intern v1.0.0 // indirect | ||
| github.com/json-iterator/go v1.1.12 // indirect | ||
| github.com/mailru/easyjson v0.7.7 // indirect | ||
| github.com/matttproud/golang_protobuf_extensions v1.0.4 // indirect | ||
| github.com/moby/spdystream v0.2.0 // indirect | ||
| github.com/lann/builder v0.0.0-20180802200727-47ae307949d0 // indirect | ||
| github.com/lann/ps v0.0.0-20150810152359-62de8c46ede0 // indirect | ||
| github.com/lib/pq v1.10.9 // indirect | ||
| github.com/liggitt/tabwriter v0.0.0-20181228230101-89fcab3d43de // indirect | ||
| github.com/mailru/easyjson v0.9.0 // indirect | ||
| github.com/mattn/go-colorable v0.1.13 // indirect | ||
| github.com/mattn/go-isatty v0.0.19 // indirect | ||
| github.com/mattn/go-runewidth v0.0.9 // indirect | ||
| github.com/mitchellh/copystructure v1.2.0 // indirect | ||
| github.com/mitchellh/go-wordwrap v1.0.1 // indirect | ||
| github.com/mitchellh/reflectwalk v1.0.2 // indirect | ||
| github.com/moby/spdystream v0.5.0 // indirect | ||
| github.com/moby/term v0.5.2 // indirect | ||
| github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect | ||
| github.com/modern-go/reflect2 v1.0.2 // indirect | ||
| github.com/monochromegane/go-gitignore v0.0.0-20200626010858-205db1a8cc00 // indirect | ||
| github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect | ||
| github.com/mxk/go-flowrate v0.0.0-20140419014527-cca7078d478f // indirect | ||
| github.com/opencontainers/go-digest v1.0.0 // indirect | ||
| github.com/opencontainers/image-spec v1.1.1 // indirect | ||
| github.com/peterbourgon/diskv v2.0.1+incompatible // indirect | ||
| github.com/pkg/errors v0.9.1 // indirect | ||
| github.com/prometheus/client_golang v1.16.0 // indirect | ||
| github.com/prometheus/client_model v0.4.0 // indirect | ||
| github.com/prometheus/common v0.44.0 // indirect | ||
| github.com/prometheus/procfs v0.12.0 // indirect | ||
| github.com/spf13/pflag v1.0.5 // indirect | ||
| golang.org/x/exp v0.0.0-20220722155223-a9213eeb770e // indirect | ||
| golang.org/x/net v0.23.0 // indirect | ||
| golang.org/x/oauth2 v0.12.0 // indirect | ||
| golang.org/x/sys v0.18.0 // indirect | ||
| golang.org/x/term v0.18.0 // indirect | ||
| golang.org/x/text v0.14.0 // indirect | ||
| golang.org/x/time v0.3.0 // indirect | ||
| github.com/prometheus/client_golang v1.22.0 // indirect | ||
| github.com/prometheus/client_model v0.6.1 // indirect | ||
| github.com/prometheus/common v0.62.0 // indirect | ||
| github.com/prometheus/procfs v0.15.1 // indirect | ||
| github.com/rubenv/sql-migrate v1.8.0 // indirect | ||
| github.com/russross/blackfriday/v2 v2.1.0 // indirect | ||
| github.com/santhosh-tekuri/jsonschema/v6 v6.0.1 // indirect | ||
| github.com/shopspring/decimal v1.4.0 // indirect | ||
| github.com/spf13/cast v1.7.0 // indirect | ||
| github.com/spf13/pflag v1.0.6 // indirect | ||
| github.com/x448/float16 v0.8.4 // indirect | ||
| github.com/xlab/treeprint v1.2.0 // indirect | ||
| golang.org/x/crypto v0.37.0 // indirect | ||
| golang.org/x/net v0.39.0 // indirect | ||
| golang.org/x/oauth2 v0.29.0 // indirect | ||
| golang.org/x/sync v0.13.0 // indirect | ||
| golang.org/x/sys v0.32.0 // indirect | ||
| golang.org/x/term v0.31.0 // indirect | ||
| golang.org/x/text v0.24.0 // indirect | ||
| golang.org/x/time v0.11.0 // indirect | ||
| gomodules.xyz/jsonpatch/v2 v2.4.0 // indirect | ||
| google.golang.org/appengine v1.6.7 // indirect | ||
| google.golang.org/protobuf v1.33.0 // indirect | ||
| google.golang.org/protobuf v1.36.5 // indirect | ||
| gopkg.in/evanphx/json-patch.v4 v4.12.0 // indirect | ||
| gopkg.in/inf.v0 v0.9.1 // indirect | ||
| gopkg.in/yaml.v2 v2.4.0 // indirect | ||
| gopkg.in/yaml.v3 v3.0.1 // indirect | ||
| k8s.io/klog/v2 v2.120.1 // indirect | ||
| k8s.io/kube-openapi v0.0.0-20240228011516-70dd3763d340 // indirect | ||
| k8s.io/utils v0.0.0-20230726121419-3b25d923346b // indirect | ||
| sigs.k8s.io/controller-runtime v0.18.4 // indirect | ||
| sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect | ||
| sigs.k8s.io/structured-merge-diff/v4 v4.4.1 // indirect | ||
| k8s.io/apiserver v0.33.0 // indirect | ||
| k8s.io/component-base v0.33.0 // indirect | ||
| k8s.io/klog/v2 v2.130.1 // indirect | ||
| k8s.io/kube-openapi v0.0.0-20250318190949-c8a335a9a2ff // indirect | ||
| k8s.io/kubectl v0.33.0 // indirect | ||
| k8s.io/utils v0.0.0-20250321185631-1f6e0b77f77e // indirect | ||
| oras.land/oras-go/v2 v2.5.0 // indirect | ||
| sigs.k8s.io/controller-runtime v0.20.4 // indirect | ||
| sigs.k8s.io/json v0.0.0-20241014173422-cfa47c3a1cc8 // indirect | ||
| sigs.k8s.io/kustomize/api v0.19.0 // indirect | ||
| sigs.k8s.io/kustomize/kyaml v0.19.0 // indirect | ||
| sigs.k8s.io/randfill v1.0.0 // indirect | ||
| sigs.k8s.io/structured-merge-diff/v4 v4.6.0 // indirect | ||
| ) | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we use the Kubernetes client from cyclops-ctrl/pkg instead? This way, you don't have to reimplement the utility package