k8s.io/test-infra@v0.0.0-20240520184403-27c6b4c223d8/experiment/print-job-image-summary.sh (about) 1 #!/usr/bin/env bash 2 # Copyright 2021 The Kubernetes Authors. 3 # 4 # Licensed under the Apache License, Version 2.0 (the "License"); 5 # you may not use this file except in compliance with the License. 6 # You may obtain a copy of the License at 7 # 8 # http://www.apache.org/licenses/LICENSE-2.0 9 # 10 # Unless required by applicable law or agreed to in writing, software 11 # distributed under the License is distributed on an "AS IS" BASIS, 12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 # See the License for the specific language governing permissions and 14 # limitations under the License. 15 16 # a silly script to audit how many jobs are using which images for prow.k8s.io 17 18 set -o errexit 19 set -o nounset 20 set -o pipefail 21 22 script_root=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd -P) 23 repo_root=$(cd ${script_root}/.. && pwd) 24 jobs_dir="${1:-${repo_root}/config/jobs}" 25 26 # NOTE: assumes ripgrep 27 if ! command -v rg >/dev/null; then 28 echo "please install ripgrep" >&2 29 exit 1 30 fi 31 32 function images() { 33 rg --no-filename --iglob "*.yaml" image: "${jobs_dir}" | sed -e 's|.*image: ||' | sort | cut -d: -f 1 34 } 35 36 function image_include_exclude() { 37 local include="${1}" 38 local exclude="${2}" 39 local debug="${3:-false}" 40 echo "$(images | grep -Ev "${exclude}" | grep -Ec "${include}") total, $(images | uniq | grep -Ev "${exclude}" | grep -Ec "${include}") unique" 41 if ${debug}; then 42 images | uniq | grep -Ev "${exclude}" | grep -E "${include}" 43 fi 44 } 45 46 cat <<EOS 47 # images used by prowjobs on prow.k8s.io 48 - total / $(image_include_exclude "" "^$") 49 - gcr.io / $(image_include_exclude "gcr\.io" "^$") 50 - kubernetes.io gcp org 51 - k8s-staging-test-infra $(image_include_exclude "gcr\.io/k8s-staging-test-infra" "^$") 52 $(for i in $(image_include_exclude "gcr\.io/k8s-staging-test-infra" "^$" true | tail -n+2 | xargs -n1 basename); do printf \ 53 " - %-43s %s\n" "${i}" "$(image_include_exclude "gcr\.io/k8s-staging-test-infra/${i}" "^$")"; \ 54 done | sort -k3 -rg) 55 - k8s-staging-the_rest $(image_include_exclude "gcr\.io/k8s-staging" "test-infra") 56 - k8s.gcr.io $(image_include_exclude "k8s\.gcr\.io" "^$") 57 - google.com gcp org 58 - k8s-prow $(image_include_exclude "gcr\.io/k8s-prow" "^$") 59 - k8s-testimages $(image_include_exclude "gcr\.io/k8s-testimages" "^$") 60 $(for i in $(image_include_exclude "gcr\.io/k8s-testimages" "^$" true | tail -n+2 | xargs -n1 basename); do printf \ 61 " - %-43s %s\n" "${i}" "$(image_include_exclude "gcr\.io/k8s-testimages/${i}" "^$")"; \ 62 done | sort -k3 -rg) 63 - other (unsure which org) $(image_include_exclude "gcr\.io" "^k8s.|k8s-(staging|prow|testimages)") 64 $(for i in $(image_include_exclude "gcr\.io" "^k8s.|k8s-(staging|prow|testimages)" true | tail -n+2 | cut -d/ -f2- ); do printf \ 65 " - %-45s %s\n" "${i}" "$(image_include_exclude "gcr\.io/${i}$" "^$")"; \ 66 done | sort -k3 -rg) 67 - not gcr.io / $(image_include_exclude "" "gcr\.io") 68 - dockerhub / $(image_include_exclude "^[^\.]+$|^[^/]+$|docker\.io" "gcr\.io") 69 - quay.io / $(image_include_exclude "quay\.io" "gcr\.io") 70 EOS