diff --git a/cmd/src/validate.go b/cmd/src/validate.go deleted file mode 100644 index ee67f5fa9a..0000000000 --- a/cmd/src/validate.go +++ /dev/null @@ -1,44 +0,0 @@ -package main - -import ( - "flag" - "fmt" -) - -var validateCommands commander - -func init() { - usage := `'src validate' is a tool that validates a Sourcegraph instance. - -EXPERIMENTAL: 'validate' is an experimental command in the 'src' tool. - -Please visit https://docs.sourcegraph.com/admin/validation for documentation of the validate command. - -Usage: - - src validate command [command options] - -The commands are: - - install validates a Sourcegraph installation - kube validates a Sourcegraph deployment on a Kubernetes cluster - -Use "src validate [command] -h" for more information about a command. -` - - flagSet := flag.NewFlagSet("validate", flag.ExitOnError) - handler := func(args []string) error { - validateCommands.run(flagSet, "src validate", usage, args) - return nil - } - - // Register the command - commands = append(commands, &command{ - flagSet: flagSet, - aliases: []string{"validate"}, - handler: handler, - usageFunc: func() { - fmt.Println(usage) - }, - }) -} diff --git a/cmd/src/validate_install.go b/cmd/src/validate_install.go deleted file mode 100644 index b298543f3d..0000000000 --- a/cmd/src/validate_install.go +++ /dev/null @@ -1,109 +0,0 @@ -package main - -import ( - "context" - "flag" - "fmt" - "io" - "os" - "strings" - - "github.com/mattn/go-isatty" - - "github.com/sourcegraph/src-cli/internal/api" - "github.com/sourcegraph/src-cli/internal/validate/install" - - "github.com/sourcegraph/sourcegraph/lib/errors" -) - -func init() { - usage := `'src validate install' is a tool that validates a Sourcegraph installation. - -Examples: - - Run default checks: - - $ src validate install - - Provide a YAML configuration file: - - $ src validate install config.yml - - Provide a JSON configuration file: - - $ src validate install config.json - -Environmental variables - - SRC_GITHUB_TOKEN GitHub access token for validation features - -` - - flagSet := flag.NewFlagSet("install", flag.ExitOnError) - usageFunc := func() { - fmt.Fprintf(flag.CommandLine.Output(), "Usage of 'src validate %s':\n", flagSet.Name()) - flagSet.PrintDefaults() - fmt.Println(usage) - } - var ( - apiFlags = api.NewFlags(flagSet) - ) - - handler := func(args []string) error { - if err := flagSet.Parse(args); err != nil { - return err - } - - client := cfg.apiClient(apiFlags, flagSet.Output()) - - var validationSpec *install.ValidationSpec - - if len(flagSet.Args()) == 1 { - fileName := flagSet.Arg(0) - f, err := os.ReadFile(fileName) - if err != nil { - return errors.Wrap(err, "failed to read installation validation config from file") - } - - if strings.HasSuffix(fileName, ".yaml") || strings.HasSuffix(fileName, ".yml") { - validationSpec, err = install.LoadYamlConfig(f) - if err != nil { - return err - } - } - - if strings.HasSuffix(fileName, ".json") { - validationSpec, err = install.LoadJsonConfig(f) - if err != nil { - return err - } - } - } - - if !isatty.IsTerminal(os.Stdin.Fd()) { - // stdin is a pipe not a terminal - input, err := io.ReadAll(os.Stdin) - if err != nil { - return errors.Wrap(err, "failed to read installation validation config from pipe") - } - validationSpec, err = install.LoadYamlConfig(input) - if err != nil { - return err - } - } - - if validationSpec == nil { - validationSpec = install.DefaultConfig() - } - - validationSpec.ExternalService.Config.GitHub.Token = os.Getenv("SRC_GITHUB_TOKEN") - - return install.Validate(context.Background(), client, validationSpec) - } - - validateCommands = append(validateCommands, &command{ - flagSet: flagSet, - handler: handler, - usageFunc: usageFunc, - }) -} diff --git a/cmd/src/validate_kube.go b/cmd/src/validate_kube.go deleted file mode 100644 index 46f9374f42..0000000000 --- a/cmd/src/validate_kube.go +++ /dev/null @@ -1,121 +0,0 @@ -package main - -import ( - "context" - "flag" - "fmt" - "path/filepath" - - "k8s.io/client-go/kubernetes" - _ "k8s.io/client-go/plugin/pkg/client/auth/azure" - _ "k8s.io/client-go/plugin/pkg/client/auth/gcp" - "k8s.io/client-go/tools/clientcmd" - "k8s.io/client-go/util/homedir" - - "github.com/sourcegraph/src-cli/internal/validate/kube" - - "github.com/sourcegraph/sourcegraph/lib/errors" -) - -func init() { - usage := `'src validate kube' is a tool that validates a Kubernetes based Sourcegraph deployment - -Examples: - - Run default deployment validation: - $ src validate kube - - Specify Kubernetes namespace: - $ src validate kube --namespace sourcegraph - - Specify the kubeconfig file())) location: - $ src validate kube --kubeconfig ~/.kube/config - - Suppress output (useful for CI/CD pipelines) - $ src validate kube --quiet - - Validate EKS cluster: - $ src validate kube --eks - - Validate GKE cluster: - $ src validate kube --gke - - Validate AKS cluster: - $ src validate kube --aks -` - - flagSet := flag.NewFlagSet("kube", flag.ExitOnError) - usageFunc := func() { - fmt.Fprintf(flag.CommandLine.Output(), "Usage of 'src validate %s':\n", flagSet.Name()) - flagSet.PrintDefaults() - fmt.Println(usage) - } - - var ( - kubeConfig *string - namespace = flagSet.String("namespace", "", "(optional) specify the kubernetes namespace to use") - quiet = flagSet.Bool("quiet", false, "(optional) suppress output and return exit status only") - eks = flagSet.Bool("eks", false, "(optional) validate EKS cluster") - gke = flagSet.Bool("gke", false, "(optional) validate GKE cluster") - aks = flagSet.Bool("aks", false, "(optional) validate AKS cluster") - ) - - if home := homedir.HomeDir(); home != "" { - kubeConfig = flagSet.String( - "kubeconfig", - filepath.Join(home, ".kube", "config"), - "(optional) absolute path to the kubeconfig file", - ) - } else { - kubeConfig = flagSet.String("kubeconfig", "", "absolute path to the kubeconfig file") - } - - handler := func(args []string) error { - ctx := context.Background() - if err := flagSet.Parse(args); err != nil { - return err - } - - // use the current context in kubeConfig - config, err := clientcmd.BuildConfigFromFlags("", *kubeConfig) - if err != nil { - return errors.Wrap(err, "failed to load kubernetes config") - } - - clientSet, err := kubernetes.NewForConfig(config) - if err != nil { - return errors.Wrap(err, "failed to create kubernetes client") - } - - // parse through flag options - var options []kube.Option - - if *namespace != "" { - options = append(options, kube.WithNamespace(*namespace)) - } - - if *quiet { - options = append(options, kube.Quiet()) - } - - if *eks { - options = append(options, kube.GenerateAWSClients(ctx)) - } - - if *gke { - options = append(options, kube.Gke()) - } - - if *aks { - options = append(options, kube.Aks()) - } - - return kube.Validate(context.Background(), clientSet, config, options...) - } - - validateCommands = append(validateCommands, &command{ - flagSet: flagSet, - handler: handler, - usageFunc: usageFunc, - }) -}