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())