Skip to content

Commit 5e1893b

Browse files
authored
Merge pull request #2 from replicatedhq/collector-job
Run cluster-info in a collector pod
2 parents 7371732 + d60de90 commit 5e1893b

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

41 files changed

+1671
-112
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,5 @@ bin
2222
*.swp
2323
*.swo
2424
*~
25+
26+
dist

Dockerfile

Lines changed: 0 additions & 17 deletions
This file was deleted.

Makefile

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -24,20 +24,20 @@ collector: generate fmt vet
2424
preflight: generate fmt vet
2525
go build -o bin/preflight github.com/replicatedhq/troubleshoot/cmd/preflight
2626

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

31-
# Install CRDs into a cluster
31+
.PHONY: install
3232
install: manifests
3333
kubectl apply -f config/crds
3434

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

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

@@ -54,16 +54,6 @@ generate: controller-gen # client-gen
5454
controller-gen object:headerFile=./hack/boilerplate.go.txt paths=./pkg/apis/...
5555
# 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
5656

57-
# Build the docker image
58-
docker-build: test
59-
docker build . -t ${IMG}
60-
@echo "updating kustomize image patch file for manager resource"
61-
sed -i'' -e 's@image: .*@image: '"${IMG}"'@' ./config/default/manager_image_patch.yaml
62-
63-
# Push the docker image
64-
docker-push:
65-
docker push ${IMG}
66-
6757
# find or download controller-gen
6858
# download controller-gen if necessary
6959
controller-gen:
@@ -82,3 +72,16 @@ CLIENT_GEN=$(shell go env GOPATH)/bin/client-gen
8272
else
8373
CLIENT_GEN=$(shell which client-gen)
8474
endif
75+
76+
.PHONY: snapshot-release
77+
snapshot-release:
78+
curl -sL https://git.io/goreleaser | bash -s -- --rm-dist --snapshot --config deploy/.goreleaser.snapshot.yml
79+
80+
.PHONY: local-release
81+
local-release: snapshot-release
82+
docker tag replicatedhq/troubleshoot:alpha localhost:32000/troubleshoot:alpha
83+
docker tag replicatedhq/preflight:alpha localhost:32000/preflight:alpha
84+
docker tag replicatedhq/troubleshoot-manager:alpha localhost:32000/troubleshoot-manager:alpha
85+
docker push localhost:32000/troubleshoot:alpha
86+
docker push localhost:32000/preflight:alpha
87+
docker push localhost:32000/troubleshoot-manager:alpha

cmd/collector/cli/root.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ func RootCmd() *cobra.Command {
1919

2020
cobra.OnInitialize(initConfig)
2121

22+
cmd.AddCommand(Run())
2223
cmd.AddCommand(Server())
2324

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

3536
func initConfig() {
36-
viper.SetEnvPrefix("TROUBLESHOT")
37+
viper.SetEnvPrefix("TROUBLESHOOT")
3738
viper.AutomaticEnv()
3839
}

cmd/collector/cli/run.go

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
package cli
2+
3+
import (
4+
"io/ioutil"
5+
6+
"github.com/replicatedhq/troubleshoot/pkg/collect"
7+
"github.com/spf13/cobra"
8+
"github.com/spf13/viper"
9+
)
10+
11+
func Run() *cobra.Command {
12+
cmd := &cobra.Command{
13+
Use: "run",
14+
Short: "run a single collector",
15+
Long: `...`,
16+
PreRun: func(cmd *cobra.Command, args []string) {
17+
viper.BindPFlag("collector", cmd.Flags().Lookup("collector"))
18+
},
19+
RunE: func(cmd *cobra.Command, args []string) error {
20+
v := viper.GetViper()
21+
22+
specContents, err := ioutil.ReadFile(v.GetString("collector"))
23+
if err != nil {
24+
return err
25+
}
26+
27+
collector := collect.Collector{
28+
Spec: string(specContents),
29+
}
30+
if err := collector.RunCollectorSync(); err != nil {
31+
return err
32+
}
33+
34+
return nil
35+
},
36+
}
37+
38+
cmd.Flags().String("collector", "", "path to a single collector spec to collect")
39+
40+
cmd.MarkFlagRequired("collector")
41+
42+
viper.BindPFlags(cmd.Flags())
43+
44+
return cmd
45+
}

cmd/collector/cli/collect.go renamed to cmd/collector/cli/server.go

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,40 @@
11
package cli
22

33
import (
4+
"context"
5+
"fmt"
6+
"os"
7+
"os/signal"
8+
9+
"github.com/replicatedhq/troubleshoot/pkg/server"
410
"github.com/spf13/cobra"
511
"github.com/spf13/viper"
612
)
713

814
func Server() *cobra.Command {
915
cmd := &cobra.Command{
1016
Use: "server",
11-
Short: "start the collector server",
17+
Short: "run the http server",
1218
Long: `...`,
1319
PreRun: func(cmd *cobra.Command, args []string) {
1420
viper.BindPFlag("port", cmd.Flags().Lookup("port"))
1521
},
1622
RunE: func(cmd *cobra.Command, args []string) error {
23+
v := viper.GetViper()
24+
25+
server.Serve(context.Background(), fmt.Sprintf(":%d", v.GetInt("port")))
26+
27+
c := make(chan os.Signal, 1)
28+
signal.Notify(c, os.Interrupt)
1729

18-
return nil
30+
select {
31+
case <-c:
32+
return nil
33+
}
1934
},
2035
}
2136

22-
cmd.Flags().Int("port", 8000, "port to bind to")
37+
cmd.Flags().Int("port", 8000, "port to listen on")
2338

2439
viper.BindPFlags(cmd.Flags())
2540

cmd/preflight/cli/root.go

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package cli
2+
3+
import (
4+
"fmt"
5+
"os"
6+
"strings"
7+
8+
"github.com/spf13/cobra"
9+
"github.com/spf13/viper"
10+
)
11+
12+
func RootCmd() *cobra.Command {
13+
cmd := &cobra.Command{
14+
Use: "troubleshoot",
15+
Short: "Generate and manage support bundles",
16+
Long: `A support bundle is an archive of files, output, metrics and state
17+
from a server that can be used to assist when troubleshooting a server.`,
18+
SilenceUsage: true,
19+
}
20+
21+
cobra.OnInitialize(initConfig)
22+
23+
viper.SetEnvKeyReplacer(strings.NewReplacer("-", "_"))
24+
return cmd
25+
}
26+
27+
func InitAndExecute() {
28+
if err := RootCmd().Execute(); err != nil {
29+
fmt.Println(err)
30+
os.Exit(1)
31+
}
32+
}
33+
34+
func initConfig() {
35+
viper.SetEnvPrefix("TROUBLESHOOT")
36+
viper.AutomaticEnv()
37+
}

cmd/preflight/main.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package main
2+
3+
import "github.com/replicatedhq/troubleshoot/cmd/preflight/cli"
4+
5+
func main() {
6+
cli.InitAndExecute()
7+
}

cmd/troubleshoot/cli/collect.go

Lines changed: 0 additions & 32 deletions
This file was deleted.

0 commit comments

Comments
 (0)