Skip to content

Commit

Permalink
Merge branch 'master' into issue-1905/support-for-multiple-images-to-…
Browse files Browse the repository at this point in the history
…kind-load
  • Loading branch information
yashvardhan-kukreja authored Dec 3, 2020
2 parents df19f6a + 8759fc6 commit e55c625
Show file tree
Hide file tree
Showing 37 changed files with 625 additions and 499 deletions.
13 changes: 3 additions & 10 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,12 @@ _As contributors and maintainers of this project, and in the interest of fosteri

## Getting Started

We have full documentation on how to get started contributing here:

<!---
If your repo has certain guidelines for contribution, put them here ahead of the general k8s resources
-->

- [Contributor License Agreement](https://git.k8s.io/community/CLA.md) Kubernetes projects require that you sign a Contributor License Agreement (CLA) before we can accept your pull requests
- [Kubernetes Contributor Guide](https://git.k8s.io/community/contributors/guide) - Main contributor documentation, or you can just jump directly to the [contributing section](https://git.k8s.io/community/contributors/guide#contributing)
- [Contributor Cheat Sheet](https://git.k8s.io/community/contributors/guide/contributor-cheatsheet) - Common resources for existing developers
We have full documentation on how to get started contributing here: https://kind.sigs.k8s.io/docs/contributing/getting-started/, _please_ read this!
A lot of work went into this guide 🙃

## Mentorship

- [Mentoring Initiatives](https://git.k8s.io/community/mentoring) - We have a diverse set of mentorship programs available that are always looking for volunteers!
- [Mentoring Initiatives](https://git.k8s.io/community/mentoring) - Kubernetes has a diverse set of mentorship programs available that are always looking for volunteers!

<!---
Custom Information - if you're copying this template for the first time you can add custom content here, for example:
Expand Down
12 changes: 10 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,9 @@ PATH:=$(shell . hack/build/setup-go.sh && echo "$${PATH}")
GOROOT:=
# enable modules
GO111MODULE=on
export PATH GOROOT GO111MODULE
# disable CGO by default for static binaries
CGO_ENABLED=0
export PATH GOROOT GO111MODULE CGO_ENABLED
# work around broken PATH export
SPACE:=$(subst ,, )
SHELL:=env PATH=$(subst $(SPACE),\$(SPACE),$(PATH)) $(SHELL)
Expand Down Expand Up @@ -70,7 +72,13 @@ install: build
# ================================= Testing ====================================
# unit tests (hermetic)
unit:
hack/make-rules/unit.sh
MODE=unit hack/make-rules/test.sh
# integration tests
integration:
MODE=integration hack/make-rules/test.sh
# all tests
test:
hack/make-rules/test.sh
################################################################################
# ================================= Cleanup ====================================
# standard cleanup target
Expand Down
31 changes: 25 additions & 6 deletions hack/make-rules/unit.sh → hack/make-rules/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,30 +13,49 @@
# See the License for the specific language governing permissions and
# limitations under the License.

# script to run unit tests, with coverage enabled and junit xml output
# script to run unit / integration tests, with coverage enabled and junit xml output
set -o errexit -o nounset -o pipefail

# cd to the repo root and setup go
REPO_ROOT="$(cd "$(dirname "${BASH_SOURCE[0]}")/../.." && pwd -P)"
cd "${REPO_ROOT}"
source hack/build/setup-go.sh

# set to 'unit' or 'integration' to run a subset
MODE="${MODE:-all}"

# build gotestsum
cd 'hack/tools'
go build -o "${REPO_ROOT}/bin/gotestsum" gotest.tools/gotestsum
cd "${REPO_ROOT}"

go_test_opts=(
"-coverprofile=${REPO_ROOT}/bin/${MODE}.cov"
'-covermode' 'count'
'-coverpkg' 'sigs.k8s.io/kind/...'
)
if [[ "${MODE}" = 'unit' ]]; then
go_test_opts+=('-short' '-tags=nointegration')
elif [[ "${MODE}" = 'integration' ]]; then
go_test_opts+=('-run' '^TestIntegration')
fi

# run unit tests with coverage enabled and junit output
"${REPO_ROOT}/bin/gotestsum" --junitfile="${REPO_ROOT}/bin/junit.xml" -- \
-coverprofile="${REPO_ROOT}/bin/unit.cov" -covermode count -coverpkg sigs.k8s.io/kind/... ./...
(
set -x;
"${REPO_ROOT}/bin/gotestsum" --junitfile="${REPO_ROOT}/bin/${MODE}-junit.xml" \
-- "${go_test_opts[@]}" './...'
)

# filter out generated files
sed '/zz_generated/d' "${REPO_ROOT}/bin/unit.cov" > "${REPO_ROOT}/bin/filtered.cov"
sed '/zz_generated/d' "${REPO_ROOT}/bin/${MODE}.cov" > "${REPO_ROOT}/bin/${MODE}-filtered.cov"

# generate cover html
go tool cover -html="${REPO_ROOT}/bin/filtered.cov" -o "${REPO_ROOT}/bin/filtered.html"
go tool cover -html="${REPO_ROOT}/bin/${MODE}-filtered.cov" -o "${REPO_ROOT}/bin/${MODE}-filtered.html"

# if we are in CI, copy to the artifact upload location
if [[ -n "${ARTIFACTS:-}" ]]; then
cp bin/junit.xml "${REPO_ROOT}/bin/filtered.cov" "${REPO_ROOT}/bin/filtered.html" "${ARTIFACTS:?}/"
cp "bin/${MODE}-junit.xml" "${ARTIFACTS:?}/junit.xml"
cp "${REPO_ROOT}/bin/${MODE}-filtered.cov" "${ARTIFACTS:?}/filtered.cov"
cp "${REPO_ROOT}/bin/${MODE}-filtered.html" "${ARTIFACTS:?}/filtered.html"
fi
2 changes: 1 addition & 1 deletion pkg/apis/config/defaults/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,4 @@ limitations under the License.
package defaults

// Image is the default for the Config.Image field, aka the default node image.
const Image = "kindest/node:v1.19.3@sha256:e1ac015e061da4b931cc4f693e22d7bc1110f031faf7b2af4c4fefac9e65565d"
const Image = "kindest/node:v1.19.4@sha256:796d09e217d93bed01ecf8502633e48fd806fe42f9d02fdd468b81cd4e3bd40b"
35 changes: 25 additions & 10 deletions pkg/build/nodeimage/internal/kube/builder_docker.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ import (
"sigs.k8s.io/kind/pkg/errors"
"sigs.k8s.io/kind/pkg/exec"
"sigs.k8s.io/kind/pkg/log"

"k8s.io/apimachinery/pkg/util/version"
)

// TODO(bentheelder): plumb through arch
Expand Down Expand Up @@ -63,6 +65,26 @@ func (b *dockerBuilder) Build() (Bits, error) {
return nil, err
}

// capture version info
sourceVersionRaw, err := sourceVersion(b.kubeRoot)
if err != nil {
return nil, err
}

// check for version specific workarounds
ver, err := version.ParseSemantic(sourceVersionRaw)
if err != nil {
return nil, errors.Wrap(err, "failed to parse source version")
}
// leverage in-tree-cloud-provider-free builds by default
// https://github.com/kubernetes/kubernetes/pull/80353
// leverage dockershim free builds by default
// https://github.com/kubernetes/kubernetes/pull/87746
goflags := "GOFLAGS=-tags=providerless,dockerless"
if ver.LessThan(version.MustParseSemantic("v1.19.0")) {
goflags = "GOFLAGS=-tags=providerless"
}

// we will pass through the environment variables, prepending defaults
// NOTE: if env are specified multiple times the last one wins
env := append(
Expand All @@ -74,9 +96,8 @@ func (b *dockerBuilder) Build() (Bits, error) {
"KUBE_BUILD_CONFORMANCE=n",
// build for the host platform
"KUBE_BUILD_PLATFORMS=" + dockerBuildOsAndArch(b.arch),
// leverage in-tree-cloud-provider-free builds by default
// https://github.com/kubernetes/kubernetes/pull/80353
"GOFLAGS=-tags=providerless",
// pass goflags
goflags,
},
os.Environ()...,
)
Expand All @@ -103,12 +124,6 @@ func (b *dockerBuilder) Build() (Bits, error) {
return nil, errors.Wrap(err, "failed to build images")
}

// capture version info
version, err := sourceVersion(b.kubeRoot)
if err != nil {
return nil, err
}

binDir := filepath.Join(b.kubeRoot,
"_output", "dockerized", "bin", "linux", b.arch,
)
Expand All @@ -128,7 +143,7 @@ func (b *dockerBuilder) Build() (Bits, error) {
filepath.Join(imageDir, "kube-scheduler.tar"),
filepath.Join(imageDir, "kube-proxy.tar"),
},
version: version,
version: sourceVersionRaw,
}, nil
}

Expand Down
81 changes: 81 additions & 0 deletions pkg/cluster/internal/providers/docker/network_integration_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
// +build !nointegration

/*
Copyright 2020 The Kubernetes Authors.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package docker

import (
"fmt"
"regexp"
"testing"

"sigs.k8s.io/kind/pkg/errors"
"sigs.k8s.io/kind/pkg/exec"

"sigs.k8s.io/kind/pkg/internal/integration"
)

func TestIntegrationEnsureNetworkConcurrent(t *testing.T) {
integration.MaybeSkip(t)

testNetworkName := "integration-test-ensure-kind-network"

// cleanup
cleanup := func() {
ids, _ := networksWithName(testNetworkName)
if len(ids) > 0 {
_ = deleteNetworks(ids...)
}
}
cleanup()
defer cleanup()

// this is more than enough to trigger race conditions
networkConcurrency := 10

// Create multiple networks concurrently
errCh := make(chan error, networkConcurrency)
for i := 0; i < networkConcurrency; i++ {
go func() {
errCh <- ensureNetwork(testNetworkName)
}()
}
for i := 0; i < networkConcurrency; i++ {
if err := <-errCh; err != nil {
t.Errorf("error creating network: %v", err)
rerr := exec.RunErrorForError(err)
if rerr != nil {
t.Errorf("%q", rerr.Output)
}
t.Errorf("%+v", errors.StackTrace(err))
}
}

cmd := exec.Command(
"docker", "network", "ls",
fmt.Sprintf("--filter=name=^%s$", regexp.QuoteMeta(testNetworkName)),
"--format={{.Name}}",
)

lines, err := exec.OutputLines(cmd)
if err != nil {
t.Errorf("obtaining the docker networks")
}
if len(lines) != 1 {
t.Errorf("wrong number of networks created: %d", len(lines))
}
}
56 changes: 0 additions & 56 deletions pkg/cluster/internal/providers/docker/network_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,67 +18,11 @@ package docker

import (
"fmt"
"regexp"
"testing"

"sigs.k8s.io/kind/pkg/errors"
"sigs.k8s.io/kind/pkg/exec"

"sigs.k8s.io/kind/pkg/internal/assert"
"sigs.k8s.io/kind/pkg/internal/integration"
)

func TestIntegrationEnsureNetworkConcurrent(t *testing.T) {
integration.MaybeSkip(t)

testNetworkName := "integration-test-ensure-kind-network"

// cleanup
cleanup := func() {
ids, _ := networksWithName(testNetworkName)
if len(ids) > 0 {
_ = deleteNetworks(ids...)
}
}
cleanup()
defer cleanup()

// this is more than enough to trigger race conditions
networkConcurrency := 10

// Create multiple networks concurrently
errCh := make(chan error, networkConcurrency)
for i := 0; i < networkConcurrency; i++ {
go func() {
errCh <- ensureNetwork(testNetworkName)
}()
}
for i := 0; i < networkConcurrency; i++ {
if err := <-errCh; err != nil {
t.Errorf("error creating network: %v", err)
rerr := exec.RunErrorForError(err)
if rerr != nil {
t.Errorf("%q", rerr.Output)
}
t.Errorf("%+v", errors.StackTrace(err))
}
}

cmd := exec.Command(
"docker", "network", "ls",
fmt.Sprintf("--filter=name=^%s$", regexp.QuoteMeta(testNetworkName)),
"--format={{.Name}}",
)

lines, err := exec.OutputLines(cmd)
if err != nil {
t.Errorf("obtaining the docker networks")
}
if len(lines) != 1 {
t.Errorf("wrong number of networks created: %d", len(lines))
}
}

func Test_generateULASubnetFromName(t *testing.T) {
t.Parallel()
cases := []struct {
Expand Down
Loading

0 comments on commit e55c625

Please sign in to comment.