Skip to content

Commit 1ec14d6

Browse files
authored
[backups] Add indices to core backup resources (#1719)
## What this PR does This adds custom indexable fields on core backup resources to enable filtering by backed-up application. This will later be useful for displaying backup resources in the dashboard: it will be possible to filter them with a field selector to display only those backup resources that are relevant to a given application. ### Release note ```release-note [backups] Enable filtering backup resources by backed up application for per-app views of backups. ``` <!-- This is an auto-generated comment: release notes by coderabbit.ai --> ## Summary by CodeRabbit ## Release Notes * **New Features** * Introduced new Backup, BackupJob, Plan, and RestoreJob API resources for enhanced backup management. * Added selectable fields to backup resources, enabling efficient filtering and querying by application reference. * Added status subresource with conditions to Plan resources for improved status tracking and observability. * **Chores** * Updated repository metadata configuration. <sub>✏️ Tip: You can customize this high-level summary in your review settings.</sub> <!-- end of auto-generated comment: release notes by coderabbit.ai -->
2 parents 03a71eb + 0f7bd3e commit 1ec14d6

10 files changed

Lines changed: 160 additions & 20 deletions

‎api/backups/v1alpha1/backup_types.go‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,19 @@ package v1alpha1
88
import (
99
corev1 "k8s.io/api/core/v1"
1010
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
11+
"k8s.io/apimachinery/pkg/runtime"
1112
)
1213

14+
func init() {
15+
SchemeBuilder.Register(func(s *runtime.Scheme) error {
16+
s.AddKnownTypes(GroupVersion,
17+
&Backup{},
18+
&BackupList{},
19+
)
20+
return nil
21+
})
22+
}
23+
1324
// BackupPhase represents the lifecycle phase of a Backup.
1425
type BackupPhase string
1526

@@ -81,7 +92,12 @@ type BackupStatus struct {
8192
Conditions []metav1.Condition `json:"conditions,omitempty"`
8293
}
8394

95+
// The field indexing on applicationRef will be needed later to display per-app backup resources.
96+
8497
// +kubebuilder:object:root=true
98+
// +kubebuilder:selectablefield:JSONPath=`.spec.applicationRef.apiGroup`
99+
// +kubebuilder:selectablefield:JSONPath=`.spec.applicationRef.kind`
100+
// +kubebuilder:selectablefield:JSONPath=`.spec.applicationRef.name`
85101

86102
// Backup represents a single backup artifact for a given application.
87103
type Backup struct {

‎api/backups/v1alpha1/backupjob_types.go‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,19 @@ package v1alpha1
88
import (
99
corev1 "k8s.io/api/core/v1"
1010
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
11+
"k8s.io/apimachinery/pkg/runtime"
1112
)
1213

14+
func init() {
15+
SchemeBuilder.Register(func(s *runtime.Scheme) error {
16+
s.AddKnownTypes(GroupVersion,
17+
&BackupJob{},
18+
&BackupJobList{},
19+
)
20+
return nil
21+
})
22+
}
23+
1324
// BackupJobPhase represents the lifecycle phase of a BackupJob.
1425
type BackupJobPhase string
1526

@@ -71,7 +82,12 @@ type BackupJobStatus struct {
7182
Conditions []metav1.Condition `json:"conditions,omitempty"`
7283
}
7384

85+
// The field indexing on applicationRef will be needed later to display per-app backup resources.
86+
7487
// +kubebuilder:object:root=true
88+
// +kubebuilder:selectablefield:JSONPath=`.spec.applicationRef.apiGroup`
89+
// +kubebuilder:selectablefield:JSONPath=`.spec.applicationRef.kind`
90+
// +kubebuilder:selectablefield:JSONPath=`.spec.applicationRef.name`
7591

7692
// BackupJob represents a single execution of a backup.
7793
// It is typically created by a Plan controller when a schedule fires.

‎api/backups/v1alpha1/groupversion_info.go‎

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -26,28 +26,12 @@ import (
2626
)
2727

2828
var (
29-
// GroupVersion is group version used to register these objects.
30-
GroupVersion = schema.GroupVersion{Group: "backups.cozystack.io", Version: "v1alpha1"}
31-
32-
// SchemeBuilder is used to add go types to the GroupVersionKind scheme.
33-
SchemeBuilder = runtime.NewSchemeBuilder(addKnownTypes)
34-
35-
// AddToScheme adds the types in this group-version to the given scheme.
36-
AddToScheme = SchemeBuilder.AddToScheme
29+
GroupVersion = schema.GroupVersion{Group: "backups.cozystack.io", Version: "v1alpha1"}
30+
SchemeBuilder = runtime.NewSchemeBuilder(addGroupVersion)
31+
AddToScheme = SchemeBuilder.AddToScheme
3732
)
3833

39-
func addKnownTypes(scheme *runtime.Scheme) error {
40-
scheme.AddKnownTypes(
41-
GroupVersion,
42-
&Plan{},
43-
&PlanList{},
44-
&BackupJob{},
45-
&BackupJobList{},
46-
&Backup{},
47-
&BackupList{},
48-
&RestoreJob{},
49-
&RestoreJobList{},
50-
)
34+
func addGroupVersion(scheme *runtime.Scheme) error {
5135
metav1.AddToGroupVersion(scheme, GroupVersion)
5236
return nil
5337
}

‎api/backups/v1alpha1/plan_types.go‎

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,19 @@ package v1alpha1
88
import (
99
corev1 "k8s.io/api/core/v1"
1010
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
11+
"k8s.io/apimachinery/pkg/runtime"
1112
)
1213

14+
func init() {
15+
SchemeBuilder.Register(func(s *runtime.Scheme) error {
16+
s.AddKnownTypes(GroupVersion,
17+
&Plan{},
18+
&PlanList{},
19+
)
20+
return nil
21+
})
22+
}
23+
1324
type PlanScheduleType string
1425

1526
const (
@@ -22,8 +33,13 @@ const (
2233
PlanConditionError = "Error"
2334
)
2435

36+
// The field indexing on applicationRef will be needed later to display per-app backup resources.
37+
2538
// +kubebuilder:object:root=true
2639
// +kubebuilder:subresource:status
40+
// +kubebuilder:selectablefield:JSONPath=`.spec.applicationRef.apiGroup`
41+
// +kubebuilder:selectablefield:JSONPath=`.spec.applicationRef.kind`
42+
// +kubebuilder:selectablefield:JSONPath=`.spec.applicationRef.name`
2743

2844
// Plan describes the schedule, method and storage location for the
2945
// backup of a given target application.

‎api/backups/v1alpha1/restorejob_types.go‎

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,19 @@ package v1alpha1
88
import (
99
corev1 "k8s.io/api/core/v1"
1010
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
11+
"k8s.io/apimachinery/pkg/runtime"
1112
)
1213

14+
func init() {
15+
SchemeBuilder.Register(func(s *runtime.Scheme) error {
16+
s.AddKnownTypes(GroupVersion,
17+
&RestoreJob{},
18+
&RestoreJobList{},
19+
)
20+
return nil
21+
})
22+
}
23+
1324
// RestoreJobPhase represents the lifecycle phase of a RestoreJob.
1425
type RestoreJobPhase string
1526

‎api/backups/v1alpha1/zz_generated.deepcopy.go‎

Lines changed: 23 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
* linguist-generated
2+
.gitattributes -linguist-generated

‎packages/system/backup-controller/definitions/backups.cozystack.io_backupjobs.yaml‎

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎packages/system/backup-controller/definitions/backups.cozystack.io_backups.yaml‎

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎packages/system/backup-controller/definitions/backups.cozystack.io_plans.yaml‎

Lines changed: 65 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)