github.com/deis/workflow-e2e@v2.12.2-0.20180227201524-4105be7001fe+incompatible/tests/settings/settings.go (about)

     1  package settings
     2  
     3  import (
     4  	"fmt"
     5  	"log"
     6  	"os"
     7  	"time"
     8  
     9  	"github.com/deis/workflow-e2e/tests/util"
    10  )
    11  
    12  const (
    13  	DeisRootHostname = "k8s.local"
    14  )
    15  
    16  var (
    17  	ActualHome               = os.Getenv("HOME")
    18  	TestHome                 string
    19  	TestRoot                 string
    20  	DeisControllerURL        string
    21  	DefaultEventuallyTimeout time.Duration
    22  	MaxEventuallyTimeout     time.Duration
    23  	GitSSH                   string
    24  	Debug                    = os.Getenv("DEBUG") != ""
    25  )
    26  
    27  func init() {
    28  	DeisControllerURL = getControllerURL()
    29  	defaultEventuallyTimeoutStr := os.Getenv("DEFAULT_EVENTUALLY_TIMEOUT")
    30  	if defaultEventuallyTimeoutStr == "" {
    31  		DefaultEventuallyTimeout = 60 * time.Second
    32  	} else {
    33  		DefaultEventuallyTimeout, _ = time.ParseDuration(defaultEventuallyTimeoutStr)
    34  	}
    35  
    36  	maxEventuallyTimeoutStr := os.Getenv("MAX_EVENTUALLY_TIMEOUT")
    37  	if maxEventuallyTimeoutStr == "" {
    38  		MaxEventuallyTimeout = 600 * time.Second
    39  	} else {
    40  		MaxEventuallyTimeout, _ = time.ParseDuration(maxEventuallyTimeoutStr)
    41  	}
    42  }
    43  
    44  func getControllerURL() string {
    45  	// if DEIS_CONTROLLER_URL exists in the environment, use that
    46  	controllerURL := os.Getenv("DEIS_CONTROLLER_URL")
    47  	if controllerURL != "" {
    48  		return controllerURL
    49  	}
    50  
    51  	// otherwise, rely on kubernetes and some DNS magic
    52  	host := "deis." + DeisRootHostname
    53  	if err := util.AddToEtcHosts(host); err != nil {
    54  		log.Fatalf("Could not write %s to /etc/hosts (%s)", host, err)
    55  	}
    56  	// also gotta write a route for the builder
    57  	builderHost := "deis-builder." + DeisRootHostname
    58  	if err := util.AddToEtcHosts(builderHost); err != nil {
    59  		log.Fatalf("Could not write %s to /etc/hosts (%s)", builderHost, err)
    60  	}
    61  
    62  	port := os.Getenv("DEIS_ROUTER_SERVICE_PORT")
    63  	switch port {
    64  	case "443":
    65  		return "https://" + host
    66  	case "80", "":
    67  		return "http://" + host
    68  	default:
    69  		return fmt.Sprintf("http://%s:%s", host, port)
    70  	}
    71  }