github.com/abayer/test-infra@v0.0.5/kubetest/build.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  	"fmt"
    21  	"os/exec"
    22  
    23  	"k8s.io/test-infra/kubetest/dind"
    24  	"k8s.io/test-infra/kubetest/util"
    25  )
    26  
    27  const (
    28  	buildDefault = "quick"
    29  )
    30  
    31  type buildStrategy string
    32  
    33  // Support both --build and --build=foo
    34  func (b *buildStrategy) IsBoolFlag() bool {
    35  	return true
    36  }
    37  
    38  // Return b as a string
    39  func (b *buildStrategy) String() string {
    40  	return string(*b)
    41  }
    42  
    43  // Set to --build=B or buildDefault if just --build
    44  func (b *buildStrategy) Set(value string) error {
    45  	if value == "true" { // just --build, choose default
    46  		value = buildDefault
    47  	}
    48  	switch value {
    49  	case "bazel", "dind", "e2e", "host-go", "quick", "release":
    50  		*b = buildStrategy(value)
    51  		return nil
    52  	}
    53  	return fmt.Errorf("bad build strategy: %v (use: bazel, dind, e2e, host-go, quick, release)", value)
    54  }
    55  
    56  func (b *buildStrategy) Type() string {
    57  	return "buildStrategy"
    58  }
    59  
    60  // True when this kubetest invocation wants to build a release
    61  func (b *buildStrategy) Enabled() bool {
    62  	return *b != ""
    63  }
    64  
    65  // Build kubernetes according to specified strategy.
    66  // This may be a bazel, host-go, quick or full release build depending on --build=B.
    67  func (b *buildStrategy) Build() error {
    68  	var target string
    69  	switch *b {
    70  	case "bazel":
    71  		target = "bazel-release"
    72  	case "dind":
    73  		return dind.NewBuilder(util.K8s("kubernetes"), util.K8s("test-infra", "dind"), control).Build()
    74  	case "e2e":
    75  		//TODO(Q-Lee): we should have a better way of build just the e2e tests
    76  		target = "bazel-release"
    77  	// you really should use "bazel" or "quick" in most cases, but in CI
    78  	// we are mimicking these in our job container without an extra level
    79  	// of sandboxing in some cases
    80  	case "host-go":
    81  		target = "all"
    82  	case "quick":
    83  		target = "quick-release"
    84  	case "release":
    85  		target = "release"
    86  	default:
    87  		return fmt.Errorf("Unknown build strategy: %v", b)
    88  	}
    89  
    90  	// TODO(fejta): FIX ME
    91  	// The build-release script needs stdin to ask the user whether
    92  	// it's OK to download the docker image.
    93  	return control.FinishRunning(exec.Command("make", "-C", util.K8s("kubernetes"), target))
    94  }
    95  
    96  type buildFederationStrategy struct {
    97  	buildStrategy
    98  }
    99  
   100  type buildIngressGCEStrategy struct {
   101  	buildStrategy
   102  }
   103  
   104  func (b *buildFederationStrategy) Type() string {
   105  	return "buildFederationStrategy"
   106  }
   107  
   108  func (b *buildIngressGCEStrategy) Type() string {
   109  	return "buildIngressGCEStrategy"
   110  }
   111  
   112  // Build federation according to specified strategy.
   113  // This may be a bazel, quick or full release build depending on --build=B.
   114  func (b *buildFederationStrategy) Build() error {
   115  	var target string
   116  	switch b.String() {
   117  	case "bazel":
   118  		target = "bazel-release"
   119  	case "quick":
   120  		target = "quick-release"
   121  	case "release":
   122  		target = "release"
   123  	default:
   124  		return fmt.Errorf("unknown federation build strategy: %v", b)
   125  	}
   126  
   127  	return control.FinishRunning(exec.Command("make", "-C", util.K8s("federation"), target))
   128  }