Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Script based hyperkube to avoid dependencies #84662

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
22 changes: 22 additions & 0 deletions build/lib/release.sh
Expand Up @@ -28,6 +28,7 @@ readonly RELEASE_STAGE="${LOCAL_OUTPUT_ROOT}/release-stage"
readonly RELEASE_TARS="${LOCAL_OUTPUT_ROOT}/release-tars"
readonly RELEASE_IMAGES="${LOCAL_OUTPUT_ROOT}/release-images"

KUBE_BUILD_HYPERKUBE=${KUBE_BUILD_HYPERKUBE:-y}
dims marked this conversation as resolved.
Show resolved Hide resolved
KUBE_BUILD_CONFORMANCE=${KUBE_BUILD_CONFORMANCE:-y}
KUBE_BUILD_PULL_LATEST_IMAGES=${KUBE_BUILD_PULL_LATEST_IMAGES:-y}

Expand Down Expand Up @@ -278,6 +279,23 @@ function kube::release::sha1() {
fi
}

function kube::release::build_hyperkube_image() {
local -r arch="$1"
local -r registry="$2"
local -r version="$3"
local -r save_dir="${4-}"
kube::log::status "Building hyperkube image for arch: ${arch}"
ARCH="${arch}" REGISTRY="${registry}" VERSION="${version}" \
make -C cluster/images/hyperkube/ build >/dev/null

local hyperkube_tag="${registry}/hyperkube-${arch}:${version}"
if [[ -n "${save_dir}" ]]; then
"${DOCKER[@]}" save "${hyperkube_tag}" > "${save_dir}/hyperkube-${arch}.tar"
fi
kube::log::status "Deleting hyperkube image ${hyperkube_tag}"
"${DOCKER[@]}" rmi "${hyperkube_tag}" &>/dev/null || true
}

function kube::release::build_conformance_image() {
local -r arch="$1"
local -r registry="$2"
Expand Down Expand Up @@ -378,6 +396,10 @@ EOF
) &
done

if [[ "${KUBE_BUILD_HYPERKUBE}" =~ [yY] ]]; then
kube::release::build_hyperkube_image "${arch}" "${docker_registry}" \
"${docker_tag}" "${images_dir}" &
fi
if [[ "${KUBE_BUILD_CONFORMANCE}" =~ [yY] ]]; then
kube::release::build_conformance_image "${arch}" "${docker_registry}" \
"${docker_tag}" "${images_dir}" &
Expand Down
32 changes: 29 additions & 3 deletions cluster/images/hyperkube/BUILD
@@ -1,16 +1,42 @@
load("@io_bazel_rules_docker//container:container.bzl", "container_layer")
load("//build:container.bzl", "multi_arch_container")
load("//build:platforms.bzl", "SERVER_PLATFORMS")

container_layer(
name = "scripts",
directory = "/",
files = [
"hyperkube",
],
)

container_layer(
name = "bins",
directory = "/usr/local/bin",
files = [
"//cmd/kube-apiserver",
"//cmd/kube-controller-manager",
"//cmd/kube-proxy",
"//cmd/kube-scheduler",
"//cmd/kubectl",
"//cmd/kubelet",
],
)

multi_arch_container(
name = "hyperkube",
name = "image",
liggitt marked this conversation as resolved.
Show resolved Hide resolved
architectures = SERVER_PLATFORMS["linux"],
base = "@debian-hyperkube-base-{ARCH}//image",
cmd = [
"/hyperkube",
dims marked this conversation as resolved.
Show resolved Hide resolved
],
# {ARCH} is replaced by the macro, but STABLE_ vars are replaced by the
# build stamping, so we need to escape them
docker_push_tags = ["{{STABLE_DOCKER_PUSH_REGISTRY}}/hyperkube-{ARCH}:{{STABLE_DOCKER_TAG}}"],
docker_tags = ["{{STABLE_DOCKER_REGISTRY}}/hyperkube-{ARCH}:{{STABLE_DOCKER_TAG}}"],
files = [
"//cmd/hyperkube",
layers = [
":bins",
":scripts",
],
stamp = True,
tags = ["manual"],
Expand Down
7 changes: 6 additions & 1 deletion cluster/images/hyperkube/Dockerfile
Expand Up @@ -14,5 +14,10 @@

FROM BASEIMAGE

# Copy the hyperkube binary
# Cleanup all the soft links
ADD binaries.tgz /usr/local/bin
dims marked this conversation as resolved.
Show resolved Hide resolved
dims marked this conversation as resolved.
Show resolved Hide resolved

# Copy the shell script
COPY hyperkube /hyperkube
dims marked this conversation as resolved.
Show resolved Hide resolved

ENTRYPOINT ["/hyperkube"]
10 changes: 8 additions & 2 deletions cluster/images/hyperkube/Makefile
Expand Up @@ -20,9 +20,13 @@
REGISTRY?=staging-k8s.gcr.io
ARCH?=amd64
OUT_DIR?=_output
HYPERKUBE_BIN?=$(shell pwd)/../../../$(OUT_DIR)/dockerized/bin/linux/$(ARCH)/hyperkube

BASEIMAGE=k8s.gcr.io/debian-hyperkube-base-$(ARCH):0.12.1

LOCAL_OUTPUT_PATH=$(shell pwd)/../../../$(OUT_DIR)/local/bin/linux/$(ARCH)
DOCKERIZED_OUTPUT_PATH=$(shell pwd)/../../../$(OUT_DIR)/dockerized/bin/linux/$(ARCH)
OUTPUT_PATH?=$(shell test -d $(LOCAL_OUTPUT_PATH) && echo $(LOCAL_OUTPUT_PATH) || echo $(DOCKERIZED_OUTPUT_PATH))

TEMP_DIR:=$(shell mktemp -d -t hyperkubeXXXXXX)

all: build
Expand All @@ -33,7 +37,9 @@ ifndef VERSION
$(error VERSION is undefined)
endif
cp -r ./* ${TEMP_DIR}
cp ${HYPERKUBE_BIN} ${TEMP_DIR}

tar -cvzf ${TEMP_DIR}/binaries.tgz -C ${OUTPUT_PATH} kube-apiserver kube-controller-manager \
kube-proxy kube-scheduler kubectl kubelet

chmod a+rx ${TEMP_DIR}/hyperkube
dims marked this conversation as resolved.
Show resolved Hide resolved

Expand Down
76 changes: 76 additions & 0 deletions cluster/images/hyperkube/hyperkube
@@ -0,0 +1,76 @@
#!/usr/bin/env bash

# Copyright 2019 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.

set -o errexit
set -o nounset
set -o pipefail

BINS=(
kube-apiserver
kube-controller-manager
kube-proxy
kube-scheduler
kubectl
kubelet
)

function array_contains() {
local search="$1"
local element
shift
for element; do
if [[ "${element}" == "${search}" ]]; then
return 0
fi
done
return 1
}

function print_usage() {
cat <<EOF
Usage:
$(basename "$0") [command]

Available Commands:
help Help about any command
kube-apiserver
kube-controller-manager
kube-proxy
kube-scheduler
kubectl kubectl controls the Kubernetes cluster manager
kubelet
EOF
exit 0
}

function main() {
dims marked this conversation as resolved.
Show resolved Hide resolved
if [[ "$#" -lt 1 || "${1:-}" == "--help" || "${1:-}" == "help" ]]; then
print_usage
fi
if ! array_contains "$1" "${BINS[@]}"; then
echo "$1: command not supported"
print_usage
fi
command=${1}
shift
if ! command -v "${command}" &>/dev/null; then
echo "${command}: command not found"
exit 1
fi
exec "${command}" "${@}"
}

main "${@}"
1 change: 0 additions & 1 deletion cmd/BUILD
Expand Up @@ -20,7 +20,6 @@ filegroup(
"//cmd/genswaggertypedocs:all-srcs",
"//cmd/genutils:all-srcs",
"//cmd/genyaml:all-srcs",
"//cmd/hyperkube:all-srcs",
"//cmd/importverifier:all-srcs",
"//cmd/kube-apiserver:all-srcs",
"//cmd/kube-controller-manager:all-srcs",
Expand Down
48 changes: 0 additions & 48 deletions cmd/hyperkube/BUILD

This file was deleted.

4 changes: 0 additions & 4 deletions cmd/hyperkube/OWNERS

This file was deleted.

125 changes: 0 additions & 125 deletions cmd/hyperkube/main.go

This file was deleted.