Update ctl integration tests to use new local factory package
Signed-off-by: joshvanl <vleeuwenjoshua@gmail.com>
This commit is contained in:
parent
80a7bc5412
commit
4cdbb64003
@ -58,7 +58,7 @@ kubectl cert-manager is a CLI tool manage and configure cert-manager resources f
|
||||
}
|
||||
|
||||
ioStreams := genericclioptions.IOStreams{In: in, Out: out, ErrOut: err}
|
||||
cmds.AddCommand(version.NewCmdVersion(ctx, ioStreams, factory))
|
||||
cmds.AddCommand(version.NewCmdVersion(ctx, ioStreams))
|
||||
cmds.AddCommand(convert.NewCmdConvert(ctx, ioStreams))
|
||||
cmds.AddCommand(create.NewCmdCreate(ctx, ioStreams))
|
||||
cmds.AddCommand(renew.NewCmdRenew(ctx, ioStreams))
|
||||
|
||||
@ -9,6 +9,7 @@ go_library(
|
||||
importpath = "github.com/jetstack/cert-manager/cmd/ctl/pkg/install",
|
||||
visibility = ["//visibility:public"],
|
||||
deps = [
|
||||
"//cmd/ctl/pkg/factory:go_default_library",
|
||||
"//cmd/ctl/pkg/install/helm:go_default_library",
|
||||
"@com_github_spf13_cobra//:go_default_library",
|
||||
"@com_github_spf13_pflag//:go_default_library",
|
||||
|
||||
@ -35,6 +35,7 @@ import (
|
||||
"helm.sh/helm/v3/pkg/release"
|
||||
"k8s.io/cli-runtime/pkg/genericclioptions"
|
||||
|
||||
"github.com/jetstack/cert-manager/cmd/ctl/pkg/factory"
|
||||
"github.com/jetstack/cert-manager/cmd/ctl/pkg/install/helm"
|
||||
)
|
||||
|
||||
@ -49,6 +50,7 @@ type InstallOptions struct {
|
||||
Wait bool
|
||||
|
||||
genericclioptions.IOStreams
|
||||
*factory.Factory
|
||||
}
|
||||
|
||||
const (
|
||||
@ -113,9 +115,6 @@ func NewCmdInstall(ctx context.Context, ioStreams genericclioptions.IOStreams) *
|
||||
}
|
||||
|
||||
addInstallUninstallFlags(cmd.Flags(), &options.client.Timeout, &options.Wait)
|
||||
// Set default namespace cli flag value
|
||||
// TODO:
|
||||
//cmd.Flag("namespace").DefValue = defaultCertManagerNamespace
|
||||
|
||||
addInstallFlags(cmd.Flags(), options.client)
|
||||
addValueOptionsFlags(cmd.Flags(), options.valueOpts)
|
||||
@ -127,6 +126,10 @@ func NewCmdInstall(ctx context.Context, ioStreams genericclioptions.IOStreams) *
|
||||
cmd.Flags().MarkHidden("chart-name")
|
||||
cmd.Flags().BoolVar(&options.DryRun, "dry-run", false, "Simulate install and output manifest")
|
||||
|
||||
options.Factory = factory.New(cmd)
|
||||
// Set default namespace cli flag value
|
||||
cmd.Flag("namespace").DefValue = defaultCertManagerNamespace
|
||||
|
||||
return cmd
|
||||
}
|
||||
|
||||
|
||||
@ -6,6 +6,7 @@ go_library(
|
||||
importpath = "github.com/jetstack/cert-manager/cmd/ctl/pkg/version",
|
||||
visibility = ["//visibility:public"],
|
||||
deps = [
|
||||
"//cmd/ctl/pkg/factory:go_default_library",
|
||||
"//pkg/util:go_default_library",
|
||||
"//pkg/util/versionchecker:go_default_library",
|
||||
"@com_github_spf13_cobra//:go_default_library",
|
||||
|
||||
@ -28,6 +28,7 @@ import (
|
||||
"k8s.io/kubectl/pkg/scheme"
|
||||
"sigs.k8s.io/yaml"
|
||||
|
||||
"github.com/jetstack/cert-manager/cmd/ctl/pkg/factory"
|
||||
"github.com/jetstack/cert-manager/pkg/util"
|
||||
"github.com/jetstack/cert-manager/pkg/util/versionchecker"
|
||||
)
|
||||
@ -53,6 +54,7 @@ type Options struct {
|
||||
VersionChecker versionchecker.Interface
|
||||
|
||||
genericclioptions.IOStreams
|
||||
*factory.Factory
|
||||
}
|
||||
|
||||
// NewOptions returns initialized Options
|
||||
@ -87,7 +89,7 @@ or
|
||||
`
|
||||
|
||||
// NewCmdVersion returns a cobra command for fetching versions
|
||||
func NewCmdVersion(ctx context.Context, ioStreams genericclioptions.IOStreams, factory cmdutil.Factory) *cobra.Command {
|
||||
func NewCmdVersion(ctx context.Context, ioStreams genericclioptions.IOStreams) *cobra.Command {
|
||||
o := NewOptions(ioStreams)
|
||||
|
||||
cmd := &cobra.Command{
|
||||
@ -96,7 +98,6 @@ func NewCmdVersion(ctx context.Context, ioStreams genericclioptions.IOStreams, f
|
||||
Long: versionLong,
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
cmdutil.CheckErr(o.Validate())
|
||||
cmdutil.CheckErr(o.Complete(factory))
|
||||
cmdutil.CheckErr(o.Run(ctx))
|
||||
},
|
||||
}
|
||||
@ -104,6 +105,9 @@ func NewCmdVersion(ctx context.Context, ioStreams genericclioptions.IOStreams, f
|
||||
cmd.Flags().BoolVar(&o.ClientOnly, "client", o.ClientOnly, "If true, shows client version only (no server required).")
|
||||
cmd.Flags().BoolVar(&o.Short, "short", o.Short, "If true, print just the version number.")
|
||||
cmd.Flags().StringVarP(&o.Output, "output", "o", o.Output, "One of 'yaml' or 'json'.")
|
||||
|
||||
o.Factory = factory.New(cmd)
|
||||
|
||||
return cmd
|
||||
}
|
||||
|
||||
|
||||
@ -15,6 +15,7 @@ go_test(
|
||||
deps = [
|
||||
"//cmd/ctl/pkg/convert:go_default_library",
|
||||
"//cmd/ctl/pkg/create/certificaterequest:go_default_library",
|
||||
"//cmd/ctl/pkg/factory:go_default_library",
|
||||
"//cmd/ctl/pkg/renew:go_default_library",
|
||||
"//cmd/ctl/pkg/status/certificate:go_default_library",
|
||||
"//pkg/api/util:go_default_library",
|
||||
|
||||
@ -26,12 +26,12 @@ import (
|
||||
"time"
|
||||
|
||||
corev1 "k8s.io/api/core/v1"
|
||||
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/apimachinery/pkg/util/wait"
|
||||
"k8s.io/cli-runtime/pkg/genericclioptions"
|
||||
|
||||
"github.com/jetstack/cert-manager/cmd/ctl/pkg/create/certificaterequest"
|
||||
"github.com/jetstack/cert-manager/cmd/ctl/pkg/factory"
|
||||
cmapiv1 "github.com/jetstack/cert-manager/pkg/apis/certmanager/v1"
|
||||
cmmeta "github.com/jetstack/cert-manager/pkg/apis/meta/v1"
|
||||
"github.com/jetstack/cert-manager/pkg/util/pki"
|
||||
@ -105,14 +105,17 @@ func TestCtlCreateCRBeforeCRIsCreated(t *testing.T) {
|
||||
|
||||
// Options to run create CR command
|
||||
opts := &certificaterequest.Options{
|
||||
CMClient: cmCl,
|
||||
RESTConfig: config,
|
||||
IOStreams: streams,
|
||||
CmdNamespace: test.inputNamespace,
|
||||
EnforceNamespace: test.inputNamespace != "",
|
||||
InputFilename: test.inputFile,
|
||||
CertFileName: test.certFilename,
|
||||
InputFilename: test.inputFile,
|
||||
CertFileName: test.certFilename,
|
||||
Factory: &factory.Factory{
|
||||
CMClient: cmCl,
|
||||
RESTConfig: config,
|
||||
Namespace: test.inputNamespace,
|
||||
EnforceNamespace: test.inputNamespace != "",
|
||||
},
|
||||
IOStreams: streams,
|
||||
}
|
||||
|
||||
err := opts.Run(ctx, test.inputArgs)
|
||||
if err != nil {
|
||||
t.Fatal("failed to set up test to fail after writing private key to file and during creating CR")
|
||||
@ -272,16 +275,18 @@ func TestCtlCreateCRSuccessful(t *testing.T) {
|
||||
|
||||
// Options to run create CR command
|
||||
opts := &certificaterequest.Options{
|
||||
CMClient: cmCl,
|
||||
RESTConfig: config,
|
||||
IOStreams: streams,
|
||||
CmdNamespace: test.inputNamespace,
|
||||
EnforceNamespace: test.inputNamespace != "",
|
||||
InputFilename: test.inputFile,
|
||||
KeyFilename: test.keyFilename,
|
||||
CertFileName: test.certFilename,
|
||||
FetchCert: test.fetchCert,
|
||||
Timeout: test.timeout,
|
||||
Factory: &factory.Factory{
|
||||
CMClient: cmCl,
|
||||
RESTConfig: config,
|
||||
Namespace: test.inputNamespace,
|
||||
EnforceNamespace: test.inputNamespace != "",
|
||||
},
|
||||
IOStreams: streams,
|
||||
InputFilename: test.inputFile,
|
||||
KeyFilename: test.keyFilename,
|
||||
CertFileName: test.certFilename,
|
||||
FetchCert: test.fetchCert,
|
||||
Timeout: test.timeout,
|
||||
}
|
||||
|
||||
// Validating args and flags
|
||||
|
||||
@ -26,6 +26,7 @@ import (
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"k8s.io/cli-runtime/pkg/genericclioptions"
|
||||
|
||||
"github.com/jetstack/cert-manager/cmd/ctl/pkg/factory"
|
||||
"github.com/jetstack/cert-manager/cmd/ctl/pkg/renew"
|
||||
apiutil "github.com/jetstack/cert-manager/pkg/api/util"
|
||||
cmapi "github.com/jetstack/cert-manager/pkg/apis/certmanager/v1"
|
||||
@ -163,13 +164,14 @@ func TestCtlRenew(t *testing.T) {
|
||||
|
||||
cmd := &renew.Options{
|
||||
LabelSelector: test.inputLabels,
|
||||
Namespace: test.inputNamespace,
|
||||
All: test.inputAll,
|
||||
AllNamespaces: test.inputAllNamespaces,
|
||||
|
||||
CMClient: cmCl,
|
||||
RESTConfig: config,
|
||||
IOStreams: streams,
|
||||
Factory: &factory.Factory{
|
||||
CMClient: cmCl,
|
||||
RESTConfig: config,
|
||||
Namespace: test.inputNamespace,
|
||||
},
|
||||
IOStreams: streams,
|
||||
}
|
||||
|
||||
if err := cmd.Run(ctx, test.inputArgs); err != nil {
|
||||
|
||||
@ -36,6 +36,7 @@ import (
|
||||
"k8s.io/client-go/kubernetes"
|
||||
"k8s.io/client-go/tools/reference"
|
||||
|
||||
"github.com/jetstack/cert-manager/cmd/ctl/pkg/factory"
|
||||
statuscertcmd "github.com/jetstack/cert-manager/cmd/ctl/pkg/status/certificate"
|
||||
apiutil "github.com/jetstack/cert-manager/pkg/api/util"
|
||||
cmacme "github.com/jetstack/cert-manager/pkg/apis/acme/v1"
|
||||
@ -530,10 +531,12 @@ CertificateRequest:
|
||||
// Options to run status command
|
||||
streams, _, outBuf, _ := genericclioptions.NewTestIOStreams()
|
||||
opts := &statuscertcmd.Options{
|
||||
CMClient: cmCl,
|
||||
RESTConfig: config,
|
||||
IOStreams: streams,
|
||||
Namespace: test.inputNamespace,
|
||||
Factory: &factory.Factory{
|
||||
CMClient: cmCl,
|
||||
RESTConfig: config,
|
||||
Namespace: test.inputNamespace,
|
||||
},
|
||||
IOStreams: streams,
|
||||
}
|
||||
|
||||
err = opts.Run(ctx, test.inputArgs)
|
||||
|
||||
Loading…
Reference in New Issue
Block a user