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

Add check tools and update outputs #68

Merged
merged 10 commits into from
Jul 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
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
12 changes: 12 additions & 0 deletions cmd/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,15 @@ General overview of the code, to help shuffling parts around.
|cfgFile|String| .flare config file|
|NebolousVersion|String|CLI version|


# Commands Available

| Command | Short Description | Long Description|
|:---|:---|:---|
|checktools|Present, needs review.|Present, needs review.|
|clean|Missing Text|Missing Text|
|create|Missing Text|Missing Text|
|destroy|Missing Text|Missing Text|
|info|Present, needs review.|Present, needs review.|
|init|Missing Text|Missing Text|
|version|Present, needs review.|Present, needs review.|
56 changes: 56 additions & 0 deletions cmd/checktools.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/*
Copyright © 2022 NAME HERE <EMAIL ADDRESS>

*/
package cmd

import (
"fmt"
"log"
"bytes"
"os/exec"
"github.com/spf13/cobra"
)

// checktoolsCmd represents the checktools command
var checktoolsCmd = &cobra.Command{
Use: "checktools",
Short: "use to check compatibility of .kubefirst/tools",
Long: `Execute a compatibility check of the tools downloaded by the installer.
Execute After callint "init". If executed before init, tools will not be available.
`,
Run: func(cmd *cobra.Command, args []string) {
fmt.Println("Checking the tools installed used by installer:")

kubectlVersion, kubectlStdErr,errKubectl := execShellReturnStrings(kubectlClientPath, "version", "--client", "--short")
fmt.Printf("-> kubectl version:\n\t%s\n\t%s\n",kubectlVersion,kubectlStdErr)
terraformVersion, terraformStdErr,errTerraform := execShellReturnStrings(terraformPath, "version")
fmt.Printf("-> terraform version:\n\t%s\n\t%s\n",terraformVersion,terraformStdErr)
helmVersion, helmStdErr,errHelm := execShellReturnStrings(helmClientPath, "version", "--client", "--short")
fmt.Printf("-> helm version:\n\t%s\n\t%s\n",helmVersion,helmStdErr)

if errKubectl != nil {
fmt.Println("failed to call kubectlVersionCmd.Run(): %v", errKubectl)
}
if errHelm != nil {
fmt.Println("failed to call helmVersionCmd.Run(): %v", errHelm)
}
if errTerraform != nil {
fmt.Println("failed to call terraformVersionCmd.Run(): %v", errTerraform)
}

},
}

func init() {
rootCmd.AddCommand(checktoolsCmd)
}
func execShellReturnStrings(command string, args ...string) (string, string, error) {
var outb, errb bytes.Buffer
k := exec.Command(command, args...)
k.Stdout = &outb
k.Stderr = &errb
err := k.Run()
log.Println("Error executing command: %v", err)
return outb.String(), errb.String(), err
}
Loading