Skip to content
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

Release workflows #43

Merged
merged 5 commits into from
Nov 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 67 additions & 0 deletions .github/workflows/build-and-push-image.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
name: Build Image and Publish to Dockerhub

on:
release:
types: [ published ]
workflow_dispatch:
inputs:
tag:
description: 'Image tag'
required: true
default: 'test'
permissions:
contents: read

jobs:
image:
name: Build Image from Dockerfile and binaries
runs-on: ubuntu-latest
steps:
# environment
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: '0'

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Get Image Tag Name
run: |
if [ x${{ github.event.inputs.tag }} == x"" ]; then
echo "TAG_NAME=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV
else
echo "TAG_NAME=${{ github.event.inputs.tag }}" >> $GITHUB_ENV
fi

- name: Login to DockerHub
uses: docker/login-action@v3
with:
username: ${{ secrets.DOCKERHUB_USERNAME }}
password: ${{ secrets.DOCKERHUB_PASSWORD }}

# prepare image tags
- name: Prepare Image Tags
run: |
echo "TAG_MANAGER=akyriako78/rekuberate-io-sleepcycles:${{ env.TAG_NAME }}" >> $GITHUB_ENV
echo "TAG_RUNNER=akyriako78/rekuberate-io-sleepcycles:${{ env.TAG_NAME }}" >> $GITHUB_ENV

- name: Build and push manager
uses: docker/build-push-action@v5
with:
context: .
file: ./Dockerfile
platforms: linux/amd64,linux/arm/v7,linux/arm64
push: true
tags: |
${{ env.TAG_MANAGER }}

- name: Build and push runner
uses: docker/build-push-action@v5
with:
context: .
file: ./Dockerfile.runner
platforms: linux/amd64,linux/arm/v7,linux/arm64
push: true
tags: |
${{ env.TAG_RUNNER }}
50 changes: 50 additions & 0 deletions .github/workflows/golangci-lint.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
name: golangci-lint
on:
push:
branches:
- master
- dev
pull_request:
permissions:
contents: read
# Optional: allow read access to pull request. Use with `only-new-issues` option.
pull-requests: read
jobs:
golangci:
name: lint
runs-on: ubuntu-latest
timeout-minutes: 5
strategy:
fail-fast: true
steps:
- uses: actions/checkout@v4

- uses: actions/setup-go@v5
with:
go-version: '1.23'
cache: false

- name: golangci-lint
uses: golangci/golangci-lint-action@v4
with:
version: v1.61
args: --timeout 5m

- name: Go Format
run: gofmt -s -w . && git diff --exit-code

- name: Go Vet
run: go vet ./...

- name: Go Tidy
run: go mod tidy && git diff --exit-code

- name: Go Mod
run: go mod download

- name: Go Mod Verify
run: go mod verify

# TODO: enable tests
# - name: Go Test
# run: go test -v -count=1 -race -shuffle=on -coverprofile=coverage.txt ./...
45 changes: 45 additions & 0 deletions .github/workflows/lint-helm-test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name: Lint and Test Charts

on: pull_request

jobs:
lint-test:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Set up Helm
uses: azure/setup-helm@v4.2.0
with:
version: v3.14.4

- uses: actions/setup-python@v5
with:
python-version: '3.x'
check-latest: true

- name: Set up chart-testing
uses: helm/chart-testing-action@v2.6.1

- name: Run chart-testing (list-changed)
id: list-changed
run: |
changed=$(ct list-changed --target-branch ${{ github.event.repository.default_branch }})
if [[ -n "$changed" ]]; then
echo "changed=true" >> "$GITHUB_OUTPUT"
fi

- name: Run chart-testing (lint)
if: steps.list-changed.outputs.changed == 'true'
run: ct lint --target-branch ${{ github.event.repository.default_branch }}

- name: Create kind cluster
if: steps.list-changed.outputs.changed == 'true'
uses: helm/kind-action@v1.10.0

- name: Run chart-testing (install)
if: steps.list-changed.outputs.changed == 'true'
run: ct install --target-branch ${{ github.event.repository.default_branch }}
11 changes: 3 additions & 8 deletions controllers/sleepcycle_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ package controllers
import (
"context"
"fmt"
"strings"
"time"

"github.com/go-logr/logr"
"github.com/hashicorp/go-multierror"
corev1alpha1 "github.com/rekuberate-io/sleepcycles/api/v1alpha1"
Expand All @@ -34,8 +37,6 @@ import (
"sigs.k8s.io/controller-runtime/pkg/event"
"sigs.k8s.io/controller-runtime/pkg/log"
"sigs.k8s.io/controller-runtime/pkg/predicate"
"strings"
"time"
)

const (
Expand All @@ -61,12 +62,6 @@ type runtimeObjectReconciler func(
sleepcycle *corev1alpha1.SleepCycle,
) (int, int, error)

type runtimeObjectFinalizer func(
ctx context.Context,
req ctrl.Request,
original *corev1alpha1.SleepCycle,
) (ctrl.Result, error)

var (
eventFilters = builder.WithPredicates(predicate.Funcs{
UpdateFunc: func(e event.UpdateEvent) bool {
Expand Down
9 changes: 5 additions & 4 deletions controllers/sleepcycle_runners_cronjobs.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,16 @@ package controllers
import (
"context"
"fmt"
"strconv"
"strings"

"github.com/go-logr/logr"
corev1alpha1 "github.com/rekuberate-io/sleepcycles/api/v1alpha1"
batchv1 "k8s.io/api/batch/v1"
v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/client"
"strconv"
"strings"
)

var (
Expand Down Expand Up @@ -74,8 +75,8 @@ func (r *SleepCycleReconciler) createCronJob(
}

labels := make(map[string]string)
labels[OwnedBy] = fmt.Sprintf("%s", sleepcycle.Name)
labels[Target] = fmt.Sprintf("%s", targetMeta.Name)
labels[OwnedBy] = sleepcycle.Name
labels[Target] = targetMeta.Name
labels[TargetKind] = targetKind

annotations := make(map[string]string)
Expand Down
13 changes: 5 additions & 8 deletions runners/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ import (
"context"
"flag"
"fmt"
"os"
"strconv"
"strings"
"time"

"github.com/go-logr/logr"
"github.com/pkg/errors"
"go.uber.org/zap/zapcore"
Expand All @@ -15,12 +20,8 @@ import (
typedv1core "k8s.io/client-go/kubernetes/typed/core/v1"
"k8s.io/client-go/rest"
"k8s.io/client-go/tools/record"
"os"
ctrl "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/log/zap"
"strconv"
"strings"
"time"
)

var (
Expand Down Expand Up @@ -171,10 +172,6 @@ func run(ns string, cronjob *batchv1.CronJob, target string, kind string, target

func syncReplicas(ctx context.Context, namespace string, cronjob *batchv1.CronJob, currentReplicas int32, targetReplicas int32) error {
if currentReplicas != targetReplicas && currentReplicas > 0 {
if targetReplicas != 0 {
targetReplicas = currentReplicas
}

cronjob.Annotations["rekuberate.io/replicas"] = fmt.Sprint(currentReplicas)
_, err := clientSet.BatchV1().CronJobs(namespace).Update(ctx, cronjob, metav1.UpdateOptions{})
if err != nil {
Expand Down
Loading