mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-29 14:37:00 +00:00
[Federation][init-11] Switch federation e2e tests to use the new federation control plane bootstrap via the kubefed init
command.
This commit is contained in:
parent
e2a9fc1022
commit
5a7644c502
@ -22,8 +22,5 @@ set -o pipefail
|
|||||||
|
|
||||||
KUBE_ROOT=$(dirname "${BASH_SOURCE}")/..
|
KUBE_ROOT=$(dirname "${BASH_SOURCE}")/..
|
||||||
|
|
||||||
source "${KUBE_ROOT}/build/util.sh"
|
make -C "${KUBE_ROOT}/federation/" build_image
|
||||||
|
make -C "${KUBE_ROOT}/federation/" push
|
||||||
source "${KUBE_ROOT}/federation/cluster/common.sh"
|
|
||||||
|
|
||||||
FEDERATION_IMAGE_TAG="$(kube::release::semantic_image_tag_version)" push-federation-images
|
|
||||||
|
@ -42,13 +42,5 @@ fi
|
|||||||
|
|
||||||
kube::build::copy_output
|
kube::build::copy_output
|
||||||
|
|
||||||
if [[ "${FEDERATION:-}" == "true" ]];then
|
|
||||||
(
|
|
||||||
source "${KUBE_ROOT}/build/util.sh"
|
|
||||||
# Write federated docker image tag to workspace
|
|
||||||
kube::release::semantic_image_tag_version > "${KUBE_ROOT}/federation/manifests/federated-image.tag"
|
|
||||||
)
|
|
||||||
fi
|
|
||||||
|
|
||||||
kube::release::package_tarballs
|
kube::release::package_tarballs
|
||||||
kube::release::package_hyperkube
|
kube::release::package_hyperkube
|
||||||
|
@ -35,11 +35,21 @@ fi
|
|||||||
|
|
||||||
# Federation utils
|
# Federation utils
|
||||||
|
|
||||||
|
# Sets the kubeconfig context value for the current cluster.
|
||||||
|
#
|
||||||
|
# Vars set:
|
||||||
|
# CLUSTER_CONTEXT
|
||||||
|
function kubeconfig-federation-context() {
|
||||||
|
CLUSTER_CONTEXT="federation-e2e-${KUBERNETES_PROVIDER}-$zone"
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
# Should NOT be called within the global scope, unless setting the desired global zone vars
|
# Should NOT be called within the global scope, unless setting the desired global zone vars
|
||||||
# This function is currently NOT USED in the global scope
|
# This function is currently NOT USED in the global scope
|
||||||
function set-federation-zone-vars {
|
function set-federation-zone-vars {
|
||||||
zone="$1"
|
zone="$1"
|
||||||
export OVERRIDE_CONTEXT="federation-e2e-${KUBERNETES_PROVIDER}-$zone"
|
kubeconfig-federation-context "${zone}"
|
||||||
|
export OVERRIDE_CONTEXT="${CLUSTER_CONTEXT}"
|
||||||
echo "Setting zone vars to: $OVERRIDE_CONTEXT"
|
echo "Setting zone vars to: $OVERRIDE_CONTEXT"
|
||||||
if [[ "$KUBERNETES_PROVIDER" == "gce" ]];then
|
if [[ "$KUBERNETES_PROVIDER" == "gce" ]];then
|
||||||
|
|
||||||
|
@ -46,7 +46,7 @@ if [[ -z "${FEDERATION_PUSH_REPO_BASE}" ]]; then
|
|||||||
fi
|
fi
|
||||||
|
|
||||||
FEDERATION_IMAGE_REPO_BASE=${FEDERATION_IMAGE_REPO_BASE:-'gcr.io/google_containers'}
|
FEDERATION_IMAGE_REPO_BASE=${FEDERATION_IMAGE_REPO_BASE:-'gcr.io/google_containers'}
|
||||||
FEDERATION_NAMESPACE=${FEDERATION_NAMESPACE:-federation}
|
FEDERATION_NAMESPACE=${FEDERATION_NAMESPACE:-federation-system}
|
||||||
|
|
||||||
KUBE_PLATFORM=${KUBE_PLATFORM:-linux}
|
KUBE_PLATFORM=${KUBE_PLATFORM:-linux}
|
||||||
KUBE_ARCH=${KUBE_ARCH:-amd64}
|
KUBE_ARCH=${KUBE_ARCH:-amd64}
|
||||||
|
@ -18,15 +18,66 @@ set -o errexit
|
|||||||
set -o nounset
|
set -o nounset
|
||||||
set -o pipefail
|
set -o pipefail
|
||||||
|
|
||||||
KUBE_ROOT=$(readlink -m $(dirname "${BASH_SOURCE}")/../../)
|
# This script is only used for e2e tests! Don't use it in production!
|
||||||
|
# This is also a temporary bridge to slowly switch over everything to
|
||||||
|
# federation/develop.sh. Carefully moving things step-by-step, ensuring
|
||||||
|
# things don't break.
|
||||||
|
# TODO(madhusudancs): Remove this script and its dependencies.
|
||||||
|
|
||||||
. ${KUBE_ROOT}/federation/cluster/common.sh
|
|
||||||
|
|
||||||
tagfile="${KUBE_ROOT}/federation/manifests/federated-image.tag"
|
KUBE_ROOT=$(dirname "${BASH_SOURCE}")/../..
|
||||||
if [[ ! -f "$tagfile" ]]; then
|
# For `kube::log::status` function since it already sources
|
||||||
echo "FATAL: tagfile ${tagfile} does not exist. Make sure that you have run build/push-federation-images.sh"
|
# "${KUBE_ROOT}/cluster/lib/logging.sh" and DEFAULT_KUBECONFIG
|
||||||
exit 1
|
source "${KUBE_ROOT}/cluster/common.sh"
|
||||||
fi
|
# For $KUBE_PLATFORM, $KUBE_ARCH, $KUBE_BUILD_STAGE,
|
||||||
export FEDERATION_IMAGE_TAG="$(cat "${KUBE_ROOT}/federation/manifests/federated-image.tag")"
|
# $FEDERATION_PUSH_REPO_BASE and $FEDERATION_NAMESPACE.
|
||||||
|
source "${KUBE_ROOT}/federation/cluster/common.sh"
|
||||||
|
# For `get_version` function and $KUBE_REGISTRY.
|
||||||
|
# TODO(madhusudancs): Remove this when the code here is moved
|
||||||
|
# to federation/develop.sh
|
||||||
|
source "${KUBE_ROOT}/federation/develop/develop.sh"
|
||||||
|
|
||||||
create-federation-api-objects
|
FEDERATION_NAME="${FEDERATION_NAME:-e2e-federation}"
|
||||||
|
DNS_ZONE_NAME="${FEDERATION_DNS_ZONE_NAME:-}"
|
||||||
|
HOST_CLUSTER_CONTEXT="${FEDERATION_HOST_CLUSTER_CONTEXT:-${1}}"
|
||||||
|
|
||||||
|
readonly CLIENT_BIN_DIR="${KUBE_ROOT}/_output/${KUBE_BUILD_STAGE}/client/${KUBE_PLATFORM}-${KUBE_ARCH}/kubernetes/client/bin"
|
||||||
|
kubefed="${CLIENT_BIN_DIR}/kubefed"
|
||||||
|
kubectl="${CLIENT_BIN_DIR}/kubectl"
|
||||||
|
|
||||||
|
# Initializes the control plane.
|
||||||
|
# TODO(madhusudancs): Move this to federation/develop.sh.
|
||||||
|
function init() {
|
||||||
|
kube::log::status "Deploying federation control plane for ${FEDERATION_NAME} in cluster ${HOST_CLUSTER_CONTEXT}"
|
||||||
|
|
||||||
|
local -r kube_version="$(get_version)"
|
||||||
|
|
||||||
|
${kubefed} init \
|
||||||
|
"${FEDERATION_NAME}" \
|
||||||
|
--host-cluster-context="${HOST_CLUSTER_CONTEXT}" \
|
||||||
|
--dns-zone-name="${DNS_ZONE_NAME}" \
|
||||||
|
--image="${KUBE_REGISTRY}/hyperkube-amd64:${kube_version}"
|
||||||
|
}
|
||||||
|
|
||||||
|
# create_cluster_secrets creates the secrets containing the kubeconfigs
|
||||||
|
# of the participating clusters in the host cluster. The kubeconfigs itself
|
||||||
|
# are created while deploying clusters, i.e. when kube-up is run.
|
||||||
|
function create_cluster_secrets() {
|
||||||
|
local -r kubeconfig_dir="$(dirname ${DEFAULT_KUBECONFIG})"
|
||||||
|
local -r base_dir="${kubeconfig_dir}/federation/kubernetes-apiserver"
|
||||||
|
|
||||||
|
# Create secrets with all the kubernetes-apiserver's kubeconfigs.
|
||||||
|
for dir in $(ls "${base_dir}"); do
|
||||||
|
# We create a secret with the same name as the directory name (which is
|
||||||
|
# same as cluster name in kubeconfig).
|
||||||
|
# Massage the name so that it is valid (should not contain "_" and max 253
|
||||||
|
# chars)
|
||||||
|
name=$(echo "${dir}" | sed -e "s/_/-/g") # Replace "_" by "-"
|
||||||
|
name=${name:0:252}
|
||||||
|
kube::log::status "Creating secret with name: ${name} in namespace ${FEDERATION_NAMESPACE}"
|
||||||
|
${kubectl} create secret generic ${name} --from-file="${base_dir}/${dir}/kubeconfig" --namespace="${FEDERATION_NAMESPACE}"
|
||||||
|
done
|
||||||
|
}
|
||||||
|
|
||||||
|
init
|
||||||
|
create_cluster_secrets
|
||||||
|
@ -117,7 +117,7 @@ function build_image() {
|
|||||||
make -C "${KUBE_ROOT}/cluster/images/hyperkube" build
|
make -C "${KUBE_ROOT}/cluster/images/hyperkube" build
|
||||||
}
|
}
|
||||||
|
|
||||||
function push() {
|
function get_version() {
|
||||||
local kube_version=""
|
local kube_version=""
|
||||||
if [[ -n "${KUBE_VERSION:-}" ]]; then
|
if [[ -n "${KUBE_VERSION:-}" ]]; then
|
||||||
kube_version="${KUBE_VERSION}"
|
kube_version="${KUBE_VERSION}"
|
||||||
@ -125,6 +125,11 @@ function push() {
|
|||||||
# Read the version back from the versions file if no version is given.
|
# Read the version back from the versions file if no version is given.
|
||||||
kube_version="$(jq -r '.KUBE_VERSION' ${VERSIONS_FILE})"
|
kube_version="$(jq -r '.KUBE_VERSION' ${VERSIONS_FILE})"
|
||||||
fi
|
fi
|
||||||
|
echo "${kube_version}"
|
||||||
|
}
|
||||||
|
|
||||||
|
function push() {
|
||||||
|
local -r kube_version="$(get_version)"
|
||||||
|
|
||||||
kube::log::status "Pushing hyperkube image to the registry"
|
kube::log::status "Pushing hyperkube image to the registry"
|
||||||
gcloud docker -- push "${KUBE_REGISTRY}/hyperkube-amd64:${kube_version}"
|
gcloud docker -- push "${KUBE_REGISTRY}/hyperkube-amd64:${kube_version}"
|
||||||
|
@ -43,14 +43,11 @@ if [[ "${FEDERATION:-}" == "true" ]]; then
|
|||||||
)
|
)
|
||||||
cur_ip_octet2="$((cur_ip_octet2 + 1))"
|
cur_ip_octet2="$((cur_ip_octet2 + 1))"
|
||||||
done
|
done
|
||||||
tagfile="${KUBE_ROOT}/federation/manifests/federated-image.tag"
|
|
||||||
if [[ ! -f "$tagfile" ]]; then
|
|
||||||
echo "FATAL: tagfile ${tagfile} does not exist. Make sure that you have run build/push-federation-images.sh"
|
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
export FEDERATION_IMAGE_TAG="$(cat "${KUBE_ROOT}/federation/manifests/federated-image.tag")"
|
|
||||||
|
|
||||||
"${KUBE_ROOT}/federation/cluster/federation-up.sh"
|
# Sets ${CLUSTER_CONTEXT}
|
||||||
|
kubeconfig-federation-context "${zone}"
|
||||||
|
|
||||||
|
"${KUBE_ROOT}/federation/cluster/federation-up.sh" "${CLUSTER_CONTEXT}"
|
||||||
else
|
else
|
||||||
test-setup
|
test-setup
|
||||||
fi
|
fi
|
||||||
|
@ -128,6 +128,7 @@ export PATH=$(dirname "${e2e_test}"):"${PATH}"
|
|||||||
--node-instance-group="${NODE_INSTANCE_GROUP:-}" \
|
--node-instance-group="${NODE_INSTANCE_GROUP:-}" \
|
||||||
--prefix="${KUBE_GCE_INSTANCE_PREFIX:-e2e}" \
|
--prefix="${KUBE_GCE_INSTANCE_PREFIX:-e2e}" \
|
||||||
--network="${KUBE_GCE_NETWORK:-${KUBE_GKE_NETWORK:-e2e}}" \
|
--network="${KUBE_GCE_NETWORK:-${KUBE_GKE_NETWORK:-e2e}}" \
|
||||||
|
--federated-kube-context="${FEDERATION_KUBE_CONTEXT:-e2e-federation}" \
|
||||||
${KUBE_CONTAINER_RUNTIME:+"--container-runtime=${KUBE_CONTAINER_RUNTIME}"} \
|
${KUBE_CONTAINER_RUNTIME:+"--container-runtime=${KUBE_CONTAINER_RUNTIME}"} \
|
||||||
${MASTER_OS_DISTRIBUTION:+"--master-os-distro=${MASTER_OS_DISTRIBUTION}"} \
|
${MASTER_OS_DISTRIBUTION:+"--master-os-distro=${MASTER_OS_DISTRIBUTION}"} \
|
||||||
${NODE_OS_DISTRIBUTION:+"--node-os-distro=${NODE_OS_DISTRIBUTION}"} \
|
${NODE_OS_DISTRIBUTION:+"--node-os-distro=${NODE_OS_DISTRIBUTION}"} \
|
||||||
|
@ -750,7 +750,7 @@ func (f *Framework) GetUnderlyingFederatedContexts() []E2EContext {
|
|||||||
|
|
||||||
e2eContexts := []E2EContext{}
|
e2eContexts := []E2EContext{}
|
||||||
for _, context := range kubeconfig.Contexts {
|
for _, context := range kubeconfig.Contexts {
|
||||||
if strings.HasPrefix(context.Name, "federation") && context.Name != "federation-cluster" {
|
if strings.HasPrefix(context.Name, "federation") && context.Name != federatedKubeContext {
|
||||||
|
|
||||||
user := kubeconfig.findUser(context.Context.User)
|
user := kubeconfig.findUser(context.Context.User)
|
||||||
if user == nil {
|
if user == nil {
|
||||||
|
@ -163,7 +163,7 @@ func RegisterClusterFlags() {
|
|||||||
flag.StringVar(&TestContext.KubeConfig, clientcmd.RecommendedConfigPathFlag, os.Getenv(clientcmd.RecommendedConfigPathEnvVar), "Path to kubeconfig containing embedded authinfo.")
|
flag.StringVar(&TestContext.KubeConfig, clientcmd.RecommendedConfigPathFlag, os.Getenv(clientcmd.RecommendedConfigPathEnvVar), "Path to kubeconfig containing embedded authinfo.")
|
||||||
flag.StringVar(&TestContext.KubeContext, clientcmd.FlagContext, "", "kubeconfig context to use/override. If unset, will use value from 'current-context'")
|
flag.StringVar(&TestContext.KubeContext, clientcmd.FlagContext, "", "kubeconfig context to use/override. If unset, will use value from 'current-context'")
|
||||||
flag.StringVar(&TestContext.KubeAPIContentType, "kube-api-content-type", "application/vnd.kubernetes.protobuf", "ContentType used to communicate with apiserver")
|
flag.StringVar(&TestContext.KubeAPIContentType, "kube-api-content-type", "application/vnd.kubernetes.protobuf", "ContentType used to communicate with apiserver")
|
||||||
flag.StringVar(&federatedKubeContext, "federated-kube-context", "federation-cluster", "kubeconfig context for federation-cluster.")
|
flag.StringVar(&federatedKubeContext, "federated-kube-context", "e2e-federation", "kubeconfig context for federation.")
|
||||||
|
|
||||||
flag.StringVar(&TestContext.KubeVolumeDir, "volume-dir", "/var/lib/kubelet", "Path to the directory containing the kubelet volumes.")
|
flag.StringVar(&TestContext.KubeVolumeDir, "volume-dir", "/var/lib/kubelet", "Path to the directory containing the kubelet volumes.")
|
||||||
flag.StringVar(&TestContext.CertDir, "cert-dir", "", "Path to the directory containing the certs. Default is empty, which doesn't use certs.")
|
flag.StringVar(&TestContext.CertDir, "cert-dir", "", "Path to the directory containing the certs. Default is empty, which doesn't use certs.")
|
||||||
|
@ -363,7 +363,7 @@ func SkipUnlessServerVersionGTE(v *utilversion.Version, c discovery.ServerVersio
|
|||||||
func SkipUnlessFederated(c clientset.Interface) {
|
func SkipUnlessFederated(c clientset.Interface) {
|
||||||
federationNS := os.Getenv("FEDERATION_NAMESPACE")
|
federationNS := os.Getenv("FEDERATION_NAMESPACE")
|
||||||
if federationNS == "" {
|
if federationNS == "" {
|
||||||
federationNS = "federation"
|
federationNS = "federation-system"
|
||||||
}
|
}
|
||||||
|
|
||||||
_, err := c.Core().Namespaces().Get(federationNS, metav1.GetOptions{})
|
_, err := c.Core().Namespaces().Get(federationNS, metav1.GetOptions{})
|
||||||
|
Loading…
Reference in New Issue
Block a user