diff --git a/api/backups/v1alpha1/backup_types.go b/api/backups/v1alpha1/backup_types.go index da4cf02e2..9371c27f2 100644 --- a/api/backups/v1alpha1/backup_types.go +++ b/api/backups/v1alpha1/backup_types.go @@ -59,8 +59,7 @@ type BackupSpec struct { // StrategyRef refers to the driver-specific BackupStrategy that was used // to create this backup. This allows the driver to later perform restores. - // This references a cluster-scoped resource, so it does not include a namespace. - StrategyRef TypedClusterObjectReference `json:"strategyRef"` + StrategyRef corev1.TypedLocalObjectReference `json:"strategyRef"` // TakenAt is the time at which the backup was taken (as reported by the // driver). It may differ slightly from metadata.creationTimestamp. diff --git a/api/backups/v1alpha1/backupclass_types.go b/api/backups/v1alpha1/backupclass_types.go index a7a2714d0..19bcfd523 100644 --- a/api/backups/v1alpha1/backupclass_types.go +++ b/api/backups/v1alpha1/backupclass_types.go @@ -6,6 +6,7 @@ package v1alpha1 import ( + corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime" ) @@ -53,8 +54,7 @@ type BackupClassSpec struct { // BackupClassStrategy defines a backup strategy for a specific application type. type BackupClassStrategy struct { // StrategyRef references the driver-specific BackupStrategy (e.g., Velero). - // This references a cluster-scoped resource, so it does not include a namespace. - StrategyRef TypedClusterObjectReference `json:"strategyRef"` + StrategyRef corev1.TypedLocalObjectReference `json:"strategyRef"` // Application specifies which application types this strategy applies to. Application ApplicationSelector `json:"application"` @@ -66,43 +66,6 @@ type BackupClassStrategy struct { Parameters map[string]string `json:"parameters,omitempty"` } -// TypedClusterObjectReference contains enough information to let you locate a -// cluster-scoped typed resource. It does not include a namespace because -// cluster-scoped resources do not have namespaces. -type TypedClusterObjectReference struct { - // APIGroup is the group for the resource being referenced. - // If APIGroup is not specified, the specified Kind must be in the core API group. - // For any other third-party types, APIGroup is required. - // +optional - APIGroup *string `json:"apiGroup,omitempty"` - - // Kind is the type of resource being referenced. - Kind string `json:"kind"` - - // Name is the name of resource being referenced. - Name string `json:"name"` -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *TypedClusterObjectReference) DeepCopyInto(out *TypedClusterObjectReference) { - *out = *in - if in.APIGroup != nil { - in, out := &in.APIGroup, &out.APIGroup - *out = new(string) - **out = **in - } -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new TypedClusterObjectReference. -func (in *TypedClusterObjectReference) DeepCopy() *TypedClusterObjectReference { - if in == nil { - return nil - } - out := new(TypedClusterObjectReference) - in.DeepCopyInto(out) - return out -} - // ApplicationSelector specifies which application types a strategy applies to. type ApplicationSelector struct { // APIGroup is the API group of the application. diff --git a/internal/backupcontroller/backupclass_resolver.go b/internal/backupcontroller/backupclass_resolver.go index b28c16cb7..a1449c49d 100644 --- a/internal/backupcontroller/backupclass_resolver.go +++ b/internal/backupcontroller/backupclass_resolver.go @@ -26,7 +26,7 @@ func NormalizeApplicationRef(ref corev1.TypedLocalObjectReference) corev1.TypedL // ResolvedBackupConfig contains the resolved strategy and storage configuration // from a BackupClass. type ResolvedBackupConfig struct { - StrategyRef backupsv1alpha1.TypedClusterObjectReference + StrategyRef corev1.TypedLocalObjectReference Parameters map[string]string } diff --git a/internal/backupcontroller/backupclass_resolver_test.go b/internal/backupcontroller/backupclass_resolver_test.go index 2fe77006d..a606f241b 100644 --- a/internal/backupcontroller/backupclass_resolver_test.go +++ b/internal/backupcontroller/backupclass_resolver_test.go @@ -113,7 +113,7 @@ func TestResolveBackupClass(t *testing.T) { applicationRef corev1.TypedLocalObjectReference backupClassName string wantErr bool - expectedStrategyRef *backupsv1alpha1.TypedClusterObjectReference + expectedStrategyRef *corev1.TypedLocalObjectReference expectedParams map[string]string }{ { @@ -125,7 +125,7 @@ func TestResolveBackupClass(t *testing.T) { Spec: backupsv1alpha1.BackupClassSpec{ Strategies: []backupsv1alpha1.BackupClassStrategy{ { - StrategyRef: backupsv1alpha1.TypedClusterObjectReference{ + StrategyRef: corev1.TypedLocalObjectReference{ APIGroup: stringPtr("strategy.backups.cozystack.io"), Kind: "Velero", Name: "velero-strategy-vm", @@ -138,7 +138,7 @@ func TestResolveBackupClass(t *testing.T) { }, }, { - StrategyRef: backupsv1alpha1.TypedClusterObjectReference{ + StrategyRef: corev1.TypedLocalObjectReference{ APIGroup: stringPtr("strategy.backups.cozystack.io"), Kind: "Velero", Name: "velero-strategy-mysql", @@ -159,7 +159,7 @@ func TestResolveBackupClass(t *testing.T) { }, backupClassName: "velero", wantErr: false, - expectedStrategyRef: &backupsv1alpha1.TypedClusterObjectReference{ + expectedStrategyRef: &corev1.TypedLocalObjectReference{ APIGroup: stringPtr("strategy.backups.cozystack.io"), Kind: "Velero", Name: "velero-strategy-vm", @@ -177,7 +177,7 @@ func TestResolveBackupClass(t *testing.T) { Spec: backupsv1alpha1.BackupClassSpec{ Strategies: []backupsv1alpha1.BackupClassStrategy{ { - StrategyRef: backupsv1alpha1.TypedClusterObjectReference{ + StrategyRef: corev1.TypedLocalObjectReference{ APIGroup: stringPtr("strategy.backups.cozystack.io"), Kind: "Velero", Name: "velero-strategy-mysql", @@ -200,7 +200,7 @@ func TestResolveBackupClass(t *testing.T) { }, backupClassName: "velero", wantErr: false, - expectedStrategyRef: &backupsv1alpha1.TypedClusterObjectReference{ + expectedStrategyRef: &corev1.TypedLocalObjectReference{ APIGroup: stringPtr("strategy.backups.cozystack.io"), Kind: "Velero", Name: "velero-strategy-mysql", @@ -218,7 +218,7 @@ func TestResolveBackupClass(t *testing.T) { Spec: backupsv1alpha1.BackupClassSpec{ Strategies: []backupsv1alpha1.BackupClassStrategy{ { - StrategyRef: backupsv1alpha1.TypedClusterObjectReference{ + StrategyRef: corev1.TypedLocalObjectReference{ APIGroup: stringPtr("strategy.backups.cozystack.io"), Kind: "Velero", Name: "velero-strategy-vm", @@ -240,7 +240,7 @@ func TestResolveBackupClass(t *testing.T) { }, backupClassName: "velero", wantErr: false, - expectedStrategyRef: &backupsv1alpha1.TypedClusterObjectReference{ + expectedStrategyRef: &corev1.TypedLocalObjectReference{ APIGroup: stringPtr("strategy.backups.cozystack.io"), Kind: "Velero", Name: "velero-strategy-vm", @@ -275,7 +275,7 @@ func TestResolveBackupClass(t *testing.T) { Spec: backupsv1alpha1.BackupClassSpec{ Strategies: []backupsv1alpha1.BackupClassStrategy{ { - StrategyRef: backupsv1alpha1.TypedClusterObjectReference{ + StrategyRef: corev1.TypedLocalObjectReference{ APIGroup: stringPtr("strategy.backups.cozystack.io"), Kind: "Velero", Name: "velero-strategy-vm", @@ -303,7 +303,7 @@ func TestResolveBackupClass(t *testing.T) { Spec: backupsv1alpha1.BackupClassSpec{ Strategies: []backupsv1alpha1.BackupClassStrategy{ { - StrategyRef: backupsv1alpha1.TypedClusterObjectReference{ + StrategyRef: corev1.TypedLocalObjectReference{ APIGroup: stringPtr("strategy.backups.cozystack.io"), Kind: "Velero", Name: "velero-strategy-vm", diff --git a/internal/backupcontroller/velerostrategy_controller_test.go b/internal/backupcontroller/velerostrategy_controller_test.go index 0241a2b90..a7de20769 100644 --- a/internal/backupcontroller/velerostrategy_controller_test.go +++ b/internal/backupcontroller/velerostrategy_controller_test.go @@ -137,7 +137,7 @@ func TestCreateVeleroBackup_TemplateContext(t *testing.T) { // Create ResolvedBackupConfig with parameters resolved := &ResolvedBackupConfig{ - StrategyRef: backupsv1alpha1.TypedClusterObjectReference{ + StrategyRef: corev1.TypedLocalObjectReference{ APIGroup: stringPtr("strategy.backups.cozystack.io"), Kind: "Velero", Name: "velero-strategy",