github.com/shashidharatd/test-infra@v0.0.0-20171006011030-71304e1ca560/kubetest/bash.go (about)

     1  /*
     2  Copyright 2017 The Kubernetes Authors.
     3  
     4  Licensed under the Apache License, Version 2.0 (the "License");
     5  you may not use this file except in compliance with the License.
     6  You may obtain a copy of the License at
     7  
     8      http://www.apache.org/licenses/LICENSE-2.0
     9  
    10  Unless required by applicable law or agreed to in writing, software
    11  distributed under the License is distributed on an "AS IS" BASIS,
    12  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    13  See the License for the specific language governing permissions and
    14  limitations under the License.
    15  */
    16  
    17  package main
    18  
    19  import (
    20  	"os"
    21  	"os/exec"
    22  	"strconv"
    23  )
    24  
    25  type bashDeployer struct {
    26  	clusterIPRange *string
    27  }
    28  
    29  var _ deployer = &bashDeployer{}
    30  
    31  func newBash(clusterIPRange *string) *bashDeployer {
    32  	b := &bashDeployer{clusterIPRange}
    33  	return b
    34  }
    35  
    36  func (b *bashDeployer) Up() error {
    37  	if b.clusterIPRange == nil || *b.clusterIPRange == "" {
    38  		if numNodes, err := strconv.Atoi(os.Getenv("NUM_NODES")); err == nil {
    39  			*b.clusterIPRange = getClusterIPRange(numNodes)
    40  		}
    41  	}
    42  	if *b.clusterIPRange != "" {
    43  		pop, err := pushEnv("CLUSTER_IP_RANGE", *b.clusterIPRange)
    44  		if err != nil {
    45  			return err
    46  		}
    47  		defer pop()
    48  	}
    49  	return finishRunning(exec.Command("./hack/e2e-internal/e2e-up.sh"))
    50  }
    51  
    52  func (b *bashDeployer) IsUp() error {
    53  	return finishRunning(exec.Command("./hack/e2e-internal/e2e-status.sh"))
    54  }
    55  
    56  func (b *bashDeployer) DumpClusterLogs(localPath, gcsPath string) error {
    57  	return defaultDumpClusterLogs(localPath, gcsPath)
    58  }
    59  
    60  func (b *bashDeployer) TestSetup() error {
    61  	return nil
    62  }
    63  
    64  func (b *bashDeployer) Down() error {
    65  	return finishRunning(exec.Command("./hack/e2e-internal/e2e-down.sh"))
    66  }
    67  
    68  // Calculates the cluster IP range based on the no. of nodes in the cluster.
    69  // Note: This mimics the function get-cluster-ip-range used by kube-up script.
    70  func getClusterIPRange(numNodes int) string {
    71  	suggestedRange := "10.64.0.0/14"
    72  	if numNodes > 1000 {
    73  		suggestedRange = "10.64.0.0/13"
    74  	}
    75  	if numNodes > 2000 {
    76  		suggestedRange = "10.64.0.0/12"
    77  	}
    78  	if numNodes > 4000 {
    79  		suggestedRange = "10.64.0.0/11"
    80  	}
    81  	return suggestedRange
    82  }