From 0cd9f20ed4063aff32e351d22c40adbb365f7f17 Mon Sep 17 00:00:00 2001 From: Florian Lemaitre Date: Wed, 22 May 2024 18:01:36 +0200 Subject: [PATCH] Pod Deletion Cost --- .editorconfig | 45 + .github/ISSUE_TEMPLATE/bug_report.md | 36 + .github/ISSUE_TEMPLATE/custom.md | 8 + .github/ISSUE_TEMPLATE/feature_request.md | 20 + .github/workflows/build.yml | 165 ++ .github/workflows/release.yml | 79 + .github/workflows/semantic-pull-request.yml | 47 + .gitignore | 48 + CHANGELOG.md | 10 + CONTRIBUTING.md | 60 + LICENSE | 175 ++ README.md | 25 + pdc-update/.dockerignore | 1 + pdc-update/Cargo.lock | 2113 +++++++++++++++++++ pdc-update/Cargo.toml | 30 + pdc-update/Dockerfile | 33 + pdc-update/src/cost/age.rs | 78 + pdc-update/src/cost/mod.rs | 9 + pdc-update/src/main.rs | 107 + pdc-update/src/metrics/mod.rs | 23 + pdc-update/src/metrics/prometheus.rs | 109 + pdc-update/src/updater/mod.rs | 46 + pdc-update/src/updater/pod.rs | 70 + renovate.json | 25 + 24 files changed, 3362 insertions(+) create mode 100644 .editorconfig create mode 100644 .github/ISSUE_TEMPLATE/bug_report.md create mode 100644 .github/ISSUE_TEMPLATE/custom.md create mode 100644 .github/ISSUE_TEMPLATE/feature_request.md create mode 100644 .github/workflows/build.yml create mode 100644 .github/workflows/release.yml create mode 100644 .github/workflows/semantic-pull-request.yml create mode 100644 .gitignore create mode 100644 CHANGELOG.md create mode 100644 CONTRIBUTING.md create mode 100644 LICENSE create mode 100644 README.md create mode 100644 pdc-update/.dockerignore create mode 100644 pdc-update/Cargo.lock create mode 100644 pdc-update/Cargo.toml create mode 100644 pdc-update/Dockerfile create mode 100644 pdc-update/src/cost/age.rs create mode 100644 pdc-update/src/cost/mod.rs create mode 100644 pdc-update/src/main.rs create mode 100644 pdc-update/src/metrics/mod.rs create mode 100644 pdc-update/src/metrics/prometheus.rs create mode 100644 pdc-update/src/updater/mod.rs create mode 100644 pdc-update/src/updater/pod.rs create mode 100644 renovate.json diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..8a1ca4d --- /dev/null +++ b/.editorconfig @@ -0,0 +1,45 @@ +# EditorConfig is awesome: http://EditorConfig.org +# Uses editorconfig to maintain consistent coding styles + +# top-most EditorConfig file +root = true + +# Unix-style newlines with a newline ending every file +[*] +charset = utf-8 +end_of_line = lf +indent_size = 2 +indent_style = space +insert_final_newline = true +max_line_length = 124 +tab_width = 2 +trim_trailing_whitespace = true + +[*.{bash,sh,zsh}] +indent_size = 4 +tab_width = 4 +indent_style = tab + +[*.{tf,tfvars}] +indent_size = 2 +tab_width = 2 + +[*.json] +indent_size = 2 +tab_width = 2 + +[*.{yml,yaml}] +indent_size = 2 +tab_width = 2 +indent_style = space + +[*.md] +trim_trailing_whitespace = false + +[Makefile] +indent_size = 4 +tab_width = 4 +indent_style = tab + +[COMMIT_EDITMSG] +max_line_length = 0 diff --git a/.github/ISSUE_TEMPLATE/bug_report.md b/.github/ISSUE_TEMPLATE/bug_report.md new file mode 100644 index 0000000..b44bbba --- /dev/null +++ b/.github/ISSUE_TEMPLATE/bug_report.md @@ -0,0 +1,36 @@ +--- +name: Bug report +about: Create a report to help us improve +title: '' +labels: '' +assignees: '' + +--- + +**Describe the bug** +A clear and concise description of what the bug is. + +**To Reproduce** +Steps to reproduce the behavior: +1. Go to '...' +2. Click on '....' +3. Scroll down to '....' +4. See error + +**Expected behavior** +A clear and concise description of what you expected to happen. + +**Screenshots** +If applicable, add screenshots to help explain your problem. + +**Infra** +- Target (Local, AWS, Docker compose, etc..) : +- Queue (Activemq managed or not) : +- DataBase (MongoDB) : +- Cache (Redis managed or not) : +- Infra Version : +- Core Images and Version (if known) : +- Worker Image and Version (if known) : + +**Additional context** +Add any other context about the problem here. diff --git a/.github/ISSUE_TEMPLATE/custom.md b/.github/ISSUE_TEMPLATE/custom.md new file mode 100644 index 0000000..b894315 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/custom.md @@ -0,0 +1,8 @@ +--- +name: Custom issue template +about: Describe this issue template's purpose here. +title: '' +labels: '' +assignees: '' + +--- diff --git a/.github/ISSUE_TEMPLATE/feature_request.md b/.github/ISSUE_TEMPLATE/feature_request.md new file mode 100644 index 0000000..bbcbbe7 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/feature_request.md @@ -0,0 +1,20 @@ +--- +name: Feature request +about: Suggest an idea for this project +title: '' +labels: '' +assignees: '' + +--- + +**Is your feature request related to a problem? Please describe.** +A clear and concise description of what the problem is. Ex. I'm always frustrated when [...] + +**Describe the solution you'd like** +A clear and concise description of what you want to happen. + +**Describe alternatives you've considered** +A clear and concise description of any alternative solutions or features you've considered. + +**Additional context** +Add any other context or screenshots about the feature request here. diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml new file mode 100644 index 0000000..f3428f2 --- /dev/null +++ b/.github/workflows/build.yml @@ -0,0 +1,165 @@ +name: Build +on: + push: + branches: + - main + pull_request: + branches: + - main +jobs: + versionning: + name: Versionning + runs-on: ubuntu-latest + outputs: + version: ${{ steps.genver.outputs.version }} + release: ${{ steps.genver.outputs.release }} + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Generate Version + id: genver + run: | + VERSION=$(docker run --rm -v $(pwd):/repo codacy/git-version /bin/git-version --folder=/repo --release-branch=${{ github.ref_name }}-pre --dev-branch=main) + echo "version=$VERSION" >> $GITHUB_OUTPUT + echo "VERSION : $VERSION" + RELEASE=$(docker run --rm -v $(pwd):/repo codacy/git-version /bin/git-version --folder=/repo --release-branch=${{ github.ref_name }} --dev-branch=main) + echo "release=$RELEASE" >> $GITHUB_OUTPUT + echo "RELEASE : $RELEASE" + echo "Version :" >> $GITHUB_STEP_SUMMARY + echo "$VERSION" >> $GITHUB_STEP_SUMMARY + echo "Release :" >> $GITHUB_STEP_SUMMARY + echo "$RELEASE" >> $GITHUB_STEP_SUMMARY + + docker: + name: Docker image Build + runs-on: ubuntu-latest + needs: + - versionning + strategy: + fail-fast: false + matrix: + image: + - { path: pdc-update, name: armonik-pdc-update, platforms: "linux/amd64" } + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Set up QEMU + uses: docker/setup-qemu-action@v2 + - name: Set up Docker Buildx + id: buildx + uses: docker/setup-buildx-action@v2 + + - name: login + uses: docker/login-action@v2 + with: + username: ${{ secrets.DOCKER_HUB_LOGIN }} + password: ${{ secrets.DOCKER_HUB_TOKEN }} + + - name: Build and push + uses: docker/build-push-action@v4 + with: + file: "${{ matrix.image.path }}/Dockerfile" + context: "${{ matrix.image.path }}" + platforms: "${{ matrix.image.platforms }}" + push: true + tags: | + dockerhubaneo/${{ matrix.image.name }}:${{ needs.versionning.outputs.version }} + rust: + name: Rust Build and Test + strategy: + fail-fast: false + matrix: + project: + - pdc-update + target: + # Linux Musl + - { platform: aarch64-unknown-linux-musl, os: linux, runner: ubuntu-latest, run: true } + - { platform: arm-unknown-linux-musleabi, os: linux, runner: ubuntu-latest, run: true } + - { platform: i686-unknown-linux-musl, os: linux, runner: ubuntu-latest, run: true } + - { platform: x86_64-unknown-linux-musl, os: linux, runner: ubuntu-latest, run: true } + + # Windows + - { platform: aarch64-pc-windows-msvc, os: windows, runner: windows-latest, run: false } + - { platform: i686-pc-windows-msvc, os: windows, runner: windows-latest, run: true } + - { platform: x86_64-pc-windows-msvc, os: windows, runner: windows-latest, run: true } + toolchain: + - stable + - nightly + runs-on: ${{ matrix.target.runner }} + steps: + - name: Checkout + uses: actions/checkout@v4 + - uses: taiki-e/install-action@v2 + with: + tool: protoc,sccache + - name: Install toolchain + if: ${{ !contains(matrix.toolchain, 'nightly') }} + uses: dtolnay/rust-toolchain@stable + with: + targets: ${{ matrix.target.platform }} + toolchain: ${{ matrix.toolchain }} + components: rust-src,rust-docs,rustfmt,clippy + - name: Install toolchain (with miri) + if: contains(matrix.toolchain, 'nightly') + uses: dtolnay/rust-toolchain@stable + with: + targets: ${{ matrix.target.platform }} + toolchain: ${{ matrix.toolchain }} + components: rust-src,rust-docs,rustfmt,clippy,miri + - name: Install cross-compilation tools + uses: taiki-e/setup-cross-toolchain-action@v1 + with: + target: ${{ matrix.target.platform }} + - name: Setup Cache + uses: Swatinem/rust-cache@v2.7.3 + with: + shared-key: "build-${{ matrix.project }}-${{ matrix.toolchain }}-${{ matrix.target.platform }}" + workspaces: "${{ matrix.project }}" + - name: Build + working-directory: "${{ matrix.project }}" + run: | + cargo build --all --locked + - name: Test + if: matrix.target.run + working-directory: "${{ matrix.project }}" + run: | + cargo test --all --locked + - name: Test Release + if: matrix.target.run + working-directory: "${{ matrix.project }}" + run: | + cargo test --all --locked --release + - name: Test Miri + if: contains(matrix.toolchain, 'nightly') + working-directory: "${{ matrix.project }}" + run: | + cargo miri test --all --locked + - name: Format + working-directory: "${{ matrix.project }}" + run: | + cargo fmt --all --check + - name: Doc + if: matrix.target.os == 'linux' + working-directory: "${{ matrix.project }}" + run: | + RUSTDOCFLAGS="-Dwarnings" cargo doc + - name: Example + if: matrix.target.os == 'linux' && matrix.target.run + working-directory: "${{ matrix.project }}" + timeout-minutes: 1 + run: | + set -x + for example in examples/*.rs; do + if [ -e "$example" ]; then + example="${example#examples/}" + example="${example%.rs}" + RUST_LOG=trace cargo run --locked --example "$example" + fi + done + - name: Clippy + working-directory: "${{ matrix.project }}" + run: | + cargo clippy --all --no-deps -- -Dwarnings -Dunused-crate-dependencies diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..4537e3e --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,79 @@ +name: Release + +permissions: + contents: write + +on: + push: + tags: + - "[0-9]+.[0-9]+.[0-9]+" + +jobs: + versionning: + runs-on: ubuntu-latest + outputs: + version: ${{ steps.snapshot.outputs.version }} + release: ${{ steps.release.outputs.version }} + steps: + - name: Checkout + uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3 + with: + ref: ${{ github.ref }} + fetch-depth: 0 + + - name: Remove tag locally + # This is done so that codacy/git-version can compute the version of the images deployed on docker hub + run: | + git tag -d ${{ github.ref_name }} + + - name: Compute branch for codacy + # This is the branch to give to codacy to compute the snapshot version + id: rev + run: | + export CURRENT_BRANCH=$(git describe --tags) + echo "current-branch=$CURRENT_BRANCH" >> $GITHUB_OUTPUT + + - name: Generate Snapshot Version + id: snapshot + uses: codacy/git-version@80c816f11db8dea5e3a81025f598193015b51832 # 2.8.0 + with: + minor-identifier: "feat:" + release-branch: ${{ github.ref_name }}-pre + dev-branch: ${{ steps.rev.outputs.current-branch }} + + - name: Generate Release Version + id: release + uses: codacy/git-version@80c816f11db8dea5e3a81025f598193015b51832 # 2.8.0 + with: + minor-identifier: "feat:" + release-branch: ${{ steps.rev.outputs.current-branch }} + dev-branch: main + + - name: Put versions in step summary + run: | + echo SNAPSHOT => ${{ steps.snapshot.outputs.version }} >> $GITHUB_STEP_SUMMARY + echo RELASE => ${{ steps.release.outputs.version }} >> $GITHUB_STEP_SUMMARY + + - name: Validate tag + run : test ${{ steps.release.outputs.version }} == ${{ github.ref_name }} + + - name: Delete tag if invalid + if: failure() || cancelled() + run : git push origin -d ${{ github.ref_name }} + + update-changelog: + runs-on: ubuntu-latest + needs: + - versionning + steps: + - uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # v3 + with: + fetch-depth: 0 + + - uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d # v3 + with: + node-version: 18 + + - run: npx @aneoconsultingfr/order-github-release-notes + env: + GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}} diff --git a/.github/workflows/semantic-pull-request.yml b/.github/workflows/semantic-pull-request.yml new file mode 100644 index 0000000..3496423 --- /dev/null +++ b/.github/workflows/semantic-pull-request.yml @@ -0,0 +1,47 @@ +name: "Lint PR" + +on: + pull_request_target: + types: + - opened + - edited + - synchronize + +permissions: {} + +jobs: + main: + permissions: + pull-requests: read # to analyze PRs (amannn/action-semantic-pull-request) + statuses: write # to mark status of analyzed PR (amannn/action-semantic-pull-request) + name: Validate PR title + runs-on: ubuntu-latest + steps: + - uses: amannn/action-semantic-pull-request@v5.2.0 + id: lint_pr_title + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + + - uses: marocchino/sticky-pull-request-comment@v2.8.0 + # When the previous steps fails, the workflow would stop. By adding this + # condition you can continue the execution with the populated error message. + if: always() && (steps.lint_pr_title.outputs.error_message != null) + with: + header: pr-title-lint-error + message: | + Hey there and thank you for opening this pull request! 👋🏼 + + We require pull request titles to follow the [Conventional Commits specification](https://www.conventionalcommits.org/en/v1.0.0/) and it looks like your proposed title needs to be adjusted. + + Details: + + ``` + ${{ steps.lint_pr_title.outputs.error_message }} + ``` + + # Delete a previous comment when the issue has been resolved + - if: ${{ steps.lint_pr_title.outputs.error_message == null }} + uses: marocchino/sticky-pull-request-comment@v2.8.0 + with: + header: pr-title-lint-error + delete: true diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..20c6a08 --- /dev/null +++ b/.gitignore @@ -0,0 +1,48 @@ +# Local .terraform directories +**/.terraform/* + +# Terraform lockfile +.terraform.lock.hcl + +# .tfstate files +*.tfstate +*.tfstate.* + +# Crash log files +crash.log +crash.*.log + +# Exclude all .tfvars files, which are likely to contain sensitive data, such as +# password, private keys, and other secrets. These should not be part of version +# control as they are data points which are potentially sensitive and subject +# to change depending on the environment. +*.tfvars.json + +# Ignore override files as they are usually used to override resources locally and so +# are not checked in +override.tf +override.tf.json +*_override.tf +*_override.tf.json + +# Include override files you do wish to add to version control using negated pattern +# !example_override.tf + +# Include tfplan files to ignore the plan output of command: terraform plan -out=tfplan +*tfplan* + +# Ignore CLI configuration files +.terraformrc +terraform.rc + +# Ignore Terraform plugins +terraform-plugins + +# others +.idea +kubeconfig_* +generated +.external_modules + +# Rust +target diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..0a3f241 --- /dev/null +++ b/CHANGELOG.md @@ -0,0 +1,10 @@ +# Changelog + +All notable changes to this project will be documented in this file. + +## main + +Added +--- + +* Pod Deletion Cost update daemon diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 0000000..5c63184 --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,60 @@ +# Contributing to ArmoniK Infrastructure + +Thanks for helping to make ArmoniK better! + +## Conventional pull request commit rules + +It is important to note that this repository [ArmoniK Infrastructure Plugins](https://github.com/aneoconsulting/ArmoniK.Infra.Plugins) +adheres to semantic releases. Familiarity with conventional commit rules is imperative and make it easier to +find and understand commits of the main branch. In addition, failure to follow the conventional commit guidelines may result +in rejection of the pull requests. + +Conventional Commits rules is a convention for structuring pull request commit messages to describe changes. A pull request +message format must be as follows: + +```text +(): + + + +