Skip to content

Commit 54b735c

Browse files
authoredAug 2, 2022
update test case for db2wh (#12)
* update test case for db2wh Signed-off-by: Andrew Trice <amtrice@us.ibm.com>
1 parent f88c69c commit 54b735c

21 files changed

+552
-483
lines changed
 

‎.github/scripts/validate-deploy.sh

Lines changed: 30 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,39 @@
11
#!/usr/bin/env bash
22

3+
SCRIPT_DIR=$(cd $(dirname "$0"); pwd -P)
4+
35
GIT_REPO=$(cat git_repo)
46
GIT_TOKEN=$(cat git_token)
57

8+
BIN_DIR=$(cat .bin_dir)
9+
10+
export PATH="${BIN_DIR}:${PATH}"
11+
12+
source "${SCRIPT_DIR}/validation-functions.sh"
13+
14+
if ! command -v oc 1> /dev/null 2> /dev/null; then
15+
echo "oc cli not found" >&2
16+
exit 1
17+
fi
18+
19+
if ! command -v kubectl 1> /dev/null 2> /dev/null; then
20+
echo "kubectl cli not found" >&2
21+
exit 1
22+
fi
23+
24+
if ! command -v ibmcloud 1> /dev/null 2> /dev/null; then
25+
echo "ibmcloud cli not found" >&2
26+
exit 1
27+
fi
28+
629
export KUBECONFIG=$(cat .kubeconfig)
7-
NAMESPACE=$(jq -r '.cpd_namespace // "gitops-cp4d-instance"' gitops-output.json)
30+
NAMESPACE=$(jq -r '.cpd_namespace // "gitops-cp-db2"' gitops-output.json)
831
COMPONENT_NAME=$(jq -r '.name // "my-module"' gitops-output.json)
932
BRANCH=$(jq -r '.branch // "main"' gitops-output.json)
1033
SERVER_NAME=$(jq -r '.server_name // "default"' gitops-output.json)
1134
LAYER=$(jq -r '.layer_dir // "2-services"' gitops-output.json)
1235
TYPE=$(jq -r '.type // "base"' gitops-output.json)
36+
CPD_NAMESPACE="cp4d"
1337

1438
mkdir -p .testrepo
1539

@@ -19,61 +43,13 @@ cd .testrepo || exit 1
1943

2044
find . -name "*"
2145

22-
if [[ ! -f "argocd/${LAYER}/cluster/${SERVER_NAME}/${TYPE}/${NAMESPACE}-${COMPONENT_NAME}.yaml" ]]; then
23-
echo "ArgoCD config missing - argocd/${LAYER}/cluster/${SERVER_NAME}/${TYPE}/${NAMESPACE}-${COMPONENT_NAME}.yaml"
24-
exit 1
25-
fi
26-
27-
echo "Printing argocd/${LAYER}/cluster/${SERVER_NAME}/${TYPE}/${NAMESPACE}-${COMPONENT_NAME}.yaml"
28-
cat "argocd/${LAYER}/cluster/${SERVER_NAME}/${TYPE}/${NAMESPACE}-${COMPONENT_NAME}.yaml"
46+
set -e
2947

30-
if [[ ! -f "payload/${LAYER}/namespace/${NAMESPACE}/${COMPONENT_NAME}/values.yaml" ]]; then
31-
echo "Application values not found - payload/${LAYER}/namespace/${NAMESPACE}/${COMPONENT_NAME}/values.yaml"
32-
exit 1
33-
fi
48+
# sleep so that the db2wh operator and service can be deployed
49+
sleep 5m
3450

35-
echo "Printing payload/${LAYER}/namespace/${NAMESPACE}/${COMPONENT_NAME}/values.yaml"
36-
cat "payload/${LAYER}/namespace/${NAMESPACE}/${COMPONENT_NAME}/values.yaml"
51+
check_k8s_namespace "${CPD_NAMESPACE}"
52+
check_k8s_resource "${CPD_NAMESPACE}" "job" "cp-db2-job"
3753

38-
count=0
39-
until kubectl get namespace "${NAMESPACE}" 1> /dev/null 2> /dev/null || [[ $count -eq 20 ]]; do
40-
echo "Waiting for namespace: ${NAMESPACE}"
41-
count=$((count + 1))
42-
sleep 15
43-
done
44-
45-
if [[ $count -eq 20 ]]; then
46-
echo "Timed out waiting for namespace: ${NAMESPACE}"
47-
exit 1
48-
else
49-
echo "Found namespace: ${NAMESPACE}. Sleeping for 30 seconds to wait for everything to settle down"
50-
sleep 30
51-
fi
52-
53-
RESOURCE01="db2oltp"
54-
55-
count=0
56-
57-
SS_COUNT=$(kubectl get statefulset -l icpdsupport/addOnId=${RESOURCE01} -n "${NAMESPACE}"|wc -l)
58-
59-
until [[ `expr ${SS_COUNT} + 0`>0 ]] || [[ $count -eq 26 ]]; do
60-
echo "Waiting for statefulset in ${NAMESPACE}"
61-
SS_COUNT=$(kubectl get statefulset -l icpdsupport/addOnId=${RESOURCE01} -n "${NAMESPACE}"|wc -l)
62-
echo "SSCount: ${SS_COUNT}"
63-
count=$((count + 1))
64-
sleep 45
65-
done
66-
STATEFULSET=$(kubectl get statefulset -l icpdsupport/addOnId=${RESOURCE01} -n "${NAMESPACE}" | grep ${RESOURCE01} | awk -v k="text" '{n=split($0,a," "); print a[1]}')
67-
echo "Waiting for Statefulset: ${STATEFULSET}"
68-
if [[ $count -eq 26 ]]; then
69-
echo "Timed out waiting for statefulset ${STATEFULSET} in ${NAMESPACE}"
70-
kubectl get all -n "${NAMESPACE}"
71-
exit 1
72-
fi
7354

74-
#kubectl get all -l icpdsupport/addOnId=${RESOURCE01} -n "${NAMESPACE}"|| exit 1
75-
#kubectl wait --for=condition=complete job/${JOB} || exit 1
76-
kubectl rollout status "statefulset/"${STATEFULSET} -n "${NAMESPACE}" || exit 1
7755

78-
cd ..
79-
rm -rf .testrepo
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
#!/usr/bin/env bash
2+
3+
validate_gitops_content () {
4+
local NS="$1"
5+
local GITOPS_LAYER="$2"
6+
local GITOPS_SERVER_NAME="$3"
7+
local GITOPS_TYPE="$4"
8+
local GITOPS_COMPONENT_NAME="$5"
9+
local PAYLOAD_FILE="${6:-values.yaml}"
10+
11+
echo "Validating: namespace=${NS}, layer=${GITOPS_LAYER}, server=${GITOPS_SERVER_NAME}, type=${GITOPS_TYPE}, component=${GITOPS_COMPONENT_NAME}"
12+
13+
if [[ ! -f "argocd/${GITOPS_LAYER}/cluster/${GITOPS_SERVER_NAME}/${GITOPS_TYPE}/${NS}-${GITOPS_COMPONENT_NAME}.yaml" ]]; then
14+
echo "ArgoCD config missing - argocd/${GITOPS_LAYER}/cluster/${GITOPS_SERVER_NAME}/${GITOPS_TYPE}/${NS}-${GITOPS_COMPONENT_NAME}.yaml" >&2
15+
exit 1
16+
fi
17+
18+
echo "Printing argocd/${GITOPS_LAYER}/cluster/${GITOPS_SERVER_NAME}/${GITOPS_TYPE}/${NS}-${GITOPS_COMPONENT_NAME}.yaml"
19+
cat "argocd/${GITOPS_LAYER}/cluster/${GITOPS_SERVER_NAME}/${GITOPS_TYPE}/${NS}-${GITOPS_COMPONENT_NAME}.yaml"
20+
21+
if [[ ! -f "payload/${GITOPS_LAYER}/namespace/${NS}/${GITOPS_COMPONENT_NAME}/${PAYLOAD_FILE}" ]]; then
22+
echo "Application values not found - payload/${GITOPS_LAYER}/namespace/${NS}/${GITOPS_COMPONENT_NAME}/${PAYLOAD_FILE}" >&2
23+
exit 1
24+
fi
25+
26+
echo "Printing payload/${GITOPS_LAYER}/namespace/${NS}/${GITOPS_COMPONENT_NAME}/${PAYLOAD_FILE}"
27+
cat "payload/${GITOPS_LAYER}/namespace/${NS}/${GITOPS_COMPONENT_NAME}/${PAYLOAD_FILE}"
28+
}
29+
30+
check_k8s_namespace () {
31+
local NS="$1"
32+
33+
count=0
34+
until kubectl get namespace "${NS}" 1> /dev/null 2> /dev/null || [[ $count -eq 20 ]]; do
35+
echo "Waiting for namespace: ${NS}"
36+
count=$((count + 1))
37+
sleep 15
38+
done
39+
40+
if [[ $count -eq 20 ]]; then
41+
echo "Timed out waiting for namespace: ${NS}" >&2
42+
exit 1
43+
else
44+
echo "Found namespace: ${NS}. Sleeping for 30 seconds to wait for everything to settle down"
45+
sleep 30
46+
fi
47+
}
48+
49+
check_k8s_resource () {
50+
local NS="$1"
51+
local GITOPS_TYPE="$2"
52+
local NAME="$3"
53+
54+
echo "Checking for resource: ${NS}/${GITOPS_TYPE}/${NAME}"
55+
56+
count=0
57+
until kubectl get "${GITOPS_TYPE}" "${NAME}" -n "${NS}" 1> /dev/null 2> /dev/null || [[ $count -gt 20 ]]; do
58+
echo "Waiting for ${GITOPS_TYPE}/${NAME} in ${NS}"
59+
count=$((count + 1))
60+
sleep 30
61+
done
62+
63+
if [[ $count -gt 20 ]]; then
64+
echo "Timed out waiting for ${GITOPS_TYPE}/${NAME}" >&2
65+
kubectl get "${GITOPS_TYPE}" -n "${NS}"
66+
exit 1
67+
fi
68+
69+
kubectl get "${GITOPS_TYPE}" "${NAME}" -n "${NS}" -o yaml
70+
71+
if [[ "${GITOPS_TYPE}" =~ deployment|statefulset|daemonset ]]; then
72+
kubectl rollout status "${GITOPS_TYPE}" "${NAME}" -n "${NS}" || exit 1
73+
elif [[ "${GITOPS_TYPE}" == "job" ]]; then
74+
kubectl wait --for=condition=complete "job/${NAME}" -n "${NS}" || exit 1
75+
fi
76+
77+
echo "Done checking for resource: ${NS}/${GITOPS_TYPE}/${NAME}"
78+
}

‎.github/workflows/manual-test-repo-delete.yaml

Lines changed: 5 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -7,38 +7,9 @@ on:
77
required: true
88

99
jobs:
10-
create_repo:
10+
delete_repo:
1111
if: ${{ github.event.inputs.confirm == 'Delete' }}
12-
runs-on: ubuntu-latest
13-
steps:
14-
- id: variables
15-
name: Set up variables
16-
env:
17-
GIT_ORG: ${{ secrets.GIT_ORG }}
18-
GITHUB_REPOSITORY: ${{ env.GITHUB_REPOSITORY }}
19-
shell: bash
20-
run: |
21-
repo=$(echo ${GITHUB_REPOSITORY} | sed -E "s~.*/[^-]+-(.*)~\1~g")
22-
echo "Repo: $repo"
23-
echo "::set-output name=repo::$repo"
24-
25-
org="${GIT_ORG:-cloud-native-toolkit-test}"
26-
echo "Org: $org"
27-
echo "::set-output name=org::$org"
28-
29-
- name: Delete test repo
30-
env:
31-
GITHUB_REPOSITORY: ${{ env.GITHUB_REPOSITORY }}
32-
GITHUB_TOKEN: ${{ secrets.GIT_ADMIN_TOKEN }}
33-
run: |
34-
GIT_SLUG=${{ steps.variables.outputs.org }}/${{ steps.variables.outputs.repo }}
35-
if [[ -z "${{ steps.variables.outputs.org }}" ]] || [[ -z "${{ steps.variables.outputs.repo }}" ]]; then
36-
echo "GIT_SLUG value is invalid"
37-
exit 1
38-
fi
39-
if [[ "${GIT_SLUG}" == "${GITHUB_REPOSITORY}" ]]; then
40-
echo "You cannot delete the current repository!!!!"
41-
exit 1
42-
fi
43-
44-
gh repo delete ${GIT_SLUG} --confirm
12+
uses: cloud-native-toolkit/action-workflows/.github/workflows/manual-test-repo-delete.yaml@v1
13+
secrets:
14+
GIT_ORG: ${{ secrets.GIT_ORG }}
15+
GIT_ADMIN_TOKEN: ${{ secrets.GIT_ADMIN_TOKEN }}

‎.github/workflows/notify.yaml

Lines changed: 5 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,11 @@
1+
name: Notify
2+
13
on:
24
release:
35
types: [published]
46

57
jobs:
68
notify:
7-
runs-on: ubuntu-latest
8-
9-
strategy:
10-
matrix:
11-
repo:
12-
- cloud-native-toolkit/ibm-garage-iteration-zero
13-
- cloud-native-toolkit/garage-terraform-modules
14-
15-
steps:
16-
- name: Repository dispatch ${{ matrix.repo }}
17-
uses: cloud-native-toolkit/action-repository-dispatch@main
18-
with:
19-
notifyRepo: ${{ matrix.repo }}
20-
eventType: released
21-
env:
22-
GITHUB_TOKEN: ${{ secrets.TOKEN }}
9+
uses: cloud-native-toolkit/action-workflows/.github/workflows/notify.yaml@v1
10+
secrets:
11+
TOKEN: ${{ secrets.TOKEN }}

‎.github/workflows/publish-assets.yaml

Lines changed: 0 additions & 36 deletions
This file was deleted.
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
name: Publish metadata
2+
3+
on:
4+
release:
5+
types:
6+
- published
7+
8+
jobs:
9+
publish-assets:
10+
uses: cloud-native-toolkit/action-workflows/.github/workflows/publish-metadata.yaml@v1
11+
secrets:
12+
TOKEN: ${{ secrets.GITHUB_TOKEN }}

‎.github/workflows/verify-pr.yaml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
2+
3+
name: Verify PR
4+
5+
# Controls when the action will run. Triggers the workflow on push or pull request
6+
# events but only for the main branch
7+
on:
8+
pull_request:
9+
branches: [ main ]
10+
11+
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
12+
jobs:
13+
verify:
14+
if: ${{ !contains( github.event.pull_request.labels.*.name, 'skip ci' ) }}
15+
uses: cloud-native-toolkit/action-workflows/.github/workflows/verify-gitops-module.yaml@v1
16+
with:
17+
testcase: ocp4_latest_gitops_db2wh
18+
secrets:
19+
GIT_ORG: ${{ secrets.GIT_ORG }}
20+
AWS_CLUSTER_USERNAME: ${{ secrets.AWS_CLUSTER_USERNAME }}
21+
AWS_CLUSTER_PASSWORD: ${{ secrets.AWS_CLUSTER_PASSWORD }}
22+
IBMCLOUD_API_KEY: ${{ secrets.IBMCLOUD_API_KEY }}
23+
GIT_ADMIN_USERNAME: ${{ secrets.GIT_ADMIN_USERNAME }}
24+
GIT_ADMIN_TOKEN: ${{ secrets.GIT_ADMIN_TOKEN }}
25+
CP_ENTITLEMENT_KEY: ${{ secrets.CP_ENTITLEMENT_KEY }}
26+
27+
verifyMetadata:
28+
uses: cloud-native-toolkit/action-workflows/.github/workflows/verify-module-metadata.yaml@v1

0 commit comments

Comments
 (0)