Skip to content

Commit

Permalink
v0.0.1
Browse files Browse the repository at this point in the history
Signed-off-by: Christian Hernandez <[email protected]>
  • Loading branch information
Christian Hernandez committed Jun 10, 2022
1 parent 10a8be2 commit 841a445
Show file tree
Hide file tree
Showing 5 changed files with 225 additions and 15 deletions.
22 changes: 20 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,28 @@ Currently working:

# Installation

TBD
Install the `mta` binary from the releases page (x64_64 currenly)

```shell
sudo wget -O /usr/local/bin/mta https://github.com/christianh814/mta/releases/download/v0.0.1/mta-amd64-$(uname -s | tr [:upper:] [:lower:])
```

Make sure it's executable

```shell
sudo chmod +x /usr/local/bin/mta
```

There is bash completion

> *NOTE* it's probably `zsh` on a Mac
```shell
mta completion bash
```

# Quickstarts

Quickstarts to test the functionality after downloading the CLI

* [Kustomizations](#)
* [Kustomizations](docs/kustomizations.md)
17 changes: 6 additions & 11 deletions cmd/kustomization.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,22 +148,17 @@ with kubectl.`,

func init() {
rootCmd.AddCommand(kustomizationCmd)

// Here you will define your flags and configuration settings.

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

//Require the following flags
kustomizationCmd.MarkFlagRequired("name")
kustomizationCmd.MarkFlagRequired("namespace")
/*
kustomizationCmd.MarkFlagRequired("name")
kustomizationCmd.MarkFlagRequired("namespace")
*/

// Cobra supports local flags which will only run when this command
// is called directly, e.g.:
// kustomizationCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
}
5 changes: 3 additions & 2 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,9 @@ var cfgFile string

// rootCmd represents the base command when called without any subcommands
var rootCmd = &cobra.Command{
Use: "mta",
Short: "This commands turns Flux Kustomizations and HelmReleases into Argo CD Applications",
Use: "mta",
Version: "v0.0.1",
Short: "This commands turns Flux Kustomizations and HelmReleases into Argo CD Applications",
Long: `This is a migration tool that helps you move your Flux Kustomizations and HelmReleases
into Argo CD ApplicationSet. Kustomization example:
Expand Down
39 changes: 39 additions & 0 deletions cmd/version.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
Copyright © 2022 Christian Hernandez [email protected]
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package cmd

import (
"encoding/json"
"fmt"

"github.com/spf13/cobra"
)

// versionCmd represents the version command
var versionCmd = &cobra.Command{
Use: "version",
Short: "Displays version.",
Long: `This command will display the version of the CLI in json format`,
Run: func(cmd *cobra.Command, args []string) {
versionMap := map[string]string{rootCmd.Use: rootCmd.Version}
versionJson, _ := json.Marshal(versionMap)
fmt.Println(string(versionJson))
},
}

func init() {
rootCmd.AddCommand(versionCmd)
}
157 changes: 157 additions & 0 deletions docs/kustomizations.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
# Kustomization Quickstart

This is a quickstart so you can test how this migration tool works.

# Setup Flux

If you already have Flux running, you can skip ahead. If not, you'll need to install/bootstrap Flux on to your Kubernetes cluster.

You'll need

* [Flux CLI](https://github.com/fluxcd/flux2/releases)
* A GitHub token
* Kubernetes Cluster

Easiest way to test is with a [KIND cluster](https://github.com/kubernetes-sigs/kind)

```shell
kind create cluster
```

## Bootstrapping

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:

Export your GitHub Token

```shell
export GITHUB_TOKEN=123abc456def789
```

Install/Configure Flux on the cluster

> *NOTE* replace the username with your GitHub username
```shell
flux bootstrap github --owner christianh814 --private --personal --repository flux-demo
```

## Add Applications

To test the migration, add some applications.

First, clone the repo from GitHub and `cd` into that repo's directory.

> *NOTE* Again, replace the username with your GitHub username
```shell
git clone [email protected]:christianh814/flux-demo.git
cd flux-demo
```

Add some applications (you can probably copy/paste this)

```shell
mkdir welcome-php
cd welcome-php
kubectl create ns welcome-php --dry-run=client -o yaml > welcome-php-ns.yaml
kubectl create deployment welcome-php -n welcome-php --image=quay.io/redhatworkshops/welcome-php:latest --dry-run=client -o yaml > welcome-php-deployment.yaml
kubectl create service clusterip welcome-php -n welcome-php --tcp=8080:8080 -o yaml --dry-run=client > welcome-php-service.yaml
kustomize create --autodetect --recursive --namespace welcome-php

cd ../

mkdir bgd
cd bgd
kubectl create deployment --image=quay.io/redhatworkshops/bgd:latest bgd -n bgd --dry-run=client -o yaml > bgd-deployment.yaml
kubectl create service clusterip bgd -n bgd --tcp=8080:8080 -o yaml --dry-run=client > bgd-service.yaml
kubectl create ns bgd --dry-run=client -o yaml > bgd-namespace.yaml
kustomize create --autodetect --recursive --namespace bgd

cd ../
```

You should have 3 directories. Two with the apps you've just created and one for the flux system.

```shell
$ tree -d .
.
├── bgd
├── flux-system
└── welcome-php
```

Commit and push

```shell
git add .
git commit -am "added test applications"
git push
```

Reconcile the changes

```shell
flux reconcile source git flux-system
```

# Migrate

Migration happens via an ApplicationSet. To see what will be created, just run the migration tool.

> *NOTE* If youre Kustomizations are in a different namespace or named differnt, use `--namespace` and `--name` respectively.
```shell
mta kustomization
```

You can redirect this to a file or pipe it directly into `kubectl apply`.

First make sure Argo CD is installed

```shell
kubectl create namespace argocd
kubectl apply -n argocd -f https://raw.githubusercontent.com/argoproj/argo-cd/stable/manifests/install.yaml
```

Then pipe it into `kubectl apply`

```shell
mta kustomization | kubectl apply -n argocd -f -
```

This should create an ApplicationSet with two Applications (discarding the `flux-system` directory)

```shell
$ kubectl get appsets,apps -n argocd
NAME AGE
applicationset.argoproj.io/mta-migration 53s

NAME SYNC STATUS HEALTH STATUS
application.argoproj.io/bgd Synced Healthy
application.argoproj.io/welcome-php Synced Healthy
```

Now suspend reconciliation on Flux

```shell
flux suspend kustomization --namespace flux-system flux-system
```

Once suspended, you can safely delete the Kustomization

```shell
flux delete kustomization flux-system -s
```

It is now safe to delete Flux

```shell
flux uninstall -s
```

The applications should still be running

```shell
kubectl get pods,svc,deploy -A | egrep 'bgd|welcome-php'
```

0 comments on commit 841a445

Please sign in to comment.