Skip to content

Commit

Permalink
able to specify gke endpoint via --environment flag
Browse files Browse the repository at this point in the history
  • Loading branch information
cofyc authored and amwat committed Jul 7, 2020
1 parent a9bf508 commit 0b216a6
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
16 changes: 16 additions & 0 deletions kubetest2-gke/deployer/commandutils.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,22 @@ func (d *deployer) prepareGcpIfNeeded() error {
// TODO(RonWeber): This is an almost direct copy/paste from kubetest's prepareGcp()
// It badly needs refactored.

var endpoint string
switch env := d.environment; {
case env == "test":
endpoint = "https://test-container.sandbox.googleapis.com/"
case env == "staging":
endpoint = "https://staging-container.sandbox.googleapis.com/"
case env == "staging2":
endpoint = "https://staging2-container.sandbox.googleapis.com/"
case env == "prod":
endpoint = "https://container.googleapis.com/"
case urlRe.MatchString(env):
endpoint = env
default:
return fmt.Errorf("--environment must be one of {test,staging,staging2,prod} or match %v, found %q", urlRe, env)
}

//TODO(RonWeber): boskos
if err := os.Setenv("CLOUDSDK_CORE_PRINT_UNHANDLED_TRACEBACKS", "1"); err != nil {
return fmt.Errorf("could not set CLOUDSDK_CORE_PRINT_UNHANDLED_TRACEBACKS=1: %v", err)
Expand Down
5 changes: 3 additions & 2 deletions kubetest2-gke/deployer/deployer.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@ const (
defaultPool = "default"
e2eAllow = "tcp:22,tcp:80,tcp:8080,tcp:30000-32767,udp:30000-32767"
defaultCreate = "container clusters create --quiet"
endpoint = "https://staging-container.sandbox.googleapis.com/"
image = "cos"
)

Expand Down Expand Up @@ -84,6 +83,7 @@ type deployer struct {
region string
cluster string
network string
environment string
createCommandFlag string
gcpServiceAccount string

Expand Down Expand Up @@ -135,7 +135,7 @@ func (d *deployer) location() (string, error) {
if d.zone != "" {
return "--zone=" + d.zone, nil
}
return "--region" + d.region, nil
return "--region=" + d.region, nil
}

func (d *deployer) createCommand() []string {
Expand All @@ -152,6 +152,7 @@ func bindFlags(d *deployer) *pflag.FlagSet {
flags.StringVar(&d.createCommandFlag, "create-command", defaultCreate, "gcloud subcommand used to create a cluster. Modify if you need to pass arbitrary arguments to create.")
flags.StringVar(&d.gcpServiceAccount, "gcp-service-account", "", "Service account to activate before using gcloud")
flags.StringVar(&d.network, "network", "default", "Cluster network. Defaults to the default network.")
flags.StringVar(&d.environment, "environment", "staging", "Container API endpoint to use, one of 'test', 'staging', 'prod', or a custom https:// URL")
flags.StringVar(&d.project, "project", "", "Project to deploy to.")
flags.StringVar(&d.region, "region", "", "For use with gcloud commands")
flags.StringVar(&d.zone, "zone", "", "For use with gcloud commands")
Expand Down

0 comments on commit 0b216a6

Please sign in to comment.