Skip to content

Commit

Permalink
rename to hasAppBackup
Browse files Browse the repository at this point in the history
  • Loading branch information
emosbaugh committed Dec 5, 2024
1 parent 29d5e55 commit a1170e3
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 30 deletions.
12 changes: 6 additions & 6 deletions pkg/kotsadmsnapshot/backup.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{
Expand Down Expand Up @@ -493,15 +493,15 @@ 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")
}
}
}

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")
}
Expand All @@ -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
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -696,7 +696,7 @@ func appendCommonAnnotations(k8sClient kubernetes.Interface, annotations map[str
marshalledAppVersions := string(b)

numBackups := 1
if hasAppBackupSpec {
if hasAppBackup {
numBackups = 2
}

Expand Down
48 changes: 24 additions & 24 deletions pkg/kotsadmsnapshot/backup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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}",
Expand Down Expand Up @@ -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}",
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand All @@ -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)
})
}
Expand Down

0 comments on commit a1170e3

Please sign in to comment.