mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-07-23 19:56:01 +00:00
Simplifying the code to create kubeconfig
This commit is contained in:
parent
9026195614
commit
864b267a8d
@ -1308,14 +1308,7 @@ function build-config() {
|
|||||||
# Update the user's kubeconfig to include credentials for this apiserver.
|
# Update the user's kubeconfig to include credentials for this apiserver.
|
||||||
create-kubeconfig
|
create-kubeconfig
|
||||||
|
|
||||||
if [[ "${FEDERATION:-}" == "true" ]]; then
|
create-kubeconfig-for-federation
|
||||||
# Create a kubeconfig with credentials for this apiserver. We will later use
|
|
||||||
# this kubeconfig to create a secret which the federation control plane can
|
|
||||||
# use to talk to this apiserver.
|
|
||||||
KUBECONFIG_DIR=$(dirname ${KUBECONFIG:-$DEFAULT_KUBECONFIG})
|
|
||||||
KUBECONFIG="${KUBECONFIG_DIR}/federation/kubernetes-apiserver/${CONTEXT}/kubeconfig" \
|
|
||||||
create-kubeconfig
|
|
||||||
fi
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -152,6 +152,19 @@ function clear-kubeconfig() {
|
|||||||
echo "Cleared config for ${CONTEXT} from ${KUBECONFIG}"
|
echo "Cleared config for ${CONTEXT} from ${KUBECONFIG}"
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# Creates a kubeconfig file with the credentials for only the current-context
|
||||||
|
# cluster. This is used by federation to create secrets in test setup.
|
||||||
|
function create-kubeconfig-for-federation() {
|
||||||
|
if [[ "${FEDERATION:-}" == "true" ]]; then
|
||||||
|
echo "creating kubeconfig for federation secret"
|
||||||
|
local kubectl="${KUBE_ROOT}/cluster/kubectl.sh"
|
||||||
|
local cc=$("${kubectl}" config view -o jsonpath='{.current-context}')
|
||||||
|
KUBECONFIG_DIR=$(dirname ${KUBECONFIG:-$DEFAULT_KUBECONFIG})
|
||||||
|
KUBECONFIG_PATH="${KUBECONFIG_DIR}/federation/kubernetes-apiserver/${cc}"
|
||||||
|
mkdir -p "${KUBECONFIG_PATH}"
|
||||||
|
"${kubectl}" config view --minify --flatten > "${KUBECONFIG_PATH}/kubeconfig"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
function tear_down_alive_resources() {
|
function tear_down_alive_resources() {
|
||||||
local kubectl="${KUBE_ROOT}/cluster/kubectl.sh"
|
local kubectl="${KUBE_ROOT}/cluster/kubectl.sh"
|
||||||
|
@ -920,14 +920,7 @@ function check-cluster() {
|
|||||||
# Update the user's kubeconfig to include credentials for this apiserver.
|
# Update the user's kubeconfig to include credentials for this apiserver.
|
||||||
create-kubeconfig
|
create-kubeconfig
|
||||||
|
|
||||||
if [[ "${FEDERATION:-}" == "true" ]]; then
|
create-kubeconfig-for-federation
|
||||||
# Create a kubeconfig with credentials for this apiserver. We will later use
|
|
||||||
# this kubeconfig to create a secret which the federation control plane can
|
|
||||||
# use to talk to this apiserver.
|
|
||||||
KUBECONFIG_DIR=$(dirname ${KUBECONFIG:-$DEFAULT_KUBECONFIG})
|
|
||||||
KUBECONFIG="${KUBECONFIG_DIR}/federation/kubernetes-apiserver/${CONTEXT}/kubeconfig" \
|
|
||||||
create-kubeconfig
|
|
||||||
fi
|
|
||||||
)
|
)
|
||||||
|
|
||||||
# ensures KUBECONFIG is set
|
# ensures KUBECONFIG is set
|
||||||
|
@ -26,7 +26,6 @@ NETWORK="${NETWORK:-default}"
|
|||||||
NETWORK_RANGE="${NETWORK_RANGE:-10.240.0.0/16}"
|
NETWORK_RANGE="${NETWORK_RANGE:-10.240.0.0/16}"
|
||||||
FIREWALL_SSH="${FIREWALL_SSH:-${NETWORK}-allow-ssh}"
|
FIREWALL_SSH="${FIREWALL_SSH:-${NETWORK}-allow-ssh}"
|
||||||
GCLOUD="${GCLOUD:-gcloud}"
|
GCLOUD="${GCLOUD:-gcloud}"
|
||||||
KUBECTL="${KUBECTL:-kubectl}"
|
|
||||||
CMD_GROUP="${CMD_GROUP:-}"
|
CMD_GROUP="${CMD_GROUP:-}"
|
||||||
GCLOUD_CONFIG_DIR="${GCLOUD_CONFIG_DIR:-${HOME}/.config/gcloud/kubernetes}"
|
GCLOUD_CONFIG_DIR="${GCLOUD_CONFIG_DIR:-${HOME}/.config/gcloud/kubernetes}"
|
||||||
MACHINE_TYPE="${MACHINE_TYPE:-n1-standard-2}"
|
MACHINE_TYPE="${MACHINE_TYPE:-n1-standard-2}"
|
||||||
|
@ -23,6 +23,7 @@ KUBE_PROMPT_FOR_UPDATE=y
|
|||||||
KUBE_SKIP_UPDATE=${KUBE_SKIP_UPDATE-"n"}
|
KUBE_SKIP_UPDATE=${KUBE_SKIP_UPDATE-"n"}
|
||||||
KUBE_ROOT=$(dirname "${BASH_SOURCE}")/../..
|
KUBE_ROOT=$(dirname "${BASH_SOURCE}")/../..
|
||||||
source "${KUBE_ROOT}/cluster/gke/${KUBE_CONFIG_FILE:-config-default.sh}"
|
source "${KUBE_ROOT}/cluster/gke/${KUBE_CONFIG_FILE:-config-default.sh}"
|
||||||
|
source "${KUBE_ROOT}/cluster/common.sh"
|
||||||
source "${KUBE_ROOT}/cluster/lib/util.sh"
|
source "${KUBE_ROOT}/cluster/lib/util.sh"
|
||||||
|
|
||||||
# Perform preparations required to run e2e tests
|
# Perform preparations required to run e2e tests
|
||||||
@ -193,25 +194,7 @@ function kube-up() {
|
|||||||
# Bring up the cluster.
|
# Bring up the cluster.
|
||||||
"${GCLOUD}" ${CMD_GROUP:-} container clusters create "${CLUSTER_NAME}" "${create_args[@]}"
|
"${GCLOUD}" ${CMD_GROUP:-} container clusters create "${CLUSTER_NAME}" "${create_args[@]}"
|
||||||
|
|
||||||
if [[ "${FEDERATION:-}" == "true" ]]; then
|
create-kubeconfig-for-federation
|
||||||
# Create a kubeconfig with credentials for this apiserver. We will later use
|
|
||||||
# this kubeconfig to create a secret which the federation control plane can
|
|
||||||
# use to talk to this apiserver.
|
|
||||||
KUBECONFIG=${KUBECONFIG:-${HOME}/.kube/config}
|
|
||||||
KUBECONFIG_DIR=$(dirname $KUBECONFIG)
|
|
||||||
CONTEXT=$($KUBECTL config current-context)
|
|
||||||
DEST_KUBECONFIG="${KUBECONFIG_DIR}/federation/kubernetes-apiserver/${CONTEXT}/kubeconfig"
|
|
||||||
mkdir -p $(dirname $DEST_KUBECONFIG) >&2
|
|
||||||
# TODO: Original kubeconfig can contain credential information about
|
|
||||||
# other clusters as well. Extract the information about only this cluster
|
|
||||||
# and then create a file with that.
|
|
||||||
# For now, we use the whole kubeconfig file.
|
|
||||||
# Note: This is not as dangerous as it sounds because this code path is
|
|
||||||
# only expected to run during tests. Users are not expected to set
|
|
||||||
# FEDERATION=true while bringing up their kubernetes clusters.
|
|
||||||
# But there is nothing stopping them from doing so.
|
|
||||||
cp $KUBECONFIG $DEST_KUBECONFIG >&2
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [[ ! -z "${HEAPSTER_MACHINE_TYPE:-}" ]]; then
|
if [[ ! -z "${HEAPSTER_MACHINE_TYPE:-}" ]]; then
|
||||||
"${GCLOUD}" ${CMD_GROUP:-} container node-pools create "heapster-pool" --cluster "${CLUSTER_NAME}" --num-nodes=1 --machine-type="${HEAPSTER_MACHINE_TYPE}" "${shared_args[@]}"
|
"${GCLOUD}" ${CMD_GROUP:-} container node-pools create "heapster-pool" --cluster "${CLUSTER_NAME}" --num-nodes=1 --machine-type="${HEAPSTER_MACHINE_TYPE}" "${shared_args[@]}"
|
||||||
|
@ -298,14 +298,7 @@ function kube-up {
|
|||||||
# Update the user's kubeconfig to include credentials for this apiserver.
|
# Update the user's kubeconfig to include credentials for this apiserver.
|
||||||
create-kubeconfig
|
create-kubeconfig
|
||||||
|
|
||||||
if [[ "${FEDERATION:-}" == "true" ]]; then
|
create-kubeconfig-for-federation
|
||||||
# Create a kubeconfig with credentials for this apiserver. We will later use
|
|
||||||
# this kubeconfig to create a secret which the federation control plane can
|
|
||||||
# use to talk to this apiserver.
|
|
||||||
KUBECONFIG_DIR=$(dirname ${KUBECONFIG:-$DEFAULT_KUBECONFIG})
|
|
||||||
KUBECONFIG="${KUBECONFIG_DIR}/federation/kubernetes-apiserver/${CONTEXT}/kubeconfig" \
|
|
||||||
create-kubeconfig
|
|
||||||
fi
|
|
||||||
)
|
)
|
||||||
|
|
||||||
verify-cluster
|
verify-cluster
|
||||||
|
Loading…
Reference in New Issue
Block a user