Disallow both pre and proxy flags for check (#2026)

Signed-off-by: Alena Varkockova <varkockova.a@gmail.com>
This commit is contained in:
Alena Varkockova 2019-01-02 22:36:04 +01:00 committed by Andrew Seigner
parent a9511aba06
commit ef02cd6828
1 changed files with 18 additions and 3 deletions

View File

@ -1,6 +1,7 @@
package cmd
import (
"errors"
"fmt"
"io"
"os"
@ -57,8 +58,8 @@ non-zero exit code.`,
# Check that the Linkerd data plane proxies in the "app" namespace are up and running
linkerd check --proxy --namespace app`,
Args: cobra.NoArgs,
Run: func(cmd *cobra.Command, args []string) {
configureAndRunChecks(options)
RunE: func(cmd *cobra.Command, args []string) error {
return configureAndRunChecks(options)
},
}
@ -73,7 +74,11 @@ non-zero exit code.`,
return cmd
}
func configureAndRunChecks(options *checkOptions) {
func configureAndRunChecks(options *checkOptions) error {
err := options.validate()
if err != nil {
return fmt.Errorf("Validation error when executing check command: %v", err)
}
checks := []healthcheck.Checks{healthcheck.KubernetesAPIChecks}
if options.preInstallOnly {
@ -103,6 +108,7 @@ func configureAndRunChecks(options *checkOptions) {
success := runChecks(os.Stdout, hc)
// this empty line separates final results from the checks list in the output
fmt.Println("")
if !success {
@ -111,6 +117,15 @@ func configureAndRunChecks(options *checkOptions) {
}
fmt.Printf("Status check results are %s\n", okStatus)
return nil
}
func (o *checkOptions) validate() error {
if o.preInstallOnly && o.dataPlaneOnly {
return errors.New("--pre and --proxy flags are mutually exclusive")
}
return nil
}
func runChecks(w io.Writer, hc *healthcheck.HealthChecker) bool {