Skip to content

Commit

Permalink
Merge pull request vmware-tanzu#7697 from blackpiglet/backup_volumein…
Browse files Browse the repository at this point in the history
…fo_cli_update

Modify namespace filter logic for backup with label selector
  • Loading branch information
blackpiglet authored Apr 22, 2024
2 parents 9d66438 + 884bcbe commit 5f9c53a
Show file tree
Hide file tree
Showing 20 changed files with 613 additions and 154 deletions.
14 changes: 11 additions & 3 deletions .github/workflows/pr-linter-check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,16 @@ jobs:
runs-on: ubuntu-latest
steps:

- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: '1.22'

- name: Check out the code
uses: actions/checkout@v2
uses: actions/checkout@v4

- name: Linter check
run: make lint
- name: golangci-lint
uses: golangci/golangci-lint-action@v4
with:
version: v1.57.2
args: --out-format=colored-line-number
25 changes: 12 additions & 13 deletions golangci.yaml → .golangci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,6 @@ run:
# exit code when at least one issue was found, default is 1
issues-exit-code: 1

# which dirs to skip: issues from them won't be reported;
# can use regexp here: generated.*, regexp is applied on full path;
# default value is empty list, but default dirs are skipped independently
# from this option's value (see skip-dirs-use-default).
# "/" will be replaced by current OS file path separator to properly work
# on Windows.
skip-dirs:
- pkg/plugin/generated/*

# default is true. Enables skipping of directories:
# vendor$, third_party$, testdata$, examples$, Godeps$, builtin$
Expand All @@ -44,7 +36,7 @@ run:
# output configuration options
output:
# colored-line-number|line-number|json|tab|checkstyle|code-climate, default is "colored-line-number"
format: colored-line-number
formats: colored-line-number

# print lines of code with issue, default is true
print-issued-lines: true
Expand Down Expand Up @@ -148,10 +140,8 @@ linters-settings:
# minimal confidence for issues, default is 0.8
min-confidence: 0.8
gomnd:
settings:
mnd:
# the list of enabled checks, see https://github.com/tommy-muehle/go-mnd/#checks for description.
checks: argument,case,condition,operation,return,assign
# the list of enabled checks, see https://github.com/tommy-muehle/go-mnd/#checks for description.
checks: argument,case,condition,operation,return,assign
gomodguard:
allowed:
modules: # List of allowed modules
Expand Down Expand Up @@ -389,6 +379,15 @@ issues:
# Show only new issues created after git revision `REV`
# new-from-rev: origin/main

# which dirs to skip: issues from them won't be reported;
# can use regexp here: generated.*, regexp is applied on full path;
# default value is empty list, but default dirs are skipped independently
# from this option's value (see skip-dirs-use-default).
# "/" will be replaced by current OS file path separator to properly work
# on Windows.
exclude-dirs:
- pkg/plugin/generated/*

severity:
# Default value is empty string.
# Set the default severity for issues. If severity rules are defined and the issues
Expand Down
1 change: 1 addition & 0 deletions changelogs/unreleased/7697-blackpiglet
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
When Included/ExcludedNamespaces are omitted, and LabelSelector or OrLabelSelector is used, namespaces without selected items are excluded from backup.
2 changes: 1 addition & 1 deletion hack/build-image/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ RUN ARCH=$(go env GOARCH) && \
chmod +x /usr/bin/goreleaser

# get golangci-lint
RUN curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.55.0
RUN curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin v1.57.2

# install kubectl
RUN curl -LO https://storage.googleapis.com/kubernetes-release/release/$(curl -s https://storage.googleapis.com/kubernetes-release/release/stable.txt)/bin/linux/$(go env GOARCH)/kubectl
Expand Down
4 changes: 1 addition & 3 deletions hack/lint.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,12 @@
# See the License for the specific language governing permissions and
# limitations under the License.

HACK_DIR=$(dirname "${BASH_SOURCE[0]}")

# Printing out cache status
golangci-lint cache status

# Enable GL_DEBUG line below for debug messages for golangci-lint
# export GL_DEBUG=loader,gocritic,env
CMD="golangci-lint run -c $HACK_DIR/../golangci.yaml"
CMD="golangci-lint run"
echo "Running $CMD"

eval $CMD
2 changes: 1 addition & 1 deletion internal/hook/item_hook_handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1976,7 +1976,7 @@ func TestValidateContainer(t *testing.T) {
expectedError := fmt.Errorf("invalid InitContainer in restore hook, it doesn't have Command, Name or Image field")

// valid string should return nil as result.
assert.Equal(t, nil, ValidateContainer([]byte(valid)))
assert.Nil(t, ValidateContainer([]byte(valid)))

// noName string should return expected error as result.
assert.Equal(t, expectedError, ValidateContainer([]byte(noName)))
Expand Down
30 changes: 22 additions & 8 deletions pkg/backup/backup_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4327,19 +4327,14 @@ func TestBackupNamespaces(t *testing.T) {
"resources/namespaces/v1-preferredversion/cluster/ns-1.json",
"resources/deployments.apps/namespaces/ns-1/deploy-1.json",
"resources/deployments.apps/v1-preferredversion/namespaces/ns-1/deploy-1.json",
"resources/namespaces/cluster/ns-2.json",
"resources/namespaces/v1-preferredversion/cluster/ns-2.json",
"resources/namespaces/cluster/ns-3.json",
"resources/namespaces/v1-preferredversion/cluster/ns-3.json",
},
},
{
name: "OrLabelSelector test",
backup: defaultBackup().OrLabelSelector([]*metav1.LabelSelector{
{MatchLabels: map[string]string{"a": "b"}},
{MatchLabels: map[string]string{"c": "d"}},
}).
Result(),
}).Result(),
apiResources: []*test.APIResource{
test.Namespaces(
builder.ForNamespace("ns-1").Result(),
Expand All @@ -4356,8 +4351,6 @@ func TestBackupNamespaces(t *testing.T) {
"resources/namespaces/v1-preferredversion/cluster/ns-1.json",
"resources/namespaces/cluster/ns-2.json",
"resources/namespaces/v1-preferredversion/cluster/ns-2.json",
"resources/namespaces/cluster/ns-3.json",
"resources/namespaces/v1-preferredversion/cluster/ns-3.json",
"resources/deployments.apps/namespaces/ns-1/deploy-1.json",
"resources/deployments.apps/v1-preferredversion/namespaces/ns-1/deploy-1.json",
"resources/deployments.apps/namespaces/ns-2/deploy-2.json",
Expand Down Expand Up @@ -4385,6 +4378,27 @@ func TestBackupNamespaces(t *testing.T) {
"resources/deployments.apps/v1-preferredversion/namespaces/ns-1/deploy-1.json",
},
},
{
name: "LabelSelector and Namespace exclude filtering test",
backup: defaultBackup().ExcludedNamespaces("ns-1", "ns-2").LabelSelector(&metav1.LabelSelector{MatchLabels: map[string]string{"a": "b"}}).
Result(),
apiResources: []*test.APIResource{
test.Namespaces(
builder.ForNamespace("ns-1").ObjectMeta(builder.WithLabels("a", "b")).Result(),
builder.ForNamespace("ns-2").Result(),
builder.ForNamespace("ns-3").Result(),
),
test.Deployments(
builder.ForDeployment("ns-1", "deploy-1").ObjectMeta(builder.WithLabels("a", "b")).Result(),
),
},
want: []string{
"resources/namespaces/cluster/ns-1.json",
"resources/namespaces/v1-preferredversion/cluster/ns-1.json",
"resources/namespaces/cluster/ns-3.json",
"resources/namespaces/v1-preferredversion/cluster/ns-3.json",
},
},
{
name: "Empty namespace test",
backup: defaultBackup().IncludedNamespaces("invalid*").Result(),
Expand Down
Loading

0 comments on commit 5f9c53a

Please sign in to comment.