Skip to content

Commit

Permalink
Fix the logic to verify network configs when boskos is used
Browse files Browse the repository at this point in the history
  • Loading branch information
chizhg committed Aug 7, 2020
1 parent 3d57413 commit 8c0280e
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
9 changes: 6 additions & 3 deletions kubetest2-gke/deployer/deployer.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,10 +141,13 @@ func New(opts types.Options) (types.Deployer, *pflag.FlagSet) {

// verifyCommonFlags validates flags for up phase.
func (d *deployer) verifyUpFlags() error {
if len(d.projects) == 0 && d.boskosProjectsRequested <= 0 {
return fmt.Errorf("either --project or --projects-requested with a value larger than 0 must be set for GKE deployment")
}
if err := d.verifyNetworkFlags(); err != nil {
return err
}
if d.clusters == nil {
if len(d.clusters) == 0 {
return fmt.Errorf("--cluster-name must be set for GKE deployment")
}
if _, err := d.location(); err != nil {
Expand All @@ -158,10 +161,10 @@ func (d *deployer) verifyUpFlags() error {

// verifyDownFlags validates flags for down phase.
func (d *deployer) verifyDownFlags() error {
if d.clusters == nil {
if len(d.clusters) == 0 {
return fmt.Errorf("--cluster-name must be set for GKE deployment")
}
if d.projects == nil {
if len(d.projects) == 0 {
return fmt.Errorf("--project must be set for GKE deployment")
}
if _, err := d.location(); err != nil {
Expand Down
10 changes: 7 additions & 3 deletions kubetest2-gke/deployer/network.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,17 +39,21 @@ etag: %s

func (d *deployer) verifyNetworkFlags() error {
// For single project, no verification is needed.
if len(d.projects) == 1 {
numProjects := len(d.projects)
if numProjects == 0 {
numProjects = d.boskosProjectsRequested
}
if numProjects == 1 {
return nil
}

if d.network == "default" {
return errors.New("the default network cannot be used for multi-project profile")
}

if len(d.subnetworkRanges) != len(d.projects)-1 {
if len(d.subnetworkRanges) != numProjects-1 {
return fmt.Errorf("the number of subnetwork ranges provided "+
"should be the same as the number of service projects: %d!=%d", len(d.subnetworkRanges), len(d.projects)-1)
"should be the same as the number of service projects: %d!=%d", len(d.subnetworkRanges), numProjects-1)
}

for _, sr := range d.subnetworkRanges {
Expand Down

0 comments on commit 8c0280e

Please sign in to comment.