-
Notifications
You must be signed in to change notification settings - Fork 4
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
Adds mithrilctl initial implementation #24
Open
alexandrealvino
wants to merge
3
commits into
main
Choose a base branch
from
f-mithrilctl
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 all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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 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
This file contains 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
This file contains 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,30 @@ | ||
# mithrilctl | ||
|
||
Mithrilctl is a tool to easily deploy Mithril in a cluster. | ||
|
||
## Requirements | ||
|
||
1. kubectl | ||
2. helm | ||
3. A running cluster | ||
|
||
## Setting up mithrilctl | ||
|
||
At first, you need to build the mithrilctl binary. You can move it to the binary directory in order to be able to use it everywhere you need. | ||
|
||
```bash | ||
cd <Mithril repository path>/mithrilctl && go build -o mithril && sudo mv mithril /usr/local/bin/mithril | ||
``` | ||
|
||
## Install Mithril | ||
|
||
```bash | ||
$ mithril install | ||
``` | ||
|
||
## Getting installed manifests | ||
|
||
```bash | ||
$ mithril get manifest --spire | ||
$ mithril get manifest --istio | ||
``` |
This file contains 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,34 @@ | ||
package cmd | ||
|
||
import ( | ||
"os" | ||
|
||
"github.com/spf13/cobra" | ||
) | ||
|
||
// getCmd represents the get command | ||
var getCmd = &cobra.Command{ | ||
Use: "get", | ||
Short: "Gets resources definitions ", | ||
Long: `Command used for outputing a helm release manifest`, | ||
Run: func(cmd *cobra.Command, args []string) { | ||
if len(args) == 0 || args[0] == "" { | ||
cmd.Help() | ||
os.Exit(0) | ||
} | ||
}, | ||
} | ||
|
||
func init() { | ||
rootCmd.AddCommand(getCmd) | ||
|
||
// Here you will define your flags and configuration settings. | ||
|
||
// Cobra supports Persistent Flags which will work for this command | ||
// and all subcommands, e.g.: | ||
// getCmd.PersistentFlags().String("foo", "", "A help for foo") | ||
|
||
// Cobra supports local flags which will only run when this command | ||
// is called directly, e.g.: | ||
// getCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle") | ||
} |
This file contains 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,71 @@ | ||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
"github.com/spf13/cobra" | ||
"mithril/pkg/istio" | ||
"mithril/pkg/spire" | ||
"mithril/util" | ||
"os" | ||
"time" | ||
) | ||
|
||
var spinner = util.NewSpinner(os.Stderr) | ||
|
||
// installCmd represents the install command | ||
var installCmd = &cobra.Command{ | ||
Use: "install", | ||
Short: "Installs Mithril", | ||
Long: `Command used to install Istio integrated with SPIRE on a Kubernetes cluster`, | ||
Run: func(cmd *cobra.Command, args []string) { | ||
fmt.Println(fmt.Sprintf(" %s ", "Installing Mithril ⚒️ ...")) | ||
spinner.SetSuffix(fmt.Sprintf(" %s ", "Deploying SPIRE 🗝️")) | ||
go func() { | ||
spinner.Start() | ||
}() | ||
|
||
time.Sleep(time.Millisecond * 500) | ||
err := spire.DeploySpire() | ||
fmt.Fprint(spinner.Writer, "\r") | ||
successFormat := " \x1b[32m✓\x1b[0m %s\n" | ||
failureFormat := " \033[31mx\x1b[0m %s\n" | ||
|
||
if err != nil { | ||
fmt.Fprintf(spinner.Writer, failureFormat, "Deploying SPIRE 🗝️") | ||
} else { | ||
fmt.Fprintf(spinner.Writer, successFormat, "Deploying SPIRE 🗝️") | ||
} | ||
spinner.Stop() | ||
spinner.SetSuffix(fmt.Sprintf(" %s ", "Deploying Istio 🛡️")) | ||
go func() { | ||
spinner.Start() | ||
}() | ||
|
||
time.Sleep(time.Millisecond * 500) | ||
err = istio.DeployIstio() | ||
fmt.Fprint(spinner.Writer, "\r") | ||
if err != nil { | ||
fmt.Fprintf(spinner.Writer, failureFormat, "Deploying Istio 🛡️") | ||
} else { | ||
fmt.Fprintf(spinner.Writer, successFormat, "Deploying Istio 🛡️") | ||
} | ||
spinner.Stop() | ||
if err == nil { | ||
fmt.Fprintf(spinner.Writer, "\nIstio automatic injection is enabled in all namespaces!\nStart using Mithril by deploying a workload\n") | ||
} | ||
}, | ||
} | ||
|
||
func init() { | ||
rootCmd.AddCommand(installCmd) | ||
|
||
// Here you will define your flags and configuration settings. | ||
|
||
// Cobra supports Persistent Flags which will work for this command | ||
// and all subcommands, e.g.: | ||
// installCmd.PersistentFlags().String("foo", "", "A help for foo") | ||
|
||
// Cobra supports local flags which will only run when this command | ||
// is called directly, e.g.: | ||
// installCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle") | ||
} |
This file contains 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,98 @@ | ||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
"os" | ||
"strings" | ||
|
||
"github.com/spf13/cobra" | ||
"k8s.io/utils/exec" | ||
) | ||
|
||
// manifestCmd represents the manifest command | ||
var manifestCmd = &cobra.Command{ | ||
Use: "manifest", | ||
Short: "Get manifest from a helm release", | ||
Long: `Command for getting helm manifests from releases`, | ||
Run: func(cmd *cobra.Command, args []string) { | ||
spiref, _ := cmd.Flags().GetBool("spire") | ||
istiof, _ := cmd.Flags().GetBool("istio") | ||
Comment on lines
+18
to
+19
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. spireFlag and istioFlag? |
||
if !spiref && !istiof { | ||
cmd.Help() | ||
os.Exit(0) | ||
} | ||
if spiref { | ||
command := fmt.Sprintf("get manifest spire-server") | ||
cmdArgs := strings.Fields(command) | ||
cmd := exec.New() | ||
spireInstall := cmd.Command("helm", cmdArgs[0:]...) | ||
out, err := spireInstall.CombinedOutput() | ||
if err != nil { | ||
fmt.Fprintf(os.Stderr, "\nerror getting SPIRE server manifest err: %s", err) | ||
} | ||
fmt.Fprintf(os.Stdout, "# SPIRE-Server manifest\n") | ||
fmt.Fprintf(os.Stdout, "%s", out) | ||
|
||
command = fmt.Sprintf("get manifest spire-agent") | ||
cmdArgs = strings.Fields(command) | ||
cmd = exec.New() | ||
spireInstall = cmd.Command("helm", cmdArgs[0:]...) | ||
out, err = spireInstall.CombinedOutput() | ||
if err != nil { | ||
fmt.Fprintf(os.Stderr, "\nerror getting SPIRE agent manifest err: %s", err) | ||
} | ||
fmt.Fprintf(os.Stdout, "# SPIRE-Agent manifest\n") | ||
fmt.Fprintf(os.Stdout, "%s", out) | ||
} | ||
|
||
if istiof { | ||
command := fmt.Sprintf("get manifest base") | ||
cmdArgs := strings.Fields(command) | ||
cmd := exec.New() | ||
spireInstall := cmd.Command("helm", cmdArgs[0:]...) | ||
out, err := spireInstall.CombinedOutput() | ||
if err != nil { | ||
fmt.Fprintf(os.Stderr, "\nerror getting istio base manifest err: %s", err) | ||
} | ||
fmt.Fprintf(os.Stdout, "# Istio base manifest\n") | ||
fmt.Fprintf(os.Stdout, "%s", out) | ||
|
||
command = fmt.Sprintf("get manifest istiod -n istio-system") | ||
cmdArgs = strings.Fields(command) | ||
cmd = exec.New() | ||
spireInstall = cmd.Command("helm", cmdArgs[0:]...) | ||
out, err = spireInstall.CombinedOutput() | ||
if err != nil { | ||
fmt.Fprintf(os.Stderr, "\nerror getting istiod manifest err: %s", err) | ||
} | ||
fmt.Fprintf(os.Stdout, "# Istio istiod manifest\n") | ||
fmt.Fprintf(os.Stdout, "%s", out) | ||
|
||
command = fmt.Sprintf("get manifest ingressgateway -n istio-system") | ||
cmdArgs = strings.Fields(command) | ||
cmd = exec.New() | ||
spireInstall = cmd.Command("helm", cmdArgs[0:]...) | ||
out, err = spireInstall.CombinedOutput() | ||
if err != nil { | ||
fmt.Fprintf(os.Stderr, "\nerror getting istio ingressgateway manifest err: %s", err) | ||
} | ||
fmt.Fprintf(os.Stdout, "# Istio ingressgateway manifest\n") | ||
fmt.Fprintf(os.Stdout, "%s", out) | ||
} | ||
}, | ||
} | ||
|
||
func init() { | ||
getCmd.AddCommand(manifestCmd) | ||
|
||
// Here you will define your flags and configuration settings. | ||
|
||
// Cobra supports Persistent Flags which will work for this command | ||
// and all subcommands, e.g.: | ||
// manifestCmd.PersistentFlags().String("foo", "", "A help for foo") | ||
|
||
// Cobra supports local flags which will only run when this command | ||
// is called directly, e.g.: | ||
manifestCmd.Flags().BoolP("spire", "", false, "Selects spire manifests") | ||
manifestCmd.Flags().BoolP("istio", "", false, "Selects istio manifests") | ||
} |
This file contains 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,65 @@ | ||
package cmd | ||
|
||
import ( | ||
"fmt" | ||
"github.com/spf13/cobra" | ||
"mithril/pkg" | ||
"os" | ||
) | ||
|
||
var cfgFile string | ||
|
||
// rootCmd represents the base command when called without any subcommands | ||
var rootCmd = &cobra.Command{ | ||
Use: "mithril", | ||
Short: "CLI tool to simplify Mithril deployment", | ||
Long: `Mithril configuration command line utility for managing SPIRE and Istio installations`, | ||
// Uncomment the following line if your bare application | ||
// has an action associated with it: | ||
Run: func(cmd *cobra.Command, args []string) { | ||
if len(args) == 0 { | ||
cmd.Help() | ||
os.Exit(0) | ||
} | ||
}, | ||
} | ||
|
||
// Execute adds all child commands to the root command and sets flags appropriately. | ||
// This is called by main.main(). It only needs to happen once to the rootCmd. | ||
func Execute() { | ||
if err := rootCmd.Execute(); err != nil { | ||
fmt.Println(err) | ||
os.Exit(1) | ||
} | ||
} | ||
|
||
func init() { | ||
cobra.OnInitialize(initConfig) | ||
|
||
// Here you will define your flags and configuration settings. | ||
// Cobra supports persistent flags, which, if defined here, | ||
// will be global for your application. | ||
rootCmd.CompletionOptions.DisableDefaultCmd = true | ||
//rootCmd.PersistentFlags().StringVar(&cfgFile, "config", "", "config file (default is $HOME/.mithril.yaml)") | ||
|
||
// Cobra also supports local flags, which will only run | ||
// when this action is called directly. | ||
rootCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle") | ||
} | ||
|
||
// initConfig adds and updates Mithril helm charts | ||
func initConfig() { | ||
// adds Mithril helm charts | ||
err := pkg.AddMithril() | ||
if err != nil { | ||
fmt.Printf(err.Error()) | ||
os.Exit(1) | ||
} | ||
|
||
// updates Mithril helm charts | ||
err = pkg.UpdateMithril() | ||
if err != nil { | ||
fmt.Printf(err.Error()) | ||
os.Exit(1) | ||
} | ||
} |
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.
If we get an error, why does it print "Deploying SPIRE"?