...
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
17set -o errexit
18set -o nounset
19set -o pipefail
20
21KUBE_ROOT=$(dirname "${BASH_SOURCE[0]}")/..
22source "${KUBE_ROOT}/hack/lib/init.sh"
23
24kube::golang::setup_env
25kube::util::require-jq
26kube::util::ensure_clean_working_dir
27
28PUBLISHED_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
30LATEST_KYAML=$(echo "${PUBLISHED_RELEASES}" | jq -r '[ .[] | select(.tag_name | startswith("kyaml/v")) ] | sort_by(.published_at) | last | .tag_name | scan("\/(v[\\d.]+)") | .[0]')
31LATEST_CONFIG=$(echo "${PUBLISHED_RELEASES}" | jq -r '[ .[] | select(.tag_name | startswith("cmd/config/v")) ] | sort_by(.published_at) | last | .tag_name | scan("\/(v[\\d.]+)") | .[0]')
32LATEST_API=$(echo "${PUBLISHED_RELEASES}" | jq -r '[ .[] | select(.tag_name | startswith("api/v")) ] | sort_by(.published_at) | last | .tag_name | scan("\/(v[\\d.]+)") | .[0]')
33LATEST_KUSTOMIZE=$(echo "${PUBLISHED_RELEASES}" | jq -r '[ .[] | select(.tag_name | startswith("kustomize/v")) ] | sort_by(.published_at) | last | .tag_name | scan("\/(v[\\d.]+)") | .[0]')
34
35echo "----------------------------------------"
36echo "Latest kyaml: $LATEST_KYAML"
37echo "Latest cmd/config: $LATEST_CONFIG"
38echo "Latest api: $LATEST_API"
39echo "Latest kustomize: $LATEST_KUSTOMIZE"
40echo -e "----------------------------------------\n"
41read -p "Update kubectl kustomize to these versions? [y/N] " -n 1 -r
42echo
43
44if [[ $REPLY =~ ^[Yy]$ ]]; then
45 echo -e "\n${color_blue:?}Updating kubectl kustomize${color_norm:?}"
46else
47 echo -e "\n${color_red:?}Update aborted${color_norm:?}"
48 exit 1
49fi
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
60sed -i '' -e "s/const kustomizeVersion.*$/const kustomizeVersion = \"${LATEST_KUSTOMIZE}\"/" staging/src/k8s.io/kubectl/pkg/cmd/version/version.go
61
62echo -e "\n${color_blue}Committing changes${color_norm}"
63git add .
64git commit -a -m "Update kubectl kustomize to kyaml/$LATEST_KYAML, cmd/config/$LATEST_CONFIG, api/$LATEST_API, kustomize/$LATEST_KUSTOMIZE"
65
66echo -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.
69make -C "${KUBE_ROOT}" WHAT=./cmd/kubectl
70
71if [[ $(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
74fi
75
76echo -e "\n${color_green:?}Update successful${color_norm:?}"
77echo "Note: If any of the integration points changed, you may need to update them manually."
78echo "See https://github.com/kubernetes-sigs/kustomize/tree/master/releasing#update-kustomize-in-kubectl for more information"
View as plain text