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