Skip to content

Commit

Permalink
Merge branch 'main' into issue-fix-7535
Browse files Browse the repository at this point in the history
  • Loading branch information
Lyndon-Li committed Mar 29, 2024
2 parents 070e99d + d640cc1 commit 026f776
Show file tree
Hide file tree
Showing 86 changed files with 1,761 additions and 147 deletions.
1 change: 1 addition & 0 deletions changelogs/unreleased/7451-qiuming-best
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add repository maintenance job
41 changes: 29 additions & 12 deletions golangci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,24 +19,12 @@ run:
# "/" will be replaced by current OS file path separator to properly work
# on Windows.
skip-dirs:
- test/*
- pkg/plugin/generated/*
# - autogenerated_by_my_lib

# default is true. Enables skipping of directories:
# vendor$, third_party$, testdata$, examples$, Godeps$, builtin$
skip-dirs-use-default: true

# which files to skip: they will be analyzed, but issues from them
# won't be reported. Default value is empty list, but there is
# no need to include all autogenerated files, we confidently recognize
# autogenerated files. If it's not please let us know.
# "/" will be replaced by current OS file path separator to properly work
# on Windows.
skip-files:
- ".*_test.go$"
# - lib/bad.go

# by default isn't set. If set we pass it to "go list -mod={option}". From "go help modules":
# If invoked with -mod=readonly, the go command is disallowed from the implicit
# automatic updating of go.mod described above. Instead, it fails when any changes
Expand Down Expand Up @@ -364,6 +352,35 @@ issues:
- linters:
- staticcheck
text: "DefaultVolumesToRestic" # No need to report deprecate for DefaultVolumesToRestic.
- path: ".*_test.go$"
linters:
- dupword
- errcheck
- ginkgolinter
- goconst
- gosec
- govet
- staticcheck
- stylecheck
- unconvert
- unparam
- unused
- path: test/
linters:
- bodyclose
- dupword
- errcheck
- goconst
- gosec
- gosimple
- ginkgolinter
- nilerr
- noctx
- staticcheck
- stylecheck
- unconvert
- unparam
- unused

# The list of ids of default excludes to include or disable. By default it's empty.
include:
Expand Down
1 change: 0 additions & 1 deletion internal/hook/hook_tracker_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,6 @@ func TestHookTracker_Record(t *testing.T) {

err = tracker.Record("ns2", "pod2", "container1", HookSourceAnnotation, "h1", PhasePre, true)
assert.NotNil(t, err)

}

func TestHookTracker_Stat(t *testing.T) {
Expand Down
2 changes: 0 additions & 2 deletions internal/hook/item_hook_handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2351,14 +2351,12 @@ func TestBackupHookTracker(t *testing.T) {
}
}
h.HandleHooks(velerotest.NewLogger(), groupResource, pod.item, pod.hooks, test.phase, hookTracker)

}
actualAtemptted, actualFailed := hookTracker.Stat()
assert.Equal(t, test.expectedHookAttempted, actualAtemptted)
assert.Equal(t, test.expectedHookFailed, actualFailed)
})
}

}

func TestRestoreHookTrackerAdd(t *testing.T) {
Expand Down
2 changes: 0 additions & 2 deletions internal/hook/wait_exec_hook_handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -710,7 +710,6 @@ func TestWaitExecHandleHooks(t *testing.T) {

for _, test := range tests {
t.Run(test.name, func(t *testing.T) {

source := fcache.NewFakeControllerSource()
go func() {
// This is the state of the pod that will be seen by the AddFunc handler.
Expand Down Expand Up @@ -1251,7 +1250,6 @@ func TestRestoreHookTrackerUpdate(t *testing.T) {

for _, test := range tests1 {
t.Run(test.name, func(t *testing.T) {

source := fcache.NewFakeControllerSource()
go func() {
// This is the state of the pod that will be seen by the AddFunc handler.
Expand Down
1 change: 0 additions & 1 deletion internal/resourcemodifiers/resource_modifiers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,6 @@ func TestGetResourceModifiersFromConfig(t *testing.T) {
}

func TestResourceModifiers_ApplyResourceModifierRules(t *testing.T) {

pvcStandardSc := &unstructured.Unstructured{
Object: map[string]interface{}{
"apiVersion": "v1",
Expand Down
3 changes: 0 additions & 3 deletions internal/resourcepolicies/volume_resources_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,6 @@ func TestCapacityIsInRange(t *testing.T) {
actual := test.capacity.isInRange(test.quantity)

assert.Equal(t, test.isInRange, actual)

})
}
}
Expand Down Expand Up @@ -141,7 +140,6 @@ func TestStorageClassConditionMatch(t *testing.T) {
}

func TestNFSConditionMatch(t *testing.T) {

tests := []struct {
name string
condition *nfsCondition
Expand Down Expand Up @@ -196,7 +194,6 @@ func TestNFSConditionMatch(t *testing.T) {
}

func TestCSIConditionMatch(t *testing.T) {

tests := []struct {
name string
condition *csiCondition
Expand Down
1 change: 0 additions & 1 deletion internal/velero/images_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,6 @@ func testDefaultImage(t *testing.T, defaultImageFn func() string, imageName stri
assert.Equal(t, tc.want, defaultImageFn())
})
}

}

func TestDefaultVeleroImage(t *testing.T) {
Expand Down
4 changes: 2 additions & 2 deletions pkg/backup/backup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,8 @@ func TestBackupProgressIsUpdated(t *testing.T) {
h.backupper.Backup(h.log, req, backupFile, nil, nil)

require.NotNil(t, req.Status.Progress)
assert.Equal(t, len(req.BackedUpItems), req.Status.Progress.TotalItems)
assert.Equal(t, len(req.BackedUpItems), req.Status.Progress.ItemsBackedUp)
assert.Len(t, req.BackedUpItems, req.Status.Progress.TotalItems)
assert.Len(t, req.BackedUpItems, req.Status.Progress.ItemsBackedUp)
}

// TestBackupResourceFiltering runs backups with different combinations
Expand Down
1 change: 0 additions & 1 deletion pkg/backup/item_collector_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -76,5 +76,4 @@ func TestSortOrderedResource(t *testing.T) {
}
sortedPvResources := sortResourcesByOrder(log, pvResources, pvOrder)
assert.Equal(t, sortedPvResources, expectedPvResources)

}
2 changes: 0 additions & 2 deletions pkg/backup/remap_crd_version_action_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,6 @@ func TestRemapCRDVersionAction(t *testing.T) {
// set it back to the default one
a.discoveryHelper = fakeDiscoveryHelper()
})

}

// TestRemapCRDVersionActionData tests the RemapCRDVersionAction plugin against actual CRD to confirm that the v1beta1 version is returned when the v1 version is passed in to the plugin.
Expand Down Expand Up @@ -217,7 +216,6 @@ func TestRemapCRDVersionActionData(t *testing.T) {
betaClient.Delete(context.TODO(), crd.Name, metav1.DeleteOptions{})
})
}

}

func fakeDiscoveryHelper() velerodiscovery.Helper {
Expand Down
2 changes: 0 additions & 2 deletions pkg/backup/service_account_action_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -400,7 +400,6 @@ func TestServiceAccountActionExecute(t *testing.T) {
assert.Equal(t, test.expectedAdditionalItems, additional)
})
}

}

func TestServiceAccountActionExecuteOnBeta1(t *testing.T) {
Expand Down Expand Up @@ -608,5 +607,4 @@ func TestServiceAccountActionExecuteOnBeta1(t *testing.T) {
assert.Equal(t, test.expectedAdditionalItems, additional)
})
}

}
1 change: 0 additions & 1 deletion pkg/buildinfo/buildinfo_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,5 +49,4 @@ func TestFormattedGitSHA(t *testing.T) {
assert.Equal(t, FormattedGitSHA(), test.expected)
})
}

}
1 change: 0 additions & 1 deletion pkg/client/config_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ func removeConfigfileName() error {
return nil
}
func TestConfigOperations(t *testing.T) {

preHomeEnv := ""
prevEnv := os.Environ()
for _, entry := range prevEnv {
Expand Down
2 changes: 0 additions & 2 deletions pkg/cmd/cli/backup/create_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,15 +148,13 @@ func TestCreateOptions_OrderedResources(t *testing.T) {
"persistentvolumes": "pv1,pv2",
}
assert.Equal(t, orderedResources, expectedMixedResources)

}

func TestCreateCommand(t *testing.T) {
name := "nameToBeCreated"
args := []string{name}

t.Run("create a backup create command with full options except fromSchedule and wait, then run by create option", func(t *testing.T) {

// create a factory
f := &factorymocks.Factory{}

Expand Down
4 changes: 2 additions & 2 deletions pkg/cmd/cli/backup/get_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ func TestNewGetCommand(t *testing.T) {
i++
}
}
assert.Equal(t, len(args), i)
assert.Len(t, args, i)
}

d := NewGetCommand(f, "velero backup get")
Expand All @@ -98,6 +98,6 @@ func TestNewGetCommand(t *testing.T) {
i++
}
}
assert.Equal(t, len(args), i)
assert.Len(t, args, i)
}
}
2 changes: 0 additions & 2 deletions pkg/cmd/cli/backuplocation/delete_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ import (
)

func TestNewDeleteCommand(t *testing.T) {

// create a factory
f := &factorymocks.Factory{}
kbclient := velerotest.NewFakeControllerRuntimeClient(t)
Expand Down Expand Up @@ -75,7 +74,6 @@ func TestNewDeleteCommand(t *testing.T) {
return
}
t.Fatalf("process ran with err %v, want backups by get()", err)

}
func TestDeleteFunctions(t *testing.T) {
//t.Run("create the other create command with fromSchedule option for Run() other branches", func(t *testing.T) {
Expand Down
11 changes: 11 additions & 0 deletions pkg/cmd/cli/install/install.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"strings"
"time"

"github.com/vmware-tanzu/velero/pkg/repository"
"github.com/vmware-tanzu/velero/pkg/uploader"

"github.com/pkg/errors"
Expand Down Expand Up @@ -84,6 +85,7 @@ type Options struct {
DefaultSnapshotMoveData bool
DisableInformerCache bool
ScheduleSkipImmediately bool
MaintenanceCfg repository.MaintenanceConfig
}

// BindFlags adds command line values to the options struct.
Expand Down Expand Up @@ -128,6 +130,11 @@ func (o *Options) BindFlags(flags *pflag.FlagSet) {
flags.BoolVar(&o.DefaultSnapshotMoveData, "default-snapshot-move-data", o.DefaultSnapshotMoveData, "Bool flag to configure Velero server to move data by default for all snapshots supporting data movement. Optional.")
flags.BoolVar(&o.DisableInformerCache, "disable-informer-cache", o.DisableInformerCache, "Disable informer cache for Get calls on restore. With this enabled, it will speed up restore in cases where there are backup resources which already exist in the cluster, but for very large clusters this will increase velero memory usage. Default is false (don't disable). Optional.")
flags.BoolVar(&o.ScheduleSkipImmediately, "schedule-skip-immediately", o.ScheduleSkipImmediately, "Skip the first scheduled backup immediately after creating a schedule. Default is false (don't skip).")
flags.IntVar(&o.MaintenanceCfg.KeepLatestMaitenanceJobs, "keep-latest-maintenance-jobs", o.MaintenanceCfg.KeepLatestMaitenanceJobs, "Number of latest maintenance jobs to keep each repository. Optional.")
flags.StringVar(&o.MaintenanceCfg.CPURequest, "maintenance-job-cpu-request", o.MaintenanceCfg.CPURequest, "CPU request for maintenance jobs. Default is no limit.")
flags.StringVar(&o.MaintenanceCfg.MemRequest, "maintenance-job-mem-request", o.MaintenanceCfg.MemRequest, "Memory request for maintenance jobs. Default is no limit.")
flags.StringVar(&o.MaintenanceCfg.CPULimit, "maintenance-job-cpu-limit", o.MaintenanceCfg.CPULimit, "CPU limit for maintenance jobs. Default is no limit.")
flags.StringVar(&o.MaintenanceCfg.MemLimit, "maintenance-job-mem-limit", o.MaintenanceCfg.MemLimit, "Memory limit for maintenance jobs. Default is no limit.")
}

// NewInstallOptions instantiates a new, default InstallOptions struct.
Expand Down Expand Up @@ -157,6 +164,9 @@ func NewInstallOptions() *Options {
DefaultSnapshotMoveData: false,
DisableInformerCache: false,
ScheduleSkipImmediately: false,
MaintenanceCfg: repository.MaintenanceConfig{
KeepLatestMaitenanceJobs: repository.DefaultKeepLatestMaitenanceJobs,
},
}
}

Expand Down Expand Up @@ -224,6 +234,7 @@ func (o *Options) AsVeleroOptions() (*install.VeleroOptions, error) {
DefaultSnapshotMoveData: o.DefaultSnapshotMoveData,
DisableInformerCache: o.DisableInformerCache,
ScheduleSkipImmediately: o.ScheduleSkipImmediately,
MaintenanceCfg: o.MaintenanceCfg,
}, nil
}

Expand Down
Loading

0 comments on commit 026f776

Please sign in to comment.