Compare commits

...

1 Commits

Author SHA1 Message Date
Ashwathi Shiva
ed7e97332b Preflight fix output to remove symbols (#340)
* removed symbols and have all preflight checks working
2020-04-22 09:01:07 -04:00
3 changed files with 54 additions and 56 deletions

View File

@@ -3,7 +3,6 @@ package main
import (
"fmt"
"github.com/kyokomi/emoji"
ansi "github.com/mattn/go-colorable"
"github.com/qlik-oss/sense-installer/pkg/preflight"
"github.com/ttacon/chalk"
@@ -38,7 +37,7 @@ func pfDnsCheckCmd(q *qliksense.Qliksense) *cobra.Command {
// Preflight DNS check
namespace, kubeConfigContents, err := preflight.InitPreflight()
if err != nil {
emoji.Fprintf(out, "%s\n", chalk.Red.Color(":heavy_multiplication_x: Preflight DNS check"))
fmt.Fprintf(out, "%s\n", chalk.Red.Color("Preflight DNS check FAILED"))
fmt.Printf("Error: %v\n", err)
return nil
}
@@ -46,11 +45,11 @@ func pfDnsCheckCmd(q *qliksense.Qliksense) *cobra.Command {
namespace = "default"
}
if err = qp.CheckDns(namespace, kubeConfigContents); err != nil {
emoji.Fprintf(out, "%s\n", chalk.Red.Color(":heavy_multiplication_x: Preflight DNS check"))
fmt.Fprintf(out, "%s\n", chalk.Red.Color("Preflight DNS check FAILED"))
fmt.Printf("Error: %v\n", err)
return nil
}
emoji.Fprintf(out, "%s\n", chalk.Green.Color(":heavy_check_mark: Preflight DNS check"))
fmt.Fprintf(out, "%s\n", chalk.Green.Color("Preflight DNS check PASSED"))
return nil
},
}
@@ -76,16 +75,16 @@ func pfK8sVersionCheckCmd(q *qliksense.Qliksense) *cobra.Command {
// Preflight Kubernetes minimum version check
namespace, kubeConfigContents, err := preflight.InitPreflight()
if err != nil {
emoji.Fprintf(out, "%s\n", chalk.Red.Color(":heavy_multiplication_x: Preflight kubernetes minimum version check"))
fmt.Fprintf(out, "%s\n", chalk.Red.Color("Preflight kubernetes minimum version check FAILED"))
fmt.Printf("Error: %v\n", err)
return nil
}
if err = qp.CheckK8sVersion(namespace, kubeConfigContents); err != nil {
emoji.Fprintf(out, "%s\n", chalk.Red.Color(":heavy_multiplication_x: Preflight kubernetes minimum version check"))
fmt.Fprintf(out, "%s\n", chalk.Red.Color("Preflight kubernetes minimum version check FAILED"))
fmt.Printf("Error: %v\n", err)
return nil
}
emoji.Fprintf(out, "%s\n", chalk.Green.Color(":heavy_check_mark: Preflight kubernetes minimum version check"))
fmt.Fprintf(out, "%s\n", chalk.Green.Color("Preflight kubernetes minimum version check PASSED"))
return nil
},
}
@@ -113,7 +112,7 @@ func pfAllChecksCmd(q *qliksense.Qliksense) *cobra.Command {
fmt.Printf("Running all preflight checks...\n\n")
namespace, kubeConfigContents, err := preflight.InitPreflight()
if err != nil {
emoji.Fprintf(out, "%s\n", chalk.Red.Color(":heavy_multiplication_x: Unable to run the preflight checks suite"))
fmt.Fprintf(out, "%s\n", chalk.Red.Color("Unable to run the preflight checks suite"))
fmt.Printf("Error: %v\n", err)
return nil
}
@@ -121,11 +120,11 @@ func pfAllChecksCmd(q *qliksense.Qliksense) *cobra.Command {
namespace = "default"
}
if err = qp.RunAllPreflightChecks(kubeConfigContents, namespace, preflightOpts); err != nil {
emoji.Fprintf(out, "%s\n", chalk.Red.Color(":heavy_multiplication_x: 1 or more preflight checks have FAILED"))
fmt.Fprintf(out, "%s\n", chalk.Red.Color("1 or more preflight checks have FAILED"))
fmt.Println("Completed running all preflight checks")
return nil
}
emoji.Fprintf(out, "%s\n\n", chalk.Green.Color(":heavy_check_mark: All preflight checks have PASSED"))
fmt.Fprintf(out, "%s\n\n", chalk.Green.Color("All preflight checks have PASSED"))
return nil
},
}
@@ -157,7 +156,7 @@ func pfDeploymentCheckCmd(q *qliksense.Qliksense) *cobra.Command {
// Preflight deployments check
namespace, kubeConfigContents, err := preflight.InitPreflight()
if err != nil {
emoji.Fprintf(out, "%s\n", chalk.Red.Color(":heavy_multiplication_x: Preflight deployment check"))
fmt.Fprintf(out, "%s\n", chalk.Red.Color("Preflight deployment check FAILED"))
fmt.Printf("Error: %v\n", err)
return nil
}
@@ -165,11 +164,11 @@ func pfDeploymentCheckCmd(q *qliksense.Qliksense) *cobra.Command {
namespace = "default"
}
if err = qp.CheckDeployment(namespace, kubeConfigContents); err != nil {
emoji.Fprintf(out, "%s\n", chalk.Red.Color(":heavy_multiplication_x: Preflight deployment check"))
fmt.Fprintf(out, "%s\n", chalk.Red.Color("Preflight deployment check FAILED"))
fmt.Printf("Error: %v\n", err)
return nil
}
emoji.Fprintf(out, "%s\n", chalk.Green.Color(":heavy_check_mark: Preflight deployment check"))
fmt.Fprintf(out, "%s\n", chalk.Green.Color("Preflight deployment check PASSED"))
return nil
},
}
@@ -195,7 +194,7 @@ func pfServiceCheckCmd(q *qliksense.Qliksense) *cobra.Command {
// Preflight service check
namespace, kubeConfigContents, err := preflight.InitPreflight()
if err != nil {
emoji.Fprintf(out, "%s\n", chalk.Red.Color(":heavy_multiplication_x: Preflight service check"))
fmt.Fprintf(out, "%s\n", chalk.Red.Color("Preflight service check FAILED"))
fmt.Printf("Error: %v\n", err)
return nil
}
@@ -204,11 +203,11 @@ func pfServiceCheckCmd(q *qliksense.Qliksense) *cobra.Command {
namespace = "default"
}
if err = qp.CheckService(namespace, kubeConfigContents); err != nil {
emoji.Fprintf(out, "%s\n", chalk.Red.Color(":heavy_multiplication_x: Preflight service check"))
fmt.Fprintf(out, "%s\n", chalk.Red.Color("Preflight service check FAILED"))
fmt.Printf("Error: %v\n", err)
return nil
}
emoji.Fprintf(out, "%s\n", chalk.Green.Color(":heavy_check_mark: Preflight service check"))
fmt.Fprintf(out, "%s\n", chalk.Green.Color("Preflight service check PASSED"))
return nil
},
}
@@ -234,7 +233,7 @@ func pfPodCheckCmd(q *qliksense.Qliksense) *cobra.Command {
// Preflight pod check
namespace, kubeConfigContents, err := preflight.InitPreflight()
if err != nil {
emoji.Fprintf(out, "%s\n", chalk.Red.Color(":heavy_multiplication_x: Preflight pod check"))
fmt.Fprintf(out, "%s\n", chalk.Red.Color("Preflight pod check FAILED"))
fmt.Printf("Error: %v\n", err)
return nil
}
@@ -242,11 +241,11 @@ func pfPodCheckCmd(q *qliksense.Qliksense) *cobra.Command {
namespace = "default"
}
if err = qp.CheckPod(namespace, kubeConfigContents); err != nil {
emoji.Fprintf(out, "%s\n", chalk.Red.Color(":heavy_multiplication_x: Preflight pod check"))
fmt.Fprintf(out, "%s\n", chalk.Red.Color("Preflight pod check FAILED"))
fmt.Printf("Error: %v\n", err)
return nil
}
emoji.Fprintf(out, "%s\n", chalk.Green.Color(":heavy_check_mark: Preflight pod check"))
fmt.Fprintf(out, "%s\n", chalk.Green.Color("Preflight pod check PASSED"))
return nil
},
}
@@ -272,16 +271,16 @@ func pfCreateRoleCheckCmd(q *qliksense.Qliksense) *cobra.Command {
// Preflight role check
namespace, _, err := preflight.InitPreflight()
if err != nil {
emoji.Fprintf(out, "%s\n", chalk.Red.Color(":heavy_multiplication_x: Preflight role check"))
fmt.Fprintf(out, "%s\n", chalk.Red.Color("Preflight role check FAILED"))
fmt.Printf("Error: %v\n", err)
return nil
}
if err = qp.CheckCreateRole(namespace); err != nil {
emoji.Fprintf(out, "%s\n", chalk.Red.Color(":heavy_multiplication_x: Preflight role check"))
fmt.Fprintf(out, "%s\n", chalk.Red.Color("Preflight role check FAILED"))
fmt.Printf("Error: %v\n", err)
return nil
}
emoji.Fprintf(out, "%s\n", chalk.Green.Color(":heavy_check_mark: Preflight role check"))
fmt.Fprintf(out, "%s\n", chalk.Green.Color("Preflight role check PASSED"))
return nil
},
}
@@ -307,16 +306,16 @@ func pfCreateRoleBindingCheckCmd(q *qliksense.Qliksense) *cobra.Command {
// Preflight createRoleBinding check
namespace, _, err := preflight.InitPreflight()
if err != nil {
emoji.Fprintf(out, "%s\n", chalk.Red.Color(":heavy_multiplication_x: Preflight rolebinding check"))
fmt.Fprintf(out, "%s\n", chalk.Red.Color("Preflight rolebinding check FAILED"))
fmt.Printf("Error: %v\n", err)
return nil
}
if err = qp.CheckCreateRoleBinding(namespace); err != nil {
emoji.Fprintf(out, "%s\n", chalk.Red.Color(":heavy_multiplication_x: Preflight rolebinding check"))
fmt.Fprintf(out, "%s\n", chalk.Red.Color("Preflight rolebinding check FAILED"))
fmt.Printf("Error: %v\n", err)
return nil
}
emoji.Fprintf(out, "%s\n", chalk.Green.Color(":heavy_check_mark: Preflight rolebinding check"))
fmt.Fprintf(out, "%s\n", chalk.Green.Color("Preflight rolebinding check PASSED"))
return nil
},
}
@@ -342,16 +341,16 @@ func pfCreateServiceAccountCheckCmd(q *qliksense.Qliksense) *cobra.Command {
// Preflight createServiceAccount check
namespace, _, err := preflight.InitPreflight()
if err != nil {
emoji.Fprintf(out, "%s\n", chalk.Red.Color(":heavy_multiplication_x: Preflight ServiceAccount check"))
fmt.Fprintf(out, "%s\n", chalk.Red.Color("Preflight ServiceAccount check FAILED"))
fmt.Printf("Error: %v\n", err)
return nil
}
if err = qp.CheckCreateServiceAccount(namespace); err != nil {
emoji.Fprintf(out, "%s\n", chalk.Red.Color(":heavy_multiplication_x: Preflight ServiceAccount check"))
fmt.Fprintf(out, "%s\n", chalk.Red.Color("Preflight ServiceAccount check FAILED"))
fmt.Printf("Error: %v\n", err)
return nil
}
emoji.Fprintf(out, "%s\n", chalk.Green.Color(":heavy_check_mark: Preflight rolebinding check"))
fmt.Fprintf(out, "%s\n", chalk.Green.Color("Preflight ServiceAccount check PASSED"))
return nil
},
}
@@ -376,16 +375,16 @@ func pfCreateAuthCheckCmd(q *qliksense.Qliksense) *cobra.Command {
// Preflight authcheck
namespace, kubeConfigContents, err := preflight.InitPreflight()
if err != nil {
emoji.Fprintf(out, "%s\n", chalk.Red.Color(":heavy_multiplication_x: Preflight authcheck"))
fmt.Fprintf(out, "%s\n", chalk.Red.Color("Preflight authcheck FAILED"))
fmt.Printf("Error: %v\n", err)
return nil
}
if err = qp.CheckCreateRB(namespace, kubeConfigContents); err != nil {
emoji.Fprintf(out, "%s\n", chalk.Red.Color(":heavy_multiplication_x: Preflight authcheck"))
fmt.Fprintf(out, "%s\n", chalk.Red.Color("Preflight authcheck FAILED"))
fmt.Printf("Error: %v\n", err)
return nil
}
emoji.Fprintf(out, "%s\n", chalk.Green.Color(":heavy_check_mark: Preflight authcheck"))
fmt.Fprintf(out, "%s\n", chalk.Green.Color("Preflight authcheck PASSED"))
return nil
},
}
@@ -411,7 +410,7 @@ func pfMongoCheckCmd(q *qliksense.Qliksense) *cobra.Command {
// Preflight mongo check
namespace, kubeConfigContents, err := preflight.InitPreflight()
if err != nil {
emoji.Fprintf(out, "%s\n", chalk.Red.Color(":heavy_multiplication_x: Preflight mongo check"))
fmt.Fprintf(out, "%s\n", chalk.Red.Color("Preflight mongo check FAILED"))
fmt.Printf("Error: %v\n", err)
return nil
}
@@ -419,11 +418,11 @@ func pfMongoCheckCmd(q *qliksense.Qliksense) *cobra.Command {
namespace = "default"
}
if err = qp.CheckMongo(kubeConfigContents, namespace, preflightOpts); err != nil {
emoji.Fprintf(out, "%s\n", chalk.Red.Color(":heavy_multiplication_x: Preflight mongo check"))
fmt.Fprintf(out, "%s\n", chalk.Red.Color("Preflight mongo check FAILED"))
fmt.Printf("Error: %v\n", err)
return nil
}
emoji.Fprintf(out, "%s\n", chalk.Green.Color(":heavy_check_mark: Preflight mongo check"))
fmt.Fprintf(out, "%s\n", chalk.Green.Color("Preflight mongo check PASSED"))
return nil
},
}

View File

@@ -3,103 +3,102 @@ package preflight
import (
"fmt"
"github.com/kyokomi/emoji"
ansi "github.com/mattn/go-colorable"
"github.com/pkg/errors"
"github.com/ttacon/chalk"
)
func (qp *QliksensePreflight) RunAllPreflightChecks(kubeConfigContents []byte, namespace string, preflightOpts *PreflightOptions) error {
out := ansi.NewColorableStdout()
checkCount := 0
totalCount := 0
out := ansi.NewColorableStdout()
// Preflight minimum kuberenetes version check
if err := qp.CheckK8sVersion(namespace, kubeConfigContents); err != nil {
emoji.Fprintf(out, "%s\n", chalk.Red.Color(":heavy_multiplication_x: Preflight kubernetes minimum version check"))
fmt.Fprintf(out, "%s\n", chalk.Red.Color("Preflight kubernetes minimum version check FAILED"))
fmt.Printf("Error: %v\n\n", err)
} else {
emoji.Fprintf(out, "%s\n\n", chalk.Green.Color(":heavy_check_mark: Preflight kubernetes minimum version check"))
fmt.Fprintf(out, "%s\n\n", chalk.Green.Color("Preflight kubernetes minimum version check PASSED"))
checkCount++
}
totalCount++
// Preflight deployment check
if err := qp.CheckDeployment(namespace, kubeConfigContents); err != nil {
emoji.Fprintf(out, "%s\n", chalk.Red.Color(":heavy_multiplication_x: Preflight deployment check"))
fmt.Fprintf(out, "%s\n", chalk.Red.Color("Preflight deployment check FAILED"))
fmt.Printf("Error: %v\n\n", err)
} else {
emoji.Fprintf(out, "%s\n\n", chalk.Green.Color(":heavy_check_mark: Preflight deployment check"))
fmt.Fprintf(out, "%s\n\n", chalk.Green.Color("Preflight deployment check PASSED"))
checkCount++
}
totalCount++
// Preflight service check
if err := qp.CheckService(namespace, kubeConfigContents); err != nil {
emoji.Fprintf(out, "%s\n", chalk.Red.Color(":heavy_multiplication_x: Preflight service check"))
fmt.Fprintf(out, "%s\n", chalk.Red.Color("Preflight service check FAILED"))
fmt.Printf("Error: %v\n\n", err)
} else {
emoji.Fprintf(out, "%s\n\n", chalk.Green.Color(":heavy_check_mark: Preflight service check"))
fmt.Fprintf(out, "%s\n\n", chalk.Green.Color("Preflight service check PASSED"))
checkCount++
}
totalCount++
// Preflight pod check
if err := qp.CheckPod(namespace, kubeConfigContents); err != nil {
emoji.Fprintf(out, "%s\n", chalk.Red.Color(":heavy_multiplication_x: Preflight pod check"))
fmt.Fprintf(out, "%s\n", chalk.Red.Color("Preflight pod check FAILED"))
fmt.Printf("Error: %v\n\n", err)
} else {
emoji.Fprintf(out, "%s\n\n", chalk.Green.Color(":heavy_check_mark: Preflight pod check"))
fmt.Fprintf(out, "%s\n\n", chalk.Green.Color("Preflight pod check PASSED"))
checkCount++
}
totalCount++
// Preflight role check
if err := qp.CheckCreateRole(namespace); err != nil {
emoji.Fprintf(out, "%s\n", chalk.Red.Color(":heavy_multiplication_x: Preflight role check"))
fmt.Fprintf(out, "%s\n", chalk.Red.Color("Preflight role check FAILED"))
fmt.Printf("Error: %v\n\n", err)
} else {
emoji.Fprintf(out, "%s\n\n", chalk.Green.Color(":heavy_check_mark: Preflight role check"))
fmt.Fprintf(out, "%s\n\n", chalk.Green.Color("Preflight role check PASSED"))
checkCount++
}
totalCount++
// Preflight rolebinding check
if err := qp.CheckCreateRoleBinding(namespace); err != nil {
emoji.Fprintf(out, "%s\n", chalk.Red.Color(":heavy_multiplication_x: Preflight rolebinding check"))
fmt.Fprintf(out, "%s\n", chalk.Red.Color(" Preflight rolebinding check FAILED"))
fmt.Printf("Error: %v\n\n", err)
} else {
emoji.Fprintf(out, "%s\n\n", chalk.Green.Color(":heavy_check_mark: Preflight rolebinding check"))
fmt.Fprintf(out, "%s\n\n", chalk.Green.Color("Preflight rolebinding check PASSED"))
checkCount++
}
totalCount++
// Preflight serviceaccount check
if err := qp.CheckCreateServiceAccount(namespace); err != nil {
emoji.Fprintf(out, "%s\n", chalk.Red.Color(":heavy_multiplication_x: Preflight serviceaccount check"))
fmt.Fprintf(out, "%s\n", chalk.Red.Color(" Preflight serviceaccount check FAILED"))
fmt.Printf("Error: %v\n\n", err)
} else {
emoji.Fprintf(out, "%s\n\n", chalk.Green.Color(":heavy_check_mark: Preflight serviceaccount check"))
fmt.Fprintf(out, "%s\n\n", chalk.Green.Color("Preflight serviceaccount check PASSED"))
checkCount++
}
totalCount++
// Preflight mongo check
if err := qp.CheckMongo(kubeConfigContents, namespace, preflightOpts); err != nil {
emoji.Fprintf(out, "%s\n", chalk.Red.Color(":heavy_multiplication_x: Preflight mongo check"))
fmt.Fprintf(out, "%s\n", chalk.Red.Color(" Preflight mongo check FAILED"))
fmt.Printf("Error: %v\n\n", err)
} else {
emoji.Fprintf(out, "%s\n\n", chalk.Green.Color(":heavy_check_mark: Preflight mongo check"))
fmt.Fprintf(out, "%s\n\n", chalk.Green.Color("Preflight mongo check PASSED"))
checkCount++
}
totalCount++
// Preflight DNS check
if err := qp.CheckDns(namespace, kubeConfigContents); err != nil {
emoji.Fprintf(out, "%s\n", chalk.Red.Color(":heavy_multiplication_x: Preflight DNS check"))
fmt.Fprintf(out, "%s\n", chalk.Red.Color(" Preflight DNS check FAILED"))
fmt.Printf("Error: %v\n\n", err)
} else {
emoji.Fprintf(out, "%s\n\n", chalk.Green.Color(":heavy_check_mark: Preflight DNS check"))
fmt.Fprintf(out, "%s\n\n", chalk.Green.Color("Preflight DNS check PASSED"))
checkCount++
}
totalCount++

View File

@@ -60,7 +60,7 @@ func (qp *QliksensePreflight) mongoConnCheck(kubeConfigContents []byte, namespac
caCertSecretName = "preflight-mongo-test-cacert"
caCertSecret, err := qp.createSecret(clientset, namespace, preflightOpts.MongoOptions.CaCertFile, caCertSecretName)
if err != nil {
err = fmt.Errorf("unable to create a create ca cert kubernetes secret: %v\n", err)
err = fmt.Errorf("unable to create a ca cert kubernetes secret: %v\n", err)
return err
}
@@ -71,7 +71,7 @@ func (qp *QliksensePreflight) mongoConnCheck(kubeConfigContents []byte, namespac
clientCertSecretName = "preflight-mongo-test-clientcert"
clientCertSecret, err := qp.createSecret(clientset, namespace, preflightOpts.MongoOptions.ClientCertFile, clientCertSecretName)
if err != nil {
err = fmt.Errorf("unable to create a create client cert kubernetes secret: %v\n", err)
err = fmt.Errorf("unable to create a client cert kubernetes secret: %v\n", err)
return err
}