-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
OPSEXP-1776: refactor dbp verify helm action to allow for keeping logs #173
Merged
Merged
Changes from 18 commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
59e0379
add an action to upload kubernetes resource logs
alxgomz 794c96a
add an action to generate k8s friendly name
alxgomz 8288e96
delegate ns name generation to dedicated action
alxgomz 7f4d23c
run helm deleetions in a dedicated action
alxgomz 561ad9d
add a step to upload logs
alxgomz a98ea32
configurable log retention
alxgomz e974d0e
Merge remote-tracking branch 'origin/master' into OPEXP-1776
alxgomz 496424d
clean garbage
alxgomz a87159c
fixup
alxgomz 8260734
fixup
alxgomz 0d047fb
restore release-prefix usage and avoid leaking non-scoped resource
alxgomz 411bc4c
always upload logs
alxgomz 3538c4c
fixup
alxgomz 4005f14
match path and resource type names
alxgomz 9315ff9
change artifact name
alxgomz aca2171
supress node12 warnings
alxgomz a8de3d9
prefix artifact name with ns name for clarity
alxgomz 0cbf543
Merge remote-tracking branch 'origin/master' into OPSEXP-1776
alxgomz a991ca2
clean debug statements
alxgomz 18191d3
review comments
alxgomz 3f995c1
add doc
alxgomz 72e4ca1
use commit sha as ref while release is pending
alxgomz File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
name: kubernetes valid namespace | ||
description: | | ||
Generate a sanitized namespace name for kubernetes to use based on the release | ||
name, ap version and some other parameters | ||
inputs: | ||
branch_name: | ||
description: name of the git branch we're executing from | ||
required: true | ||
release_prefix: | ||
description: a release prefix to differentiate from other releases | ||
required: true | ||
outputs: | ||
namespace: | ||
description: generated namespace | ||
value: ${{ steps.genns.outputs.namespace }} | ||
runs: | ||
using: composite | ||
steps: | ||
- name: generate namespace | ||
id: genns | ||
shell: bash | ||
env: | ||
BRANCH_NAME: ${{ inputs.branch_name }} | ||
RELEASE_PREFIX: ${{ inputs.release_prefix }} | ||
run: | | ||
BRANCH_PREFIX="${BRANCH_NAME:0:28}" | ||
BRANCH_NS="${BRANCH_PREFIX//[^[:alnum:]]/-}" | ||
RELEASE_NS=$"${RELEASE_PREFIX//[^[:alnum:]]/-}" | ||
NS_SUFFIX=${GITHUB_RUN_NUMBER:-0} | ||
echo namespace="${BRANCH_NS,,}"-"${RELEASE_NS,,}"-"${NS_SUFFIX}" >> $GITHUB_OUTPUT |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -63,7 +63,7 @@ runs: | |
uses: actions/checkout@v3 | ||
with: | ||
fetch-depth: 0 | ||
- uses: aws-actions/configure-aws-credentials@v1 | ||
- uses: aws-actions/configure-aws-credentials@v1-node16 | ||
with: | ||
aws-region: ${{ inputs.aws_region }} | ||
aws-access-key-id: ${{ inputs.aws_access_key_id }} | ||
|
@@ -89,14 +89,35 @@ runs: | |
- name: Get commit msg | ||
uses: >- | ||
Alfresco/alfresco-build-tools/.github/actions/[email protected] | ||
- name: Get a namespace to deploy on | ||
id: k8sns | ||
uses: >- | ||
Alfresco/alfresco-build-tools/.github/actions/dbp-charts/kubernetes-valid-ns@OPSEXP-1776 | ||
with: | ||
branch_name: ${{ env.BRANCH_NAME }} | ||
release_prefix: ${{ inputs.release_prefix }} | ||
- name: Run helm chart test script | ||
run: ${{ github.action_path }}/helm_install.sh | ||
shell: bash | ||
env: | ||
K8SNS: ${{ steps.k8sns.outputs.namespace }} | ||
ACM_CERTIFICATE: ${{ inputs.acm_certificate }} | ||
AWS_SG: ${{ inputs.aws_sg }} | ||
DOMAIN: ${{ inputs.domain }} | ||
ACS_VERSION: ${{ inputs.acs_version }} | ||
RELEASE_PREFIX: ${{ inputs.release_prefix }} | ||
PROJECT_NAME: ${{ inputs.chart_name }} | ||
RELEASE_PREFIX: ${{ inputs.release_prefix }} | ||
TEST_NEWMAN: ${{ inputs.test_newman }} | ||
- name: Upload helm deployments logs as artifacts | ||
if: always() | ||
uses: >- | ||
Alfresco/alfresco-build-tools/.github/actions/kubectl-keep-nslogs@OPSEXP-1776 | ||
with: | ||
namespace: ${{ steps.k8sns.outputs.namespace }} | ||
- name: Uninstall Helm releases | ||
if: always() && ! contains(env.COMMIT_MESSAGE, '[keep env]') | ||
run: ${{ github.action_path }}/helm_delete.sh | ||
shell: bash | ||
env: | ||
RELEASE_PREFIX: ${{ inputs.release_prefix }} | ||
K8SNS: ${{ steps.k8sns.outputs.namespace }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#!/bin/bash +e | ||
# | ||
gionn marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
out_of_ns_ingress_cleanup() { | ||
echo "Something went wrong uninstalling ingress release... Need to do some cleanup" | ||
for i in clusterrole clusterrolebindings; do kubectl delete "$i" "ing-${RELEASE_PREFIX}-${GITHUB_RUN_NUMBER}-ingress-nginx" | ||
done | ||
} | ||
|
||
echo "cleaning up releases" | ||
helm delete "ing-${RELEASE_PREFIX}-${GITHUB_RUN_NUMBER}" -n "${K8SNS}" || out_of_ns_ingress_cleanup | ||
helm delete "${RELEASE_PREFIX}-${GITHUB_RUN_NUMBER}" -n "${K8SNS}" | ||
kubectl delete secret quay-registry-secret -n "${K8SNS}" | ||
kubectl delete namespace "${K8SNS}" --grace-period=1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
--- | ||
name: upload k8s logs as artifacts | ||
description: > | ||
Upload Kubernetes logs (jobs and pods) as a github artifact. | ||
Special attention must be payed to repo's storage limits. | ||
inputs: | ||
namespace: | ||
description: The kubernetes namespace to get logs from | ||
required: false | ||
default: default | ||
log_retention: | ||
description: Number of days to keep the logs for | ||
required: false | ||
default: "10" | ||
runs: | ||
using: composite | ||
steps: | ||
- id: artifactdir | ||
name: Create artifact directory | ||
shell: bash | ||
run: | | ||
ARTIFACTS_DIR=$(mktemp -d) | ||
echo "ARTIFACTS_DIR=${ARTIFACTS_DIR}" >> $GITHUB_OUTPUT | ||
- name: Fetch logs | ||
shell: bash | ||
working-directory: ${{ steps.artifactdir.outputs.ARTIFACTS_DIR }} | ||
run: | | ||
echo "checking pwd (should be ${{ steps.artifactdir.outputs.ARTIFACTS_DIR }})" | ||
pwd | ||
gionn marked this conversation as resolved.
Show resolved
Hide resolved
|
||
kubectl config set-context --current --namespace=${{ inputs.namespace }} | ||
for type in deployment.apps statefulset.apps jobs; do | ||
[ -d "${type}" ] || mkdir "${type}" | ||
for i in $(kubectl get "$type" -o name); do \ | ||
kubectl logs "$i" --all-containers=true | \ | ||
gzip > "${i}.log.gz" | ||
done | ||
done | ||
- name: upload kubernetes logs as artifact | ||
uses: actions/[email protected] | ||
with: | ||
name: >- | ||
${{ inputs.namespace }}_logs.${{ github.run_number }}.${{ github.run_attempt }} | ||
alxgomz marked this conversation as resolved.
Show resolved
Hide resolved
|
||
retention-days: ${{ inputs.log_retention }} | ||
path: ${{ steps.artifactdir.outputs.ARTIFACTS_DIR }} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remember that you probably want to immediately do a new release changing those references in the release PR after merging this PR