Skip to content

Commit 73d6e30

Browse files
committed
fix
Signed-off-by: Andrey Kolkov <[email protected]>
1 parent 8755497 commit 73d6e30

5 files changed

Lines changed: 53 additions & 15 deletions

File tree

‎api/backups/v1alpha1/backup_types.go‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,8 @@ type BackupSpec struct {
5959

6060
// StrategyRef refers to the driver-specific BackupStrategy that was used
6161
// to create this backup. This allows the driver to later perform restores.
62-
StrategyRef corev1.TypedLocalObjectReference `json:"strategyRef"`
62+
// This references a cluster-scoped resource, so it does not include a namespace.
63+
StrategyRef TypedClusterObjectReference `json:"strategyRef"`
6364

6465
// TakenAt is the time at which the backup was taken (as reported by the
6566
// driver). It may differ slightly from metadata.creationTimestamp.

‎api/backups/v1alpha1/backupclass_types.go‎

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
package v1alpha1
77

88
import (
9-
corev1 "k8s.io/api/core/v1"
109
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
1110
"k8s.io/apimachinery/pkg/runtime"
1211
)
@@ -54,7 +53,8 @@ type BackupClassSpec struct {
5453
// BackupClassStrategy defines a backup strategy for a specific application type.
5554
type BackupClassStrategy struct {
5655
// StrategyRef references the driver-specific BackupStrategy (e.g., Velero).
57-
StrategyRef corev1.TypedLocalObjectReference `json:"strategyRef"`
56+
// This references a cluster-scoped resource, so it does not include a namespace.
57+
StrategyRef TypedClusterObjectReference `json:"strategyRef"`
5858

5959
// Application specifies which application types this strategy applies to.
6060
Application ApplicationSelector `json:"application"`
@@ -66,6 +66,43 @@ type BackupClassStrategy struct {
6666
Parameters map[string]string `json:"parameters,omitempty"`
6767
}
6868

69+
// TypedClusterObjectReference contains enough information to let you locate a
70+
// cluster-scoped typed resource. It does not include a namespace because
71+
// cluster-scoped resources do not have namespaces.
72+
type TypedClusterObjectReference struct {
73+
// APIGroup is the group for the resource being referenced.
74+
// If APIGroup is not specified, the specified Kind must be in the core API group.
75+
// For any other third-party types, APIGroup is required.
76+
// +optional
77+
APIGroup *string `json:"apiGroup,omitempty"`
78+
79+
// Kind is the type of resource being referenced.
80+
Kind string `json:"kind"`
81+
82+
// Name is the name of resource being referenced.
83+
Name string `json:"name"`
84+
}
85+
86+
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
87+
func (in *TypedClusterObjectReference) DeepCopyInto(out *TypedClusterObjectReference) {
88+
*out = *in
89+
if in.APIGroup != nil {
90+
in, out := &in.APIGroup, &out.APIGroup
91+
*out = new(string)
92+
**out = **in
93+
}
94+
}
95+
96+
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new TypedClusterObjectReference.
97+
func (in *TypedClusterObjectReference) DeepCopy() *TypedClusterObjectReference {
98+
if in == nil {
99+
return nil
100+
}
101+
out := new(TypedClusterObjectReference)
102+
in.DeepCopyInto(out)
103+
return out
104+
}
105+
69106
// ApplicationSelector specifies which application types a strategy applies to.
70107
type ApplicationSelector struct {
71108
// APIGroup is the API group of the application.

‎internal/backupcontroller/backupclass_resolver.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ func NormalizeApplicationRef(ref corev1.TypedLocalObjectReference) corev1.TypedL
2626
// ResolvedBackupConfig contains the resolved strategy and storage configuration
2727
// from a BackupClass.
2828
type ResolvedBackupConfig struct {
29-
StrategyRef corev1.TypedLocalObjectReference
29+
StrategyRef backupsv1alpha1.TypedClusterObjectReference
3030
Parameters map[string]string
3131
}
3232

‎internal/backupcontroller/backupclass_resolver_test.go‎

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ func TestResolveBackupClass(t *testing.T) {
113113
applicationRef corev1.TypedLocalObjectReference
114114
backupClassName string
115115
wantErr bool
116-
expectedStrategyRef *corev1.TypedLocalObjectReference
116+
expectedStrategyRef *backupsv1alpha1.TypedClusterObjectReference
117117
expectedParams map[string]string
118118
}{
119119
{
@@ -125,7 +125,7 @@ func TestResolveBackupClass(t *testing.T) {
125125
Spec: backupsv1alpha1.BackupClassSpec{
126126
Strategies: []backupsv1alpha1.BackupClassStrategy{
127127
{
128-
StrategyRef: corev1.TypedLocalObjectReference{
128+
StrategyRef: backupsv1alpha1.TypedClusterObjectReference{
129129
APIGroup: stringPtr("strategy.backups.cozystack.io"),
130130
Kind: "Velero",
131131
Name: "velero-strategy-vm",
@@ -138,7 +138,7 @@ func TestResolveBackupClass(t *testing.T) {
138138
},
139139
},
140140
{
141-
StrategyRef: corev1.TypedLocalObjectReference{
141+
StrategyRef: backupsv1alpha1.TypedClusterObjectReference{
142142
APIGroup: stringPtr("strategy.backups.cozystack.io"),
143143
Kind: "Velero",
144144
Name: "velero-strategy-mysql",
@@ -159,7 +159,7 @@ func TestResolveBackupClass(t *testing.T) {
159159
},
160160
backupClassName: "velero",
161161
wantErr: false,
162-
expectedStrategyRef: &corev1.TypedLocalObjectReference{
162+
expectedStrategyRef: &backupsv1alpha1.TypedClusterObjectReference{
163163
APIGroup: stringPtr("strategy.backups.cozystack.io"),
164164
Kind: "Velero",
165165
Name: "velero-strategy-vm",
@@ -177,7 +177,7 @@ func TestResolveBackupClass(t *testing.T) {
177177
Spec: backupsv1alpha1.BackupClassSpec{
178178
Strategies: []backupsv1alpha1.BackupClassStrategy{
179179
{
180-
StrategyRef: corev1.TypedLocalObjectReference{
180+
StrategyRef: backupsv1alpha1.TypedClusterObjectReference{
181181
APIGroup: stringPtr("strategy.backups.cozystack.io"),
182182
Kind: "Velero",
183183
Name: "velero-strategy-mysql",
@@ -200,7 +200,7 @@ func TestResolveBackupClass(t *testing.T) {
200200
},
201201
backupClassName: "velero",
202202
wantErr: false,
203-
expectedStrategyRef: &corev1.TypedLocalObjectReference{
203+
expectedStrategyRef: &backupsv1alpha1.TypedClusterObjectReference{
204204
APIGroup: stringPtr("strategy.backups.cozystack.io"),
205205
Kind: "Velero",
206206
Name: "velero-strategy-mysql",
@@ -218,7 +218,7 @@ func TestResolveBackupClass(t *testing.T) {
218218
Spec: backupsv1alpha1.BackupClassSpec{
219219
Strategies: []backupsv1alpha1.BackupClassStrategy{
220220
{
221-
StrategyRef: corev1.TypedLocalObjectReference{
221+
StrategyRef: backupsv1alpha1.TypedClusterObjectReference{
222222
APIGroup: stringPtr("strategy.backups.cozystack.io"),
223223
Kind: "Velero",
224224
Name: "velero-strategy-vm",
@@ -240,7 +240,7 @@ func TestResolveBackupClass(t *testing.T) {
240240
},
241241
backupClassName: "velero",
242242
wantErr: false,
243-
expectedStrategyRef: &corev1.TypedLocalObjectReference{
243+
expectedStrategyRef: &backupsv1alpha1.TypedClusterObjectReference{
244244
APIGroup: stringPtr("strategy.backups.cozystack.io"),
245245
Kind: "Velero",
246246
Name: "velero-strategy-vm",
@@ -275,7 +275,7 @@ func TestResolveBackupClass(t *testing.T) {
275275
Spec: backupsv1alpha1.BackupClassSpec{
276276
Strategies: []backupsv1alpha1.BackupClassStrategy{
277277
{
278-
StrategyRef: corev1.TypedLocalObjectReference{
278+
StrategyRef: backupsv1alpha1.TypedClusterObjectReference{
279279
APIGroup: stringPtr("strategy.backups.cozystack.io"),
280280
Kind: "Velero",
281281
Name: "velero-strategy-vm",
@@ -303,7 +303,7 @@ func TestResolveBackupClass(t *testing.T) {
303303
Spec: backupsv1alpha1.BackupClassSpec{
304304
Strategies: []backupsv1alpha1.BackupClassStrategy{
305305
{
306-
StrategyRef: corev1.TypedLocalObjectReference{
306+
StrategyRef: backupsv1alpha1.TypedClusterObjectReference{
307307
APIGroup: stringPtr("strategy.backups.cozystack.io"),
308308
Kind: "Velero",
309309
Name: "velero-strategy-vm",

‎internal/backupcontroller/velerostrategy_controller_test.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ func TestCreateVeleroBackup_TemplateContext(t *testing.T) {
137137

138138
// Create ResolvedBackupConfig with parameters
139139
resolved := &ResolvedBackupConfig{
140-
StrategyRef: corev1.TypedLocalObjectReference{
140+
StrategyRef: backupsv1alpha1.TypedClusterObjectReference{
141141
APIGroup: stringPtr("strategy.backups.cozystack.io"),
142142
Kind: "Velero",
143143
Name: "velero-strategy",

0 commit comments

Comments
 (0)