From 7ab1734cb6b213893dd76c7745e180ae6ce5706b Mon Sep 17 00:00:00 2001 From: Marc Campbell Date: Wed, 18 Dec 2019 01:52:06 +0000 Subject: [PATCH] Remove manager and collector commands --- Makefile | 19 +---- cmd/collector/cli/root.go | 39 --------- cmd/collector/cli/run.go | 58 ------------- cmd/collector/cli/server.go | 43 ---------- cmd/collector/main.go | 7 -- cmd/manager/main.go | 84 ------------------- ...roubleshoot.replicated.com_collectors.yaml | 11 +++ ...roubleshoot.replicated.com_preflights.yaml | 11 +++ config/crds/zz_generated.deepcopy.go | 21 +++++ 9 files changed, 44 insertions(+), 249 deletions(-) delete mode 100644 cmd/collector/cli/root.go delete mode 100644 cmd/collector/cli/run.go delete mode 100644 cmd/collector/cli/server.go delete mode 100644 cmd/collector/main.go delete mode 100644 cmd/manager/main.go diff --git a/Makefile b/Makefile index 9b8c8fbc0..ae1e1db68 100644 --- a/Makefile +++ b/Makefile @@ -34,7 +34,7 @@ define LDFLAGS " endef -all: test manager +all: test .PHONY: ffi ffi: fmt vet @@ -44,10 +44,6 @@ ffi: fmt vet test: generate fmt vet manifests go test ./pkg/... ./cmd/... -coverprofile cover.out -.PHONY: manager -manager: generate fmt vet - go build ${LDFLAGS} -o bin/manager github.com/replicatedhq/troubleshoot/cmd/manager - .PHONY: support-bundle support-bundle: generate fmt vet go build ${LDFLAGS} -o bin/support-bundle github.com/replicatedhq/troubleshoot/cmd/troubleshoot @@ -60,10 +56,6 @@ preflight: generate fmt vet analyze: generate fmt vet go build ${LDFLAGS} -o bin/analyze github.com/replicatedhq/troubleshoot/cmd/analyze -.PHONY: run -run: generate fmt vet - TROUBLESHOOT_EXTERNAL_MANAGER=1 go run ./cmd/manager/main.go - .PHONY: install install: manifests kubectl apply -f config/crds @@ -109,13 +101,6 @@ 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 - docker push replicated/troubleshoot:alpha - docker push replicated/preflight:alpha - docker push replicated/troubleshoot-manager:alpha - .PHONY: release release: export GITHUB_TOKEN = $(shell echo ${GITHUB_TOKEN_TROUBLESHOOT}) release: @@ -126,10 +111,8 @@ local-release: curl -sL https://git.io/goreleaser | bash -s -- --rm-dist --snapshot --config deploy/.goreleaser.local.yml docker tag replicated/troubleshoot:alpha localhost:32000/troubleshoot:alpha docker tag replicated/preflight:alpha localhost:32000/preflight:alpha - docker tag replicated/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 .PHONY: run-preflight run-preflight: preflight diff --git a/cmd/collector/cli/root.go b/cmd/collector/cli/root.go deleted file mode 100644 index a4b7df6c0..000000000 --- a/cmd/collector/cli/root.go +++ /dev/null @@ -1,39 +0,0 @@ -package cli - -import ( - "fmt" - "os" - "strings" - - "github.com/spf13/cobra" - "github.com/spf13/viper" -) - -func RootCmd() *cobra.Command { - cmd := &cobra.Command{ - Use: "collector", - Short: "Run the cluster-side server for bundle collection", - Long: ``, - SilenceUsage: true, - } - - cobra.OnInitialize(initConfig) - - cmd.AddCommand(Run()) - cmd.AddCommand(Server()) - - 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() -} diff --git a/cmd/collector/cli/run.go b/cmd/collector/cli/run.go deleted file mode 100644 index 1deb144bf..000000000 --- a/cmd/collector/cli/run.go +++ /dev/null @@ -1,58 +0,0 @@ -package cli - -import ( - "fmt" - "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")) - viper.BindPFlag("redact", cmd.Flags().Lookup("redact")) - }, - RunE: func(cmd *cobra.Command, args []string) error { - v := viper.GetViper() - - specContents, err := ioutil.ReadFile(v.GetString("collector")) - if err != nil { - return err - } - - c, err := collect.ParseSpec(string(specContents)) - if err != nil { - return err - } - - collector := collect.Collector{ - Collect: c, - Redact: v.GetBool("redact"), - Namespace: v.GetString("namespace"), - } - b, err := collector.RunCollectorSync() - if err != nil { - return err - } - - fmt.Printf("%s", b) - - return nil - }, - } - - cmd.Flags().String("collector", "", "path to a single collector spec to collect") - cmd.Flags().Bool("redact", true, "enable/disable default redactions") - - cmd.MarkFlagRequired("collector") - - viper.BindPFlags(cmd.Flags()) - - return cmd -} diff --git a/cmd/collector/cli/server.go b/cmd/collector/cli/server.go deleted file mode 100644 index 090370783..000000000 --- a/cmd/collector/cli/server.go +++ /dev/null @@ -1,43 +0,0 @@ -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: "run the http server", - Hidden: true, - 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.ServeCollector(context.Background(), fmt.Sprintf(":%d", v.GetInt("port"))) - - c := make(chan os.Signal, 1) - signal.Notify(c, os.Interrupt) - - select { - case <-c: - return nil - } - }, - } - - cmd.Flags().Int("port", 8000, "port to listen on") - - viper.BindPFlags(cmd.Flags()) - - return cmd -} diff --git a/cmd/collector/main.go b/cmd/collector/main.go deleted file mode 100644 index f53cfd8ac..000000000 --- a/cmd/collector/main.go +++ /dev/null @@ -1,7 +0,0 @@ -package main - -import "github.com/replicatedhq/troubleshoot/cmd/collector/cli" - -func main() { - cli.InitAndExecute() -} diff --git a/cmd/manager/main.go b/cmd/manager/main.go deleted file mode 100644 index b792dd5a6..000000000 --- a/cmd/manager/main.go +++ /dev/null @@ -1,84 +0,0 @@ -/* -Copyright 2019 Replicated, Inc.. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package main - -import ( - "flag" - "os" - - "github.com/replicatedhq/troubleshoot/pkg/apis" - "github.com/replicatedhq/troubleshoot/pkg/controller" - "github.com/replicatedhq/troubleshoot/pkg/webhook" - _ "k8s.io/client-go/plugin/pkg/client/auth/gcp" - "sigs.k8s.io/controller-runtime/pkg/client/config" - "sigs.k8s.io/controller-runtime/pkg/manager" - logf "sigs.k8s.io/controller-runtime/pkg/runtime/log" - "sigs.k8s.io/controller-runtime/pkg/runtime/signals" -) - -func main() { - var metricsAddr string - 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") - - // Get a config to talk to the apiserver - log.Info("setting up client for manager") - cfg, err := config.GetConfig() - if err != nil { - log.Error(err, "unable to set up client config") - os.Exit(1) - } - - // Create a new Cmd to provide shared dependencies and start components - log.Info("setting up manager") - mgr, err := manager.New(cfg, manager.Options{MetricsBindAddress: metricsAddr}) - if err != nil { - log.Error(err, "unable to set up overall controller manager") - os.Exit(1) - } - - log.Info("Registering Components.") - - // Setup Scheme for all resources - log.Info("setting up scheme") - if err := apis.AddToScheme(mgr.GetScheme()); err != nil { - log.Error(err, "unable add APIs to scheme") - os.Exit(1) - } - - // Setup all Controllers - log.Info("Setting up controller") - if err := controller.AddToManager(mgr); err != nil { - log.Error(err, "unable to register controllers to the manager") - os.Exit(1) - } - - log.Info("setting up webhooks") - if err := webhook.AddToManager(mgr); err != nil { - log.Error(err, "unable to register webhooks to the manager") - os.Exit(1) - } - - // Start the Cmd - log.Info("Starting the Cmd.") - if err := mgr.Start(signals.SetupSignalHandler()); err != nil { - log.Error(err, "unable to run the manager") - os.Exit(1) - } -} diff --git a/config/crds/troubleshoot.replicated.com_collectors.yaml b/config/crds/troubleshoot.replicated.com_collectors.yaml index 317ed448d..9a94fae2c 100644 --- a/config/crds/troubleshoot.replicated.com_collectors.yaml +++ b/config/crds/troubleshoot.replicated.com_collectors.yaml @@ -444,6 +444,17 @@ spec: - namespace - containerPath type: object + data: + properties: + collectorName: + type: string + data: + type: string + name: + type: string + required: + - data + type: object exec: properties: args: diff --git a/config/crds/troubleshoot.replicated.com_preflights.yaml b/config/crds/troubleshoot.replicated.com_preflights.yaml index 2146cf2c4..d1071f6d4 100644 --- a/config/crds/troubleshoot.replicated.com_preflights.yaml +++ b/config/crds/troubleshoot.replicated.com_preflights.yaml @@ -849,6 +849,17 @@ spec: - namespace - containerPath type: object + data: + properties: + collectorName: + type: string + data: + type: string + name: + type: string + required: + - data + type: object exec: properties: args: diff --git a/config/crds/zz_generated.deepcopy.go b/config/crds/zz_generated.deepcopy.go index 8dbd570b8..afdf60ec1 100644 --- a/config/crds/zz_generated.deepcopy.go +++ b/config/crds/zz_generated.deepcopy.go @@ -419,6 +419,11 @@ func (in *Collect) DeepCopyInto(out *Collect) { *out = new(Exec) (*in).DeepCopyInto(*out) } + if in.Data != nil { + in, out := &in.Data, &out.Data + *out = new(Data) + **out = **in + } if in.Copy != nil { in, out := &in.Copy, &out.Copy *out = new(Copy) @@ -762,6 +767,22 @@ func (in *CustomResourceDefinition) DeepCopy() *CustomResourceDefinition { return out } +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *Data) DeepCopyInto(out *Data) { + *out = *in + out.CollectorMeta = in.CollectorMeta +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Data. +func (in *Data) DeepCopy() *Data { + if in == nil { + return nil + } + out := new(Data) + in.DeepCopyInto(out) + return out +} + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *DeploymentStatus) DeepCopyInto(out *DeploymentStatus) { *out = *in