Skip to content

Commit

Permalink
Merge pull request #789 from k8up-io/remove-obs-exclusive
Browse files Browse the repository at this point in the history
Free Check and Prune from internal Observer, rework exclusive job queueing
  • Loading branch information
ccremer authored Jan 4, 2023
2 parents 8eb74dd + 47eade1 commit 826937e
Show file tree
Hide file tree
Showing 40 changed files with 565 additions and 1,109 deletions.
3 changes: 0 additions & 3 deletions .golangci.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
issues:
exclude-rules:
- linters:
- staticcheck
text: "k8upv1.LegacyLabelK8upType is deprecated: LegacyLabelK8upType is the former label key that identified the job type"
- linters:
- staticcheck
text: "k8upv1.LegacyScheduleFinalizerName is deprecated: Migrate to ScheduleFinalizerName"
6 changes: 6 additions & 0 deletions api/v1/check_types.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package v1

import (
"reflect"

corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
Expand Down Expand Up @@ -156,3 +158,7 @@ func (c *CheckSpec) CreateObject(name, namespace string) runtime.Object {
Spec: *c,
}
}

var (
CheckKind = reflect.TypeOf(Check{}).Name()
)
6 changes: 6 additions & 0 deletions api/v1/prune_types.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package v1

import (
"reflect"

corev1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime"
Expand Down Expand Up @@ -169,3 +171,7 @@ func (in *PruneSchedule) GetObjectCreator() ObjectCreator {
func init() {
SchemeBuilder.Register(&Prune{}, &PruneList{})
}

var (
PruneKind = reflect.TypeOf(Prune{}).Name()
)
8 changes: 6 additions & 2 deletions cmd/k8up/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,9 @@ import (

"github.com/go-logr/logr"
"github.com/urfave/cli/v2"
"go.uber.org/zap"
"go.uber.org/zap/zapcore"
"sigs.k8s.io/controller-runtime/pkg/log/zap"
controllerzap "sigs.k8s.io/controller-runtime/pkg/log/zap"

"github.com/k8up-io/k8up/v2/cmd"
"github.com/k8up-io/k8up/v2/cmd/operator"
Expand Down Expand Up @@ -89,6 +90,9 @@ func newLogger(name string, debug bool) logr.Logger {
if debug {
level = zapcore.DebugLevel
}
logger := zap.New(zap.UseDevMode(true), zap.Level(level))
cfg := zap.NewDevelopmentConfig()
cfg.EncoderConfig.EncodeTime = zapcore.RFC3339TimeEncoder
enc := zapcore.NewConsoleEncoder(cfg.EncoderConfig)
logger := controllerzap.New(controllerzap.Level(level), controllerzap.Encoder(enc))
return logger.WithName(name)
}
36 changes: 18 additions & 18 deletions cmd/operator/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,28 +4,24 @@ import (
"fmt"
"strings"

k8upv1 "github.com/k8up-io/k8up/v2/api/v1"
"github.com/k8up-io/k8up/v2/cmd"
"github.com/k8up-io/k8up/v2/operator/archivecontroller"
"github.com/k8up-io/k8up/v2/operator/backupcontroller"
"github.com/k8up-io/k8up/v2/operator/cfg"
"github.com/k8up-io/k8up/v2/operator/checkcontroller"
"github.com/k8up-io/k8up/v2/operator/executor"
"github.com/k8up-io/k8up/v2/operator/jobcontroller"
"github.com/k8up-io/k8up/v2/operator/locker"
"github.com/k8up-io/k8up/v2/operator/prunecontroller"
"github.com/k8up-io/k8up/v2/operator/restorecontroller"
"github.com/k8up-io/k8up/v2/operator/schedulecontroller"
"k8s.io/apimachinery/pkg/api/resource"
_ "k8s.io/client-go/plugin/pkg/client/auth/gcp"

"github.com/urfave/cli/v2"
batchv1 "k8s.io/api/batch/v1"
"k8s.io/apimachinery/pkg/api/resource"
"k8s.io/apimachinery/pkg/runtime"
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
clientgoscheme "k8s.io/client-go/kubernetes/scheme"
ctrl "sigs.k8s.io/controller-runtime"

k8upv1 "github.com/k8up-io/k8up/v2/api/v1"
"github.com/k8up-io/k8up/v2/cmd"
"github.com/k8up-io/k8up/v2/controllers"
"github.com/k8up-io/k8up/v2/operator/cfg"
"github.com/k8up-io/k8up/v2/operator/executor"
// +kubebuilder:scaffold:imports
)

const (
Expand Down Expand Up @@ -119,18 +115,18 @@ func operatorMain(c *cli.Context) error {
lock := &locker.Locker{Kube: mgr.GetClient()}
executor.StartExecutor(lock)

for name, reconciler := range map[string]controllers.ReconcilerSetup{
for name, reconciler := range map[string]ReconcilerSetup{
"Schedule": &schedulecontroller.ScheduleReconciler{},
"Backup": &backupcontroller.BackupReconciler{},
"Restore": &restorecontroller.RestoreReconciler{},
"Archive": &archivecontroller.ArchiveReconciler{},
"Check": &controllers.CheckReconciler{},
"Prune": &controllers.PruneReconciler{},
"Check": &checkcontroller.CheckReconciler{},
"Prune": &prunecontroller.PruneReconciler{},
"Job": &jobcontroller.JobReconciler{},
} {
if err := reconciler.SetupWithManager(mgr, operatorLog.WithName("controllers").WithName(name)); err != nil {
operatorLog.Error(err, "unable to initialize operator mode", "step", "controller", "controller", name)
return fmt.Errorf("unable to setup reconciler: %w", err)
if setupErr := reconciler.SetupWithManager(mgr); setupErr != nil {
operatorLog.Error(setupErr, "unable to initialize operator mode", "step", "controller", "controller", name)
return fmt.Errorf("unable to setup reconciler: %w", setupErr)
}
}
// +kubebuilder:scaffold:builder
Expand All @@ -146,7 +142,6 @@ func operatorMain(c *cli.Context) error {
func k8upScheme() *runtime.Scheme {
scheme := runtime.NewScheme()
utilruntime.Must(clientgoscheme.AddToScheme(scheme))
utilruntime.Must(batchv1.AddToScheme(scheme))
utilruntime.Must(k8upv1.AddToScheme(scheme))
// +kubebuilder:scaffold:scheme
return scheme
Expand Down Expand Up @@ -174,3 +169,8 @@ func validateQuantityFlags(ctx *cli.Context) error {

return nil
}

// ReconcilerSetup is a common interface to configure reconcilers.
type ReconcilerSetup interface {
SetupWithManager(mgr ctrl.Manager) error
}
68 changes: 0 additions & 68 deletions controllers/check_controller.go

This file was deleted.

14 changes: 0 additions & 14 deletions controllers/controller_setup.go

This file was deleted.

66 changes: 0 additions & 66 deletions controllers/prune_controller.go

This file was deleted.

1 change: 0 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ require (
)

require (
cloud.google.com/go/compute v1.9.0 // indirect
github.com/PuerkitoBio/purell v1.1.1 // indirect
github.com/PuerkitoBio/urlesc v0.0.0-20170810143723-de5bf2ad4578 // indirect
github.com/benbjohnson/clock v1.1.0 // indirect
Expand Down
1 change: 0 additions & 1 deletion go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ cloud.google.com/go/compute v1.5.0/go.mod h1:9SMHyhJlzhlkJqrPAc839t2BZFTSk6Jdj6m
cloud.google.com/go/compute v1.6.0/go.mod h1:T29tfhtVbq1wvAPo0E3+7vhgmkOYeXjhFvz/FMzPu0s=
cloud.google.com/go/compute v1.6.1/go.mod h1:g85FgpzFvNULZ+S8AYq87axRKuf2Kh7deLqV/jJ3thU=
cloud.google.com/go/compute v1.7.0/go.mod h1:435lt8av5oL9P3fv1OEzSbSUe+ybHXGMPQHHZWZxy9U=
cloud.google.com/go/compute v1.9.0 h1:ED/FP4xv8GJw63v556/ASNc1CeeLUO2Bs8nzaHchkHg=
cloud.google.com/go/compute v1.9.0/go.mod h1:lWv1h/zUWTm/LozzfTJhBSkd6ShQq8la8VeeuOEGxfY=
cloud.google.com/go/datastore v1.0.0/go.mod h1:LXYbyblFSglQ5pkeyhO+Qmw7ukd3C+pD7TKLgZqpHYE=
cloud.google.com/go/datastore v1.1.0/go.mod h1:umbIZjpQpHh4hmRpGhH4tLFup+FVzqBi1b3c64qFpCk=
Expand Down
4 changes: 4 additions & 0 deletions operator/archivecontroller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ func (r *ArchiveReconciler) Reconcile(ctx context.Context, req controllerruntime
return controllerruntime.Result{}, err
}

if archive.Status.HasStarted() {
return controllerruntime.Result{}, nil
}

repository := cfg.Config.GetGlobalRepository()
if archive.Spec.Backend != nil {
repository = archive.Spec.Backend.String()
Expand Down
3 changes: 1 addition & 2 deletions operator/archivecontroller/setup.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package archivecontroller

import (
"github.com/go-logr/logr"
v1 "github.com/k8up-io/k8up/v2/api/v1"
controllerruntime "sigs.k8s.io/controller-runtime"
"sigs.k8s.io/controller-runtime/pkg/predicate"
Expand All @@ -11,7 +10,7 @@ import (
// +kubebuilder:rbac:groups=k8up.io,resources=archives/status;archives/finalizers,verbs=get;update;patch

// SetupWithManager configures the reconciler.
func (r *ArchiveReconciler) SetupWithManager(mgr controllerruntime.Manager, l logr.Logger) error {
func (r *ArchiveReconciler) SetupWithManager(mgr controllerruntime.Manager) error {
name := "archive.k8up.io"
r.Kube = mgr.GetClient()
return controllerruntime.NewControllerManagedBy(mgr).
Expand Down
Loading

0 comments on commit 826937e

Please sign in to comment.