From f68cb44209428f6ad48c18cbfd6fe69a5afe5203 Mon Sep 17 00:00:00 2001 From: Bridget McErlean Date: Mon, 12 Aug 2019 15:29:17 -0400 Subject: [PATCH] Remove `plugin` command (#833) This change removes the hidden `plugin` command. This command was intended for debugging the generation of plugin Job and DaemonSet manifests and is not in active use. There is currently other work in progress to remove the use of templates when creating plugin resources which means that a command to render the template is not required. If we decided to have a debug command there would be further work required to ensure that the same flow is used as is used in the plugin aggreator. Signed-off-by: Bridget McErlean --- cmd/sonobuoy/app/gen_plugin.go | 127 --------------------------------- cmd/sonobuoy/app/root.go | 2 - 2 files changed, 129 deletions(-) delete mode 100644 cmd/sonobuoy/app/gen_plugin.go diff --git a/cmd/sonobuoy/app/gen_plugin.go b/cmd/sonobuoy/app/gen_plugin.go deleted file mode 100644 index 30eea9e1f..000000000 --- a/cmd/sonobuoy/app/gen_plugin.go +++ /dev/null @@ -1,127 +0,0 @@ -/* -Copyright 2018 Heptio 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 app - -import ( - "crypto/ecdsa" - "crypto/elliptic" - "crypto/rand" - "crypto/tls" - "crypto/x509" - "fmt" - "math/big" - "os" - - "github.com/heptio/sonobuoy/pkg/config" - "github.com/heptio/sonobuoy/pkg/errlog" - "github.com/heptio/sonobuoy/pkg/plugin" - "github.com/heptio/sonobuoy/pkg/plugin/loader" - "github.com/pkg/errors" - "github.com/spf13/cobra" -) - -const ( - placeholderHostname = "" -) - -// GenPluginConfig are the input options for running -type GenPluginConfig struct { - Paths []string - PluginName string - ImagePullSecrets string - CustomAnnotations map[string]string -} - -var genPluginOpts GenPluginConfig - -func NewCmdGenPlugin() *cobra.Command { - cmd := &cobra.Command{ - Use: "plugin", - Short: "Generates the manifest Sonobuoy uses to run a worker for the given plugin", - Run: genPluginManifest, - Hidden: true, - Args: cobra.ExactArgs(1), - } - - cmd.PersistentFlags().StringArrayVarP( - &genPluginOpts.Paths, "paths", "p", []string{".", "./examples/plugins.d/"}, - "the paths to search for the plugins in. Defaults to . and ./plugins.d/", - ) - cmd.Flags().StringVar( - &genPluginOpts.ImagePullSecrets, "image-pull-secrets", "", - "the value for imagePullSecrets on the worker containers", - ) - return cmd -} - -func genPluginManifest(cmd *cobra.Command, args []string) { - genPluginOpts.PluginName = args[0] - code := 0 - manifest, err := generatePluginManifest(genPluginOpts) - if err == nil { - fmt.Printf("%s\n", manifest) - } else { - errlog.LogError(errors.Wrap(err, "error attempting to generate sonobuoy manifest")) - code = 1 - } - os.Exit(code) -} - -func generatePluginManifest(cfg GenPluginConfig) ([]byte, error) { - plugins, err := loader.LoadAllPlugins( - config.DefaultNamespace, - config.DefaultImage, - "Always", - cfg.ImagePullSecrets, - cfg.CustomAnnotations, - cfg.Paths, - []plugin.Selection{{Name: cfg.PluginName}}, - ) - if err != nil { - return nil, err - } - - if len(plugins) != 1 { - return nil, fmt.Errorf("expected 1 plugin, got %v", len(plugins)) - } - - cert, err := genCert() - if err != nil { - return nil, err - } - - return plugins[0].FillTemplate(placeholderHostname, cert) -} - -func genCert() (*tls.Certificate, error) { - privKey, err := ecdsa.GenerateKey(elliptic.P256(), rand.Reader) - if err != nil { - return nil, errors.Wrap(err, "couldn't generate private key") - } - tmpl := &x509.Certificate{ - SerialNumber: big.NewInt(0), - } - certDER, err := x509.CreateCertificate(rand.Reader, tmpl, tmpl, &privKey.PublicKey, privKey) - if err != nil { - return nil, errors.Wrap(err, "couldn't create certificate") - } - - return &tls.Certificate{ - Certificate: [][]byte{certDER}, - PrivateKey: privKey, - }, nil -} diff --git a/cmd/sonobuoy/app/root.go b/cmd/sonobuoy/app/root.go index 201d5dff4..9d78ca22b 100644 --- a/cmd/sonobuoy/app/root.go +++ b/cmd/sonobuoy/app/root.go @@ -45,13 +45,11 @@ func NewSonobuoyCommand() *cobra.Command { cmds.AddCommand(gen) cmds.AddCommand(NewCmdLogs()) - cmds.AddCommand(NewCmdGenPlugin()) cmds.AddCommand(NewCmdVersion()) cmds.AddCommand(NewCmdStatus()) cmds.AddCommand(NewCmdWorker()) cmds.AddCommand(NewCmdRetrieve()) cmds.AddCommand(NewCmdRun()) - cmds.AddCommand(NewCmdGenPlugin()) cmds.AddCommand(NewCmdImages()) cmds.AddCommand(NewCmdResults())