Skip to content

Commit

Permalink
Wish i could get this to be inline
Browse files Browse the repository at this point in the history
  • Loading branch information
marccampbell committed Jul 6, 2019
1 parent 342eedf commit b229d56
Show file tree
Hide file tree
Showing 14 changed files with 1,023 additions and 141 deletions.
23 changes: 15 additions & 8 deletions Makefile
Expand Up @@ -8,10 +8,18 @@ all: test manager
test: generate fmt vet manifests
go test ./pkg/... ./cmd/... -coverprofile cover.out

# Build manager binary
.PHONY: manager
manager: generate fmt vet
go build -o bin/manager github.com/replicatedhq/troubleshoot/cmd/manager

.PHONY: troubleshoot
troubleshoot: generate fmt vet
go build -o bin/troubleshoot github.com/replicatedhq/troubleshoot/cmd/troubleshoot

.PHONY: preflight
preflight: generate fmt vet
go build -o bin/preflight github.com/replicatedhq/troubleshoot/cmd/preflight

# Run against the configured Kubernetes cluster in ~/.kube/config
run: generate fmt vet
go run ./cmd/manager/main.go
Expand All @@ -26,22 +34,21 @@ deploy: manifests
kustomize build config/default | kubectl apply -f -

# Generate manifests e.g. CRD, RBAC etc.
manifests: controller-gen
manifests:
controller-gen paths=./pkg/apis/...

# Run go fmt against code
.PHONY: fmt
fmt:
go fmt ./pkg/... ./cmd/...

# Run go vet against code
.PHONY: vet
vet:
go vet ./pkg/... ./cmd/...


.PHONY: generate
generate: controller-gen client-gen
controller-gen object:headerFile=./hack/boilerplate.go.txt paths=./api/...
client-gen go run ../../vendor/k8s.io/code-generator/cmd/client-gen/main.go --output-package=github.com/replicatedhq/troubleshoot/pkg/client --clientset-name troubleshootclientset --input-base github.com/replicatedhq/troubleshoot/pkg/apis --input troubleshoot/v1beta1 -h ./hack/boilerplate.go.txt
generate: controller-gen # client-gen
controller-gen object:headerFile=./hack/boilerplate.go.txt paths=./pkg/apis/...
# client-gen --output-package=github.com/replicatedhq/troubleshoot/pkg/client --clientset-name troubleshootclientset --input-base github.com/replicatedhq/troubleshoot/pkg/apis --input troubleshoot/v1beta1 -h ./hack/boilerplate.go.txt

# Build the docker image
docker-build: test
Expand Down
2 changes: 1 addition & 1 deletion cmd/manager/main.go
Expand Up @@ -32,7 +32,7 @@ import (

func main() {
var metricsAddr string
flag.StringVar(&metricsAddr, "metrics-addr", ":8080", "The address the metric endpoint binds to.")
flag.StringVar(&metricsAddr, "metrics-addr", ":8088", "The address the metric endpoint binds to.")
flag.Parse()
logf.SetLogger(logf.ZapLogger(false))
log := logf.Log.WithName("entrypoint")
Expand Down
32 changes: 32 additions & 0 deletions cmd/troubleshoot/cli/collect.go
@@ -0,0 +1,32 @@
package cli

import (
"github.com/spf13/cobra"
"github.com/spf13/viper"
)

func Collect() *cobra.Command {
cmd := &cobra.Command{
Use: "collect",
Short: "collect a support bundle from a cluster",
Long: `...`,
PreRun: func(cmd *cobra.Command, args []string) {
viper.BindPFlag("collectors", cmd.Flags().Lookup("collectors"))
viper.BindPFlag("namespace", cmd.Flags().Lookup("namespace"))
viper.BindPFlag("kubecontext", cmd.Flags().Lookup("kubecontext"))
},
RunE: func(cmd *cobra.Command, args []string) error {

return nil
},
}

cmd.Flags().String("collectors", "", "name of the collectors to use")
cmd.Flags().String("namespace", "", "namespace the collectors can be found in")

cmd.Flags().String("kubecontext", "", "the kubecontext to use when connecting")

viper.BindPFlags(cmd.Flags())

return cmd
}
39 changes: 39 additions & 0 deletions cmd/troubleshoot/cli/root.go
@@ -0,0 +1,39 @@
package cli

import (
"fmt"
"os"
"strings"

"github.com/spf13/cobra"
"github.com/spf13/viper"
)

func RootCmd() *cobra.Command {
cmd := &cobra.Command{
Use: "troubleshoot",
Short: "Generate and manage support bundles",
Long: `A support bundle is an archive of files, output, metrics and state
from a server that can be used to assist when troubleshooting a server.`,
SilenceUsage: true,
}

cobra.OnInitialize(initConfig)

cmd.AddCommand(Collect())

viper.SetEnvKeyReplacer(strings.NewReplacer("-", "_"))
return cmd
}

func InitAndExecute() {
if err := RootCmd().Execute(); err != nil {
fmt.Println(err)
os.Exit(1)
}
}

func initConfig() {
viper.SetEnvPrefix("TROUBLESHOT")
viper.AutomaticEnv()
}
7 changes: 7 additions & 0 deletions cmd/troubleshoot/main.go
@@ -0,0 +1,7 @@
package main

import "github.com/replicatedhq/troubleshoot/cmd/troubleshoot/cli"

func main() {
cli.InitAndExecute()
}

0 comments on commit b229d56

Please sign in to comment.