Skip to content

Commit bbb67ea

Browse files
committed
feat: wip
1 parent 2507d55 commit bbb67ea

File tree

5 files changed

+114
-9
lines changed

5 files changed

+114
-9
lines changed

api/postgresql/v1alpha1/postgresqlbackup_types.go

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ package v1alpha1
1818

1919
import (
2020
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
21+
22+
"github.com/easymile/postgresql-operator/api/postgresql/common"
2123
)
2224

2325
// EDIT THIS FILE! THIS IS SCAFFOLDING FOR YOU TO OWN!
@@ -27,12 +29,38 @@ import (
2729
type PostgresqlBackupSpec struct {
2830
// Schedule for cronjob
2931
Schedule string `json:"schedule"`
32+
// One shot backup ?
33+
OneShot bool `json:"oneShot"`
34+
// Postgresql Database
35+
// +required
36+
// +kubebuilder:validation:Required
37+
Database *common.CRLink `json:"database"`
38+
// Postgresql backup provider
39+
// +required
40+
// +kubebuilder:validation:Required
41+
BackupProvider *common.CRLink `json:"backupProvider"`
3042
}
3143

44+
type BackupStatusPhase string
45+
46+
const (
47+
BackupNoPhase BackupStatusPhase = ""
48+
BackupErrorPhase BackupStatusPhase = "Error"
49+
BackupValidPhase BackupStatusPhase = "Valid"
50+
)
51+
3252
// PostgresqlBackupStatus defines the observed state of PostgresqlBackup.
3353
type PostgresqlBackupStatus struct {
34-
// INSERT ADDITIONAL STATUS FIELD - define observed state of cluster
35-
// Important: Run "make" to regenerate code after modifying this file
54+
// Current phase of the operator
55+
Phase BackupProviderStatusPhase `json:"phase,omitempty"`
56+
// Human-readable message indicating details about current operator phase or error.
57+
// +optional
58+
Message string `json:"message,omitempty"`
59+
// True if all resources are in a ready state and all work is done.
60+
// +optional
61+
Ready bool `json:"ready,omitempty"`
62+
// Resource Spec hash
63+
Hash string `json:"hash,omitempty"`
3664
}
3765

3866
// +kubebuilder:object:root=true

api/postgresql/v1alpha1/zz_generated.deepcopy.go

Lines changed: 11 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cmd/main.go

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -340,8 +340,20 @@ func main() {
340340
os.Exit(1)
341341
}
342342
if err := (&postgresqlcontrollers.PostgresqlBackupReconciler{
343-
Client: mgr.GetClient(),
344-
Scheme: mgr.GetScheme(),
343+
Client: mgr.GetClient(),
344+
Scheme: mgr.GetScheme(),
345+
Recorder: mgr.GetEventRecorderFor("postgresqlbackup-controller"),
346+
Log: ctrl.Log.WithValues(
347+
"controller",
348+
"postgresqlbackup",
349+
"controllerKind",
350+
"PostgresqlBackup",
351+
"controllerGroup",
352+
"postgresql.easymile.com",
353+
),
354+
ControllerRuntimeDetailedErrorTotal: controllerRuntimeDetailedErrorTotal,
355+
ControllerName: "postgresqlbackup",
356+
ReconcileTimeout: reconcileTimeout,
345357
}).SetupWithManager(mgr); err != nil {
346358
setupLog.Error(err, "unable to create controller", "controller", "PostgresqlBackup")
347359
os.Exit(1)

config/crd/bases/postgresql.easymile.com_postgresqlbackups.yaml

Lines changed: 49 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,13 +39,59 @@ spec:
3939
spec:
4040
description: PostgresqlBackupSpec defines the desired state of PostgresqlBackup.
4141
properties:
42-
foo:
43-
description: Foo is an example field of PostgresqlBackup. Edit postgresqlbackup_types.go
44-
to remove/update
42+
backupProvider:
43+
description: Postgresql backup provider
44+
properties:
45+
name:
46+
description: Custom resource name
47+
type: string
48+
namespace:
49+
description: Custom resource namespace
50+
type: string
51+
required:
52+
- name
53+
type: object
54+
database:
55+
description: Postgresql Database
56+
properties:
57+
name:
58+
description: Custom resource name
59+
type: string
60+
namespace:
61+
description: Custom resource namespace
62+
type: string
63+
required:
64+
- name
65+
type: object
66+
oneShot:
67+
description: One shot backup ?
68+
type: boolean
69+
schedule:
70+
description: Schedule for cronjob
4571
type: string
72+
required:
73+
- backupProvider
74+
- database
75+
- oneShot
76+
- schedule
4677
type: object
4778
status:
4879
description: PostgresqlBackupStatus defines the observed state of PostgresqlBackup.
80+
properties:
81+
hash:
82+
description: Resource Spec hash
83+
type: string
84+
message:
85+
description: Human-readable message indicating details about current
86+
operator phase or error.
87+
type: string
88+
phase:
89+
description: Current phase of the operator
90+
type: string
91+
ready:
92+
description: True if all resources are in a ready state and all work
93+
is done.
94+
type: boolean
4995
type: object
5096
type: object
5197
served: true

internal/controller/postgresql/postgresqlbackup_controller.go

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,12 @@ package postgresql
1818

1919
import (
2020
"context"
21+
"time"
2122

23+
"github.com/go-logr/logr"
24+
"github.com/prometheus/client_golang/prometheus"
2225
"k8s.io/apimachinery/pkg/runtime"
26+
"k8s.io/client-go/tools/record"
2327
"sigs.k8s.io/controller-runtime/pkg/client"
2428

2529
ctrl "sigs.k8s.io/controller-runtime"
@@ -30,8 +34,13 @@ import (
3034

3135
// PostgresqlBackupReconciler reconciles a PostgresqlBackup object.
3236
type PostgresqlBackupReconciler struct {
37+
Recorder record.EventRecorder
3338
client.Client
34-
Scheme *runtime.Scheme
39+
Scheme *runtime.Scheme
40+
ControllerRuntimeDetailedErrorTotal *prometheus.CounterVec
41+
Log logr.Logger
42+
ControllerName string
43+
ReconcileTimeout time.Duration
3544
}
3645

3746
// +kubebuilder:rbac:groups=postgresql.easymile.com,resources=postgresqlbackups,verbs=get;list;watch;create;update;patch;delete

0 commit comments

Comments
 (0)