Skip to content

Commit 8ddbedf

Browse files
committed
add script to update cri defs
1 parent c13453b commit 8ddbedf

File tree

4 files changed

+74
-1
lines changed

4 files changed

+74
-1
lines changed

Makefile

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,8 @@ docker-build:
9191
presubmit: vet
9292
@echo ">> checking go formatting"
9393
@./build/check_gofmt.sh
94+
@echo ">> checking CRI definitions"
95+
@./build/check_cri_defs.sh
9496
@echo ">> checking go mod tidy"
9597
@./build/check_gotidy.sh
9698
@echo ">> checking file boilerplate"

build/boilerplate/boilerplate.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,7 @@ def file_passes(filename, refs, regexs):
9595
def file_extension(filename):
9696
return os.path.splitext(filename)[1].split(".")[-1].lower()
9797

98-
skipped_dirs = ['Godeps', 'vendor', 'third_party', '_gopath', '_output', '.git']
98+
skipped_dirs = ['Godeps', 'vendor', 'third_party', '_gopath', '_output', '.git', 'cri-api']
9999
def normalize_files(files):
100100
newfiles = []
101101
for pathname in files:

build/check_cri_defs.sh

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
#!/usr/bin/env bash
2+
3+
# Copyright 2021 Google Inc. All rights reserved.
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
# Presubmit script that ensures that https://github.com/kubernetes/cri-api
18+
# definitions that are copied into cAdvisor codebase exactly match the ones upstream.
19+
20+
set -e
21+
22+
function check_git_dirty() {
23+
if ! [ -z "$(git status --porcelain)" ]; then
24+
echo ">>> working tree is not clean"
25+
echo ">>> git status:"
26+
echo "$(git status)"
27+
exit 1
28+
fi
29+
}
30+
31+
GIT_ROOT=$(dirname "${BASH_SOURCE}")/..
32+
33+
check_git_dirty
34+
35+
echo ">>> updating k8s CRI definitions..."
36+
"${GIT_ROOT}/build/update_cri_defs.sh"
37+
38+
# If k8s CRI definitions were manually modified or don't match the ones
39+
# upstream, git tree will be unclean.
40+
echo ">>> checking git tree clean after updating k8s CRI definitions..."
41+
check_git_dirty

build/update_cri_defs.sh

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
#!/usr/bin/env bash
2+
3+
# Copyright 2021 Google Inc. All rights reserved.
4+
#
5+
# Licensed under the Apache License, Version 2.0 (the "License");
6+
# you may not use this file except in compliance with the License.
7+
# You may obtain a copy of the License at
8+
#
9+
# http://www.apache.org/licenses/LICENSE-2.0
10+
#
11+
# Unless required by applicable law or agreed to in writing, software
12+
# distributed under the License is distributed on an "AS IS" BASIS,
13+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
# See the License for the specific language governing permissions and
15+
# limitations under the License.
16+
17+
set -e
18+
19+
CRI_VERSION="release-1.22"
20+
GIT_ROOT=$(dirname "${BASH_SOURCE}")/..
21+
22+
TMP_DIR="$(mktemp -d)"
23+
git clone --depth=1 https://github.com/kubernetes/cri-api.git --branch="${CRI_VERSION}" "${TMP_DIR}"
24+
25+
# rewrite import paths
26+
find "${TMP_DIR}" -type f -name "*.go" -exec sed -i 's:k8s.io/cri-api:github.com/google/cadvisor/cri-api:g' {} +
27+
28+
mkdir -p "${GIT_ROOT}/cri-api"
29+
cp -r "${TMP_DIR}/pkg" "${GIT_ROOT}/cri-api"
30+
rm -rf "${TMP_DIR}"

0 commit comments

Comments
 (0)