From b8ebb685684ea6fb1bae9736b74bf98e48c85e52 Mon Sep 17 00:00:00 2001 From: Mark Rossetti Date: Tue, 25 Jul 2023 09:48:49 -0700 Subject: [PATCH] Squashed 'release-tools/' changes from 78c0fb7..c10b678 c10b678 Merge pull request #227 from coulof/check-sidecar-supported-versions b055535 Header bd0a10b typo c39d73c Add comments f6491af Script to verify EOL sidecar version 4133d1d Merge pull request #226 from msau42/cloudbuild 8d519d2 Pin buildkit to v0.10.6 to workaround v0.11 bug with docker manifest 6e04a03 Merge pull request #224 from msau42/cloudbuild 26fdfff Update cloudbuild image 6613c39 Merge pull request #223 from sunnylovestiramisu/update 0e7ae99 Update k8s image repo url 77e47cc Merge pull request #222 from xinydev/fix-dep-version 155854b Fix dep version mismatch 8f83905 Merge pull request #221 from sunnylovestiramisu/go-update 1d3f94d Update go version to 1.20 to match k/k v1.27 e322ce5 Merge pull request #220 from andyzhangx/fix-golint-error b74a512 test: fix golint error aa61bfd Merge pull request #218 from xing-yang/update_csi_driver 7563d19 Update CSI_PROW_DRIVER_VERSION to v1.11.0 a2171be Merge pull request #216 from msau42/process cb98782 Merge pull request #217 from msau42/owners a11216e add new reviewers and remove inactive reviewers dd98675 Add step for checking builds b66c082 Merge pull request #214 from pohly/junit-fixes b9b6763 filter-junit.go: fix loss of testcases when parsing Ginkgo v2 JUnit d427783 filter-junit.go: preserve system error log 38e1146 prow.sh: publish individual JUnit files as separate artifacts git-subtree-dir: release-tools git-subtree-split: c10b67804e07a324fe33595040afd13f020ee000 --- KUBERNETES_CSI_OWNERS_ALIASES | 4 +- SIDECAR_RELEASE_PROCESS.md | 4 +- build.make | 2 +- cloudbuild.yaml | 2 +- contrib/get_supported_version_csi-sidecar.py | 170 +++++++++++++++++++ filter-junit.go | 8 +- prow.sh | 23 ++- 7 files changed, 196 insertions(+), 17 deletions(-) create mode 100644 contrib/get_supported_version_csi-sidecar.py diff --git a/KUBERNETES_CSI_OWNERS_ALIASES b/KUBERNETES_CSI_OWNERS_ALIASES index 344fbe4d..04a07bfb 100644 --- a/KUBERNETES_CSI_OWNERS_ALIASES +++ b/KUBERNETES_CSI_OWNERS_ALIASES @@ -22,17 +22,19 @@ aliases: - ggriffiths - gnufied - humblec + - mauriciopoppe - j-griffith - - Jiawei0227 - jingxu97 - jsafrane - pohly - RaunakShah + - sunnylovestiramisu - xing-yang # This documents who previously contributed to Kubernetes-CSI # as approver. emeritus_approvers: +- Jiawei0227 - lpabon - sbezverk - vladimirvivien diff --git a/SIDECAR_RELEASE_PROCESS.md b/SIDECAR_RELEASE_PROCESS.md index 8977fbe6..d1cc80b8 100644 --- a/SIDECAR_RELEASE_PROCESS.md +++ b/SIDECAR_RELEASE_PROCESS.md @@ -92,6 +92,8 @@ naming convention `-on-`. 1. Check that all [canary CI jobs](https://k8s-testgrid.appspot.com/sig-storage-csi-ci) are passing, and that test coverage is adequate for the changes that are going into the release. +1. Check that the post-\-push-images builds are succeeding. + [Example](https://k8s-testgrid.appspot.com/sig-storage-image-build#post-external-snapshotter-push-images) 1. Make sure that no new PRs have merged in the meantime, and no PRs are in flight and soon to be merged. 1. Create a new release following a previous release as a template. Be sure to select the correct @@ -102,7 +104,7 @@ naming convention `-on-`. 1. Check [image build status](https://k8s-testgrid.appspot.com/sig-storage-image-build). 1. Promote images from k8s-staging-sig-storage to k8s.gcr.io/sig-storage. From the [k8s image - repo](https://github.com/kubernetes/k8s.io/tree/HEAD/k8s.gcr.io/images/k8s-staging-sig-storage), + repo](https://github.com/kubernetes/k8s.io/tree/HEAD/registry.k8s.io/images/k8s-staging-sig-storage), run `./generate.sh > images.yaml`, and send a PR with the updated images. Once merged, the image promoter will copy the images from staging to prod. 1. Update [kubernetes-csi/docs](https://github.com/kubernetes-csi/docs) sidecar diff --git a/build.make b/build.make index ff428890..bceab34d 100644 --- a/build.make +++ b/build.make @@ -148,7 +148,7 @@ DOCKER_BUILDX_CREATE_ARGS ?= $(CMDS:%=push-multiarch-%): push-multiarch-%: check-pull-base-ref build-% set -ex; \ export DOCKER_CLI_EXPERIMENTAL=enabled; \ - docker buildx create $(DOCKER_BUILDX_CREATE_ARGS) --use --name multiarchimage-buildertest; \ + docker buildx create $(DOCKER_BUILDX_CREATE_ARGS) --use --name multiarchimage-buildertest --driver-opt image=moby/buildkit:v0.10.6; \ trap "docker buildx rm multiarchimage-buildertest" EXIT; \ dockerfile_linux=$$(if [ -e ./$(CMDS_DIR)/$*/Dockerfile ]; then echo ./$(CMDS_DIR)/$*/Dockerfile; else echo Dockerfile; fi); \ dockerfile_windows=$$(if [ -e ./$(CMDS_DIR)/$*/Dockerfile.Windows ]; then echo ./$(CMDS_DIR)/$*/Dockerfile.Windows; else echo Dockerfile.Windows; fi); \ diff --git a/cloudbuild.yaml b/cloudbuild.yaml index 4bcffad3..6b76a9ed 100644 --- a/cloudbuild.yaml +++ b/cloudbuild.yaml @@ -26,7 +26,7 @@ steps: # The image must contain bash and curl. Ideally it should also contain # the desired version of Go (currently defined in release-tools/prow.sh), # but that just speeds up the build and is not required. - - name: 'gcr.io/k8s-staging-test-infra/gcb-docker-gcloud:v20210917-12df099d55' + - name: 'gcr.io/k8s-testimages/gcb-docker-gcloud:v20230424-910a2a439d' entrypoint: ./.cloudbuild.sh env: - GIT_TAG=${_GIT_TAG} diff --git a/contrib/get_supported_version_csi-sidecar.py b/contrib/get_supported_version_csi-sidecar.py new file mode 100644 index 00000000..b5380ab9 --- /dev/null +++ b/contrib/get_supported_version_csi-sidecar.py @@ -0,0 +1,170 @@ +# Copyright 2023 The Kubernetes Authors. +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +import argparse +import datetime +import re +from collections import defaultdict +import subprocess +import shutil +from dateutil.relativedelta import relativedelta + +def check_gh_command(): + """ + Pretty much everything is processed from `gh` + Check that the `gh` command is in the path before anything else + """ + if not shutil.which('gh'): + print("Error: The `gh` command is not available in the PATH.") + print("Please install the GitHub CLI (https://cli.github.com/) and try again.") + exit(1) + +def duration_ago(dt): + """ + Humanize duration ouputs + """ + delta = relativedelta(datetime.datetime.now(), dt) + if delta.years > 0: + return f"{delta.years} year{'s' if delta.years > 1 else ''} ago" + elif delta.months > 0: + return f"{delta.months} month{'s' if delta.months > 1 else ''} ago" + elif delta.days > 0: + return f"{delta.days} day{'s' if delta.days > 1 else ''} ago" + elif delta.hours > 0: + return f"{delta.hours} hour{'s' if delta.hours > 1 else ''} ago" + elif delta.minutes > 0: + return f"{delta.minutes} minute{'s' if delta.minutes > 1 else ''} ago" + else: + return "just now" + +def parse_version(version): + """ + Parse version assuming it is in the form of v1.2.3 + """ + pattern = r"v(\d+)\.(\d+)\.(\d+)" + match = re.match(pattern, version) + if match: + major, minor, patch = map(int, match.groups()) + return (major, minor, patch) + +def end_of_life_grouped_versions(versions): + """ + Calculate the end of life date for a minor release version according to : https://kubernetes-csi.github.io/docs/project-policies.html#support + + The input is an array of tuples of: + * grouped versions (e.g. 1.0, 1.1) + * array of that contains all versions and their release date (e.g. 1.0.0, 01-01-2013) + + versions structure example : + [((3, 5), [('v3.5.0', datetime.datetime(2023, 4, 27, 22, 28, 6))]), + ((3, 4), + [('v3.4.1', datetime.datetime(2023, 4, 5, 17, 41, 15)), + ('v3.4.0', datetime.datetime(2022, 12, 27, 23, 43, 41))])] + """ + supported_versions = [] + # Prepare dates for later calculation + now = datetime.datetime.now() + one_year = datetime.timedelta(days=365) + three_months = datetime.timedelta(days=90) + + # get the newer versions on top + sorted_versions_list = sorted(versions.items(), key=lambda x: x[0], reverse=True) + + # the latest version is always supported no matter the release date + latest = sorted_versions_list.pop(0) + supported_versions.append(latest[1][-1]) + + for v in sorted_versions_list: + first_release = v[1][-1] + last_release = v[1][0] + # if the release is less than a year old we support the latest patch version + if now - first_release[1] < one_year: + supported_versions.append(last_release) + # if the main release is older than a year and has a recent path, this is supported + elif now - last_release[1] < three_months: + supported_versions.append(last_release) + return supported_versions + +def get_release_docker_image(repo, version): + """ + Extract docker image name from the relase page documentation + """ + output = subprocess.check_output(['gh', 'release', '-R', repo, 'view', version], text=True) + #Extract matching image name excluding ` + match = re.search(r"docker pull ([\.\/\-\:\w\d]*)", output) + docker_image = match.group(1) if match else '' + return((version, docker_image)) + +def get_versions_from_releases(repo): + """ + Using `gh` cli get the github releases page details then + create a list of grouped version on major.minor + and for each give all major.minor.patch with release dates + """ + # Run the `gh release` command to get the release list + output = subprocess.check_output(['gh', 'release', '-R', repo, 'list'], text=True) + # Parse the output and group by major and minor version numbers + versions = defaultdict(lambda: []) + for line in output.strip().split('\n'): + parts = line.split('\t') + # pprint.pprint(parts) + version = parts[0] + parsed_version = parse_version(version) + if parsed_version is None: + continue + major, minor, patch = parsed_version + + published = datetime.datetime.strptime(parts[3], '%Y-%m-%dT%H:%M:%SZ') + versions[(major, minor)].append((version, published)) + return(versions) + + +def main(): + manual = """ + This script lists the supported versions Github releases according to https://kubernetes-csi.github.io/docs/project-policies.html#support + It has been designed to help to update the tables from : https://kubernetes-csi.github.io/docs/sidecar-containers.html\n\n + It can take multiple repos as argument, for all CSI sidecars details you can run: + ./get_supported_version_csi-sidecar.py -R kubernetes-csi/external-attacher -R kubernetes-csi/external-provisioner -R kubernetes-csi/external-resizer -R kubernetes-csi/external-snapshotter -R kubernetes-csi/livenessprobe -R kubernetes-csi/node-driver-registrar -R kubernetes-csi/external-health-monitor\n + With the output you can then update the documentation manually. + """ + parser = argparse.ArgumentParser(formatter_class=argparse.RawDescriptionHelpFormatter, description=manual) + parser.add_argument('--repo', '-R', required=True, action='append', dest='repos', help='The name of the repository in the format owner/repo.') + parser.add_argument('--display', '-d', action='store_true', help='(default) Display EOL versions with their dates', default=True) + parser.add_argument('--doc', '-D', action='store_true', help='Helper to https://kubernetes-csi.github.io/docs/ that prints Docker image for each EOL version') + + args = parser.parse_args() + + # Verify pre-reqs + check_gh_command() + + # Process all repos + for repo in args.repos: + versions = get_versions_from_releases(repo) + eol_versions = end_of_life_grouped_versions(versions) + + if args.display: + print(f"Supported versions with release date and age of `{repo}`:\n") + for version in eol_versions: + print(f"{version[0]}\t{version[1].strftime('%Y-%m-%d')}\t{duration_ago(version[1])}") + + # TODO : generate proper doc output for the tables of: https://kubernetes-csi.github.io/docs/sidecar-containers.html + if args.doc: + print("\nSupported Versions with docker images for each end of life version:\n") + for version in eol_versions: + _, image = get_release_docker_image(repo, version[0]) + print(f"{version[0]}\t{image}") + print() + +if __name__ == '__main__': + main() diff --git a/filter-junit.go b/filter-junit.go index 5454092b..aab1b8b6 100644 --- a/filter-junit.go +++ b/filter-junit.go @@ -24,7 +24,6 @@ package main import ( "encoding/xml" "flag" - "io/ioutil" "os" "regexp" ) @@ -56,6 +55,7 @@ type TestCase struct { Name string `xml:"name,attr"` Time string `xml:"time,attr"` SystemOut string `xml:"system-out,omitempty"` + SystemErr string `xml:"system-err,omitempty"` Failure string `xml:"failure,omitempty"` Skipped SkipReason `xml:"skipped,omitempty"` } @@ -95,7 +95,7 @@ func main() { } } else { var err error - data, err = ioutil.ReadFile(input) + data, err = os.ReadFile(input) if err != nil { panic(err) } @@ -109,7 +109,7 @@ func main() { if err := xml.Unmarshal(data, &junitv2); err != nil { panic(err) } - junit = junitv2.TestSuite + junit.TestCases = append(junit.TestCases, junitv2.TestSuite.TestCases...) } } @@ -142,7 +142,7 @@ func main() { panic(err) } } else { - if err := ioutil.WriteFile(*output, data, 0644); err != nil { + if err := os.WriteFile(*output, data, 0644); err != nil { panic(err) } } diff --git a/prow.sh b/prow.sh index 55c3231d..6d68fd9f 100755 --- a/prow.sh +++ b/prow.sh @@ -86,7 +86,7 @@ configvar CSI_PROW_BUILD_PLATFORMS "linux amd64 amd64; linux ppc64le ppc64le -pp # which is disabled with GOFLAGS=-mod=vendor). configvar GOFLAGS_VENDOR "$( [ -d vendor ] && echo '-mod=vendor' )" "Go flags for using the vendor directory" -configvar CSI_PROW_GO_VERSION_BUILD "1.19" "Go version for building the component" # depends on component's source code +configvar CSI_PROW_GO_VERSION_BUILD "1.20" "Go version for building the component" # depends on component's source code configvar CSI_PROW_GO_VERSION_E2E "" "override Go version for building the Kubernetes E2E test suite" # normally doesn't need to be set, see install_e2e configvar CSI_PROW_GO_VERSION_SANITY "${CSI_PROW_GO_VERSION_BUILD}" "Go version for building the csi-sanity test suite" # depends on CSI_PROW_SANITY settings below configvar CSI_PROW_GO_VERSION_KIND "${CSI_PROW_GO_VERSION_BUILD}" "Go version for building 'kind'" # depends on CSI_PROW_KIND_VERSION below @@ -196,7 +196,7 @@ kindest/node:v1.18.20@sha256:738cdc23ed4be6cc0b7ea277a2ebcc454c8373d7d8fb991a7fc # If the deployment script is called with CSI_PROW_TEST_DRIVER= as # environment variable, then it must write a suitable test driver configuration # into that file in addition to installing the driver. -configvar CSI_PROW_DRIVER_VERSION "v1.8.0" "CSI driver version" +configvar CSI_PROW_DRIVER_VERSION "v1.11.0" "CSI driver version" configvar CSI_PROW_DRIVER_REPO https://github.com/kubernetes-csi/csi-driver-host-path "CSI driver repo" configvar CSI_PROW_DEPLOYMENT "" "deployment" configvar CSI_PROW_DEPLOYMENT_SUFFIX "" "additional suffix in kubernetes-x.yy[suffix].yaml files" @@ -245,7 +245,7 @@ configvar CSI_PROW_SANITY_CONTAINER "hostpath" "Kubernetes container with CSI dr # The version of dep to use for 'make test-vendor'. Ignored if the project doesn't # use dep. Only binary releases of dep are supported (https://github.com/golang/dep/releases). -configvar CSI_PROW_DEP_VERSION v0.5.1 "golang dep version to be used for vendor checking" +configvar CSI_PROW_DEP_VERSION v0.5.4 "golang dep version to be used for vendor checking" # Each job can run one or more of the following tests, identified by # a single word: @@ -469,7 +469,7 @@ install_dep () { if dep version 2>/dev/null | grep -q "version:.*${CSI_PROW_DEP_VERSION}$"; then return fi - run curl --fail --location -o "${CSI_PROW_WORK}/bin/dep" "https://github.com/golang/dep/releases/download/v0.5.4/dep-linux-amd64" && + run curl --fail --location -o "${CSI_PROW_WORK}/bin/dep" "https://github.com/golang/dep/releases/download/${CSI_PROW_DEP_VERSION}/dep-linux-amd64" && chmod u+x "${CSI_PROW_WORK}/bin/dep" } @@ -1008,7 +1008,10 @@ run_e2e () ( # the full Kubernetes E2E testsuite while only running a few tests. move_junit () { if ls "${ARTIFACTS}"/junit_[0-9]*.xml 2>/dev/null >/dev/null; then - run_filter_junit -t="External.Storage|CSI.mock.volume" -o "${ARTIFACTS}/junit_${name}.xml" "${ARTIFACTS}"/junit_[0-9]*.xml && rm -f "${ARTIFACTS}"/junit_[0-9]*.xml + mkdir -p "${ARTIFACTS}/junit/${name}" && + mkdir -p "${ARTIFACTS}/junit/steps" && + run_filter_junit -t="External.Storage|CSI.mock.volume" -o "${ARTIFACTS}/junit/steps/junit_${name}.xml" "${ARTIFACTS}"/junit_[0-9]*.xml && + mv "${ARTIFACTS}"/junit_[0-9]*.xml "${ARTIFACTS}/junit/${name}/" fi } trap move_junit EXIT @@ -1085,13 +1088,14 @@ kubectl exec "$pod" -c "${CSI_PROW_SANITY_CONTAINER}" -- /bin/sh -c "\${CHECK_PA EOF chmod u+x "${CSI_PROW_WORK}"/*dir_in_pod.sh + mkdir -p "${ARTIFACTS}/junit/steps" # This cannot run in parallel, because -csi.junitfile output # from different Ginkgo nodes would go to the same file. Also the # staging and target directories are the same. run_with_loggers "${CSI_PROW_WORK}/csi-sanity" \ -ginkgo.v \ - -csi.junitfile "${ARTIFACTS}/junit_sanity.xml" \ + -csi.junitfile "${ARTIFACTS}/junit/steps/junit_sanity.xml" \ -csi.endpoint "dns:///$(docker inspect -f '{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}' csi-prow-control-plane):$(kubectl get "services/${CSI_PROW_SANITY_SERVICE}" -o "jsonpath={..nodePort}")" \ -csi.stagingdir "/tmp/staging" \ -csi.mountdir "/tmp/mount" \ @@ -1121,7 +1125,8 @@ make_test_to_junit () { # Plain make-test.xml was not delivered as text/xml by the web # server and ignored by spyglass. It seems that the name has to # match junit*.xml. - out="${ARTIFACTS}/junit_make_test.xml" + out="${ARTIFACTS}/junit/steps/junit_make_test.xml" + mkdir -p "$(dirname "$out")" testname= echo "" >>"$out" @@ -1385,8 +1390,8 @@ main () { fi # Merge all junit files into one. This gets rid of duplicated "skipped" tests. - if ls "${ARTIFACTS}"/junit_*.xml 2>/dev/null >&2; then - run_filter_junit -o "${CSI_PROW_WORK}/junit_final.xml" "${ARTIFACTS}"/junit_*.xml && rm "${ARTIFACTS}"/junit_*.xml && mv "${CSI_PROW_WORK}/junit_final.xml" "${ARTIFACTS}" + if ls "${ARTIFACTS}"/junit/steps/junit_*.xml 2>/dev/null >&2; then + run_filter_junit -o "${ARTIFACTS}/junit_final.xml" "${ARTIFACTS}"/junit/steps/junit_*.xml fi return "$ret"