-
Notifications
You must be signed in to change notification settings - Fork 38.7k
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
Standalone kubeconfig for gce kube-up (mulligan) #5264
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
#!/bin/bash | ||
|
||
# Copyright 2015 Google Inc. All rights reserved. | ||
# | ||
# 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. | ||
|
||
# Common utilites for kube-up/kube-down | ||
|
||
set -o errexit | ||
set -o nounset | ||
set -o pipefail | ||
|
||
KUBE_ROOT=$(dirname "${BASH_SOURCE}")/.. | ||
|
||
# Generate kubeconfig data for the created cluster. | ||
# Assumed vars: | ||
# KUBE_USER | ||
# KUBE_PASSWORD | ||
# KUBE_MASTER_IP | ||
# KUBECONFIG | ||
# | ||
# KUBE_CERT | ||
# KUBE_KEY | ||
# CA_CERT | ||
# CONTEXT | ||
function create-kubeconfig() { | ||
local kubectl="${KUBE_ROOT}/cluster/kubectl.sh" | ||
|
||
# KUBECONFIG determines the file we write to, but it may not exist yet | ||
if [[ ! -e "${KUBECONFIG}" ]]; then | ||
mkdir -p $(dirname "${KUBECONFIG}") | ||
touch "${KUBECONFIG}" | ||
fi | ||
"${kubectl}" config set-cluster "${CONTEXT}" --server="https://${KUBE_MASTER_IP}" \ | ||
--certificate-authority="${CA_CERT}" \ | ||
--embed-certs=true | ||
"${kubectl}" config set-credentials "${CONTEXT}" --username="${KUBE_USER}" \ | ||
--password="${KUBE_PASSWORD}" \ | ||
--client-certificate="${KUBE_CERT}" \ | ||
--client-key="${KUBE_KEY}" \ | ||
--embed-certs=true | ||
"${kubectl}" config set-context "${CONTEXT}" --cluster="${CONTEXT}" --user="${CONTEXT}" | ||
"${kubectl}" config use-context "${CONTEXT}" --cluster="${CONTEXT}" | ||
|
||
echo "Wrote config for ${CONTEXT} to ${KUBECONFIG}" | ||
} | ||
|
||
# Clear kubeconfig data for a context | ||
# Assumed vars: | ||
# KUBECONFIG | ||
# CONTEXT | ||
function clear-kubeconfig() { | ||
local kubectl="${KUBE_ROOT}/cluster/kubectl.sh" | ||
"${kubectl}" config unset "clusters.${CONTEXT}" | ||
"${kubectl}" config unset "users.${CONTEXT}" | ||
"${kubectl}" config unset "contexts.${CONTEXT}" | ||
|
||
local current | ||
current=$("${kubectl}" config view -o template --template='{{ index . "current-context" }}') | ||
if [[ "${current}" == "${CONTEXT}" ]]; then | ||
"${kubectl}" config unset current-context | ||
fi | ||
|
||
echo "Cleared config for ${CONTEXT} from ${KUBECONFIG}" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you care about the umask here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think 077 is correct. Or do you mean I should explicitly set umask here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I was more asking if we should be explicit here. I don't think it matters much, though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
... we're not explicit elsewhere. So. Let's proceed for now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It doesn't actually matter. We'll be using
kubectl
to write to the file in the next line, andkubectl
sets permissions explicitly.