Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
K
k3s
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Jacklull
k3s
Commits
f5e8eca2
Unverified
Commit
f5e8eca2
authored
Oct 16, 2017
by
Christoph Blecker
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Extract gnu-sed detection into a function
parent
8b1bdd8e
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
33 additions
and
44 deletions
+33
-44
util.sh
cluster/gce/util.sh
+2
-9
swagger.sh
hack/lib/swagger.sh
+2
-9
util.sh
hack/lib/util.sh
+17
-0
test-cmd-util.sh
hack/make-rules/test-cmd-util.sh
+11
-18
update-bazel.sh
hack/update-bazel.sh
+1
-8
No files found.
cluster/gce/util.sh
View file @
f5e8eca2
...
@@ -2175,13 +2175,6 @@ function prepare-e2e() {
...
@@ -2175,13 +2175,6 @@ function prepare-e2e() {
# easiest way to buy us a little more room.
# easiest way to buy us a little more room.
function
prepare-startup-script
()
{
function
prepare-startup-script
()
{
# Find a standard sed instance (and ensure that the command works as expected on a Mac).
# Find a standard sed instance (and ensure that the command works as expected on a Mac).
SED
=
sed
kube::util::ensure-gnu-sed
if
which gsed &>/dev/null
;
then
${
SED
}
'/^\s*#\([^!].*\)*$/ d'
${
KUBE_ROOT
}
/cluster/gce/configure-vm.sh
>
${
KUBE_TEMP
}
/configure-vm.sh
SED
=
gsed
fi
if
!
(
$SED
--version
2>&1 |
grep
-q
GNU
)
;
then
echo
"!!! GNU sed is required. If on OS X, use 'brew install gnu-sed'."
exit
1
fi
$SED
'/^\s*#\([^!].*\)*$/ d'
${
KUBE_ROOT
}
/cluster/gce/configure-vm.sh
>
${
KUBE_TEMP
}
/configure-vm.sh
}
}
hack/lib/swagger.sh
View file @
f5e8eca2
...
@@ -127,21 +127,14 @@ kube::swagger::gen_api_ref_docs() {
...
@@ -127,21 +127,14 @@ kube::swagger::gen_api_ref_docs() {
find
.
-type
f |
cut
-sd
/
-f
2- |
LC_ALL
=
C
sort
>
.generated_html
find
.
-type
f |
cut
-sd
/
-f
2- |
LC_ALL
=
C
sort
>
.generated_html
popd
>
/dev/null
popd
>
/dev/null
if
LANG
=
C
sed
--help
2>&1 |
grep
-q
GNU
;
then
kube::util::ensure-gnu-sed
SED
=
"sed"
elif
which gsed &>/dev/null
;
then
SED
=
"gsed"
else
echo
"Failed to find GNU sed as sed or gsed. If you are on Mac: brew install gnu-sed."
>
&2
exit
1
fi
while
read
file
;
do
while
read
file
;
do
if
[[
-e
"
${
output_dir
}
/
${
file
}
"
&&
-e
"
${
output_tmp
}
/
${
file
}
"
]]
;
then
if
[[
-e
"
${
output_dir
}
/
${
file
}
"
&&
-e
"
${
output_tmp
}
/
${
file
}
"
]]
;
then
echo
"comparing
${
output_dir
}
/
${
file
}
with
${
output_tmp
}
/
${
file
}
"
echo
"comparing
${
output_dir
}
/
${
file
}
with
${
output_tmp
}
/
${
file
}
"
# Remove the timestamp to reduce conflicts in PR(s)
# Remove the timestamp to reduce conflicts in PR(s)
$
SED
-i
's/^Last updated.*$//'
"
${
output_tmp
}
/
${
file
}
"
$
{
SED
}
-i
's/^Last updated.*$//'
"
${
output_tmp
}
/
${
file
}
"
# By now, the contents should be normalized and stripped of any
# By now, the contents should be normalized and stripped of any
# auto-managed content.
# auto-managed content.
...
...
hack/lib/util.sh
View file @
f5e8eca2
...
@@ -853,6 +853,23 @@ function kube::util::ensure_dockerized {
...
@@ -853,6 +853,23 @@ function kube::util::ensure_dockerized {
fi
fi
}
}
# kube::util::ensure-gnu-sed
# Determines which sed binary is gnu-sed on linux/darwin
#
# Sets:
# SED: The name of the gnu-sed binary
#
function
kube::util::ensure-gnu-sed
{
if
LANG
=
C
sed
--help
2>&1 |
grep
-q
GNU
;
then
SED
=
"sed"
elif
which gsed &>/dev/null
;
then
SED
=
"gsed"
else
kube::log::error
"Failed to find GNU sed as sed or gsed. If you are on Mac: brew install gnu-sed."
>
&2
return
1
fi
}
# Some useful colors.
# Some useful colors.
if
[[
-z
"
${
color_start
-
}
"
]]
;
then
if
[[
-z
"
${
color_start
-
}
"
]]
;
then
declare
-r
color_start
=
"
\0
33["
declare
-r
color_start
=
"
\0
33["
...
...
hack/make-rules/test-cmd-util.sh
View file @
f5e8eca2
...
@@ -246,14 +246,7 @@ setup() {
...
@@ -246,14 +246,7 @@ setup() {
kube::etcd::start
kube::etcd::start
# Find a standard sed instance for use with edit scripts
# Find a standard sed instance for use with edit scripts
SED
=
sed
kube::util::ensure-gnu-sed
if
which gsed &>/dev/null
;
then
SED
=
gsed
fi
if
!
(
$SED
--version
2>&1 |
grep
-q
GNU
)
;
then
echo
"!!! GNU sed is required. If on OS X, use 'brew install gnu-sed'."
exit
1
fi
kube::log::status
"Building kubectl"
kube::log::status
"Building kubectl"
make
-C
"
${
KUBE_ROOT
}
"
WHAT
=
"cmd/kubectl"
make
-C
"
${
KUBE_ROOT
}
"
WHAT
=
"cmd/kubectl"
...
@@ -400,7 +393,7 @@ run_pod_tests() {
...
@@ -400,7 +393,7 @@ run_pod_tests() {
create_and_use_new_namespace
create_and_use_new_namespace
kube::test::get_object_assert pods
"{{range.items}}{{
$id_field
}}:{{end}}"
''
kube::test::get_object_assert pods
"{{range.items}}{{
$id_field
}}:{{end}}"
''
# Command
# Command
echo
"
${
output_pod
}
"
|
$
SED
'/namespace:/d'
| kubectl create
-f
-
"
${
kube_flags
[@]
}
"
echo
"
${
output_pod
}
"
|
$
{
SED
}
'/namespace:/d'
| kubectl create
-f
-
"
${
kube_flags
[@]
}
"
# Post-condition: valid-pod POD is created
# Post-condition: valid-pod POD is created
kube::test::get_object_assert pods
"{{range.items}}{{
$id_field
}}:{{end}}"
'valid-pod:'
kube::test::get_object_assert pods
"{{range.items}}{{
$id_field
}}:{{end}}"
'valid-pod:'
...
@@ -655,7 +648,7 @@ run_pod_tests() {
...
@@ -655,7 +648,7 @@ run_pod_tests() {
kube::test::get_object_assert rc
"{{range.items}}{{
$id_field
}}:{{end}}"
''
kube::test::get_object_assert rc
"{{range.items}}{{
$id_field
}}:{{end}}"
''
## kubectl create --edit can update the label filed of multiple resources. tmp-editor.sh is a fake editor
## kubectl create --edit can update the label filed of multiple resources. tmp-editor.sh is a fake editor
TEMP
=
$(
mktemp
/tmp/tmp-editor-XXXXXXXX.sh
)
TEMP
=
$(
mktemp
/tmp/tmp-editor-XXXXXXXX.sh
)
echo
-e
"#!/bin/bash
\n
$
SED
-i
\"
s/mock/modified/g
\"
\$
1"
>
${
TEMP
}
echo
-e
"#!/bin/bash
\n
$
{
SED
}
-i
\"
s/mock/modified/g
\"
\$
1"
>
${
TEMP
}
chmod
+x
${
TEMP
}
chmod
+x
${
TEMP
}
# Command
# Command
EDITOR
=
${
TEMP
}
kubectl create
--edit
-f
hack/testdata/multi-resource-json.json
"
${
kube_flags
[@]
}
"
EDITOR
=
${
TEMP
}
kubectl create
--edit
-f
hack/testdata/multi-resource-json.json
"
${
kube_flags
[@]
}
"
...
@@ -758,7 +751,7 @@ run_pod_tests() {
...
@@ -758,7 +751,7 @@ run_pod_tests() {
## --force replace pod can change other field, e.g., spec.container.name
## --force replace pod can change other field, e.g., spec.container.name
# Command
# Command
kubectl get
"
${
kube_flags
[@]
}
"
pod valid-pod
-o
json |
$
SED
's/"kubernetes-serve-hostname"/"replaced-k8s-serve-hostname"/g'
>
/tmp/tmp-valid-pod.json
kubectl get
"
${
kube_flags
[@]
}
"
pod valid-pod
-o
json |
$
{
SED
}
's/"kubernetes-serve-hostname"/"replaced-k8s-serve-hostname"/g'
>
/tmp/tmp-valid-pod.json
kubectl replace
"
${
kube_flags
[@]
}
"
--force
-f
/tmp/tmp-valid-pod.json
kubectl replace
"
${
kube_flags
[@]
}
"
--force
-f
/tmp/tmp-valid-pod.json
# Post-condition: spec.container.name = "replaced-k8s-serve-hostname"
# Post-condition: spec.container.name = "replaced-k8s-serve-hostname"
kube::test::get_object_assert
'pod valid-pod'
"{{(index .spec.containers 0).name}}"
'replaced-k8s-serve-hostname'
kube::test::get_object_assert
'pod valid-pod'
"{{(index .spec.containers 0).name}}"
'replaced-k8s-serve-hostname'
...
@@ -802,7 +795,7 @@ __EOF__
...
@@ -802,7 +795,7 @@ __EOF__
kubectl delete node node-v1-test
"
${
kube_flags
[@]
}
"
kubectl delete node node-v1-test
"
${
kube_flags
[@]
}
"
## kubectl edit can update the image field of a POD. tmp-editor.sh is a fake editor
## kubectl edit can update the image field of a POD. tmp-editor.sh is a fake editor
echo
-e
"#!/bin/bash
\n
$
SED
-i
\"
s/nginx/gcr.io
\/
google_containers
\/
serve_hostname/g
\"
\$
1"
>
/tmp/tmp-editor.sh
echo
-e
"#!/bin/bash
\n
$
{
SED
}
-i
\"
s/nginx/gcr.io
\/
google_containers
\/
serve_hostname/g
\"
\$
1"
>
/tmp/tmp-editor.sh
chmod
+x /tmp/tmp-editor.sh
chmod
+x /tmp/tmp-editor.sh
# Pre-condition: valid-pod POD has image nginx
# Pre-condition: valid-pod POD has image nginx
kube::test::get_object_assert pods
"{{range.items}}{{
$image_field
}}:{{end}}"
'nginx:'
kube::test::get_object_assert pods
"{{range.items}}{{
$image_field
}}:{{end}}"
'nginx:'
...
@@ -882,7 +875,7 @@ __EOF__
...
@@ -882,7 +875,7 @@ __EOF__
# Post-Condition: pod "test-pod" doesn't have configuration annotation
# Post-Condition: pod "test-pod" doesn't have configuration annotation
!
[[
"
$(
kubectl get pods test-pod
-o
yaml
"
${
kube_flags
[@]
}
"
|
grep
kubectl.kubernetes.io/last-applied-configuration
)
"
]]
!
[[
"
$(
kubectl get pods test-pod
-o
yaml
"
${
kube_flags
[@]
}
"
|
grep
kubectl.kubernetes.io/last-applied-configuration
)
"
]]
## 2. kubectl replace doesn't set the annotation
## 2. kubectl replace doesn't set the annotation
kubectl get pods test-pod
-o
yaml
"
${
kube_flags
[@]
}
"
|
$
SED
's/test-pod-label/test-pod-replaced/g'
>
"
${
KUBE_TEMP
}
"
/test-pod-replace.yaml
kubectl get pods test-pod
-o
yaml
"
${
kube_flags
[@]
}
"
|
$
{
SED
}
's/test-pod-label/test-pod-replaced/g'
>
"
${
KUBE_TEMP
}
"
/test-pod-replace.yaml
# Command: replace the pod "test-pod"
# Command: replace the pod "test-pod"
kubectl replace
-f
"
${
KUBE_TEMP
}
"
/test-pod-replace.yaml
"
${
kube_flags
[@]
}
"
kubectl replace
-f
"
${
KUBE_TEMP
}
"
/test-pod-replace.yaml
"
${
kube_flags
[@]
}
"
# Post-Condition: pod "test-pod" is replaced
# Post-Condition: pod "test-pod" is replaced
...
@@ -898,7 +891,7 @@ __EOF__
...
@@ -898,7 +891,7 @@ __EOF__
[[
"
$(
kubectl get pods test-pod
-o
yaml
"
${
kube_flags
[@]
}
"
|
grep
kubectl.kubernetes.io/last-applied-configuration
)
"
]]
[[
"
$(
kubectl get pods test-pod
-o
yaml
"
${
kube_flags
[@]
}
"
|
grep
kubectl.kubernetes.io/last-applied-configuration
)
"
]]
kubectl get pods test-pod
-o
yaml
"
${
kube_flags
[@]
}
"
|
grep
kubectl.kubernetes.io/last-applied-configuration
>
"
${
KUBE_TEMP
}
"
/annotation-configuration
kubectl get pods test-pod
-o
yaml
"
${
kube_flags
[@]
}
"
|
grep
kubectl.kubernetes.io/last-applied-configuration
>
"
${
KUBE_TEMP
}
"
/annotation-configuration
## 4. kubectl replace updates an existing annotation
## 4. kubectl replace updates an existing annotation
kubectl get pods test-pod
-o
yaml
"
${
kube_flags
[@]
}
"
|
$
SED
's/test-pod-applied/test-pod-replaced/g'
>
"
${
KUBE_TEMP
}
"
/test-pod-replace.yaml
kubectl get pods test-pod
-o
yaml
"
${
kube_flags
[@]
}
"
|
$
{
SED
}
's/test-pod-applied/test-pod-replaced/g'
>
"
${
KUBE_TEMP
}
"
/test-pod-replace.yaml
# Command: replace the pod "test-pod"
# Command: replace the pod "test-pod"
kubectl replace
-f
"
${
KUBE_TEMP
}
"
/test-pod-replace.yaml
"
${
kube_flags
[@]
}
"
kubectl replace
-f
"
${
KUBE_TEMP
}
"
/test-pod-replace.yaml
"
${
kube_flags
[@]
}
"
# Post-Condition: pod "test-pod" is replaced
# Post-Condition: pod "test-pod" is replaced
...
@@ -1149,7 +1142,7 @@ run_save_config_tests() {
...
@@ -1149,7 +1142,7 @@ run_save_config_tests() {
!
[[
"
$(
kubectl get pods test-pod
-o
yaml
"
${
kube_flags
[@]
}
"
|
grep
kubectl.kubernetes.io/last-applied-configuration
)
"
]]
!
[[
"
$(
kubectl get pods test-pod
-o
yaml
"
${
kube_flags
[@]
}
"
|
grep
kubectl.kubernetes.io/last-applied-configuration
)
"
]]
# Command: edit the pod "test-pod"
# Command: edit the pod "test-pod"
temp_editor
=
"
${
KUBE_TEMP
}
/tmp-editor.sh"
temp_editor
=
"
${
KUBE_TEMP
}
/tmp-editor.sh"
echo
-e
"#!/bin/bash
\n
$
SED
-i
\"
s/test-pod-label/test-pod-label-edited/g
\"
\$
@"
>
"
${
temp_editor
}
"
echo
-e
"#!/bin/bash
\n
$
{
SED
}
-i
\"
s/test-pod-label/test-pod-label-edited/g
\"
\$
@"
>
"
${
temp_editor
}
"
chmod
+x
"
${
temp_editor
}
"
chmod
+x
"
${
temp_editor
}
"
EDITOR
=
${
temp_editor
}
kubectl edit pod test-pod
--save-config
"
${
kube_flags
[@]
}
"
EDITOR
=
${
temp_editor
}
kubectl edit pod test-pod
--save-config
"
${
kube_flags
[@]
}
"
# Post-Condition: pod "test-pod" has configuration annotation
# Post-Condition: pod "test-pod" has configuration annotation
...
@@ -2817,7 +2810,7 @@ run_deployment_tests() {
...
@@ -2817,7 +2810,7 @@ run_deployment_tests() {
kubectl get rs
"
${
newrs
}
"
-o
yaml |
grep
"deployment.kubernetes.io/revision-history: 1,3"
kubectl get rs
"
${
newrs
}
"
-o
yaml |
grep
"deployment.kubernetes.io/revision-history: 1,3"
# Check that trying to watch the status of a superseded revision returns an error
# Check that trying to watch the status of a superseded revision returns an error
!
kubectl rollout status deployment/nginx
--revision
=
3
!
kubectl rollout status deployment/nginx
--revision
=
3
cat
hack/testdata/deployment-revision1.yaml |
$
SED
"s/name: nginx
$/
name: nginx2/"
| kubectl create
-f
-
"
${
kube_flags
[@]
}
"
cat
hack/testdata/deployment-revision1.yaml |
$
{
SED
}
"s/name: nginx
$/
name: nginx2/"
| kubectl create
-f
-
"
${
kube_flags
[@]
}
"
# Deletion of both deployments should not be blocked
# Deletion of both deployments should not be blocked
kubectl delete deployment nginx2
"
${
kube_flags
[@]
}
"
kubectl delete deployment nginx2
"
${
kube_flags
[@]
}
"
# Clean up
# Clean up
...
@@ -3297,7 +3290,7 @@ run_multi_resources_tests() {
...
@@ -3297,7 +3290,7 @@ run_multi_resources_tests() {
fi
fi
# Command: kubectl edit multiple resources
# Command: kubectl edit multiple resources
temp_editor
=
"
${
KUBE_TEMP
}
/tmp-editor.sh"
temp_editor
=
"
${
KUBE_TEMP
}
/tmp-editor.sh"
echo
-e
"#!/bin/bash
\n
$
SED
-i
\"
s/status
\:\
replaced/status
\:\
edited/g
\"
\$
@"
>
"
${
temp_editor
}
"
echo
-e
"#!/bin/bash
\n
$
{
SED
}
-i
\"
s/status
\:\
replaced/status
\:\
edited/g
\"
\$
@"
>
"
${
temp_editor
}
"
chmod
+x
"
${
temp_editor
}
"
chmod
+x
"
${
temp_editor
}
"
EDITOR
=
"
${
temp_editor
}
"
kubectl edit
"
${
kube_flags
[@]
}
"
-f
"
${
file
}
"
EDITOR
=
"
${
temp_editor
}
"
kubectl edit
"
${
kube_flags
[@]
}
"
-f
"
${
file
}
"
# Post-condition: mock service (and mock2) and mock rc (and mock2) are edited
# Post-condition: mock service (and mock2) and mock rc (and mock2) are edited
...
@@ -3522,7 +3515,7 @@ run_clusterroles_tests() {
...
@@ -3522,7 +3515,7 @@ run_clusterroles_tests() {
kubectl
set
subject
"
${
kube_flags
[@]
}
"
clusterrolebinding super-sa
--serviceaccount
=
otherfoo:foo
kubectl
set
subject
"
${
kube_flags
[@]
}
"
clusterrolebinding super-sa
--serviceaccount
=
otherfoo:foo
kube::test::get_object_assert clusterrolebinding/super-sa
"{{range.subjects}}{{.namespace}}:{{end}}"
'otherns:otherfoo:'
kube::test::get_object_assert clusterrolebinding/super-sa
"{{range.subjects}}{{.namespace}}:{{end}}"
'otherns:otherfoo:'
kube::test::get_object_assert clusterrolebinding/super-sa
"{{range.subjects}}{{.name}}:{{end}}"
'sa-name:foo:'
kube::test::get_object_assert clusterrolebinding/super-sa
"{{range.subjects}}{{.name}}:{{end}}"
'sa-name:foo:'
# test `kubectl create rolebinding`
# test `kubectl create rolebinding`
# test `kubectl set subject rolebinding`
# test `kubectl set subject rolebinding`
kubectl create
"
${
kube_flags
[@]
}
"
rolebinding admin
--clusterrole
=
admin
--user
=
default-admin
kubectl create
"
${
kube_flags
[@]
}
"
rolebinding admin
--clusterrole
=
admin
--user
=
default-admin
...
...
hack/update-bazel.sh
View file @
f5e8eca2
...
@@ -20,14 +20,7 @@ set -o pipefail
...
@@ -20,14 +20,7 @@ set -o pipefail
export
KUBE_ROOT
=
$(
dirname
"
${
BASH_SOURCE
}
"
)
/..
export
KUBE_ROOT
=
$(
dirname
"
${
BASH_SOURCE
}
"
)
/..
source
"
${
KUBE_ROOT
}
/hack/lib/init.sh"
source
"
${
KUBE_ROOT
}
/hack/lib/init.sh"
if
LANG
=
C
sed
--help
2>&1 |
grep
-q
GNU
;
then
kube::util::ensure-gnu-sed
SED
=
"sed"
elif
which gsed &>/dev/null
;
then
SED
=
"gsed"
else
echo
"Failed to find GNU sed as sed or gsed. If you are on Mac: brew install gnu-sed."
>
&2
exit
1
fi
# Remove generated files prior to running kazel.
# Remove generated files prior to running kazel.
# TODO(spxtr): Remove this line once Bazel is the only way to build.
# TODO(spxtr): Remove this line once Bazel is the only way to build.
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment