k8s.io/kubernetes@v1.31.0-alpha.0.0.20240520171757-56147500dadc/hack/update-kustomize.sh (about) 1 #!/usr/bin/env bash 2 3 # Copyright 2022 The Kubernetes Authors. 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 -o errexit 18 set -o nounset 19 set -o pipefail 20 21 KUBE_ROOT=$(dirname "${BASH_SOURCE[0]}")/.. 22 source "${KUBE_ROOT}/hack/lib/init.sh" 23 24 kube::golang::setup_env 25 kube::util::require-jq 26 kube::util::ensure_clean_working_dir 27 28 PUBLISHED_RELEASES=$(curl -sL 'http://api.github.com/repos/kubernetes-sigs/kustomize/releases?per_page=100' | jq '[ .[] | select(.draft == false and .prerelease == false) | { "tag_name": .tag_name, "published_at": .published_at } ]') 29 30 LATEST_KYAML=$(echo "${PUBLISHED_RELEASES}" | jq -r '[ .[] | select(.tag_name | startswith("kyaml/v")) ] | sort_by(.published_at) | last | .tag_name | scan("\/(v[\\d.]+)") | .[0]') 31 LATEST_CONFIG=$(echo "${PUBLISHED_RELEASES}" | jq -r '[ .[] | select(.tag_name | startswith("cmd/config/v")) ] | sort_by(.published_at) | last | .tag_name | scan("\/(v[\\d.]+)") | .[0]') 32 LATEST_API=$(echo "${PUBLISHED_RELEASES}" | jq -r '[ .[] | select(.tag_name | startswith("api/v")) ] | sort_by(.published_at) | last | .tag_name | scan("\/(v[\\d.]+)") | .[0]') 33 LATEST_KUSTOMIZE=$(echo "${PUBLISHED_RELEASES}" | jq -r '[ .[] | select(.tag_name | startswith("kustomize/v")) ] | sort_by(.published_at) | last | .tag_name | scan("\/(v[\\d.]+)") | .[0]') 34 35 echo "----------------------------------------" 36 echo "Latest kyaml: $LATEST_KYAML" 37 echo "Latest cmd/config: $LATEST_CONFIG" 38 echo "Latest api: $LATEST_API" 39 echo "Latest kustomize: $LATEST_KUSTOMIZE" 40 echo -e "----------------------------------------\n" 41 read -p "Update kubectl kustomize to these versions? [y/N] " -n 1 -r 42 echo 43 44 if [[ $REPLY =~ ^[Yy]$ ]]; then 45 echo -e "\n${color_blue:?}Updating kubectl kustomize${color_norm:?}" 46 else 47 echo -e "\n${color_red:?}Update aborted${color_norm:?}" 48 exit 1 49 fi 50 51 ./hack/pin-dependency.sh sigs.k8s.io/kustomize/kyaml "$LATEST_KYAML" 52 ./hack/pin-dependency.sh sigs.k8s.io/kustomize/cmd/config "$LATEST_CONFIG" 53 ./hack/pin-dependency.sh sigs.k8s.io/kustomize/api "$LATEST_API" 54 ./hack/pin-dependency.sh sigs.k8s.io/kustomize/kustomize/v5 "$LATEST_KUSTOMIZE" 55 56 ./hack/update-vendor.sh 57 ./hack/update-internal-modules.sh 58 ./hack/lint-dependencies.sh 59 60 sed -i '' -e "s/const kustomizeVersion.*$/const kustomizeVersion = \"${LATEST_KUSTOMIZE}\"/" staging/src/k8s.io/kubectl/pkg/cmd/version/version.go 61 62 echo -e "\n${color_blue}Committing changes${color_norm}" 63 git add . 64 git commit -a -m "Update kubectl kustomize to kyaml/$LATEST_KYAML, cmd/config/$LATEST_CONFIG, api/$LATEST_API, kustomize/$LATEST_KUSTOMIZE" 65 66 echo -e "\n${color_blue:?}Verifying kubectl kustomize version${color_norm:?}" 67 # We use `make` here intead of `go install` to ensure that all of the 68 # linker-defined values are set. 69 make -C "${KUBE_ROOT}" WHAT=./cmd/kubectl 70 71 if [[ $(kubectl version --client -o json | jq -r '.kustomizeVersion') != "$LATEST_KUSTOMIZE" ]]; then 72 echo -e "${color_red:?}Unexpected kubectl kustomize version${color_norm:?}" 73 exit 1 74 fi 75 76 echo -e "\n${color_green:?}Update successful${color_norm:?}" 77 echo "Note: If any of the integration points changed, you may need to update them manually." 78 echo "See https://github.com/kubernetes-sigs/kustomize/tree/master/releasing#update-kustomize-in-kubectl for more information"