Skip to content

Commit

Permalink
Merge pull request #2 from replicatedhq/collector-job
Browse files Browse the repository at this point in the history
Run cluster-info in a collector pod
  • Loading branch information
marccampbell authored Jul 11, 2019
2 parents 7371732 + d60de90 commit 5e1893b
Show file tree
Hide file tree
Showing 41 changed files with 1,671 additions and 112 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,5 @@ bin
*.swp
*.swo
*~

dist
17 changes: 0 additions & 17 deletions Dockerfile

This file was deleted.

33 changes: 18 additions & 15 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -24,20 +24,20 @@ collector: generate fmt vet
preflight: generate fmt vet
go build -o bin/preflight github.com/replicatedhq/troubleshoot/cmd/preflight

# Run against the configured Kubernetes cluster in ~/.kube/config
.PHONY: run
run: generate fmt vet
go run ./cmd/manager/main.go
TROUBLESHOOT_EXTERNAL_MANAGER=1 go run ./cmd/manager/main.go

# Install CRDs into a cluster
.PHONY: install
install: manifests
kubectl apply -f config/crds

# Deploy controller in the configured Kubernetes cluster in ~/.kube/config
.PHONY: deploy
deploy: manifests
kubectl apply -f config/crds
kustomize build config/default | kubectl apply -f -

# Generate manifests e.g. CRD, RBAC etc.
.PHONY: manifests
manifests:
controller-gen paths=./pkg/apis/... output:dir=./config/crds

Expand All @@ -54,16 +54,6 @@ 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
docker build . -t ${IMG}
@echo "updating kustomize image patch file for manager resource"
sed -i'' -e 's@image: .*@image: '"${IMG}"'@' ./config/default/manager_image_patch.yaml

# Push the docker image
docker-push:
docker push ${IMG}

# find or download controller-gen
# download controller-gen if necessary
controller-gen:
Expand All @@ -82,3 +72,16 @@ CLIENT_GEN=$(shell go env GOPATH)/bin/client-gen
else
CLIENT_GEN=$(shell which client-gen)
endif

.PHONY: snapshot-release
snapshot-release:
curl -sL https://git.io/goreleaser | bash -s -- --rm-dist --snapshot --config deploy/.goreleaser.snapshot.yml

.PHONY: local-release
local-release: snapshot-release
docker tag replicatedhq/troubleshoot:alpha localhost:32000/troubleshoot:alpha
docker tag replicatedhq/preflight:alpha localhost:32000/preflight:alpha
docker tag replicatedhq/troubleshoot-manager:alpha localhost:32000/troubleshoot-manager:alpha
docker push localhost:32000/troubleshoot:alpha
docker push localhost:32000/preflight:alpha
docker push localhost:32000/troubleshoot-manager:alpha
3 changes: 2 additions & 1 deletion cmd/collector/cli/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ func RootCmd() *cobra.Command {

cobra.OnInitialize(initConfig)

cmd.AddCommand(Run())
cmd.AddCommand(Server())

viper.SetEnvKeyReplacer(strings.NewReplacer("-", "_"))
Expand All @@ -33,6 +34,6 @@ func InitAndExecute() {
}

func initConfig() {
viper.SetEnvPrefix("TROUBLESHOT")
viper.SetEnvPrefix("TROUBLESHOOT")
viper.AutomaticEnv()
}
45 changes: 45 additions & 0 deletions cmd/collector/cli/run.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package cli

import (
"io/ioutil"

"github.com/replicatedhq/troubleshoot/pkg/collect"
"github.com/spf13/cobra"
"github.com/spf13/viper"
)

func Run() *cobra.Command {
cmd := &cobra.Command{
Use: "run",
Short: "run a single collector",
Long: `...`,
PreRun: func(cmd *cobra.Command, args []string) {
viper.BindPFlag("collector", cmd.Flags().Lookup("collector"))
},
RunE: func(cmd *cobra.Command, args []string) error {
v := viper.GetViper()

specContents, err := ioutil.ReadFile(v.GetString("collector"))
if err != nil {
return err
}

collector := collect.Collector{
Spec: string(specContents),
}
if err := collector.RunCollectorSync(); err != nil {
return err
}

return nil
},
}

cmd.Flags().String("collector", "", "path to a single collector spec to collect")

cmd.MarkFlagRequired("collector")

viper.BindPFlags(cmd.Flags())

return cmd
}
21 changes: 18 additions & 3 deletions cmd/collector/cli/collect.go → cmd/collector/cli/server.go
Original file line number Diff line number Diff line change
@@ -1,25 +1,40 @@
package cli

import (
"context"
"fmt"
"os"
"os/signal"

"github.com/replicatedhq/troubleshoot/pkg/server"
"github.com/spf13/cobra"
"github.com/spf13/viper"
)

func Server() *cobra.Command {
cmd := &cobra.Command{
Use: "server",
Short: "start the collector server",
Short: "run the http server",
Long: `...`,
PreRun: func(cmd *cobra.Command, args []string) {
viper.BindPFlag("port", cmd.Flags().Lookup("port"))
},
RunE: func(cmd *cobra.Command, args []string) error {
v := viper.GetViper()

server.Serve(context.Background(), fmt.Sprintf(":%d", v.GetInt("port")))

c := make(chan os.Signal, 1)
signal.Notify(c, os.Interrupt)

return nil
select {
case <-c:
return nil
}
},
}

cmd.Flags().Int("port", 8000, "port to bind to")
cmd.Flags().Int("port", 8000, "port to listen on")

viper.BindPFlags(cmd.Flags())

Expand Down
37 changes: 37 additions & 0 deletions cmd/preflight/cli/root.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
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)

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

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

func initConfig() {
viper.SetEnvPrefix("TROUBLESHOOT")
viper.AutomaticEnv()
}
7 changes: 7 additions & 0 deletions cmd/preflight/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package main

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

func main() {
cli.InitAndExecute()
}
32 changes: 0 additions & 32 deletions cmd/troubleshoot/cli/collect.go

This file was deleted.

Loading

0 comments on commit 5e1893b

Please sign in to comment.