Skip to content

Commit

Permalink
fix: Temporary namespace usage in combination with test command options
Browse files Browse the repository at this point in the history
When test cli command used some options (like --upload) in combination with running the test in a temporary namespace errors were reported due to the fact that those cli options were forwarded to the install command. Now avoiding to forward the cli options to the install command when
setting up cluster and operator on the temporary namespace
  • Loading branch information
christophd committed Apr 22, 2020
1 parent 105fa05 commit 70b77e8
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 32 deletions.
71 changes: 42 additions & 29 deletions pkg/cmd/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,43 +56,56 @@ type installCmdOptions struct {
// nolint: gocyclo
func (o *installCmdOptions) install(_ *cobra.Command, _ []string) error {
if !o.skipClusterSetup {
// Let's use a client provider during cluster installation, to eliminate the problem of CRD object caching
clientProvider := client.Provider{Get: o.NewCmdClient}

err := install.SetupClusterwideResourcesOrCollect(o.Context, clientProvider, nil)
if err != nil && k8serrors.IsForbidden(err) {
fmt.Println("Current user is not authorized to create cluster-wide objects like custom resource definitions or cluster roles: ", err)

meg := `please login as cluster-admin and execute "yaks install --cluster-setup" to install cluster-wide resources (one-time operation)`
return errors.New(meg)
} else if err != nil {
if err := setupCluster(o.RootCmdOptions); err != nil {
return err
}
} else {
fmt.Println("YAKS cluster setup skipped")
}

if o.clusterSetupOnly {
fmt.Println("YAKS cluster setup completed successfully")
} else {
c, err := o.GetCmdClient()
if err != nil {
return err
}
return nil
}

namespace := o.Namespace

if !o.skipOperatorSetup {
cfg := install.OperatorConfiguration{
Namespace: namespace,
}
err = install.OperatorOrCollect(o.Context, c, cfg, nil)
if err != nil {
return err
}
fmt.Println("YAKS setup completed successfully")
} else {
fmt.Println("YAKS operator installation skipped")
}
if o.skipOperatorSetup {
fmt.Println("YAKS operator installation skipped")
return nil
}

err := setupOperator(o.RootCmdOptions, o.Namespace)
return err
}

func setupCluster(o *RootCmdOptions) error {
// Let's use a client provider during cluster installation, to eliminate the problem of CRD object caching
clientProvider := client.Provider{Get: o.NewCmdClient}

err := install.SetupClusterwideResourcesOrCollect(o.Context, clientProvider, nil)
if err != nil && k8serrors.IsForbidden(err) {
fmt.Println("Current user is not authorized to create cluster-wide objects like custom resource definitions or cluster roles: ", err)

meg := `please login as cluster-admin and execute "yaks install --cluster-setup" to install cluster-wide resources (one-time operation)`
return errors.New(meg)
}

return err
}

func setupOperator(o *RootCmdOptions, namespace string) error {
c, err := o.GetCmdClient()
if err != nil {
return err
}

cfg := install.OperatorConfiguration{
Namespace: namespace,
}
err = install.OperatorOrCollect(o.Context, c, cfg, nil)
if err != nil {
return err
}

fmt.Println("YAKS setup completed successfully")
return nil
}
8 changes: 5 additions & 3 deletions pkg/cmd/test.go
Original file line number Diff line number Diff line change
Expand Up @@ -296,9 +296,11 @@ func (o *testCmdOptions) createTempNamespace(runConfig *config.RunConfig, c clie
}
runConfig.Config.Namespace.Name = namespaceName

cmdOptionsCopy := o.RootCmdOptions
cmdOptionsCopy.Namespace = namespaceName
if err := newCmdInstall(cmdOptionsCopy).Execute(); err != nil {
if err := setupCluster(o.RootCmdOptions); err != nil {
return namespace, err
}

if err := setupOperator(o.RootCmdOptions, namespaceName); err != nil {
return namespace, err
}

Expand Down

0 comments on commit 70b77e8

Please sign in to comment.