From a1170e3790b363cc70a545a2da567a5e62cdcf2d Mon Sep 17 00:00:00 2001 From: Ethan Mosbaugh Date: Thu, 5 Dec 2024 10:56:57 -0800 Subject: [PATCH] rename to hasAppBackup --- pkg/kotsadmsnapshot/backup.go | 12 ++++---- pkg/kotsadmsnapshot/backup_test.go | 48 +++++++++++++++--------------- 2 files changed, 30 insertions(+), 30 deletions(-) diff --git a/pkg/kotsadmsnapshot/backup.go b/pkg/kotsadmsnapshot/backup.go index 7c56140acf..bb7fd1284d 100644 --- a/pkg/kotsadmsnapshot/backup.go +++ b/pkg/kotsadmsnapshot/backup.go @@ -451,7 +451,7 @@ func getECInstanceBackupMetadata(ctx context.Context, ctrlClient ctrlclient.Clie // getInfrastructureInstanceBackupSpec returns the velero backup spec for the instance backup. This // is either the kotsadm backup or the legacy backup if this is not using improved DR. -func getInfrastructureInstanceBackupSpec(ctx context.Context, k8sClient kubernetes.Interface, metadata instanceBackupMetadata, hasAppBackupSpec bool) (*velerov1.Backup, error) { +func getInfrastructureInstanceBackupSpec(ctx context.Context, k8sClient kubernetes.Interface, metadata instanceBackupMetadata, hasAppBackup bool) (*velerov1.Backup, error) { // veleroBackup is the kotsadm backup or legacy backup if usesImprovedDR is false veleroBackup := &velerov1.Backup{ ObjectMeta: metav1.ObjectMeta{ @@ -493,7 +493,7 @@ func getInfrastructureInstanceBackupSpec(ctx context.Context, k8sClient kubernet for _, appMeta := range metadata.apps { // Don't merge the backup spec if we are using the new improved DR. - if !hasAppBackupSpec { + if !hasAppBackup { err := mergeAppBackupSpec(veleroBackup, appMeta, metadata.kotsadmNamespace, metadata.ec != nil) if err != nil { return nil, errors.Wrap(err, "failed to merge app backup spec") @@ -501,7 +501,7 @@ func getInfrastructureInstanceBackupSpec(ctx context.Context, k8sClient kubernet } } - veleroBackup.Annotations, err = appendCommonAnnotations(k8sClient, veleroBackup.Annotations, metadata, hasAppBackupSpec) + veleroBackup.Annotations, err = appendCommonAnnotations(k8sClient, veleroBackup.Annotations, metadata, hasAppBackup) if err != nil { return nil, errors.Wrap(err, "failed to add annotations to backup") } @@ -510,7 +510,7 @@ func getInfrastructureInstanceBackupSpec(ctx context.Context, k8sClient kubernet veleroBackup.Labels = map[string]string{} } veleroBackup.Labels[InstanceBackupNameLabel] = metadata.backupName - if hasAppBackupSpec { + if hasAppBackup { veleroBackup.Annotations[InstanceBackupTypeAnnotation] = InstanceBackupTypeInfra } else { veleroBackup.Annotations[InstanceBackupTypeAnnotation] = InstanceBackupTypeLegacy @@ -662,7 +662,7 @@ func mergeAppBackupSpec(backup *velerov1.Backup, appMeta appInstanceBackupMetada } // appendCommonAnnotations appends common annotations to the backup annotations -func appendCommonAnnotations(k8sClient kubernetes.Interface, annotations map[string]string, metadata instanceBackupMetadata, hasAppBackupSpec bool) (map[string]string, error) { +func appendCommonAnnotations(k8sClient kubernetes.Interface, annotations map[string]string, metadata instanceBackupMetadata, hasAppBackup bool) (map[string]string, error) { kotsadmImage, err := k8sutil.FindKotsadmImage(k8sClient, metadata.kotsadmNamespace) if err != nil { return nil, errors.Wrap(err, "failed to find kotsadm image") @@ -696,7 +696,7 @@ func appendCommonAnnotations(k8sClient kubernetes.Interface, annotations map[str marshalledAppVersions := string(b) numBackups := 1 - if hasAppBackupSpec { + if hasAppBackup { numBackups = 2 } diff --git a/pkg/kotsadmsnapshot/backup_test.go b/pkg/kotsadmsnapshot/backup_test.go index 84a2d3ac90..3ef6597ab6 100644 --- a/pkg/kotsadmsnapshot/backup_test.go +++ b/pkg/kotsadmsnapshot/backup_test.go @@ -957,10 +957,10 @@ func Test_appendCommonAnnotations(t *testing.T) { } type args struct { - k8sClient kubernetes.Interface - annotations map[string]string - metadata instanceBackupMetadata - hasAppBackupSpec bool + k8sClient kubernetes.Interface + annotations map[string]string + metadata instanceBackupMetadata + hasAppBackup bool } tests := []struct { name string @@ -1010,7 +1010,7 @@ func Test_appendCommonAnnotations(t *testing.T) { snapshotTTL: 24 * time.Hour, ec: nil, }, - hasAppBackupSpec: false, + hasAppBackup: false, }, want: map[string]string{ "kots.io/apps-sequences": "{\"app-1\":1,\"app-2\":2}", @@ -1075,7 +1075,7 @@ func Test_appendCommonAnnotations(t *testing.T) { seaweedFSS3ServiceIP: "10.96.0.10", }, }, - hasAppBackupSpec: true, + hasAppBackup: true, }, want: map[string]string{ "kots.io/apps-sequences": "{\"app-1\":1}", @@ -1106,7 +1106,7 @@ func Test_appendCommonAnnotations(t *testing.T) { if tt.setup != nil { tt.setup(t) } - got, err := appendCommonAnnotations(tt.args.k8sClient, tt.args.annotations, tt.args.metadata, tt.args.hasAppBackupSpec) + got, err := appendCommonAnnotations(tt.args.k8sClient, tt.args.annotations, tt.args.metadata, tt.args.hasAppBackup) if tt.wantErr { require.Error(t, err) } else { @@ -2080,9 +2080,9 @@ func Test_getInfrastructureInstanceBackupSpec(t *testing.T) { } type args struct { - k8sClient kubernetes.Interface - metadata instanceBackupMetadata - hasAppBackupSpec bool + k8sClient kubernetes.Interface + metadata instanceBackupMetadata + hasAppBackup bool } tests := []struct { name string @@ -2112,7 +2112,7 @@ func Test_getInfrastructureInstanceBackupSpec(t *testing.T) { isScheduled: true, ec: nil, }, - hasAppBackupSpec: false, + hasAppBackup: false, }, assert: func(t *testing.T, got *velerov1.Backup, err error) { require.NoError(t, err) @@ -2148,7 +2148,7 @@ func Test_getInfrastructureInstanceBackupSpec(t *testing.T) { isScheduled: true, ec: nil, }, - hasAppBackupSpec: false, + hasAppBackup: false, }, assert: func(t *testing.T, got *velerov1.Backup, err error) { require.NoError(t, err) @@ -2183,7 +2183,7 @@ func Test_getInfrastructureInstanceBackupSpec(t *testing.T) { isScheduled: true, ec: nil, }, - hasAppBackupSpec: false, + hasAppBackup: false, }, assert: func(t *testing.T, got *velerov1.Backup, err error) { require.NoError(t, err) @@ -2212,7 +2212,7 @@ func Test_getInfrastructureInstanceBackupSpec(t *testing.T) { isScheduled: true, ec: nil, }, - hasAppBackupSpec: false, + hasAppBackup: false, }, assert: func(t *testing.T, got *velerov1.Backup, err error) { require.NoError(t, err) @@ -2256,7 +2256,7 @@ func Test_getInfrastructureInstanceBackupSpec(t *testing.T) { isScheduled: true, ec: nil, }, - hasAppBackupSpec: false, + hasAppBackup: false, }, assert: func(t *testing.T, got *velerov1.Backup, err error) { require.NoError(t, err) @@ -2288,7 +2288,7 @@ func Test_getInfrastructureInstanceBackupSpec(t *testing.T) { isScheduled: true, ec: ecMeta, }, - hasAppBackupSpec: false, + hasAppBackup: false, }, assert: func(t *testing.T, got *velerov1.Backup, err error) { require.NoError(t, err) @@ -2321,7 +2321,7 @@ func Test_getInfrastructureInstanceBackupSpec(t *testing.T) { isScheduled: true, ec: ecMeta, }, - hasAppBackupSpec: true, + hasAppBackup: true, }, assert: func(t *testing.T, got *velerov1.Backup, err error) { require.NoError(t, err) @@ -2356,7 +2356,7 @@ func Test_getInfrastructureInstanceBackupSpec(t *testing.T) { isScheduled: true, ec: ecMeta, }, - hasAppBackupSpec: false, + hasAppBackup: false, }, assert: func(t *testing.T, got *velerov1.Backup, err error) { require.NoError(t, err) @@ -2388,7 +2388,7 @@ func Test_getInfrastructureInstanceBackupSpec(t *testing.T) { isScheduled: true, ec: ecMeta, }, - hasAppBackupSpec: false, + hasAppBackup: false, }, assert: func(t *testing.T, got *velerov1.Backup, err error) { require.NoError(t, err) @@ -2421,7 +2421,7 @@ func Test_getInfrastructureInstanceBackupSpec(t *testing.T) { snapshotTTL: 24 * time.Hour, ec: ecMeta, }, - hasAppBackupSpec: false, + hasAppBackup: false, }, assert: func(t *testing.T, got *velerov1.Backup, err error) { require.NoError(t, err) @@ -2453,7 +2453,7 @@ func Test_getInfrastructureInstanceBackupSpec(t *testing.T) { isScheduled: true, ec: ecMeta, }, - hasAppBackupSpec: false, + hasAppBackup: false, }, assert: func(t *testing.T, got *velerov1.Backup, err error) { require.NoError(t, err) @@ -2485,7 +2485,7 @@ func Test_getInfrastructureInstanceBackupSpec(t *testing.T) { isScheduled: true, ec: ecMeta, }, - hasAppBackupSpec: false, + hasAppBackup: false, }, assert: func(t *testing.T, got *velerov1.Backup, err error) { require.NoError(t, err) @@ -2523,7 +2523,7 @@ func Test_getInfrastructureInstanceBackupSpec(t *testing.T) { isScheduled: true, ec: ecMeta, }, - hasAppBackupSpec: false, + hasAppBackup: false, }, assert: func(t *testing.T, got *velerov1.Backup, err error) { require.NoError(t, err) @@ -2546,7 +2546,7 @@ func Test_getInfrastructureInstanceBackupSpec(t *testing.T) { if tt.setup != nil { tt.setup(t, mockStore) } - got, err := getInfrastructureInstanceBackupSpec(context.Background(), tt.args.k8sClient, tt.args.metadata, tt.args.hasAppBackupSpec) + got, err := getInfrastructureInstanceBackupSpec(context.Background(), tt.args.k8sClient, tt.args.metadata, tt.args.hasAppBackup) tt.assert(t, got, err) }) }