mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-31 15:25:57 +00:00
Merge pull request #84662 from dims/script-based-hyperkube-to-avoid-dependencies
Script based hyperkube to avoid dependencies
This commit is contained in:
commit
84fcf126c1
@ -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}
|
||||
KUBE_BUILD_CONFORMANCE=${KUBE_BUILD_CONFORMANCE:-y}
|
||||
KUBE_BUILD_PULL_LATEST_IMAGES=${KUBE_BUILD_PULL_LATEST_IMAGES:-y}
|
||||
|
||||
@ -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"
|
||||
@ -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}" &
|
||||
|
@ -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",
|
||||
architectures = SERVER_PLATFORMS["linux"],
|
||||
base = "@debian-hyperkube-base-{ARCH}//image",
|
||||
cmd = [
|
||||
"/hyperkube",
|
||||
],
|
||||
# {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"],
|
||||
|
@ -14,5 +14,10 @@
|
||||
|
||||
FROM BASEIMAGE
|
||||
|
||||
# Copy the hyperkube binary
|
||||
# Cleanup all the soft links
|
||||
ADD binaries.tgz /usr/local/bin
|
||||
|
||||
# Copy the shell script
|
||||
COPY hyperkube /hyperkube
|
||||
|
||||
ENTRYPOINT ["/hyperkube"]
|
@ -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
|
||||
@ -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
|
||||
|
||||
|
76
cluster/images/hyperkube/hyperkube
Executable file
76
cluster/images/hyperkube/hyperkube
Executable file
@ -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() {
|
||||
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 "${@}"
|
@ -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",
|
||||
|
@ -1,48 +0,0 @@
|
||||
package(default_visibility = ["//visibility:public"])
|
||||
|
||||
load(
|
||||
"//build:go.bzl",
|
||||
go_binary = "go_binary_conditional_pure",
|
||||
)
|
||||
load("@io_bazel_rules_go//go:def.bzl", "go_library")
|
||||
load("//staging/src/k8s.io/component-base/version:def.bzl", "version_x_defs")
|
||||
|
||||
go_binary(
|
||||
name = "hyperkube",
|
||||
embed = [":go_default_library"],
|
||||
x_defs = version_x_defs(),
|
||||
)
|
||||
|
||||
go_library(
|
||||
name = "go_default_library",
|
||||
srcs = ["main.go"],
|
||||
importpath = "k8s.io/kubernetes/cmd/hyperkube",
|
||||
deps = [
|
||||
"//cmd/cloud-controller-manager/app:go_default_library",
|
||||
"//cmd/kube-apiserver/app:go_default_library",
|
||||
"//cmd/kube-controller-manager/app:go_default_library",
|
||||
"//cmd/kube-proxy/app:go_default_library",
|
||||
"//cmd/kube-scheduler/app:go_default_library",
|
||||
"//cmd/kubelet/app:go_default_library",
|
||||
"//pkg/kubectl/cmd:go_default_library",
|
||||
"//staging/src/k8s.io/component-base/cli/flag:go_default_library",
|
||||
"//staging/src/k8s.io/component-base/logs:go_default_library",
|
||||
"//staging/src/k8s.io/component-base/metrics/prometheus/restclient:go_default_library",
|
||||
"//staging/src/k8s.io/component-base/metrics/prometheus/version:go_default_library",
|
||||
"//vendor/github.com/spf13/cobra:go_default_library",
|
||||
"//vendor/github.com/spf13/pflag:go_default_library",
|
||||
],
|
||||
)
|
||||
|
||||
filegroup(
|
||||
name = "package-srcs",
|
||||
srcs = glob(["**"]),
|
||||
tags = ["automanaged"],
|
||||
visibility = ["//visibility:private"],
|
||||
)
|
||||
|
||||
filegroup(
|
||||
name = "all-srcs",
|
||||
srcs = [":package-srcs"],
|
||||
tags = ["automanaged"],
|
||||
)
|
@ -1,4 +0,0 @@
|
||||
# See the OWNERS docs at https://go.k8s.io/owners
|
||||
|
||||
labels:
|
||||
- sig/release
|
@ -1,125 +0,0 @@
|
||||
/*
|
||||
Copyright 2014 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.
|
||||
*/
|
||||
|
||||
// A binary that can morph into all of the other kubernetes binaries. You can
|
||||
// also soft-link to it busybox style.
|
||||
//
|
||||
package main
|
||||
|
||||
import (
|
||||
goflag "flag"
|
||||
"math/rand"
|
||||
"os"
|
||||
"path/filepath"
|
||||
"time"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/spf13/pflag"
|
||||
|
||||
cliflag "k8s.io/component-base/cli/flag"
|
||||
"k8s.io/component-base/logs"
|
||||
_ "k8s.io/component-base/metrics/prometheus/restclient" // for client metric registration
|
||||
_ "k8s.io/component-base/metrics/prometheus/version" // for version metric registration
|
||||
cloudcontrollermanager "k8s.io/kubernetes/cmd/cloud-controller-manager/app"
|
||||
kubeapiserver "k8s.io/kubernetes/cmd/kube-apiserver/app"
|
||||
kubecontrollermanager "k8s.io/kubernetes/cmd/kube-controller-manager/app"
|
||||
kubeproxy "k8s.io/kubernetes/cmd/kube-proxy/app"
|
||||
kubescheduler "k8s.io/kubernetes/cmd/kube-scheduler/app"
|
||||
kubelet "k8s.io/kubernetes/cmd/kubelet/app"
|
||||
kubectl "k8s.io/kubernetes/pkg/kubectl/cmd"
|
||||
)
|
||||
|
||||
func main() {
|
||||
rand.Seed(time.Now().UnixNano())
|
||||
|
||||
hyperkubeCommand, allCommandFns := NewHyperKubeCommand()
|
||||
|
||||
// TODO: once we switch everything over to Cobra commands, we can go back to calling
|
||||
// cliflag.InitFlags() (by removing its pflag.Parse() call). For now, we have to set the
|
||||
// normalize func and add the go flag set by hand.
|
||||
pflag.CommandLine.SetNormalizeFunc(cliflag.WordSepNormalizeFunc)
|
||||
pflag.CommandLine.AddGoFlagSet(goflag.CommandLine)
|
||||
// cliflag.InitFlags()
|
||||
logs.InitLogs()
|
||||
defer logs.FlushLogs()
|
||||
|
||||
basename := filepath.Base(os.Args[0])
|
||||
if err := commandFor(basename, hyperkubeCommand, allCommandFns).Execute(); err != nil {
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
func commandFor(basename string, defaultCommand *cobra.Command, commands []func() *cobra.Command) *cobra.Command {
|
||||
for _, commandFn := range commands {
|
||||
command := commandFn()
|
||||
if command.Name() == basename {
|
||||
return command
|
||||
}
|
||||
for _, alias := range command.Aliases {
|
||||
if alias == basename {
|
||||
return command
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return defaultCommand
|
||||
}
|
||||
|
||||
// NewHyperKubeCommand is the entry point for hyperkube
|
||||
func NewHyperKubeCommand() (*cobra.Command, []func() *cobra.Command) {
|
||||
// these have to be functions since the command is polymorphic. Cobra wants you to be top level
|
||||
// command to get executed
|
||||
apiserver := func() *cobra.Command { return kubeapiserver.NewAPIServerCommand() }
|
||||
controller := func() *cobra.Command { return kubecontrollermanager.NewControllerManagerCommand() }
|
||||
proxy := func() *cobra.Command { return kubeproxy.NewProxyCommand() }
|
||||
scheduler := func() *cobra.Command { return kubescheduler.NewSchedulerCommand() }
|
||||
kubectlCmd := func() *cobra.Command { return kubectl.NewDefaultKubectlCommand() }
|
||||
kubelet := func() *cobra.Command { return kubelet.NewKubeletCommand() }
|
||||
cloudController := func() *cobra.Command {
|
||||
cmd := cloudcontrollermanager.NewCloudControllerManagerCommand()
|
||||
cmd.Deprecated = "please use the cloud controller manager specific " +
|
||||
"to your external cloud provider"
|
||||
return cmd
|
||||
}
|
||||
|
||||
commandFns := []func() *cobra.Command{
|
||||
apiserver,
|
||||
controller,
|
||||
proxy,
|
||||
scheduler,
|
||||
kubectlCmd,
|
||||
kubelet,
|
||||
cloudController,
|
||||
}
|
||||
|
||||
cmd := &cobra.Command{
|
||||
Use: "hyperkube",
|
||||
Short: "Request a new project",
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
if len(args) != 0 {
|
||||
cmd.Help()
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
},
|
||||
}
|
||||
|
||||
for i := range commandFns {
|
||||
cmd.AddCommand(commandFns[i]())
|
||||
}
|
||||
|
||||
return cmd, commandFns
|
||||
}
|
Loading…
Reference in New Issue
Block a user