Step: ocm-e2e-clusterpool-list

This step queries the cluster pool host for a list of available cluster pools, potentially filters and sorts the list of cluster pools, and then writes that list to a file in SHARED_DIR.

Container image used for this step: open-cluster-management/builder:go1.16-linux

open-cluster-management/builder:go1.16-linux resolves to an image imported from the specified imagestream tag on the build farm (documentation).

Environment

In addition to the default environment, the step exposes the following:

Variable Name Type Variable Content
MAKEFILE Parameter[?] Location of the build harness Makefile for use on OSCI. (default: /opt/build-harness/Makefile.prow)
CLUSTERPOOL_HOST_API Parameter[?] API URL of the cluster running the target clusterpool, used in oc login, so port :6443 is required (default: https://api.collective.aws.red-chesterfield.com:6443)
CLUSTERPOOL_HOST_NAMESPACE Parameter[?] Namespace on the cluster pool host to use.
CLUSTERPOOL_HOST_PROW_KUBE_SECRET Parameter[?] The name of the kube secret with the kube API user and token.
CLUSTERPOOL_LIST_INCLUSION_FILTER Parameter[?] A filter used by grep to select a set of cluster pools to use when checking out clusters. If the filter is empty, all cluster pools will be used. This filter is applied before the EXCLUSION filter.
CLUSTERPOOL_LIST_EXCLUSION_FILTER Parameter[?] A filter used by grep to prevent a set of cluster pools from being used when checking out clusters. If the filter is empty, no cluster pools will be eliminated. This filter is applied after the INCLUSION filter.
CLUSTERPOOL_LIST_ORDER Parameter[?] Valid values are "sort" and "shuffle". Any other value leaves the list in its original order. (default: shuffle)
CLUSTERPOOL_LIST_FILE Parameter[?] File name to use for the cluster pool list. (default: clusterpool-list)

Source Code

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
#!/bin/bash

temp=$(mktemp -d -t ocm-XXXXX)
cd "$temp" || exit 1

echo "INFO Setting clusterpool list file"
LIST_FILE="$SHARED_DIR/$CLUSTERPOOL_LIST_FILE"
echo "     LIST_FILE: $LIST_FILE"

echo "INFO Copying make file"
echo "     MAKEFILE: $MAKEFILE"
cp "$MAKEFILE" ./Makefile

echo "INFO Setting location of oc and jq binarys for build harness"
OC=$(which oc)
JQ=$(which jq)
export OC
export JQ
if [[ -z "$OC" ]]; then
    echo "ERROR The oc command is not installed"
    exit 1
fi
if [[ -z "$JQ" ]]; then
    echo "ERROR The jq command is not installed"
    exit 1
fi

echo "INFO Getting list of all clusterpools in json format"
make clusterpool/list-clusterpools CLUSTERPOOL_LIST_ARGUMENTS=" -o json" > list.json
echo "INFO Saving clusterpool json file to artifact directory"
cp list.json "${ARTIFACT_DIR}/list.json"
echo "INFO Clusterpool list json file"
cat list.json
echo "     --- end ---"

echo "Info Getting the names of all clusterpools in a ready state"
jq -r '.items[] | select(.status.ready > 0) | .metadata.name' list.json > "$LIST_FILE"
echo "INFO Saving clusterpool ready list to artifact directory"
cp "$LIST_FILE" "${ARTIFACT_DIR}/$CLUSTERPOOL_LIST_FILE"
echo "INFO All ready clusterpools:"
cat "$LIST_FILE"
echo "     --- end ---"

echo "INFO Checking inclusion filter..."
if [[ -n "$CLUSTERPOOL_LIST_INCLUSION_FILTER" ]]; then
    echo "     CLUSTERPOOL_LIST_INCLUSION_FILTER: $CLUSTERPOOL_LIST_INCLUSION_FILTER"

    echo "INFO Applying inclusion filter"
    grep -e "$CLUSTERPOOL_LIST_INCLUSION_FILTER" "$LIST_FILE" > "$LIST_FILE.tmp" || true

    echo "INFO Cluster list after filtering:"
    cat "$LIST_FILE"
    echo "     --- end ---"

    echo "INFO Number of clusterpools after inclusion filter:"
    echo "     ---$(wc -l < "$LIST_FILE.tmp")---"

    echo "INFO Checking if any clusters are left..."
    if [[ $(wc -l < "$LIST_FILE.tmp") == 0 ]]; then
        echo "ERROR No clusters left after applying inclusion filter."
        exit 1
    fi

    echo "INFO Updating list of available clusters"
    mv "$LIST_FILE.tmp" "$LIST_FILE"
else
    echo "     inclusion filter not provided"
fi

echo "INFO Checking exclusion filter"
if [[ -n "$CLUSTERPOOL_LIST_EXCLUSION_FILTER" ]]; then
    echo "     CLUSTERPOOL_LIST_EXCLUSION_FILTER: $CLUSTERPOOL_LIST_EXCLUSION_FILTER"

    echo "INFO Applying exclusion filter"
    grep -v -e "$CLUSTERPOOL_LIST_EXCLUSION_FILTER" "$LIST_FILE" > "$LIST_FILE.tmp" || true

    echo "INFO Cluster list after filtering:"
    cat "$LIST_FILE.tmp"
    echo "     --- end ---"

    echo "INFO Number of clusterpools after exclusion filter:"
    echo "     ---$(wc -l < "$LIST_FILE.tmp")---"

    echo "INFO Checking if any clusters are left..."
    if [[ $(wc -l < "$LIST_FILE.tmp") == 0 ]]; then
        echo "ERROR No clusters left after applying exclusion filter."
        exit 1
    fi
    echo "INFO Updating list of available clusterpools"
    mv "$LIST_FILE.tmp" "$LIST_FILE"
else
    echo "     exclusion filter not provided"
fi

echo "INFO Available clusterpool list:"
cat "$LIST_FILE"
echo "     --- end ---"

echo "INFO Checking if list needs to be reordered"
echo "     CLUSTERPOOL_LIST_ORDER: $CLUSTERPOOL_LIST_ORDER"
case "$CLUSTERPOOL_LIST_ORDER" in
    "")
        echo "     CLUSTERPOOL_LIST_ORDER is empty"
        echo "     Will not change list order"
        ;;
    sort)
        echo "INFO Sorting clusterpool list"
        sort "$LIST_FILE" > "$LIST_FILE.tmp"
        
        echo "INFO Sorted clusterpool list:"
        cat "$LIST_FILE.tmp"
        echo "     --- end ---"

        echo "INFO Updating list of available clusterpools"
        mv "$LIST_FILE.tmp" "$LIST_FILE"
        ;;
    shuffle)
        echo "INFO Shuffling clusterpool list"
        shuf "$LIST_FILE" > "$LIST_FILE.tmp"
        
        echo "INFO Shuffled clusterpool list:"
        cat "$LIST_FILE.tmp"
        echo "     --- end ---"

        echo "INFO Updating list of available clusterpools"
        mv "$LIST_FILE.tmp" "$LIST_FILE"
        ;;
    *)
        echo "     Invalid CLUSTERPOOL_LIST_ORDER"
        echo "     Ignoring"
        ;;
esac

echo "INFO Final clusterpool list:"
cat "$LIST_FILE"
echo "     --- end ---"

Properties

Property Value Description
Resource requests (cpu) 100m Used in .resources.requests of the pod running this step.
Resource requests (memory) 100Mi Used in .resources.requests of the pod running this step.

GitHub Link:

https://github.com/openshift/release/blob/master/ci-operator/step-registry/ocm/e2e/clusterpool/list/ocm-e2e-clusterpool-list-ref.yaml

Owners:

Approvers:

Source code for this page located on GitHub