Repository: kubernetes-sigs/azurefile-csi-driver
Pull request #2403 (2025-03-04 09:36:22)

fix: incomplete azcopy job state during volume snapshot restore and clone
<!--  Thanks for sending a pull request!  Here are some tips for you:

1. If this is your first time, please read our contributor guidelines: https://git.k8s.io/community/contributors/guide#your-first-contribution and developer guide https://git.k8s.io/community/contributors/devel/development.md#development-guide
2. Please label this pull request according to what type of issue you are addressing, especially if this is a release targeted pull request. For reference on required PR/issue labels, read here:
https://git.k8s.io/community/contributors/devel/release.md#issue-kind-label
3. Ensure you have added or ran the appropriate tests for your PR: https://git.k8s.io/community/contributors/devel/testing.md
4. If you want *faster* PR reviews, read how: https://git.k8s.io/community/contributors/guide/pull-requests.md#best-practices-for-faster-reviews
5. Follow the instructions for writing a release note: https://git.k8s.io/community/contributors/guide/release-notes.md
6. If the PR is unfinished, see how to mark it: https://git.k8s.io/community/contributors/guide/pull-requests.md#marking-unfinished-pull-requests
-->

**What type of PR is this?**
/kind bug

**What this PR does / why we need it**:
fix: incomplete azcopy job state during volume snapshot restore and clone

**Which issue(s) this PR fixes**:
<!-- 
*Automatically closes linked issue when PR is merged.
Usage: `Fixes #<issue number>`, or `Fixes (paste link of issue)`.
_If PR is about `failing-tests or flakes`, please post the related issues/tests in a comment and do not use `Fixes`_*
-->
Fixes #

**Requirements**:
- [ ] uses [conventional commit messages](https://www.conventionalcommits.org/)
  <!-- Common commit types:
        build: Build 🏭
        chore: Maintenance 🔧
        ci: Continuous Integration 💜
        docs: Documentation 📘
        feat: Features 🌈
        fix: Bug Fixes 🐞
        perf: Performance Improvements 🚀
        refactor: Code Refactoring 💎
        revert: Revert Change ◀️
        style: Code Style 🎶
        security: Security Fix 🛡️
        test: Testing 💚 -->
- [ ] includes documentation
- [ ] adds unit tests
- [ ] tested upgrade from previous version

**Special notes for your reviewer**:


**Release note**:
```
fix: incomplete azcopy job state during volume snapshot restore and clone
```


k8s-ci-robot: [APPROVALNOTIFIER] This PR is **APPROVED**

This pull-request has been approved by: *<a href="https://github.com/kubernetes-sigs/azurefile-csi-driver/pull/2403#" title="Author self-approved">andyzhangx</a>*

The full list of commands accepted by this bot can be found [here](https://go.k8s.io/bot-commands?repo=kubernetes-sigs%2Fazurefile-csi-driver).

The pull request process is described [here](https://git.k8s.io/community/contributors/guide/owners.md#the-code-review-process)

<details >
Needs approval from an approver in each of these files:

- ~~[OWNERS](https://github.com/kubernetes-sigs/azurefile-csi-driver/blob/master/OWNERS)~~ [andyzhangx]

Approvers can indicate their approval by writing `/approve` in a comment
Approvers can cancel approval by writing `/approve cancel` in a comment
</details>
<!-- META={"approvers":[]} -->

Patch:
diff --git a/pkg/util/util.go b/pkg/util/util.go
index 416e9fce4..30f681713 100644
--- a/pkg/util/util.go
+++ b/pkg/util/util.go
@@ -121,7 +121,7 @@ func (ac *Azcopy) GetAzcopyJob(dstFileshare string, authAzcopyEnv []string) (Azc
 		klog.Warningf("failed to get azcopy job with error: %v, jobState: %v", err, jobState)
 		return AzcopyJobError, "", fmt.Errorf("couldn't parse azcopy job list in azcopy %v", err)
 	}
-	if jobState == AzcopyJobCompleted {
+	if jobState == AzcopyJobCompleted || jobState == AzcopyJobCompletedWithErrors || jobState == AzcopyJobCompletedWithSkipped || jobState == AzcopyJobCompletedWithErrorsAndSkipped {
 		return jobState, "100.0", err
 	}
 	if jobid == "" {
@@ -170,6 +170,12 @@ func parseAzcopyJobList(joblist string) (string, AzcopyJobState, error) {
 			jobid = segments[0]
 		case "Completed":
 			return jobid, AzcopyJobCompleted, nil
+		case "CompletedWithErrors":
+			return jobid, AzcopyJobCompletedWithErrors, nil
+		case "CompletedWithSkipped":
+			return jobid, AzcopyJobCompletedWithSkipped, nil
+		case "CompletedWithErrorsAndSkipped":
+			return jobid, AzcopyJobCompletedWithErrorsAndSkipped, nil
 		}
 	}
 	if jobid == "" {


Test patch:
diff --git a/pkg/util/util_test.go b/pkg/util/util_test.go
index 0e7c6417e..ec93c1126 100644
--- a/pkg/util/util_test.go
+++ b/pkg/util/util_test.go
@@ -116,6 +116,39 @@ func TestGetAzcopyJob(t *testing.T) {
 			expectedPercent:  "100.0",
 			expectedErr:      nil,
 		},
+		{
+			desc:             "run exec parse azcopy job CompletedWithErrors",
+			listStr:          "JobId: ed1c3833-eaff-fe42-71d7-513fb065a9d9\nStart Time: Monday, 07-Aug-23 03:29:54 UTC\nStatus: CompletedWithErrors\nCommand: copy https://{accountName}.file.core.windows.net/{srcFileshare}{SAStoken} https://{accountName}.file.core.windows.net/{dstFileshare}{SAStoken} --recursive --check-length=false",
+			listErr:          nil,
+			enableShow:       false,
+			showStr:          "",
+			showErr:          nil,
+			expectedJobState: AzcopyJobCompletedWithErrors,
+			expectedPercent:  "100.0",
+			expectedErr:      nil,
+		},
+		{
+			desc:             "run exec parse azcopy job CompletedWithSkipped",
+			listStr:          "JobId: ed1c3833-eaff-fe42-71d7-513fb065a9d9\nStart Time: Monday, 07-Aug-23 03:29:54 UTC\nStatus: CompletedWithSkipped\nCommand: copy https://{accountName}.file.core.windows.net/{srcFileshare}{SAStoken} https://{accountName}.file.core.windows.net/{dstFileshare}{SAStoken} --recursive --check-length=false",
+			listErr:          nil,
+			enableShow:       false,
+			showStr:          "",
+			showErr:          nil,
+			expectedJobState: AzcopyJobCompletedWithSkipped,
+			expectedPercent:  "100.0",
+			expectedErr:      nil,
+		},
+		{
+			desc:             "run exec parse azcopy job CompletedWithErrorsAndSkipped",
+			listStr:          "JobId: ed1c3833-eaff-fe42-71d7-513fb065a9d9\nStart Time: Monday, 07-Aug-23 03:29:54 UTC\nStatus: CompletedWithErrorsAndSkipped\nCommand: copy https://{accountName}.file.core.windows.net/{srcFileshare}{SAStoken} https://{accountName}.file.core.windows.net/{dstFileshare}{SAStoken} --recursive --check-length=false",
+			listErr:          nil,
+			enableShow:       false,
+			showStr:          "",
+			showErr:          nil,
+			expectedJobState: AzcopyJobCompletedWithErrorsAndSkipped,
+			expectedPercent:  "100.0",
+			expectedErr:      nil,
+		},
 		{
 			desc:             "run exec get error in azcopy jobs show",
 			listStr:          "JobId: ed1c3833-eaff-fe42-71d7-513fb065a9d9\nStart Time: Monday, 07-Aug-23 03:29:54 UTC\nStatus: InProgress\nCommand: copy https://{accountName}.file.core.windows.net/{srcFileshare}{SAStoken} https://{accountName}.file.core.windows.net/{dstFileshare}{SAStoken} --recursive --check-length=false",
@@ -248,6 +281,27 @@ func TestParseAzcopyJobList(t *testing.T) {
 			expectedJobState: AzcopyJobCompleted,
 			expectedErr:      nil,
 		},
+		{
+			desc:             "parse azcopy job CompletedWithErrors",
+			str:              "JobId: ed1c3833-eaff-fe42-71d7-513fb065a9d9\nStart Time: Monday, 07-Aug-23 03:29:54 UTC\nStatus: CompletedWithErrors\nCommand: copy https://{accountName}.file.core.windows.net/{srcFileshare}{SAStoken} https://{accountName}.file.core.windows.net/{dstFileshare}{SAStoken} --recursive --check-length=false",
+			expectedJobid:    "",
+			expectedJobState: AzcopyJobCompletedWithErrors,
+			expectedErr:      nil,
+		},
+		{
+			desc:             "parse azcopy job CompletedWithSkipped",
+			str:              "JobId: ed1c3833-eaff-fe42-71d7-513fb065a9d9\nStart Time: Monday, 07-Aug-23 03:29:54 UTC\nStatus: CompletedWithSkipped\nCommand: copy https://{accountName}.file.core.windows.net/{srcFileshare}{SAStoken} https://{accountName}.file.core.windows.net/{dstFileshare}{SAStoken} --recursive --check-length=false",
+			expectedJobid:    "",
+			expectedJobState: AzcopyJobCompletedWithSkipped,
+			expectedErr:      nil,
+		},
+		{
+			desc:             "parse azcopy job CompletedWithErrorsAndSkipped",
+			str:              "JobId: ed1c3833-eaff-fe42-71d7-513fb065a9d9\nStart Time: Monday, 07-Aug-23 03:29:54 UTC\nStatus: CompletedWithErrorsAndSkipped\nCommand: copy https://{accountName}.file.core.windows.net/{srcFileshare}{SAStoken} https://{accountName}.file.core.windows.net/{dstFileshare}{SAStoken} --recursive --check-length=false",
+			expectedJobid:    "",
+			expectedJobState: AzcopyJobCompletedWithErrorsAndSkipped,
+			expectedErr:      nil,
+		},
 		{
 			desc:             "parse azcopy job InProgress",
 			str:              "JobId: ed1c3833-eaff-fe42-71d7-513fb065a9d9\nStart Time: Monday, 07-Aug-23 03:29:54 UTC\nStatus: InProgress\nCommand: copy https://{accountName}.file.core.windows.net/{srcFileshare}{SAStoken} https://{accountName}.file.core.windows.net/{dstFileshare}{SAStoken} --recursive --check-length=false",