Repository: GoogleContainerTools/skaffold
Pull request #8979 (2023-07-31 06:18:24)

fix: remote kustomize manifest being watched
<!-- Thank you for your contribution! -->

<!-- Include if applicable: -->
Fixes: #8976 <!-- tracking issues that this PR will close -->


**Description**
 - kustomize patch can be a url, skaffold should not watch a remote resource 


codecov[bot]: ## [Codecov](https://app.codecov.io/gh/GoogleContainerTools/skaffold/pull/8979?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=GoogleContainerTools) Report
> Merging [#8979](https://app.codecov.io/gh/GoogleContainerTools/skaffold/pull/8979?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=GoogleContainerTools) (4f4d57e) into [main](https://app.codecov.io/gh/GoogleContainerTools/skaffold/commit/290280e8c6c19231e9ed5b5c027f2c01d22f75be?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=GoogleContainerTools) (290280e) will **decrease** coverage by `6.84%`.
> Report is 985 commits behind head on main.
> The diff coverage is `49.80%`.

```diff
@@            Coverage Diff             @@
##             main    #8979      +/-   ##
==========================================
- Coverage   70.48%   63.64%   -6.84%     
==========================================
  Files         515      624     +109     
  Lines       23150    31941    +8791     
==========================================
+ Hits        16317    20330    +4013     
- Misses       5776    10081    +4305     
- Partials     1057     1530     +473     
```


| [Files Changed](https://app.codecov.io/gh/GoogleContainerTools/skaffold/pull/8979?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=GoogleContainerTools) | Coverage Δ | |
|---|---|---|
| [cmd/skaffold/app/cmd/completion.go](https://app.codecov.io/gh/GoogleContainerTools/skaffold/pull/8979?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=GoogleContainerTools#diff-Y21kL3NrYWZmb2xkL2FwcC9jbWQvY29tcGxldGlvbi5nbw==) | `13.04% <0.00%> (-1.25%)` | :arrow_down: |
| [cmd/skaffold/app/cmd/config/list.go](https://app.codecov.io/gh/GoogleContainerTools/skaffold/pull/8979?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=GoogleContainerTools#diff-Y21kL3NrYWZmb2xkL2FwcC9jbWQvY29uZmlnL2xpc3QuZ28=) | `65.21% <ø> (ø)` | |
| [cmd/skaffold/app/cmd/config/set.go](https://app.codecov.io/gh/GoogleContainerTools/skaffold/pull/8979?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=GoogleContainerTools#diff-Y21kL3NrYWZmb2xkL2FwcC9jbWQvY29uZmlnL3NldC5nbw==) | `88.72% <ø> (ø)` | |
| [cmd/skaffold/app/cmd/config/util.go](https://app.codecov.io/gh/GoogleContainerTools/skaffold/pull/8979?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=GoogleContainerTools#diff-Y21kL3NrYWZmb2xkL2FwcC9jbWQvY29uZmlnL3V0aWwuZ28=) | `54.28% <ø> (ø)` | |
| [cmd/skaffold/app/cmd/credits.go](https://app.codecov.io/gh/GoogleContainerTools/skaffold/pull/8979?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=GoogleContainerTools#diff-Y21kL3NrYWZmb2xkL2FwcC9jbWQvY3JlZGl0cy5nbw==) | `100.00% <ø> (ø)` | |
| [cmd/skaffold/app/cmd/credits/export.go](https://app.codecov.io/gh/GoogleContainerTools/skaffold/pull/8979?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=GoogleContainerTools#diff-Y21kL3NrYWZmb2xkL2FwcC9jbWQvY3JlZGl0cy9leHBvcnQuZ28=) | `0.00% <0.00%> (ø)` | |
| [cmd/skaffold/app/cmd/deploy.go](https://app.codecov.io/gh/GoogleContainerTools/skaffold/pull/8979?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=GoogleContainerTools#diff-Y21kL3NrYWZmb2xkL2FwcC9jbWQvZGVwbG95Lmdv) | `40.90% <0.00%> (-12.94%)` | :arrow_down: |
| [cmd/skaffold/app/cmd/generate\_pipeline.go](https://app.codecov.io/gh/GoogleContainerTools/skaffold/pull/8979?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=GoogleContainerTools#diff-Y21kL3NrYWZmb2xkL2FwcC9jbWQvZ2VuZXJhdGVfcGlwZWxpbmUuZ28=) | `60.00% <ø> (ø)` | |
| [cmd/skaffold/app/cmd/inspect\_modules.go](https://app.codecov.io/gh/GoogleContainerTools/skaffold/pull/8979?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=GoogleContainerTools#diff-Y21kL3NrYWZmb2xkL2FwcC9jbWQvaW5zcGVjdF9tb2R1bGVzLmdv) | `65.00% <ø> (ø)` | |
| [cmd/skaffold/app/cmd/inspect\_profiles.go](https://app.codecov.io/gh/GoogleContainerTools/skaffold/pull/8979?src=pr&el=tree&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=GoogleContainerTools#diff-Y21kL3NrYWZmb2xkL2FwcC9jbWQvaW5zcGVjdF9wcm9maWxlcy5nbw==) | `66.66% <ø> (ø)` | |
| ... and [40 more](https://app.codecov.io/gh/GoogleContainerTools/skaffold/pull/8979?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=GoogleContainerTools) | |

... and [415 files with indirect coverage changes](https://app.codecov.io/gh/GoogleContainerTools/skaffold/pull/8979/indirect-changes?src=pr&el=tree-more&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=GoogleContainerTools)

:mega: We’re building smart automated test selection to slash your CI/CD build times. [Learn more](https://about.codecov.io/iterative-testing/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=GoogleContainerTools)


Patch:
diff --git a/pkg/skaffold/render/renderer/kustomize/kustomize.go b/pkg/skaffold/render/renderer/kustomize/kustomize.go
index 624d8fcc1..b64d33820 100644
--- a/pkg/skaffold/render/renderer/kustomize/kustomize.go
+++ b/pkg/skaffold/render/renderer/kustomize/kustomize.go
@@ -479,12 +479,20 @@ func DependenciesForKustomization(dir string) ([]string, error) {
 
 	for _, patch := range content.Patches {
 		if patch.Path != "" {
+			local, _ := pathExistsLocally(patch.Path, dir)
+			if !local {
+				continue
+			}
 			deps = append(deps, filepath.Join(dir, patch.Path))
 		}
 	}
 
 	for _, jsonPatch := range content.PatchesJson6902 {
 		if jsonPatch.Path != "" {
+			local, _ := pathExistsLocally(jsonPatch.Path, dir)
+			if !local {
+				continue
+			}
 			deps = append(deps, filepath.Join(dir, jsonPatch.Path))
 		}
 	}


Test patch:
diff --git a/pkg/skaffold/deploy/kubectl/kustomize_test.go b/pkg/skaffold/deploy/kubectl/kustomize_test.go
index 499186ae7..24ca3567c 100644
--- a/pkg/skaffold/deploy/kubectl/kustomize_test.go
+++ b/pkg/skaffold/deploy/kubectl/kustomize_test.go
@@ -266,6 +266,9 @@ func TestDependenciesForKustomization(t *testing.T) {
 - path: patch1.yaml
   target:
     kind: Deployment`},
+			createFiles: map[string]string{
+				"patch1.yaml": "",
+			},
 			expected: []string{"kustomization.yaml", "patch1.yaml"},
 		},
 		{
@@ -282,8 +285,19 @@ func TestDependenciesForKustomization(t *testing.T) {
 			kustomizations: map[string]string{"kustomization.yaml": `patches: 
 - path: patch1.yaml 
 - path: path/patch2.yaml`},
+			createFiles: map[string]string{
+				"patch1.yaml":      "",
+				"path/patch2.yaml": "",
+			},
 			expected: []string{"kustomization.yaml", "patch1.yaml", "path/patch2.yaml"},
 		},
+		{
+			description: "ignore patches legacy, path doesn't exist",
+			kustomizations: map[string]string{"kustomization.yaml": `patches: 
+- path: patch1.yaml 
+- path: path/patch2.yaml`},
+			expected: []string{"kustomization.yaml"},
+		},
 		{
 			description:    "patchesStrategicMerge",
 			kustomizations: map[string]string{"kustomization.yaml": `patchesStrategicMerge: [patch1.yaml, "patch2.yaml", 'path/patch3.yaml']`},
@@ -306,8 +320,19 @@ func TestDependenciesForKustomization(t *testing.T) {
 			kustomizations: map[string]string{"kustomization.yaml": `patchesJson6902:
 - path: patch1.json
 - path: path/patch2.json`},
+			createFiles: map[string]string{
+				"patch1.json":      "",
+				"path/patch2.json": "",
+			},
 			expected: []string{"kustomization.yaml", "patch1.json", "path/patch2.json"},
 		},
+		{
+			description: "ignore patches json 6902 path doesn't exist",
+			kustomizations: map[string]string{"kustomization.yaml": `patchesJson6902:
+- path: patch1.json`,
+			},
+			expected: []string{"kustomization.yaml"},
+		},
 		{
 			description: "ignore patch without path",
 			kustomizations: map[string]string{"kustomization.yaml": `patchesJson6902: