Skip to content

Commit bcb0f90

Browse files
authored
Merge pull request #784 from k8up-io/remove-obs-other
Free Schedule, Restore and Archive controllers from internal observer
2 parents e7ceb02 + 289f405 commit bcb0f90

35 files changed

+378
-369
lines changed

api/v1/archive_types.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package v1
22

33
import (
4+
"reflect"
5+
46
corev1 "k8s.io/api/core/v1"
57
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
68
"k8s.io/apimachinery/pkg/runtime"
@@ -137,3 +139,7 @@ func (in *ArchiveSchedule) GetSchedule() ScheduleDefinition {
137139
func (in *ArchiveSchedule) GetObjectCreator() ObjectCreator {
138140
return in
139141
}
142+
143+
var (
144+
ArchiveKind = reflect.TypeOf(Archive{}).Name()
145+
)

api/v1/restore_types.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package v1
22

33
import (
4+
"reflect"
5+
46
corev1 "k8s.io/api/core/v1"
57
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
68
"k8s.io/apimachinery/pkg/runtime"
@@ -168,3 +170,7 @@ type RestoreList struct {
168170
func init() {
169171
SchemeBuilder.Register(&Restore{}, &RestoreList{})
170172
}
173+
174+
var (
175+
RestoreKind = reflect.TypeOf(Restore{}).Name()
176+
)

cmd/operator/main.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,12 @@ import (
44
"fmt"
55
"strings"
66

7+
"github.com/k8up-io/k8up/v2/operator/archivecontroller"
78
"github.com/k8up-io/k8up/v2/operator/backupcontroller"
89
"github.com/k8up-io/k8up/v2/operator/jobcontroller"
910
"github.com/k8up-io/k8up/v2/operator/locker"
11+
"github.com/k8up-io/k8up/v2/operator/restorecontroller"
12+
"github.com/k8up-io/k8up/v2/operator/schedulecontroller"
1013
"k8s.io/apimachinery/pkg/api/resource"
1114
_ "k8s.io/client-go/plugin/pkg/client/auth/gcp"
1215

@@ -117,10 +120,10 @@ func operatorMain(c *cli.Context) error {
117120
executor.StartExecutor(lock)
118121

119122
for name, reconciler := range map[string]controllers.ReconcilerSetup{
120-
"Schedule": &controllers.ScheduleReconciler{},
123+
"Schedule": &schedulecontroller.ScheduleReconciler{},
121124
"Backup": &backupcontroller.BackupReconciler{},
122-
"Restore": &controllers.RestoreReconciler{},
123-
"Archive": &controllers.ArchiveReconciler{},
125+
"Restore": &restorecontroller.RestoreReconciler{},
126+
"Archive": &archivecontroller.ArchiveReconciler{},
124127
"Check": &controllers.CheckReconciler{},
125128
"Prune": &controllers.PruneReconciler{},
126129
"Job": &jobcontroller.JobReconciler{},

controllers/archive_controller.go

Lines changed: 0 additions & 70 deletions
This file was deleted.

controllers/restore_controller.go

Lines changed: 0 additions & 66 deletions
This file was deleted.

controllers/schedule_controller.go

Lines changed: 0 additions & 68 deletions
This file was deleted.

e2e/definitions/operator/values.yaml

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ image:
66
repository: $E2E_REPO
77
tag: $E2E_TAG
88
k8up:
9-
env:
9+
envVars:
1010
- name: K8UP_DEBUG
1111
value: "true"
12-
- name: BACKUP_ENABLE_LEADER_ELECTION
13-
value: $BACKUP_ENABLE_LEADER_ELECTION

e2e/lib/k8up.bash

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,6 @@ prepare() {
9696

9797
replace_in_file "${target_file}" E2E_IMAGE "'${E2E_IMAGE}'"
9898
replace_in_file "${target_file}" ID "$(id -u)"
99-
replace_in_file "${target_file}" BACKUP_ENABLE_LEADER_ELECTION "'${BACKUP_ENABLE_LEADER_ELECTION}'"
10099
replace_in_file "${target_file}" BACKUP_FILE_NAME "${BACKUP_FILE_NAME}"
101100
replace_in_file "${target_file}" BACKUP_FILE_CONTENT "${BACKUP_FILE_CONTENT}"
102101
}
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
package archivecontroller
2+
3+
import (
4+
"context"
5+
"time"
6+
7+
k8upv1 "github.com/k8up-io/k8up/v2/api/v1"
8+
"github.com/k8up-io/k8up/v2/operator/cfg"
9+
"github.com/k8up-io/k8up/v2/operator/job"
10+
"github.com/k8up-io/k8up/v2/operator/queue"
11+
"k8s.io/apimachinery/pkg/api/errors"
12+
controllerruntime "sigs.k8s.io/controller-runtime"
13+
"sigs.k8s.io/controller-runtime/pkg/client"
14+
)
15+
16+
// ArchiveReconciler reconciles a Archive object
17+
type ArchiveReconciler struct {
18+
Kube client.Client
19+
}
20+
21+
// Reconcile is the entrypoint to manage the given resource.
22+
func (r *ArchiveReconciler) Reconcile(ctx context.Context, req controllerruntime.Request) (controllerruntime.Result, error) {
23+
log := controllerruntime.LoggerFrom(ctx)
24+
25+
archive := &k8upv1.Archive{}
26+
err := r.Kube.Get(ctx, req.NamespacedName, archive)
27+
if err != nil {
28+
if errors.IsNotFound(err) {
29+
return controllerruntime.Result{}, nil
30+
}
31+
log.Error(err, "Failed to get Archive")
32+
return controllerruntime.Result{}, err
33+
}
34+
35+
repository := cfg.Config.GetGlobalRepository()
36+
if archive.Spec.Backend != nil {
37+
repository = archive.Spec.Backend.String()
38+
}
39+
if archive.Spec.RestoreSpec == nil {
40+
archive.Spec.RestoreSpec = &k8upv1.RestoreSpec{}
41+
}
42+
config := job.NewConfig(ctx, r.Kube, log, archive, repository)
43+
44+
executor := NewArchiveExecutor(config)
45+
46+
if archive.Status.HasFinished() {
47+
executor.cleanupOldArchives(executor.GetJobNamespacedName(), archive)
48+
return controllerruntime.Result{}, nil
49+
}
50+
51+
log.V(1).Info("adding job to the queue")
52+
queue.GetExecQueue().Add(executor)
53+
return controllerruntime.Result{RequeueAfter: time.Second * 30}, nil
54+
}

0 commit comments

Comments
 (0)