Skip to content

Commit

Permalink
GCE deployer uses sflags instead of pflag
Browse files Browse the repository at this point in the history
  • Loading branch information
michaelmdresser authored and amwat committed Jul 7, 2020
1 parent f351d6b commit cee02da
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 16 deletions.
1 change: 1 addition & 0 deletions kubetest2-gce/deployer/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ go_library(
deps = [
"//kubetest2/pkg/exec:go_default_library",
"//kubetest2/pkg/types:go_default_library",
"@com_github_octago_sflags//gen/gpflag:go_default_library",
"@com_github_spf13_pflag//:go_default_library",
],
)
Expand Down
6 changes: 3 additions & 3 deletions kubetest2-gce/deployer/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func (d *deployer) Build() error {
// this code path supports the kubernetes/cloud-provider-gcp build
// TODO: update in future patch to support legacy (k/k) build
cmd := exec.Command("bazel", "build", "//release:release-tars")
cmd.SetDir(d.repoRoot)
cmd.SetDir(d.RepoRoot)
err := cmd.Run()
if err != nil {
return fmt.Errorf("error during make step of build: %s", err)
Expand All @@ -46,15 +46,15 @@ func (d *deployer) Build() error {
}

func (d *deployer) setRepoPathIfNotSet() error {
if d.repoRoot != "" {
if d.RepoRoot != "" {
return nil
}

path, err := os.Getwd()
if err != nil {
return fmt.Errorf("Failed to get current working directory for setting Kubernetes root path: %s", err)
}
d.repoRoot = path
d.RepoRoot = path

return nil
}
Expand Down
6 changes: 3 additions & 3 deletions kubetest2-gce/deployer/build_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,15 @@ func TestSetEmptyRepoPath(t *testing.T) {
t.Fatal(err)
}

if d.repoRoot != os.TempDir() {
if d.RepoRoot != os.TempDir() {
t.Error("expected new root path to be the OS temp dir")
}
}

func TestSetPopulatedRepoPath(t *testing.T) {
path := "/test/path"
d := &deployer{
repoRoot: path,
RepoRoot: path,
}

err := d.setRepoPathIfNotSet()
Expand All @@ -52,7 +52,7 @@ func TestSetPopulatedRepoPath(t *testing.T) {
t.Fatal(err)
}

if d.repoRoot != path {
if d.RepoRoot != path {
t.Error("repo root path after call is supposed to be the same as before the call")
}
}
21 changes: 11 additions & 10 deletions kubetest2-gce/deployer/deployer.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,12 @@ limitations under the License.
package deployer

import (
"github.com/spf13/pflag"
"fmt"

"k8s.io/test-infra/kubetest2/pkg/types"

"github.com/octago/sflags/gen/gpflag"
"github.com/spf13/pflag"
)

// Name is the name of the deployer
Expand All @@ -30,7 +33,7 @@ type deployer struct {
// generic parts
commonOptions types.Options

repoRoot string
RepoRoot string `desc:"The path to the root of the local kubernetes/cloud-provider/gcp repo. Necessary to call certain scripts. Defaults to the current directory. If operating in legacy mode, this should be set to the local kubernetes/kubernetes repo."`
}

// New implements deployer.New for gce
Expand All @@ -39,20 +42,18 @@ func New(opts types.Options) (types.Deployer, *pflag.FlagSet) {
commonOptions: opts,
}

flagSet, err := gpflag.Parse(d)
if err != nil {
panic(fmt.Sprintf("couldn't parse flagset for deployer struct: %s", err))
}

// register flags and return
return d, bindFlags(d)
return d, flagSet
}

// assert that New implements types.NewDeployer
var _ types.NewDeployer = New

func bindFlags(d *deployer) *pflag.FlagSet {
flags := pflag.NewFlagSet(Name, pflag.ContinueOnError)

flags.StringVar(&d.repoRoot, "repo-root", "", "The path to the root of the local kubernetes/cloud-provider/gcp repo. Necessary to call certain scripts. Defaults to the current directory. If operating in legacy mode, this should be set to the local kubernetes/kubernetes repo.")
return flags
}

// assert that deployer implements types.Deployer
var _ types.Deployer = &deployer{}

Expand Down

0 comments on commit cee02da

Please sign in to comment.