Skip to content

Commit 1106640

Browse files
maciaszczykmzreigz
andauthored
refactor: Agent refactoring (#114)
* init * move sync loop to service reconciler * init service controller * refactor status collector * refactor status collector move engine utils to reconciler * move service controller to main * remove unused * add controller manager * add context * refactor * fix controller manager init * make console client once * refactor agent and engine * update socket * bump console client * refactor status * update socket * fix format error * fix some linter issues * update dep * refactor cmd package * fix build * minor changes * add lua unit tests * fix imports * minor enhancement * add restore controller * add velero crds * add backup controller * bump console client * add backup creation logs * add backup creation logs * init velero restore controller * refactor restore controller * update restore reconciler * add namespace for restore controller * add get cluster backup * minor update * add client mocks * update go mod * fix unit tests * fix unit tests * add make target to sync velero crds --------- Co-authored-by: Lukasz Zajaczkowski <[email protected]>
1 parent ead517e commit 1106640

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+5618
-963
lines changed

.mockery.yaml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
filename: "{{.InterfaceName}}_mock.go"
2+
dir: "pkg/test/mocks"
3+
mockname: "{{.InterfaceName}}Mock"
4+
outpkg: "mocks"
5+
packages:
6+
github.com/pluralsh/deployment-operator/pkg/client:
7+
interfaces:
8+
Client:

Dockerfile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@ COPY go.sum go.sum
1111
RUN go mod download
1212

1313
# Copy the go source
14-
COPY /cmd/main.go main.go
14+
COPY /cmd cmd/
1515
COPY /pkg pkg/
1616
COPY /api api/
1717
COPY /internal internal/
1818

1919
# Build
20-
RUN CGO_ENABLED=0 GOOS=linux GOARCH=${TARGETARCH} GO111MODULE=on go build -a -o deployment-agent main.go
20+
RUN CGO_ENABLED=0 GOOS=linux GOARCH=${TARGETARCH} GO111MODULE=on go build -a -o deployment-agent cmd/*
2121

2222
FROM alpine:3.18
2323
WORKDIR /workspace

Makefile

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,18 @@ IMG ?= deployment-agent:latest
99

1010
ENVTEST ?= $(shell which setup-envtest)
1111

12+
VELERO_CHART_VERSION := 5.2.2
13+
VELERO_CHART_URL := https://github.com/vmware-tanzu/helm-charts/releases/download/velero-$(VELERO_CHART_VERSION)/velero-$(VELERO_CHART_VERSION).tgz
14+
15+
1216
## Location to install dependencies to
1317
LOCALBIN ?= $(shell pwd)/bin
1418
$(LOCALBIN):
1519
mkdir -p $(LOCALBIN)
1620

1721
ENVTEST_K8S_VERSION := 1.28.3
1822
CONTROLLER_GEN ?= $(LOCALBIN)/controller-gen
19-
23+
MOCKERY ?= $(shell which mockery)
2024
include tools.mk
2125

2226
ifndef GOPATH
@@ -44,24 +48,34 @@ manifests: controller-gen ## Generate WebhookConfiguration, ClusterRole and Cust
4448
generate: controller-gen ## Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations.
4549
$(CONTROLLER_GEN) object:headerFile="hack/boilerplate.go.txt" paths="./..."
4650

51+
.PHONY: genmock
52+
genmock: mockery ## generates mocks before running tests
53+
$(MOCKERY)
54+
4755
##@ Run
4856

4957
.PHONY: run
5058
run: ## run
51-
go run cmd/main.go
59+
go run cmd/*
5260

5361
##@ Build
5462

5563
.PHONY: build
5664
build: ## build
57-
go build -o bin/deployment-agent cmd/main.go
65+
go build -o bin/deployment-agent cmd/*
5866

5967
docker-build: ## build image
6068
docker build -t ${IMG} .
6169

6270
docker-push: ## push image
6371
docker push ${IMG}
6472

73+
velero-crds:
74+
@curl -L $(VELERO_CHART_URL) --output velero.tgz
75+
@tar zxvf velero.tgz velero/crds
76+
@mv velero/crds/* charts/deployment-operator/crds
77+
@rm -r velero.tgz velero
78+
6579
##@ Tests
6680

6781
.PHONY: test
Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
---
2+
apiVersion: apiextensions.k8s.io/v1
3+
kind: CustomResourceDefinition
4+
metadata:
5+
labels:
6+
component: velero
7+
annotations:
8+
controller-gen.kubebuilder.io/version: v0.12.0
9+
name: backuprepositories.velero.io
10+
spec:
11+
group: velero.io
12+
names:
13+
kind: BackupRepository
14+
listKind: BackupRepositoryList
15+
plural: backuprepositories
16+
singular: backuprepository
17+
scope: Namespaced
18+
versions:
19+
- additionalPrinterColumns:
20+
- jsonPath: .metadata.creationTimestamp
21+
name: Age
22+
type: date
23+
- jsonPath: .spec.repositoryType
24+
name: Repository Type
25+
type: string
26+
name: v1
27+
schema:
28+
openAPIV3Schema:
29+
properties:
30+
apiVersion:
31+
description: 'APIVersion defines the versioned schema of this representation
32+
of an object. Servers should convert recognized schemas to the latest
33+
internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources'
34+
type: string
35+
kind:
36+
description: 'Kind is a string value representing the REST resource this
37+
object represents. Servers may infer this from the endpoint the client
38+
submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds'
39+
type: string
40+
metadata:
41+
type: object
42+
spec:
43+
description: BackupRepositorySpec is the specification for a BackupRepository.
44+
properties:
45+
backupStorageLocation:
46+
description: BackupStorageLocation is the name of the BackupStorageLocation
47+
that should contain this repository.
48+
type: string
49+
maintenanceFrequency:
50+
description: MaintenanceFrequency is how often maintenance should
51+
be run.
52+
type: string
53+
repositoryType:
54+
description: RepositoryType indicates the type of the backend repository
55+
enum:
56+
- kopia
57+
- restic
58+
- ""
59+
type: string
60+
resticIdentifier:
61+
description: ResticIdentifier is the full restic-compatible string
62+
for identifying this repository.
63+
type: string
64+
volumeNamespace:
65+
description: VolumeNamespace is the namespace this backup repository
66+
contains pod volume backups for.
67+
type: string
68+
required:
69+
- backupStorageLocation
70+
- maintenanceFrequency
71+
- resticIdentifier
72+
- volumeNamespace
73+
type: object
74+
status:
75+
description: BackupRepositoryStatus is the current status of a BackupRepository.
76+
properties:
77+
lastMaintenanceTime:
78+
description: LastMaintenanceTime is the last time maintenance was
79+
run.
80+
format: date-time
81+
nullable: true
82+
type: string
83+
message:
84+
description: Message is a message about the current status of the
85+
BackupRepository.
86+
type: string
87+
phase:
88+
description: Phase is the current state of the BackupRepository.
89+
enum:
90+
- New
91+
- Ready
92+
- NotReady
93+
type: string
94+
type: object
95+
type: object
96+
served: true
97+
storage: true
98+
subresources: {}

0 commit comments

Comments
 (0)