Skip to content
Permalink
Browse files

Add update command and improved error handling

Prints kubectl errors as warnings so that users can see if
anything went wrong.

Adds an update command to print out instructions.

Signed-off-by: Alex Ellis (OpenFaaS Ltd) <alexellis2@gmail.com>
  • Loading branch information
alexellis committed Nov 10, 2019
1 parent 66ccadb commit 6aa156d483a584c2992b33f6410a3aeddc475781
@@ -8,13 +8,10 @@ import (
func main() {

cmdInstall := cmd.MakeInstall()

cmdVersion := cmd.MakeVersion()

cmdJoin := cmd.MakeJoin()

cmdApps := cmd.MakeApps()

cmdUpdate := cmd.MakeUpdate()
printk3supASCIIArt := cmd.PrintK3supASCIIArt

var rootCmd = &cobra.Command{
@@ -29,6 +26,7 @@ func main() {
rootCmd.AddCommand(cmdVersion)
rootCmd.AddCommand(cmdJoin)
rootCmd.AddCommand(cmdApps)
rootCmd.AddCommand(cmdUpdate)

rootCmd.Execute()
}
@@ -59,6 +59,7 @@ func makeInstallCertManager() *cobra.Command {
if err != nil {
return err
}

updateRepo, _ := certManager.Flags().GetBool("update-repo")

if updateRepo {
@@ -68,9 +69,13 @@ func makeInstallCertManager() *cobra.Command {
}
}

err = kubectl("create", "namespace", namespace)
if err != nil {
return err
nsRes, nsErr := kubectlTask("create", "namespace", namespace)
if nsErr != nil {
return nsErr
}

if nsRes.ExitCode != 0 {
fmt.Printf("[Warning] unable to create namespace %s, may already exist: %s", namespace, nsRes.Stderr)
}

chartPath := path.Join(os.TempDir(), "charts")
@@ -88,18 +93,24 @@ func makeInstallCertManager() *cobra.Command {
}

log.Printf("Applying CRD\n")

res, err := kubectlTask("apply", "--validate=false", "-f", "https://raw.githubusercontent.com/jetstack/cert-manager/release-0.11/deploy/manifests/00-crds.yaml")
crdsURL := "https://raw.githubusercontent.com/jetstack/cert-manager/release-0.11/deploy/manifests/00-crds.yaml"
res, err := kubectlTask("apply", "--validate=false", "-f",
crdsURL)
if err != nil {
return err
}
if len(res.Stderr) > 0 {
return fmt.Errorf("Error applying CRD: %s", res.Stderr)

if res.ExitCode > 0 {
return fmt.Errorf("Error applying CRD from: %s, error: %s", crdsURL, res.Stderr)
}

err = kubectl("apply", "-R", "-f", outputPath)
if err != nil {
return err
applyRes, applyErr := kubectlTask("apply", "-R", "-f", outputPath)
if applyErr != nil {
return applyErr
}

if applyRes.ExitCode > 0 {
return fmt.Errorf("Error applying templated YAML files, error: %s", applyRes.Stderr)
}

fmt.Println(`=======================================================================
@@ -134,7 +134,7 @@ before using the generic helm chart installer command.`,
chart ` + chartRepoName + ` installed.
=======================================================================
Thank you for using k3sup!`)
` + thanksForUsing)

return nil
}
@@ -86,7 +86,7 @@ kubectl delete svc/nginx-1
# Find out more at:
# https://github.com/inlets/inlets-operator
Thank you for using k3sup!`)
` + thanksForUsing)

return nil
}
@@ -81,10 +81,13 @@ func makeInstallMetricsServer() *cobra.Command {
return err
}

err = kubectl("-n", namespace, "apply", "-R", "-f", outputPath)
applyRes, applyErr := kubectlTask("apply", "-R", "-f", outputPath)
if applyErr != nil {
return applyErr
}

if err != nil {
return err
if applyRes.ExitCode > 0 {
return fmt.Errorf("Error applying templated YAML files, error: %s", applyRes.Stderr)
}

fmt.Println(`=======================================================================
@@ -107,7 +110,7 @@ kubectl top node
# Find out more at:
# https://github.com/helm/charts/tree/master/stable/metrics-server
Thank you for using k3sup!`)
` + thanksForUsing)

return nil
}
@@ -122,7 +122,7 @@ kubectl get svc nginx-ingress-controller
# Find out more at:
# https://github.com/helm/charts/tree/master/stable/nginx-ingress
Thank you for using k3sup!`)
` + thanksForUsing)

return nil
}
@@ -140,10 +140,13 @@ func makeInstallOpenFaaS() *cobra.Command {
return err
}

err = kubectl("apply", "-R", "-f", outputPath)
applyRes, applyErr := kubectlTask("apply", "-R", "-f", outputPath)
if applyErr != nil {
return applyErr
}

if err != nil {
return err
if applyRes.ExitCode > 0 {
return fmt.Errorf("Error applying templated YAML files, error: %s", applyRes.Stderr)
}

fmt.Println(`=======================================================================
@@ -174,7 +177,7 @@ faas-cli store deploy figlet \
# Find out more at:
# https://github.com/openfaas/faas
Thank you for using k3sup!`)
` + thanksForUsing)

return nil
}
@@ -67,9 +67,10 @@ func makeInstallOpenFaaSIngress() *cobra.Command {
return err
}

if res.Stderr != "" {
log.Printf("Unable to install this application. Have you got OpenFaaS running in the openfaas namespace and cert-manager 0.11.0 or higher installed in cert-manager namespace? %s", res.Stderr)
return err
if res.ExitCode != 0 {
return fmt.Errorf(`Unable to apply YAML files.
Have you got OpenFaaS running in the openfaas namespace and cert-manager 0.11.0 or higher installed in cert-manager namespace? %s`,
res.Stderr)
}

fmt.Println(`=======================================================================
@@ -99,8 +100,7 @@ kubectl describe -n openfaas Certificate openfaas-gateway
# It may take a while to be issued by LetsEncrypt, in the meantime a
# self-signed cert will be installed
Thank you for using k3sup!`)
` + thanksForUsing)

return nil
}
@@ -92,7 +92,7 @@ tiller has been installed
` + helmBinary + `
Thank you for using k3sup!`)
` + thanksForUsing)

return nil
}
@@ -0,0 +1,34 @@
package cmd

import (
"fmt"

"github.com/spf13/cobra"
)

func MakeUpdate() *cobra.Command {
var command = &cobra.Command{
Use: "update",
Short: "Print update instructions",
Example: ` k3sup update`,
SilenceUsage: false,
}
command.Run = func(cmd *cobra.Command, args []string) {
fmt.Println(k3supUpdate)
}
return command
}

const k3supUpdate = `You can update k3sup with the following:
# For Linux/MacOS:
curl -SLfs https://get.k3sup.dev | sudo sh
# For Windows (using Git Bash)
curl -SLfs https://get.k3sup.dev | sh
# Or download from GitHub: https://github.com/alexellis/k3sup/releases
Thanks for using k3sup!`

const thanksForUsing = `Thanks for using k3sup!`

0 comments on commit 6aa156d

Please sign in to comment.
You can’t perform that action at this time.