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

Cleanup dapper and code #626

Draft
wants to merge 21 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 17 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
68 changes: 37 additions & 31 deletions .github/workflows/ci.yaml
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to update goreleaser and release CI as well

Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,25 @@ on:
- 'CODEOWNERS'
- 'LICENSE'
jobs:
golangci:
name: lint
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-go@v5
with:
go-version: '1.23'
- name: golangci-lint
uses: golangci/golangci-lint-action@v6
with:
version: v1.60.2
build:
strategy:
matrix:
arch:
- x64
- arm64
name : CI
name : build
runs-on : runs-on,image=ubuntu22-full-${{ matrix.arch }},runner=4cpu-linux-${{ matrix.arch }},run-id=${{ github.run_id }}
outputs:
k3sversions: ${{ steps.support.outputs.k3sversions }}
Expand All @@ -39,52 +51,46 @@ jobs:
uses : actions/checkout@v4
with :
fetch-depth : 0
- name: Set K3s support output
id : support
run: ./.github/workflows/scripts/supported-versions.sh | awk '{print "k3sversions="$0}' >> $GITHUB_OUTPUT
- name: Install go
uses: actions/setup-go@v5
with:
go-version: 1.23
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name : Install helm
run : ./.github/workflows/scripts/install-helm.sh
- name : CI
run : make ci
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: bro-build-artifacts-${{ matrix.arch }}
path: ./dist/artifacts

test:
name : integration-test
needs : [
build
]
runs-on : runs-on,image=ubuntu22-full-${{ matrix.arch }},runner=4cpu-linux-${{ matrix.arch }},run-id=${{ github.run_id }}
strategy:
matrix:
arch:
- x64
- arm64
K3S_VERSION : ${{ fromJSON(needs.build.outputs.k3sversions) }}
#FIXME: temporarily hardcoded
K3S_VERSION :
- v1.28.1-k3s1
- v1.31.0-k3s1
steps:
- name : Checkout repository
uses : actions/checkout@v4
- name : Fetch build artifacts
uses: actions/download-artifact@v4
with:
name: bro-build-artifacts-${{ matrix.arch }}
path: ./dist/artifacts/
- name : Debug
run : ls -R ./dist/artifacts
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name : Load backup-restore-operator image
run : docker image load -i ./dist/artifacts/backup-restore-operator.img
- name: Install go
uses: actions/setup-go@v5
with:
go-version: 1.23
- name : Install helm
run : ./.github/workflows/scripts/install-helm.sh
- name : Setup helm charts
run : ./scripts/package-helm
- name : Debug
run : ls -R ./dist/artifacts
- name : Install k3d
run : ./.github/workflows/scripts/install-k3d.sh
- name : Install minio client
run : ./.github/workflows/scripts/install-mc.sh
- name : Setup k3d cluster
run : CLUSTER_NAME=backup-restore K3S_VERSION=${{ matrix.K3S_VERSION }} ./.github/workflows/scripts/setup-cluster.sh
- name : Run integration tests
run : ./scripts/integration
- name : Setup test environment
run : CLUSTER_NAME=backup-restore K3S_VERSION=${{ matrix.K3S_VERSION }} ./scripts/testenv
- name : Run e2e tests
run :
CLUSTER_NAME=backup-restore K3S_VERSION=${{ matrix.K3S_VERSION }} ./scripts/testenv
cd e2e && KUBECONFIG=$KUBECONFIG CHART_NAMESPACE=cattle-resources-system go test -v -timeout 10m -count=1 ./...
5 changes: 5 additions & 0 deletions .github/workflows/scripts/install-helm.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
curl -fsSL -o get_helm.sh https://raw.githubusercontent.com/helm/helm/main/scripts/get-helm-3
chmod 700 get_helm.sh
./get_helm.sh

helm plugin install https://github.com/quintush/helm-unittest
20 changes: 20 additions & 0 deletions .vscode/launch.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Debug Operator",
"type": "go",
"request": "launch",
"mode": "auto",
"program": "${workspaceFolder}/main.go",
"env": {
"CHART_NAMESPACE": "cattle-resources-system",
// uncomment if using remote backup locations, like s3
"CATTLE_DEV_MODE": "true",
},
}
]
}
35 changes: 0 additions & 35 deletions Dockerfile.dapper

This file was deleted.

13 changes: 3 additions & 10 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,15 +1,8 @@
TARGETS := $(shell ls scripts)

.dapper:
@echo Downloading dapper
@curl -sL https://releases.rancher.com/dapper/latest/dapper-$$(uname -s)-$$(uname -m) > .dapper.tmp
@@chmod +x .dapper.tmp
@./.dapper.tmp -v
@mv .dapper.tmp .dapper

$(TARGETS): .dapper
./.dapper $@
$(TARGETS):
./scripts/$@

.DEFAULT_GOAL := ci

.PHONY: $(TARGETS)
.PHONY: $(TARGETS)
70 changes: 70 additions & 0 deletions cmd/operator/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
package main

import (
"flag"
"os"

"github.com/rancher/backup-restore-operator/pkg/operator"
"github.com/rancher/wrangler/v3/pkg/kubeconfig"
"github.com/rancher/wrangler/v3/pkg/signals"
"github.com/sirupsen/logrus"
)

const (
LogFormat = "2006/01/02 15:04:05"
)

var (
Version = "v0.0.0-dev"
GitCommit = "HEAD"
LocalBackupStorageLocation = "/var/lib/backups" // local within the pod, this is the mountPath for PVC
KubeConfig string
OperatorPVEnabled string
OperatorS3BackupStorageLocation string
ChartNamespace string
Debug bool
Trace bool
)

func init() {
flag.StringVar(&KubeConfig, "kubeconfig", "", "Path to a kubeconfig. Only required if out-of-cluster.")
flag.BoolVar(&Debug, "debug", false, "Enable debug logging.")
flag.BoolVar(&Trace, "trace", false, "Enable trace logging.")

flag.Parse()
OperatorPVEnabled = os.Getenv("DEFAULT_PERSISTENCE_ENABLED")
OperatorS3BackupStorageLocation = os.Getenv("DEFAULT_S3_BACKUP_STORAGE_LOCATION")
ChartNamespace = os.Getenv("CHART_NAMESPACE")
}

func main() {
logrus.SetFormatter(&logrus.TextFormatter{FullTimestamp: true, ForceColors: true, TimestampFormat: LogFormat})
if Debug {
logrus.SetLevel(logrus.DebugLevel)
logrus.Debugf("Loglevel set to [%v]", logrus.DebugLevel)
}
if Trace {
logrus.SetLevel(logrus.TraceLevel)
logrus.Tracef("Loglevel set to [%v]", logrus.TraceLevel)
}

logrus.Infof("Starting backup-restore controller version %s (%s)", Version, GitCommit)
ctx := signals.SetupSignalContext()
restKubeConfig, err := kubeconfig.GetNonInteractiveClientConfig(KubeConfig).ClientConfig()
if err != nil {
logrus.Fatalf("failed to find kubeconfig: %v", err)
}

dm := os.Getenv("CATTLE_DEV_MODE")
runOptions := operator.RunOptions{
OperatorPVCEnabled: OperatorPVEnabled != "",
OperatorS3BackupStorageLocation: OperatorS3BackupStorageLocation,
ChartNamespace: ChartNamespace,
UseLocalDriver: dm != "",
LocalDriverPath: "",
}

if err := operator.Run(ctx, restKubeConfig, runOptions); err != nil {
logrus.Fatalf("Error running operator: %s", err.Error())
}
}
1 change: 1 addition & 0 deletions e2e/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
backups/
Empty file added e2e/backup/.gitkeep
Empty file.
Loading
Loading