Skip to content

Commit

Permalink
Merge pull request kubernetes-sigs#46 from gofed/fix-kube-master-retr…
Browse files Browse the repository at this point in the history
…ieval-from-kubeconfig

fix retrieval of master url from kubeconfig
  • Loading branch information
ingvagabund authored Feb 15, 2017
2 parents ddfd5ec + 05660e6 commit da2c809
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
7 changes: 4 additions & 3 deletions integration-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ KUBE_MASTER_API_PORT=${KUBE_MASTER_API_PORT:-443}
KUBE_CONFIG=${KUBE_CONFIG:-~/.kube/config}

alias kubectl="kubectl --kubeconfig=${KUBE_CONFIG} --server=${KUBE_MASTER_API}:${KUBE_MASTER_API_PORT}"
alias cc="./cluster-capacity --kubeconfig ${KUBE_CONFIG}"
#### pre-tests checks

RED='\033[0;31m'
Expand Down Expand Up @@ -49,15 +50,15 @@ echo ""
echo "####RUNNING TESTS"
echo ""
echo "# Running simple estimation of examples/pod.yaml"
./cluster-capacity --kubeconfig ${KUBE_CONFIG} --master ${KUBE_MASTER_API}:${KUBE_MASTER_API_PORT} --podspec=examples/pod.yaml | tee estimation.log
cc --podspec=examples/pod.yaml | tee estimation.log
if [ -z "$(cat estimation.log | grep 'Termination reason')" ]; then
printError "Missing termination reason"
exit 1
fi

echo ""
echo "# Running simple estimation of examples/pod.yaml in verbose mode"
./cluster-capacity --kubeconfig ${KUBE_CONFIG} --master ${KUBE_MASTER_API}:${KUBE_MASTER_API_PORT} --podspec=examples/pod.yaml --verbose | tee estimation.log
cc --podspec=examples/pod.yaml --verbose | tee estimation.log
if [ -z "$(cat estimation.log | grep 'Termination reason')" ]; then
printError "Missing termination reason"
exit 1
Expand All @@ -78,7 +79,7 @@ done

echo ""
echo "# Running simple estimation of examples/pod.yaml in verbose mode with less resources"
./cluster-capacity --kubeconfig ${KUBE_CONFIG} --master ${KUBE_MASTER_API}:${KUBE_MASTER_API_PORT} --podspec=examples/pod.yaml --verbose | tee estimation.log
cc --podspec=examples/pod.yaml --verbose | tee estimation.log
if [ -z "$(cat estimation.log | grep 'Termination reason')" ]; then
printError "Missing termination reason"
exit 1
Expand Down
8 changes: 7 additions & 1 deletion pkg/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,13 @@ func GetMasterFromKubeConfig(filename string) (string, error) {
if err != nil {
return "", err
}
if val, ok := config.Clusters[config.CurrentContext]; ok {

context, ok := config.Contexts[config.CurrentContext]
if !ok {
return "", fmt.Errorf("Failed to get master address from kubeconfig")
}

if val, ok := config.Clusters[context.Cluster]; ok {
return val.Server, nil
}
return "", fmt.Errorf("Failed to get master address from kubeconfig")
Expand Down

0 comments on commit da2c809

Please sign in to comment.