mirror of
https://github.com/lukaszraczylo/jobs-manager-operator.git
synced 2026-06-06 22:39:22 +00:00
2b36071647
* Multiple fixes - add goreleaser to the build / release process - add kubectl plugin for job graphs visualization - add installation scripts - update dependencies * Update the release & CRD content. * Next set of improvements. Code Quality - Label constants: Added LabelWorkflowName, LabelGroupName, LabelJobName, LabelJobID in controllers/definitions.go - Removed commented debug code: Cleaned up dead code from multiple files - Removed unused dependencyTree field: Cleaned connPackage struct - Fixed snake_case variables: Changed to camelCase (runGroup, groupDep, runJob, jobDep, k8sJob) Kubernetes Best Practices - Finalizers: Implemented handleDeletion() and deleteChildJobs() for proper cleanup - Status enum validation: Added +kubebuilder:validation:Enum=pending;running;succeeded;failed;aborted - ImagePullPolicy default: Created getImagePullPolicy() helper that defaults to IfNotPresent - Resource limits support: Added Resources *corev1.ResourceRequirements to ManagedJobParameters Observability - Prometheus metrics: Created controllers/metrics.go with counters (jobs created/succeeded/failed), histogram (reconciliation duration), and gauge (active jobs) - Structured logging: Added logger field to connPackage, used context-based logging throughout Configuration - Leader election ID: Made configurable via --leader-election-id flag - Development mode: Made configurable via --dev-mode flag and LOG_LEVEL env var Performance - Dependency lookup optimization: Changed from O(n*m) to O(1) using lookup maps (jobDepMap, groupDepMap) - Reconciliation backoff: Added RequeueAfter: 30*time.Second when workflow is running Documentation & Testing - Godoc documentation: Added comprehensive comments to API types and controller - Unit tests: Added helpers_test.go with tests for all helper functions - Integration tests: Added managedjob_controller_test.go with Ginkgo/Gomega tests * Add the helm chart release. * Add reasonable test coverage.
153 lines
5.4 KiB
Plaintext
153 lines
5.4 KiB
Plaintext
name: Build test and release
|
|
|
|
on:
|
|
push:
|
|
branches:
|
|
- main
|
|
paths-ignore:
|
|
- 'charts/**'
|
|
- 'docs/**'
|
|
- '.github/**'
|
|
- 'README.md'
|
|
pull_request:
|
|
branches:
|
|
- main
|
|
paths-ignore:
|
|
- 'charts/**'
|
|
- 'docs/**'
|
|
- '.github/**'
|
|
- 'README.md'
|
|
workflow_dispatch:
|
|
|
|
jobs:
|
|
prepare:
|
|
name: Preparing build context
|
|
runs-on: ubuntu-latest
|
|
outputs:
|
|
SANITISED_REPOSITORY_NAME: ${{ steps.get_env.outputs.SANITISED_REPOSITORY_NAME }}
|
|
DOCKER_IMAGE: ${{ steps.get_env.outputs.DOCKER_IMAGE }}
|
|
GITHUB_COMMIT_NUMBER: ${{ steps.get_env.outputs.GITHUB_COMMIT_NUMBER }}
|
|
GITHUB_SHA: ${{ steps.get_env.outputs.GITHUB_SHA }}
|
|
DOCKER_IMAGE_SEMVER: ${{ steps.semver.outputs.semantic_version }}
|
|
CHECK_IF_MASTER_BRANCH: ${{ steps.get_env.outputs.CHECK_FOR_MASTER_BRANCH }}
|
|
steps:
|
|
- name: Checkout repo
|
|
uses: actions/checkout@v3
|
|
with:
|
|
fetch-depth: '0'
|
|
- name: Configure git for private modules
|
|
uses: extractions/netrc@v1
|
|
with:
|
|
machine: github.com
|
|
username: ${{ github.actor }}
|
|
password: ${{ secrets.GHCR_TOKEN }}
|
|
- name: Set environment variables
|
|
id: get_env
|
|
run: |
|
|
TMP_SANITISED_REPOSITORY_NAME=$(echo ${{ github.event.repository.name }} | sed -e 's|\.|-|g')
|
|
CHECK_FOR_MASTER_BRANCH="false"
|
|
echo "SANITISED_REPOSITORY_NAME=$TMP_SANITISED_REPOSITORY_NAME" >> $GITHUB_OUTPUT
|
|
echo "DOCKER_IMAGE=ghcr.io/${{ github.repository_owner }}/$TMP_SANITISED_REPOSITORY_NAME" >> $GITHUB_OUTPUT
|
|
echo "GITHUB_COMMIT_NUMBER=$(git rev-list --count HEAD)" >> $GITHUB_OUTPUT
|
|
echo "GITHUB_SHA=$(echo ${GITHUB_SHA::8})" >> $GITHUB_OUTPUT
|
|
if [[ ${{ github.ref }} == 'refs/heads/master' || ${{ github.ref }} == 'refs/heads/main' ]]; then
|
|
CHECK_FOR_MASTER_BRANCH="true"
|
|
fi
|
|
echo "CHECK_FOR_MASTER_BRANCH=$CHECK_FOR_MASTER_BRANCH" >> $GITHUB_OUTPUT
|
|
- name: Establish semver
|
|
id: semver
|
|
uses: lukaszraczylo/semver-generator@v1
|
|
with:
|
|
config_file: semver.yaml
|
|
repository_local: true
|
|
github_username: ${{ github.actor }}
|
|
github_token: ${{ secrets.GHCR_TOKEN }}
|
|
- name: Semver check
|
|
run: |
|
|
echo "Semantic version detected: ${{ steps.semver.outputs.semantic_version }}"
|
|
|
|
test:
|
|
name: "Unit testing"
|
|
needs: [prepare]
|
|
runs-on: ubuntu-20.04
|
|
# container: github/super-linter:v4
|
|
steps:
|
|
- name: Checkout repository
|
|
uses: actions/checkout@v3
|
|
- name: Install Go
|
|
uses: actions/setup-go@v3
|
|
with:
|
|
go-version: 1.21
|
|
- name: Configure git for private modules
|
|
uses: extractions/netrc@v1
|
|
with:
|
|
machine: github.com
|
|
username: ${{ github.actor }}
|
|
password: ${{ secrets.GHCR_TOKEN }}
|
|
- uses: actions/cache@v3
|
|
with:
|
|
path: |
|
|
~/.cache/go-build
|
|
~/go/pkg/mod
|
|
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
|
|
restore-keys: |
|
|
${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
|
|
- name: Run unit tests
|
|
run: |
|
|
make test
|
|
|
|
build-docker:
|
|
name: "Building docker image"
|
|
needs: [ prepare, test ]
|
|
runs-on: ubuntu-20.04
|
|
if: needs.prepare.outputs.CHECK_IF_MASTER_BRANCH == 'true'
|
|
steps:
|
|
- name: Checkout repo
|
|
uses: actions/checkout@v3
|
|
- name: Set up QEMU
|
|
uses: docker/setup-qemu-action@v2
|
|
- name: Set up Docker Buildx
|
|
uses: docker/setup-buildx-action@v2
|
|
- name: Login to GHCR
|
|
if: github.event_name != 'pull_request'
|
|
uses: docker/login-action@v2
|
|
with:
|
|
registry: ghcr.io
|
|
username: ${{ github.actor }}
|
|
password: ${{ secrets.GHCR_TOKEN }}
|
|
- uses: actions/cache@v3
|
|
with:
|
|
path: |
|
|
~/.cache/go-build
|
|
~/go/pkg/mod
|
|
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
|
|
restore-keys: |
|
|
${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
|
|
- name: Build and push
|
|
if: github.event_name != 'pull_request' && ${{ needs.prepare.outputs.CHECK_FOR_MASTER_BRANCH == 'true' }}
|
|
run: |
|
|
make docker-buildx IMG=${{ needs.prepare.outputs.DOCKER_IMAGE }}:${{ needs.prepare.outputs.DOCKER_IMAGE_SEMVER }} IMG_SECONDARY_TAG=${{ needs.prepare.outputs.DOCKER_IMAGE }}:latest
|
|
|
|
release:
|
|
name: Create Release
|
|
runs-on: ubuntu-latest
|
|
needs: [ prepare, build-docker ]
|
|
if: needs.prepare.outputs.CHECK_IF_MASTER_BRANCH == 'true'
|
|
steps:
|
|
- name: Checkout code
|
|
uses: actions/checkout@v3
|
|
with:
|
|
fetch-depth: 0
|
|
- name: Get list of the commits since last release
|
|
run: |
|
|
echo "$(git log $(git describe --tags --abbrev=0)..HEAD --pretty=format:"%h %s")" > .release_notes
|
|
- name: Create Release
|
|
id: create_release
|
|
if: needs.prepare.outputs.CHECK_IF_MASTER_BRANCH == 'true'
|
|
uses: softprops/action-gh-release@v1
|
|
with:
|
|
name: v${{ needs.prepare.outputs.DOCKER_IMAGE_SEMVER }}
|
|
body_path: .release_notes
|
|
token: ${{ secrets.GHCR_TOKEN }}
|
|
tag_name: v${{ needs.prepare.outputs.DOCKER_IMAGE_SEMVER }}
|
|
prerelease: ${{ github.ref != 'refs/heads/master' && github.ref != 'refs/heads/main' }} |