Skip to content

Commit

Permalink
Update the k8s segment to work with recent kubectl (#113)
Browse files Browse the repository at this point in the history
* Update the k8s segment to work with recent kubectl

* Adapt to docker hub rate limiting
  • Loading branch information
brujoand authored May 23, 2021
1 parent a817d00 commit 2cf2035
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 29 deletions.
34 changes: 18 additions & 16 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
language: shell
dist: bionic

jobs:
include:
- script: ./bin/ci_test_wrapper 'rc'
- script: ./bin/ci_test_wrapper '5.0.17'
- script: ./bin/ci_test_wrapper '4.4.23'
- script: ./bin/ci_test_wrapper '4.3.48'
- stage: deploy
script: ./bin/package
deploy:
provider: releases
skip_cleanup: true
token:
secure: c5h0E4QkBWe7Bka6mkowP/z6QEiqwKGV5/E9MhX9COzxhtQGlDa7rYJ7AlS43o9sXOqJR7P8Hq5KJAXqYoOamKpXB7M+1IGlDjeVB8uHBKZ/53Iwj6ZUrnXvmIrbY3X6Cr2cK2JVkmKeHx4MhT3HZKCv+MGbA3EfcIghEk/KSi8GcP84oqMLLvOhXStvVgOh2n80w4KUlqXct7DWBTc8kZAhlp2jFXBXOTdk7ihwGzS98qvHyFEO+asW63PwqpCAj74Qmj9KECIStTWGr/ieArpIuoWMVB3yvmmmZkAcm0hckwdgnwcwS47MWo3PDoUO/QuAy0CoVdWGmkz+NekudXrN7xTuTgP0afA5VF0hX7DtDsu18BoiQonauAfImNz5dYVonqMXqHSVZXcwCuyAs/zfbpFVjrngUnPrZN+rD/NwdAB3EbTIFHdQz3dqsrFhKbeHzg2dQv6NNUn9FY/hD7kol2xODONLk0A8tnZwEVRLEKSA/aBPcjh1gq63im4DpONUpf2EjtHSWVJ/kaqiKgc+kQGeF/KdH36O57qP5ttiZuYmjftiNS2n6vlu2ODgQiBrwVlbTXOdR2+lYLrQKF26L7IvslLX7PJUG9S79OjSxob/+NyuFgKYbD0SUT7nN6enwS1UVi3vO+LOJkWmq3fFULjy3stbcreH9L48iTs=
file: sbp-${TRAVIS_TAG}.tar.gz
on:
tags: true
cleanup: 'false'
- script: "./bin/ci_test_wrapper 'rc'"
- script: "./bin/ci_test_wrapper '5.0.17'"
- script: "./bin/ci_test_wrapper '4.4.23'"
- script: "./bin/ci_test_wrapper '4.3.48'"
- stage: deploy
script: "./bin/package"
deploy:
provider: releases
skip_cleanup: true
token:
secure: c5h0E4QkBWe7Bka6mkowP/z6QEiqwKGV5/E9MhX9COzxhtQGlDa7rYJ7AlS43o9sXOqJR7P8Hq5KJAXqYoOamKpXB7M+1IGlDjeVB8uHBKZ/53Iwj6ZUrnXvmIrbY3X6Cr2cK2JVkmKeHx4MhT3HZKCv+MGbA3EfcIghEk/KSi8GcP84oqMLLvOhXStvVgOh2n80w4KUlqXct7DWBTc8kZAhlp2jFXBXOTdk7ihwGzS98qvHyFEO+asW63PwqpCAj74Qmj9KECIStTWGr/ieArpIuoWMVB3yvmmmZkAcm0hckwdgnwcwS47MWo3PDoUO/QuAy0CoVdWGmkz+NekudXrN7xTuTgP0afA5VF0hX7DtDsu18BoiQonauAfImNz5dYVonqMXqHSVZXcwCuyAs/zfbpFVjrngUnPrZN+rD/NwdAB3EbTIFHdQz3dqsrFhKbeHzg2dQv6NNUn9FY/hD7kol2xODONLk0A8tnZwEVRLEKSA/aBPcjh1gq63im4DpONUpf2EjtHSWVJ/kaqiKgc+kQGeF/KdH36O57qP5ttiZuYmjftiNS2n6vlu2ODgQiBrwVlbTXOdR2+lYLrQKF26L7IvslLX7PJUG9S79OjSxob/+NyuFgKYbD0SUT7nN6enwS1UVi3vO+LOJkWmq3fFULjy3stbcreH9L48iTs=
file: sbp-${TRAVIS_TAG}.tar.gz
on:
tags: true
cleanup: 'false'
env:
global:
secure: roAB7S38UveB2rG0zo0aUHJZK7rchCmpyqNX2dn646jLW1omyDsRn6oLH6fwZf9kYk4FhJQq7Bdylzb6UGxjLxkphs2W54gmf1qzKu6zmdKLCNCSUP/h3URfyEKgLAuCAQf+pqKfFvGHjWktUSK2OyEVaY48bk0c6cN0Vq1qcWk85jNp/arj+0Sw/2ER/6q5mrKerqv0fl+dlGKd7YWg+fkjOg3ecZ+4R2C/DJckuh2MHxN8FF3H4uvbbIsaXNRaqf7jDGJWtpTPP9FcKlmZbWMOVJDFnaGzESr5omzDOKe1tJysORw944kxtQ9YeyYlrydEFVES+gMh2S/HJruXTSlwlk2FmeaQPjNsARd/b0a1EgCvOZyf/eCL5hw+jvRdjUUzqzQVjJOx5DL2Of5D2t7uKtNHvXf66OEXDsrX/k4z/hNEXDpkqEKfQ4hFZqUdTYSwsjQJM8fcaeXJWhEr7g+lHIb4kPx1WVRHizdSDzz0e43IuM5mXhSlptoJuvgwQ0Uuh9W2/tgXCtQ1mZIT0X2HUVBB9ogv98J/dl593E5TgO/vJ22ujHz8MPsMPFJqv8qagkCZlW2QCV9uHQ/q3s0nX76X03Cz/onUBxRAxroLWIlbuQO39fOEkOf4L3PA6IUG57x81G5g9W+D9R281H0LV5gFQN/P5iv8pWXsODE=
2 changes: 2 additions & 0 deletions bin/ci_test_wrapper
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

BASH=$1

docker login --username brujoand --password "$DOCKER_TOKEN"

docker pull bash:$BASH
docker run bash:$BASH --version
docker run -v $PWD:/bash bash:$BASH /bash/bin/ci_test
2 changes: 1 addition & 1 deletion bin/run_tests
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,4 @@ set -e
SBP_PATH=$( cd "$( dirname "${BASH_SOURCE[0]}" )/.." && pwd )
export SBP_PATH

bats -r "${SBP_PATH}/test/"
bats "${SBP_PATH}/test/"
19 changes: 7 additions & 12 deletions src/segments/k8s.bash
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,15 @@ segments::k8s() {
[[ -f "$KUBE_CONFIG" ]] || return 0
context="$(sed -n 's/.*current-context: \(.*\)/\1/p' "$KUBE_CONFIG")"
[[ -z "$context" ]] && return 0
user=${context##*/}
namespace_and_host=${context%/*}
host=${namespace_and_host##*/}
host=${host%:*}
namespace=${namespace_and_host%/*}
namespace="$(pcregrep -M -- "- context:\n(^\s\s\w*.*\n)* name: ${context}" ${KUBE_CONFIG} | sed -n 's/ *namespace: \(\w*\)/\1/p')"
if [[ -z "$namespace" ]]; then
namespace='default'
fi

if [[ "${user,,}" == "${SEGMENTS_K8S_DEFAULT_USER,,}" ]]; then
if [[ "$SEGMENTS_K8S_HIDE_CLUSTER" -eq 1 ]]; then
segment="${namespace}"
else
segment="${host}:${namespace}"
fi
if [[ -z $namespace || "$SEGMENTS_K8S_HIDE_CLUSTER" -eq 1 ]]; then
segment="${context}"
else
segment="${user}@${host}/${namespace}"
segment="${context}/${namespace}"
fi

print_themed_segment 'normal' "${segment,,}"
Expand Down

0 comments on commit 2cf2035

Please sign in to comment.