diff --git a/api/backups/v1alpha1/backup_types.go b/api/backups/v1alpha1/backup_types.go index 9371c27f..da4cf02e 100644 --- a/api/backups/v1alpha1/backup_types.go +++ b/api/backups/v1alpha1/backup_types.go @@ -59,7 +59,8 @@ 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. - StrategyRef corev1.TypedLocalObjectReference `json:"strategyRef"` + // This references a cluster-scoped resource, so it does not include a namespace. + StrategyRef TypedClusterObjectReference `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 19bcfd52..a7a2714d 100644 --- a/api/backups/v1alpha1/backupclass_types.go +++ b/api/backups/v1alpha1/backupclass_types.go @@ -6,7 +6,6 @@ package v1alpha1 import ( - corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime" ) @@ -54,7 +53,8 @@ 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). - StrategyRef corev1.TypedLocalObjectReference `json:"strategyRef"` + // This references a cluster-scoped resource, so it does not include a namespace. + StrategyRef TypedClusterObjectReference `json:"strategyRef"` // Application specifies which application types this strategy applies to. Application ApplicationSelector `json:"application"` @@ -66,6 +66,43 @@ 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 a1449c49..b28c16cb 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 corev1.TypedLocalObjectReference + StrategyRef backupsv1alpha1.TypedClusterObjectReference Parameters map[string]string } diff --git a/internal/backupcontroller/backupclass_resolver_test.go b/internal/backupcontroller/backupclass_resolver_test.go index a606f241..2fe77006 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 *corev1.TypedLocalObjectReference + expectedStrategyRef *backupsv1alpha1.TypedClusterObjectReference expectedParams map[string]string }{ { @@ -125,7 +125,7 @@ func TestResolveBackupClass(t *testing.T) { Spec: backupsv1alpha1.BackupClassSpec{ Strategies: []backupsv1alpha1.BackupClassStrategy{ { - StrategyRef: corev1.TypedLocalObjectReference{ + StrategyRef: backupsv1alpha1.TypedClusterObjectReference{ APIGroup: stringPtr("strategy.backups.cozystack.io"), Kind: "Velero", Name: "velero-strategy-vm", @@ -138,7 +138,7 @@ func TestResolveBackupClass(t *testing.T) { }, }, { - StrategyRef: corev1.TypedLocalObjectReference{ + StrategyRef: backupsv1alpha1.TypedClusterObjectReference{ 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: &corev1.TypedLocalObjectReference{ + expectedStrategyRef: &backupsv1alpha1.TypedClusterObjectReference{ 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: corev1.TypedLocalObjectReference{ + StrategyRef: backupsv1alpha1.TypedClusterObjectReference{ 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: &corev1.TypedLocalObjectReference{ + expectedStrategyRef: &backupsv1alpha1.TypedClusterObjectReference{ 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: corev1.TypedLocalObjectReference{ + StrategyRef: backupsv1alpha1.TypedClusterObjectReference{ 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: &corev1.TypedLocalObjectReference{ + expectedStrategyRef: &backupsv1alpha1.TypedClusterObjectReference{ 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: corev1.TypedLocalObjectReference{ + StrategyRef: backupsv1alpha1.TypedClusterObjectReference{ 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: corev1.TypedLocalObjectReference{ + StrategyRef: backupsv1alpha1.TypedClusterObjectReference{ 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 a7de2076..0241a2b9 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: corev1.TypedLocalObjectReference{ + StrategyRef: backupsv1alpha1.TypedClusterObjectReference{ APIGroup: stringPtr("strategy.backups.cozystack.io"), Kind: "Velero", Name: "velero-strategy",