|
718 | 718 | builders:
|
719 | 719 | - shell: |-
|
720 | 720 | #!/bin/bash
|
721 |
| - # gcloud auth login requires verification code from url |
722 |
| - ${{GCLOUD_SDK_PATH}}/bin/gcloud auth activate-service-account --key-file=${{GCLOUD_KEY_PATH}} |
| 721 | + # Prevent exposing credentials in the console output by adding set +x |
| 722 | + # This is to avoid other developers removing this set+x by accident |
| 723 | + set +x |
| 724 | + token_file="/var/lib/jenkins/gcp_cred" |
| 725 | + cp $token_file ${{WORKSPACE}}/gcp_cred |
| 726 | + sudo gcloud iam workforce-pools create-cred-config \ |
| 727 | + locations/global/workforcePools/${{WORKFORCE_POOL}}/providers/oidc-provider \ |
| 728 | + --subject-token-type urn:ietf:params:oauth:token-type:id_token \ |
| 729 | + --credential-source-file gcp_cred \ |
| 730 | + --workforce-pool-user-project antrea\ |
| 731 | + --project antrea\ |
| 732 | + --output-file gcp_cred_config.json |
| 733 | + sudo gcloud auth login --cred-file=gcp_cred_config.json |
| 734 | + sudo gcloud config set project antrea |
723 | 735 | sudo ./ci/test-conformance-gke.sh --cluster-name antrea-gke-${{BUILD_NUMBER}} \
|
724 |
| - --svc-account antrea-gcp@antrea.iam.gserviceaccount.com --gcloud-sdk-path ${{GCLOUD_SDK_PATH}} \ |
| 736 | + --skip-iam-policy-binding --gcloud-sdk-path ${{GCLOUD_SDK_PATH}} \ |
725 | 737 | --log-mode detail --setup-only
|
726 | 738 | triggers:
|
727 | 739 | - timed: H H */2 * *
|
|
741 | 753 | - email:
|
742 | 754 | notify-every-unstable-build: true
|
743 | 755 |
|
| 756 | + wrappers: |
| 757 | + - credentials-binding: |
| 758 | + - text: |
| 759 | + credential-id: WORKFORCE_POOL # Jenkins secret that stores the cloud resource pool id |
| 760 | + variable: WORKFORCE_POOL |
| 761 | + - 'cloud-{name}-{test_name}-credential': |
| 762 | + test_name: gke |
| 763 | + node: antrea-credential |
| 764 | + description: 'This is the cloud credential job for antrea gke tests.' |
| 765 | + builders: |
| 766 | + - shell: |- |
| 767 | + #!/bin/bash |
| 768 | + # Prevent exposing credentials in the console output by adding set +x |
| 769 | + # This is to avoid other developers removing this set+x by accident |
| 770 | + set +x |
| 771 | + token_file="/var/lib/jenkins/ci_properties.txt" |
| 772 | + if [ -e "$token_file" ]; then |
| 773 | + modification_timestamp=$(stat -c %Y "$token_file") |
| 774 | + current_timestamp=$(date +%s) |
| 775 | + time_difference=$((current_timestamp - modification_timestamp)) |
| 776 | + else |
| 777 | + time_difference=14401 |
| 778 | + fi |
| 779 | + # The credentials are valid for 12 hours, to allow sufficient time for job execution, the reuse threshold is set to 4 hours. |
| 780 | + threshold=14400 |
| 781 | + if [ "$time_difference" -gt "$threshold" ]; then |
| 782 | + echo "Generate the new Cloud Credential" |
| 783 | + json_data=$(python3 get_access_using_api_client.py ${{CLOUD_CLIENT_ID}} ${{CLOUD_CLIENT_TOKEN}} PowerUser gcp ${{GKE_RESOURCE_ID}} 43200 prd) |
| 784 | + json_data=$(echo $json_data | sed "s/'/\"/g" | sed 's/True/true/') |
| 785 | + id_token=$(echo $json_data | jq -r '.credential.idToken') |
| 786 | + echo "ID_TOKEN=$id_token" > ${{WORKSPACE}}/ci_properties.txt |
| 787 | + cp ${{WORKSPACE}}/ci_properties.txt $token_file |
| 788 | + else |
| 789 | + echo "Reuse the unexpired Cloud Credential" |
| 790 | + cp $token_file ${{WORKSPACE}}/ci_properties.txt |
| 791 | + fi |
| 792 | + triggers: |
| 793 | + - timed: H H/6 * * * |
| 794 | + publishers: |
| 795 | + - trigger-parameterized-builds: |
| 796 | + - project: |
| 797 | + - cloud-{name}-renew-credential |
| 798 | + current-parameters: true |
| 799 | + property-file: 'ci_properties.txt' |
| 800 | + - email: |
| 801 | + notify-every-unstable-build: true |
| 802 | + |
| 803 | + wrappers: |
| 804 | + - credentials-binding: |
| 805 | + - text: |
| 806 | + credential-id: CLOUD_CLIENT_ID # Jenkins secret that stores client id |
| 807 | + variable: CLOUD_CLIENT_ID |
| 808 | + - text: |
| 809 | + credential-id: CLOUD_CLIENT_TOKEN # Jenkins secret that stores client secret token |
| 810 | + variable: CLOUD_CLIENT_TOKEN |
| 811 | + - text: |
| 812 | + credential-id: GKE_RESOURCE_ID |
| 813 | + variable: GKE_RESOURCE_ID |
| 814 | + - 'cloud-{name}-{test_name}-credential': |
| 815 | + test_name: renew |
| 816 | + node: antrea-cloud |
| 817 | + description: 'This is a periodic job to renew the credential on cloud node.' |
| 818 | + builders: |
| 819 | + - shell: |- |
| 820 | + #!/bin/bash |
| 821 | + # Prevent exposing credentials in the console output by adding set +x |
| 822 | + # This is to avoid other developers removing this set+x by accident |
| 823 | + set +x |
| 824 | + cd /var/lib/jenkins |
| 825 | + if [ -z "$ID_TOKEN" ]; then |
| 826 | + echo "No Token ID Found" |
| 827 | + exit 1 |
| 828 | + else |
| 829 | + echo "${{ID_TOKEN}}" > gcp_cred |
| 830 | + fi |
| 831 | + publishers: |
| 832 | + - email: |
| 833 | + notify-every-unstable-build: true |
| 834 | + |
| 835 | + triggers: [] |
744 | 836 | wrappers: []
|
745 | 837 | - 'cloud-{name}-{test_name}-cleanup':
|
746 | 838 | test_name: gke
|
|
0 commit comments