Skip to content

Commit 841a445

Browse files
author
Christian Hernandez
committed
v0.0.1
Signed-off-by: Christian Hernandez <christian@codefresh.io>
1 parent 10a8be2 commit 841a445

File tree

5 files changed

+225
-15
lines changed

5 files changed

+225
-15
lines changed

README.md

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,28 @@ Currently working:
1313

1414
# Installation
1515

16-
TBD
16+
Install the `mta` binary from the releases page (x64_64 currenly)
17+
18+
```shell
19+
sudo wget -O /usr/local/bin/mta https://github.com/christianh814/mta/releases/download/v0.0.1/mta-amd64-$(uname -s | tr [:upper:] [:lower:])
20+
```
21+
22+
Make sure it's executable
23+
24+
```shell
25+
sudo chmod +x /usr/local/bin/mta
26+
```
27+
28+
There is bash completion
29+
30+
> *NOTE* it's probably `zsh` on a Mac
31+
32+
```shell
33+
mta completion bash
34+
```
1735

1836
# Quickstarts
1937

2038
Quickstarts to test the functionality after downloading the CLI
2139

22-
* [Kustomizations](#)
40+
* [Kustomizations](docs/kustomizations.md)

cmd/kustomization.go

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -148,22 +148,17 @@ with kubectl.`,
148148

149149
func init() {
150150
rootCmd.AddCommand(kustomizationCmd)
151-
152151
// Here you will define your flags and configuration settings.
153152

154-
// Cobra supports Persistent Flags which will work for this command
155-
// and all subcommands, e.g.:
156-
// kustomizationCmd.PersistentFlags().String("foo", "", "A help for foo")
157153
kcf, _ := os.UserHomeDir()
158154
kustomizationCmd.Flags().String("kubeconfig", kcf+"/.kube/config", "Path to the kubeconfig file to use (if not the standard one).")
159-
kustomizationCmd.Flags().String("name", "", "Name of Kustomization to export")
160-
kustomizationCmd.Flags().String("namespace", "", "Namespace of where the Kustomization is")
155+
kustomizationCmd.Flags().String("name", "flux-system", "Name of Kustomization to export")
156+
kustomizationCmd.Flags().String("namespace", "flux-system", "Namespace of where the Kustomization is")
161157

162158
//Require the following flags
163-
kustomizationCmd.MarkFlagRequired("name")
164-
kustomizationCmd.MarkFlagRequired("namespace")
159+
/*
160+
kustomizationCmd.MarkFlagRequired("name")
161+
kustomizationCmd.MarkFlagRequired("namespace")
162+
*/
165163

166-
// Cobra supports local flags which will only run when this command
167-
// is called directly, e.g.:
168-
// kustomizationCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
169164
}

cmd/root.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,9 @@ var cfgFile string
2929

3030
// rootCmd represents the base command when called without any subcommands
3131
var rootCmd = &cobra.Command{
32-
Use: "mta",
33-
Short: "This commands turns Flux Kustomizations and HelmReleases into Argo CD Applications",
32+
Use: "mta",
33+
Version: "v0.0.1",
34+
Short: "This commands turns Flux Kustomizations and HelmReleases into Argo CD Applications",
3435
Long: `This is a migration tool that helps you move your Flux Kustomizations and HelmReleases
3536
into Argo CD ApplicationSet. Kustomization example:
3637

cmd/version.go

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
Copyright © 2022 Christian Hernandez christian@chernand.io
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
package cmd
17+
18+
import (
19+
"encoding/json"
20+
"fmt"
21+
22+
"github.com/spf13/cobra"
23+
)
24+
25+
// versionCmd represents the version command
26+
var versionCmd = &cobra.Command{
27+
Use: "version",
28+
Short: "Displays version.",
29+
Long: `This command will display the version of the CLI in json format`,
30+
Run: func(cmd *cobra.Command, args []string) {
31+
versionMap := map[string]string{rootCmd.Use: rootCmd.Version}
32+
versionJson, _ := json.Marshal(versionMap)
33+
fmt.Println(string(versionJson))
34+
},
35+
}
36+
37+
func init() {
38+
rootCmd.AddCommand(versionCmd)
39+
}

docs/kustomizations.md

Lines changed: 157 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,157 @@
1+
# Kustomization Quickstart
2+
3+
This is a quickstart so you can test how this migration tool works.
4+
5+
# Setup Flux
6+
7+
If you already have Flux running, you can skip ahead. If not, you'll need to install/bootstrap Flux on to your Kubernetes cluster.
8+
9+
You'll need
10+
11+
* [Flux CLI](https://github.com/fluxcd/flux2/releases)
12+
* A GitHub token
13+
* Kubernetes Cluster
14+
15+
Easiest way to test is with a [KIND cluster](https://github.com/kubernetes-sigs/kind)
16+
17+
```shell
18+
kind create cluster
19+
```
20+
21+
## Bootstrapping
22+
23+
The easiest way to get Flux up and running is to use the CLI to bootstrap. Best to use the [official documentation](https://fluxcd.io/docs/get-started/). But in Short:
24+
25+
Export your GitHub Token
26+
27+
```shell
28+
export GITHUB_TOKEN=123abc456def789
29+
```
30+
31+
Install/Configure Flux on the cluster
32+
33+
> *NOTE* replace the username with your GitHub username
34+
35+
```shell
36+
flux bootstrap github --owner christianh814 --private --personal --repository flux-demo
37+
```
38+
39+
## Add Applications
40+
41+
To test the migration, add some applications.
42+
43+
First, clone the repo from GitHub and `cd` into that repo's directory.
44+
45+
> *NOTE* Again, replace the username with your GitHub username
46+
47+
```shell
48+
git clone git@github.com:christianh814/flux-demo.git
49+
cd flux-demo
50+
```
51+
52+
Add some applications (you can probably copy/paste this)
53+
54+
```shell
55+
mkdir welcome-php
56+
cd welcome-php
57+
kubectl create ns welcome-php --dry-run=client -o yaml > welcome-php-ns.yaml
58+
kubectl create deployment welcome-php -n welcome-php --image=quay.io/redhatworkshops/welcome-php:latest --dry-run=client -o yaml > welcome-php-deployment.yaml
59+
kubectl create service clusterip welcome-php -n welcome-php --tcp=8080:8080 -o yaml --dry-run=client > welcome-php-service.yaml
60+
kustomize create --autodetect --recursive --namespace welcome-php
61+
62+
cd ../
63+
64+
mkdir bgd
65+
cd bgd
66+
kubectl create deployment --image=quay.io/redhatworkshops/bgd:latest bgd -n bgd --dry-run=client -o yaml > bgd-deployment.yaml
67+
kubectl create service clusterip bgd -n bgd --tcp=8080:8080 -o yaml --dry-run=client > bgd-service.yaml
68+
kubectl create ns bgd --dry-run=client -o yaml > bgd-namespace.yaml
69+
kustomize create --autodetect --recursive --namespace bgd
70+
71+
cd ../
72+
```
73+
74+
You should have 3 directories. Two with the apps you've just created and one for the flux system.
75+
76+
```shell
77+
$ tree -d .
78+
.
79+
├── bgd
80+
├── flux-system
81+
└── welcome-php
82+
```
83+
84+
Commit and push
85+
86+
```shell
87+
git add .
88+
git commit -am "added test applications"
89+
git push
90+
```
91+
92+
Reconcile the changes
93+
94+
```shell
95+
flux reconcile source git flux-system
96+
```
97+
98+
# Migrate
99+
100+
Migration happens via an ApplicationSet. To see what will be created, just run the migration tool.
101+
102+
> *NOTE* If youre Kustomizations are in a different namespace or named differnt, use `--namespace` and `--name` respectively.
103+
104+
```shell
105+
mta kustomization
106+
```
107+
108+
You can redirect this to a file or pipe it directly into `kubectl apply`.
109+
110+
First make sure Argo CD is installed
111+
112+
```shell
113+
kubectl create namespace argocd
114+
kubectl apply -n argocd -f https://raw.githubusercontent.com/argoproj/argo-cd/stable/manifests/install.yaml
115+
```
116+
117+
Then pipe it into `kubectl apply`
118+
119+
```shell
120+
mta kustomization | kubectl apply -n argocd -f -
121+
```
122+
123+
This should create an ApplicationSet with two Applications (discarding the `flux-system` directory)
124+
125+
```shell
126+
$ kubectl get appsets,apps -n argocd
127+
NAME AGE
128+
applicationset.argoproj.io/mta-migration 53s
129+
130+
NAME SYNC STATUS HEALTH STATUS
131+
application.argoproj.io/bgd Synced Healthy
132+
application.argoproj.io/welcome-php Synced Healthy
133+
```
134+
135+
Now suspend reconciliation on Flux
136+
137+
```shell
138+
flux suspend kustomization --namespace flux-system flux-system
139+
```
140+
141+
Once suspended, you can safely delete the Kustomization
142+
143+
```shell
144+
flux delete kustomization flux-system -s
145+
```
146+
147+
It is now safe to delete Flux
148+
149+
```shell
150+
flux uninstall -s
151+
```
152+
153+
The applications should still be running
154+
155+
```shell
156+
kubectl get pods,svc,deploy -A | egrep 'bgd|welcome-php'
157+
```

0 commit comments

Comments
 (0)