From 2067995a7e78f1dc438b28c6d437eb8fc97df330 Mon Sep 17 00:00:00 2001 From: David Gageot Date: Fri, 10 Jan 2020 14:49:47 +0100 Subject: [PATCH] Empty, non-nil `sync` = sync all the files and infer destination Signed-off-by: David Gageot --- docs/content/en/schemas/v2alpha3.json | 40 +++++++++++-------- pkg/skaffold/schema/defaults/defaults.go | 7 ++++ pkg/skaffold/schema/defaults/defaults_test.go | 2 + pkg/skaffold/schema/latest/config.go | 4 ++ 4 files changed, 37 insertions(+), 16 deletions(-) diff --git a/docs/content/en/schemas/v2alpha3.json b/docs/content/en/schemas/v2alpha3.json index e138f3fce3e..6faf1ea50b9 100755 --- a/docs/content/en/schemas/v2alpha3.json +++ b/docs/content/en/schemas/v2alpha3.json @@ -66,8 +66,9 @@ }, "sync": { "$ref": "#/definitions/Sync", - "description": "*beta* local files synced to pods instead of triggering an image build when modified.", - "x-intellij-html-description": "beta local files synced to pods instead of triggering an image build when modified." + "description": "*beta* local files synced to pods instead of triggering an image build when modified. If no files are listed, sync all the files and infer the destination.", + "x-intellij-html-description": "beta local files synced to pods instead of triggering an image build when modified. If no files are listed, sync all the files and infer the destination.", + "default": "infer: [\"**/*\"]" } }, "preferredOrder": [ @@ -100,8 +101,9 @@ }, "sync": { "$ref": "#/definitions/Sync", - "description": "*beta* local files synced to pods instead of triggering an image build when modified.", - "x-intellij-html-description": "beta local files synced to pods instead of triggering an image build when modified." + "description": "*beta* local files synced to pods instead of triggering an image build when modified. If no files are listed, sync all the files and infer the destination.", + "x-intellij-html-description": "beta local files synced to pods instead of triggering an image build when modified. If no files are listed, sync all the files and infer the destination.", + "default": "infer: [\"**/*\"]" } }, "preferredOrder": [ @@ -135,8 +137,9 @@ }, "sync": { "$ref": "#/definitions/Sync", - "description": "*beta* local files synced to pods instead of triggering an image build when modified.", - "x-intellij-html-description": "beta local files synced to pods instead of triggering an image build when modified." + "description": "*beta* local files synced to pods instead of triggering an image build when modified. If no files are listed, sync all the files and infer the destination.", + "x-intellij-html-description": "beta local files synced to pods instead of triggering an image build when modified. If no files are listed, sync all the files and infer the destination.", + "default": "infer: [\"**/*\"]" } }, "preferredOrder": [ @@ -170,8 +173,9 @@ }, "sync": { "$ref": "#/definitions/Sync", - "description": "*beta* local files synced to pods instead of triggering an image build when modified.", - "x-intellij-html-description": "beta local files synced to pods instead of triggering an image build when modified." + "description": "*beta* local files synced to pods instead of triggering an image build when modified. If no files are listed, sync all the files and infer the destination.", + "x-intellij-html-description": "beta local files synced to pods instead of triggering an image build when modified. If no files are listed, sync all the files and infer the destination.", + "default": "infer: [\"**/*\"]" } }, "preferredOrder": [ @@ -205,8 +209,9 @@ }, "sync": { "$ref": "#/definitions/Sync", - "description": "*beta* local files synced to pods instead of triggering an image build when modified.", - "x-intellij-html-description": "beta local files synced to pods instead of triggering an image build when modified." + "description": "*beta* local files synced to pods instead of triggering an image build when modified. If no files are listed, sync all the files and infer the destination.", + "x-intellij-html-description": "beta local files synced to pods instead of triggering an image build when modified. If no files are listed, sync all the files and infer the destination.", + "default": "infer: [\"**/*\"]" } }, "preferredOrder": [ @@ -240,8 +245,9 @@ }, "sync": { "$ref": "#/definitions/Sync", - "description": "*beta* local files synced to pods instead of triggering an image build when modified.", - "x-intellij-html-description": "beta local files synced to pods instead of triggering an image build when modified." + "description": "*beta* local files synced to pods instead of triggering an image build when modified. If no files are listed, sync all the files and infer the destination.", + "x-intellij-html-description": "beta local files synced to pods instead of triggering an image build when modified. If no files are listed, sync all the files and infer the destination.", + "default": "infer: [\"**/*\"]" } }, "preferredOrder": [ @@ -275,8 +281,9 @@ }, "sync": { "$ref": "#/definitions/Sync", - "description": "*beta* local files synced to pods instead of triggering an image build when modified.", - "x-intellij-html-description": "beta local files synced to pods instead of triggering an image build when modified." + "description": "*beta* local files synced to pods instead of triggering an image build when modified. If no files are listed, sync all the files and infer the destination.", + "x-intellij-html-description": "beta local files synced to pods instead of triggering an image build when modified. If no files are listed, sync all the files and infer the destination.", + "default": "infer: [\"**/*\"]" } }, "preferredOrder": [ @@ -1904,8 +1911,9 @@ "infer" ], "additionalProperties": false, - "description": "*beta* specifies what files to sync into the container. This is a list of sync rules indicating the intent to sync for source files.", - "x-intellij-html-description": "beta specifies what files to sync into the container. This is a list of sync rules indicating the intent to sync for source files." + "description": "*beta* specifies what files to sync into the container. This is a list of sync rules indicating the intent to sync for source files. If no files are listed, sync all the files and infer the destination.", + "x-intellij-html-description": "beta specifies what files to sync into the container. This is a list of sync rules indicating the intent to sync for source files. If no files are listed, sync all the files and infer the destination.", + "default": "infer: [\"**/*\"]" }, "SyncRule": { "required": [ diff --git a/pkg/skaffold/schema/defaults/defaults.go b/pkg/skaffold/schema/defaults/defaults.go index f4ca6c684db..5b659e88c36 100644 --- a/pkg/skaffold/schema/defaults/defaults.go +++ b/pkg/skaffold/schema/defaults/defaults.go @@ -46,6 +46,7 @@ func Set(c *latest.SkaffoldConfig) error { for _, a := range c.Build.Artifacts { setDefaultWorkspace(a) + setDefaultSync(a) if c.Build.Cluster != nil && a.CustomArtifact == nil && a.BuildpackArtifact == nil { defaultToKanikoArtifact(a) @@ -213,6 +214,12 @@ func setDefaultWorkspace(a *latest.Artifact) { a.Workspace = valueOrDefault(a.Workspace, ".") } +func setDefaultSync(a *latest.Artifact) { + if a.Sync != nil && len(a.Sync.Manual) == 0 && len(a.Sync.Infer) == 0 { + a.Sync.Infer = []string{"**/*"} + } +} + func withClusterConfig(c *latest.SkaffoldConfig, opts ...func(*latest.ClusterDetails) error) error { clusterDetails := c.Build.BuildType.Cluster if clusterDetails == nil { diff --git a/pkg/skaffold/schema/defaults/defaults_test.go b/pkg/skaffold/schema/defaults/defaults_test.go index fd2e2e744b7..0e4b4c32506 100644 --- a/pkg/skaffold/schema/defaults/defaults_test.go +++ b/pkg/skaffold/schema/defaults/defaults_test.go @@ -56,6 +56,7 @@ func TestSetDefaults(t *testing.T) { ArtifactType: latest.ArtifactType{ BuildpackArtifact: &latest.BuildpackArtifact{}, }, + Sync: &latest.Sync{}, }, }, }, @@ -81,6 +82,7 @@ func TestSetDefaults(t *testing.T) { testutil.CheckDeepEqual(t, "fourth", cfg.Build.Artifacts[3].ImageName) testutil.CheckDeepEqual(t, []string{"."}, cfg.Build.Artifacts[3].BuildpackArtifact.Dependencies.Paths) testutil.CheckDeepEqual(t, []string(nil), cfg.Build.Artifacts[3].BuildpackArtifact.Dependencies.Ignore) + testutil.CheckDeepEqual(t, []string{"**/*"}, cfg.Build.Artifacts[3].Sync.Infer) } func TestSetDefaultsOnCluster(t *testing.T) { diff --git a/pkg/skaffold/schema/latest/config.go b/pkg/skaffold/schema/latest/config.go index 6c95c107203..761c08d9c39 100644 --- a/pkg/skaffold/schema/latest/config.go +++ b/pkg/skaffold/schema/latest/config.go @@ -560,6 +560,8 @@ type Artifact struct { // Sync *beta* lists local files synced to pods instead // of triggering an image build when modified. + // If no files are listed, sync all the files and infer the destination. + // Defaults to `infer: ["**/*"]`. Sync *Sync `yaml:"sync,omitempty"` // ArtifactType describes how to build an artifact. @@ -568,6 +570,8 @@ type Artifact struct { // Sync *beta* specifies what files to sync into the container. // This is a list of sync rules indicating the intent to sync for source files. +// If no files are listed, sync all the files and infer the destination. +// Defaults to `infer: ["**/*"]`. type Sync struct { // Manual lists manual sync rules indicating the source and destination. Manual []*SyncRule `yaml:"manual,omitempty" yamltags:"oneOf=sync"`