...

Text file src/k8s.io/kubernetes/test/e2e/testing-manifests/storage-csi/update-hostpath.sh

Documentation: k8s.io/kubernetes/test/e2e/testing-manifests/storage-csi

     1#!/bin/sh
     2
     3# Copyright 2021 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# This script will update all sidecar RBAC files and the CSI hostpath
    18# deployment files such that they match what is in a hostpath driver
    19# release.
    20#
    21# Beware that this will wipe out all local modifications!
    22
    23# Can be a tag or a branch.
    24script="$0"
    25hostpath_version="$1"
    26
    27if ! [ "$hostpath_version" ]; then
    28    cat >&2 <<EOF
    29Usage: $0 <hostpath tag or branch name>
    30
    31Required parameter is missing.
    32EOF
    33    exit 1
    34fi
    35
    36set -xe
    37cd "$(dirname "$0")"
    38
    39# Remove stale files.
    40rm -rf external-attacher external-provisioner external-resizer external-snapshotter external-health-monitor hostpath csi-driver-host-path
    41
    42# Check out desired release.
    43git clone https://github.com/kubernetes-csi/csi-driver-host-path.git
    44(cd csi-driver-host-path && git checkout "$hostpath_version")
    45trap "rm -rf csi-driver-host-path" EXIT
    46
    47# Main YAML files.
    48mkdir hostpath
    49cat >hostpath/README.md <<EOF
    50The files in this directory are exact copies of "kubernetes-latest" in
    51https://github.com/kubernetes-csi/csi-driver-host-path/tree/$hostpath_version/deploy/
    52
    53Do not edit manually. Run $script to refresh the content.
    54EOF
    55cp -r csi-driver-host-path/deploy/kubernetes-latest/hostpath hostpath/
    56cat >hostpath/hostpath/e2e-test-rbac.yaml <<EOF
    57# privileged Pod Security Policy, previously defined just for gcePD via PrivilegedTestPSPClusterRoleBinding()
    58kind: ClusterRoleBinding
    59apiVersion: rbac.authorization.k8s.io/v1
    60metadata:
    61  name: psp-csi-hostpath-role
    62subjects:
    63  # This list of ServiceAccount intentionally covers everything that might
    64  # be needed. In practice, only some of these accounts are actually
    65  # used.
    66  - kind: ServiceAccount
    67    name: csi-attacher
    68    namespace: default
    69  - kind: ServiceAccount
    70    name: csi-provisioner
    71    namespace: default
    72  - kind: ServiceAccount
    73    name: csi-snapshotter
    74    namespace: default
    75  - kind: ServiceAccount
    76    name: csi-resizer
    77    namespace: default
    78  - kind: ServiceAccount
    79    name: csi-external-health-monitor-controller
    80    namespace: default
    81  - kind: ServiceAccount
    82    name: csi-hostpathplugin-sa
    83    namespace: default
    84roleRef:
    85  kind: ClusterRole
    86  name: e2e-test-privileged-psp
    87  apiGroup: rbac.authorization.k8s.io
    88EOF
    89
    90download () {
    91    project="$1"
    92    path="$2"
    93    tag="$3"
    94    rbac="$4"
    95
    96    mkdir -p "$project/$path"
    97    url="https://github.com/kubernetes-csi/$project/raw/$tag/deploy/kubernetes/$path/$rbac"
    98    cat >"$project/$path/$rbac" <<EOF
    99# Do not edit, downloaded from $url
   100# for csi-driver-host-path $hostpath_version
   101# by $script
   102#
   103EOF
   104    curl --fail --location "$url" >>"$project/$path/$rbac"
   105}
   106
   107# RBAC files for each sidecar.
   108# This relies on the convention that "external-something" has "csi-something" as image name.
   109# external-health-monitor is special, it has two images.
   110# The repository for each image is ignored.
   111images=$(grep -r '^ *image:.*csi' hostpath/hostpath | sed -e 's;.*image:.*/;;' | grep -v 'node-driver-registrar' | sort -u)
   112for image in $images; do
   113    tag=$(echo "$image" | sed -e 's/.*://')
   114    path=
   115    rbac="rbac.yaml"
   116    case $image in
   117        csi-external-*)
   118            # csi-external-health-monitor-agent:v0.2.0
   119            project=$(echo "$image" | sed -e 's/csi-\(.*\)-[^:]*:.*/\1/')
   120            path=$(echo "$image" | sed -e 's/csi-\([^:]*\):.*/\1/')
   121            ;;
   122        *)
   123            project=$(echo "$image" | sed -e 's/:.*//' -e 's/^csi/external/')
   124            case $project in
   125                external-snapshotter)
   126                    # Another special case...
   127                    path="csi-snapshotter"
   128                    rbac="rbac-csi-snapshotter.yaml"
   129                    ;;
   130            esac
   131            ;;
   132    esac
   133    download "$project" "$path" "$tag" "$rbac"
   134done
   135
   136# Update the mock driver manifests, too.
   137grep -r image: hostpath/hostpath/csi-hostpath-plugin.yaml | while read -r image; do
   138    version=$(echo "$image" | sed -e 's/.*:\(.*\)/\1/')
   139    image=$(echo "$image" | sed -e 's/.*image: \([^:]*\).*/\1/')
   140    sed -i '' -e "s;$image:.*;$image:$version;" mock/*.yaml
   141done

View as plain text