Skip to content

Commit

Permalink
BUGFIX: re-enable install test and fix flags which were not parsed co…
Browse files Browse the repository at this point in the history
…rrectly

Signed-off-by: Tim Ramlot <42113979+inteon@users.noreply.github.com>
  • Loading branch information
inteon committed Jan 26, 2024
1 parent 0d9f840 commit a196412
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 20 deletions.
16 changes: 8 additions & 8 deletions pkg/factory/factory.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,12 @@ import (
cmclient "github.com/cert-manager/cert-manager/pkg/client/clientset/versioned"
)

var (
kubeConfigFlags = genericclioptions.NewConfigFlags(true)
factory = util.NewFactory(kubeConfigFlags)
)

// Factory provides a set of clients and configurations to authenticate and
// access a target Kubernetes cluster. Factory will ensure that its fields are
// populated and valid during command execution.
type Factory struct {
factory util.Factory

// Namespace is the namespace that the user has requested with the
// "--namespace" / "-n" flag. Defaults to "default" if the flag was not
// provided.
Expand Down Expand Up @@ -72,6 +69,9 @@ type Factory struct {
func New(ctx context.Context, cmd *cobra.Command) *Factory {
f := new(Factory)

kubeConfigFlags := genericclioptions.NewConfigFlags(true)
f.factory = util.NewFactory(kubeConfigFlags)

kubeConfigFlags.AddFlags(cmd.Flags())
cmd.RegisterFlagCompletionFunc("namespace", validArgsListNamespaces(ctx, f))

Expand All @@ -93,12 +93,12 @@ func New(ctx context.Context, cmd *cobra.Command) *Factory {
func (f *Factory) complete() error {
var err error

f.Namespace, f.EnforceNamespace, err = factory.ToRawKubeConfigLoader().Namespace()
f.Namespace, f.EnforceNamespace, err = f.factory.ToRawKubeConfigLoader().Namespace()
if err != nil {
return err
}

f.RESTConfig, err = factory.ToRESTConfig()
f.RESTConfig, err = f.factory.ToRESTConfig()
if err != nil {
return err
}
Expand All @@ -113,7 +113,7 @@ func (f *Factory) complete() error {
return err
}

f.RESTClientGetter = factory
f.RESTClientGetter = f.factory

return nil
}
14 changes: 7 additions & 7 deletions pkg/install/helm/settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ func NewNormalisedEnvSettings() *NormalisedEnvSettings {
ActionConfiguration: &action.Configuration{},
}
}

func (n *NormalisedEnvSettings) Namespace() string {
return n.Factory.Namespace
}
Expand All @@ -60,8 +59,8 @@ func (n *NormalisedEnvSettings) Setup(ctx context.Context, cmd *cobra.Command) {

{
// Add a PreRunE hook to initialise the action configuration.
existingPreRunE := cmd.PreRunE
cmd.PreRunE = func(cmd *cobra.Command, args []string) error {
existingPreRunE := cmd.PersistentPreRunE
cmd.PersistentPreRunE = func(cmd *cobra.Command, args []string) error {
if err := n.InitActionConfiguration(); err != nil {
return err
}
Expand Down Expand Up @@ -97,23 +96,24 @@ func (n *NormalisedEnvSettings) setupEnvSettings(ctx context.Context, cmd *cobra
{
// Add a PreRun hook to set the debug value to true if the log level is
// >= 3.
existingPreRun := cmd.PreRun
cmd.PreRun = func(cmd *cobra.Command, args []string) {
existingPreRun := cmd.PersistentPreRunE
cmd.PersistentPreRunE = func(cmd *cobra.Command, args []string) error {
if n.logger.V(debugLogLevel).Enabled() {
n.EnvSettings.Debug = true
}

if existingPreRun != nil {
existingPreRun(cmd, args)
return existingPreRun(cmd, args)
}
return nil
}
}
}

func (n *NormalisedEnvSettings) InitActionConfiguration() error {
return n.ActionConfiguration.Init(
n.Factory.RESTClientGetter,
n.EnvSettings.Namespace(),
n.Factory.Namespace,
os.Getenv("HELM_DRIVER"),
func(format string, v ...interface{}) {
n.logger.Info(fmt.Sprintf(format, v...))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import (

"github.com/cert-manager/cmctl/v2/cmd"
"github.com/cert-manager/cmctl/v2/test/integration/install_framework"
"github.com/cert-manager/cmctl/v2/test/integration/internal/util"
logsapi "k8s.io/component-base/logs/api/v1"
)

func TestCtlInstall(t *testing.T) {
Expand Down Expand Up @@ -99,12 +99,11 @@ func executeCommandAndCheckOutput(
stdin := bytes.NewBufferString("")
stdout := bytes.NewBufferString("")

chartPath := util.GetTestPath("deploy", "charts", "cert-manager", "cert-manager.tgz")
logsapi.ResetForTest(nil)
cmd := cmd.NewCertManagerCtlCommand(ctx, stdin, stdout, stdout)
cmd.SetArgs(append([]string{
fmt.Sprintf("--kubeconfig=%s", kubeConfig),
"--wait=false",
fmt.Sprintf("--chart-name=%s", chartPath),
"x",
"install",
}, inputArgs...))
Expand Down
7 changes: 5 additions & 2 deletions test/integration/install_framework/framework.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,12 @@ import (
"os"
"testing"

"github.com/cert-manager/cert-manager/test/apiserver"
"github.com/go-logr/logr/testr"
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/rest"
"sigs.k8s.io/controller-runtime/pkg/envtest"

"github.com/cert-manager/cert-manager/test/apiserver"
"sigs.k8s.io/controller-runtime/pkg/log"
)

type TestInstallApiServer struct {
Expand All @@ -39,6 +40,8 @@ type TestInstallApiServer struct {
type CleanupFunction func()

func NewTestInstallApiServer(t *testing.T) (*TestInstallApiServer, CleanupFunction) {
log.SetLogger(testr.New(t))

env, stopFn := apiserver.RunBareControlPlane(t)

testUser, err := env.ControlPlane.AddUser(
Expand Down

0 comments on commit a196412

Please sign in to comment.