From 2dfbb7bcae6e16b02b3e7fc4f7e5c36852aaff96 Mon Sep 17 00:00:00 2001 From: Yuwen Ma Date: Fri, 6 Aug 2021 07:44:32 -0700 Subject: [PATCH] [v2] enable `skafffold delete` in kpt v2 deployer Also update v2beta20. --- docs/content/en/schemas/v2beta19.json | 23 ++++++++++++++++++ docs/content/en/schemas/v2beta20.json | 23 ++++++++++++++++++ docs/content/en/schemas/v2beta21.json | 31 ++++++++++++++++++++++++- pkg/skaffold/deploy/v2/kpt/kpt.go | 4 +++- pkg/skaffold/schema/latest/v1/config.go | 4 ++-- pkg/skaffold/schema/v2beta19/config.go | 2 +- pkg/skaffold/schema/v2beta20/config.go | 2 +- 7 files changed, 83 insertions(+), 6 deletions(-) diff --git a/docs/content/en/schemas/v2beta19.json b/docs/content/en/schemas/v2beta19.json index 06a810c17e2..1356d9baa11 100755 --- a/docs/content/en/schemas/v2beta19.json +++ b/docs/content/en/schemas/v2beta19.json @@ -914,6 +914,29 @@ "description": "describes a dependency on another skaffold configuration.", "x-intellij-html-description": "describes a dependency on another skaffold configuration." }, + "ContainerHook": { + "required": [ + "command" + ], + "properties": { + "command": { + "items": { + "type": "string" + }, + "type": "array", + "description": "command to execute.", + "x-intellij-html-description": "command to execute.", + "default": "[]" + } + }, + "preferredOrder": [ + "command" + ], + "additionalProperties": false, + "type": "object", + "description": "describes a lifecycle hook definition to execute on a container. The container name is inferred from the scope in which this hook is defined.", + "x-intellij-html-description": "describes a lifecycle hook definition to execute on a container. The container name is inferred from the scope in which this hook is defined." + }, "CustomArtifact": { "properties": { "buildCommand": { diff --git a/docs/content/en/schemas/v2beta20.json b/docs/content/en/schemas/v2beta20.json index 7463346d5d3..818380f37c5 100755 --- a/docs/content/en/schemas/v2beta20.json +++ b/docs/content/en/schemas/v2beta20.json @@ -956,6 +956,29 @@ "description": "describes a dependency on another skaffold configuration.", "x-intellij-html-description": "describes a dependency on another skaffold configuration." }, + "ContainerHook": { + "required": [ + "command" + ], + "properties": { + "command": { + "items": { + "type": "string" + }, + "type": "array", + "description": "command to execute.", + "x-intellij-html-description": "command to execute.", + "default": "[]" + } + }, + "preferredOrder": [ + "command" + ], + "additionalProperties": false, + "type": "object", + "description": "describes a lifecycle hook definition to execute on a container. The container name is inferred from the scope in which this hook is defined.", + "x-intellij-html-description": "describes a lifecycle hook definition to execute on a container. The container name is inferred from the scope in which this hook is defined." + }, "CustomArtifact": { "properties": { "buildCommand": { diff --git a/docs/content/en/schemas/v2beta21.json b/docs/content/en/schemas/v2beta21.json index 7463346d5d3..daa97669ab2 100755 --- a/docs/content/en/schemas/v2beta21.json +++ b/docs/content/en/schemas/v2beta21.json @@ -956,6 +956,29 @@ "description": "describes a dependency on another skaffold configuration.", "x-intellij-html-description": "describes a dependency on another skaffold configuration." }, + "ContainerHook": { + "required": [ + "command" + ], + "properties": { + "command": { + "items": { + "type": "string" + }, + "type": "array", + "description": "command to execute.", + "x-intellij-html-description": "command to execute.", + "default": "[]" + } + }, + "preferredOrder": [ + "command" + ], + "additionalProperties": false, + "type": "object", + "description": "describes a lifecycle hook definition to execute on a container. The container name is inferred from the scope in which this hook is defined.", + "x-intellij-html-description": "describes a lifecycle hook definition to execute on a container. The container name is inferred from the scope in which this hook is defined." + }, "CustomArtifact": { "properties": { "buildCommand": { @@ -2537,6 +2560,11 @@ "description": "additional flags passed to `kubectl`.", "x-intellij-html-description": "additional flags passed to kubectl." }, + "hooks": { + "$ref": "#/definitions/DeployHooks", + "description": "describes a set of lifecycle hooks that are executed before and after every deploy.", + "x-intellij-html-description": "describes a set of lifecycle hooks that are executed before and after every deploy." + }, "manifests": { "items": { "type": "string" @@ -2560,7 +2588,8 @@ "manifests", "remoteManifests", "flags", - "defaultNamespace" + "defaultNamespace", + "hooks" ], "additionalProperties": false, "type": "object", diff --git a/pkg/skaffold/deploy/v2/kpt/kpt.go b/pkg/skaffold/deploy/v2/kpt/kpt.go index 98723fb28a8..bf27dbb659d 100644 --- a/pkg/skaffold/deploy/v2/kpt/kpt.go +++ b/pkg/skaffold/deploy/v2/kpt/kpt.go @@ -286,7 +286,9 @@ func (k *Deployer) Cleanup(ctx context.Context, out io.Writer) error { instrumentation.AddAttributesToCurrentSpanFromContext(ctx, map[string]string{ "DeployerType": deployerName, }) - + if err := kptInitFunc(ctx, out, k); err != nil { + return err + } cmd := exec.CommandContext(ctx, "kpt", k.kptArgs("live", "destroy", k.applyDir)...) cmd.Stdout = out cmd.Stderr = out diff --git a/pkg/skaffold/schema/latest/v1/config.go b/pkg/skaffold/schema/latest/v1/config.go index 968e7672a42..32e9f654e16 100644 --- a/pkg/skaffold/schema/latest/v1/config.go +++ b/pkg/skaffold/schema/latest/v1/config.go @@ -566,7 +566,7 @@ type KubectlDeploy struct { DefaultNamespace *string `yaml:"defaultNamespace,omitempty"` // LifecycleHooks describes a set of lifecycle hooks that are executed before and after every deploy. - LifecycleHooks DeployHooks `yaml:"-"` + LifecycleHooks DeployHooks `yaml:"hooks,omitempty"` } // KubectlFlags are additional flags passed on the command @@ -1397,7 +1397,7 @@ type ContainerHook struct { // NamedContainerHook describes a lifecycle hook definition to execute on a named container. type NamedContainerHook struct { // ContainerHook describes a lifecycle hook definition to execute on a container. - ContainerHook `yaml:",inline"` + ContainerHook `yaml:",inline" yamlTags:"skipTrim"` // PodName is the name of the pod to execute the command in. PodName string `yaml:"podName" yamltags:"required"` // ContainerName is the name of the container to execute the command in. diff --git a/pkg/skaffold/schema/v2beta19/config.go b/pkg/skaffold/schema/v2beta19/config.go index 68fba8059aa..c03f58e6b90 100755 --- a/pkg/skaffold/schema/v2beta19/config.go +++ b/pkg/skaffold/schema/v2beta19/config.go @@ -1381,7 +1381,7 @@ type ContainerHook struct { // NamedContainerHook describes a lifecycle hook definition to execute on a named container. type NamedContainerHook struct { // ContainerHook describes a lifecycle hook definition to execute on a container. - ContainerHook `yaml:",inline"` + ContainerHook `yaml:",inline" yamltags:"skipTrim"` // PodName is the name of the pod to execute the command in. PodName string `yaml:"podName" yamltags:"required"` // ContainerName is the name of the container to execute the command in. diff --git a/pkg/skaffold/schema/v2beta20/config.go b/pkg/skaffold/schema/v2beta20/config.go index 01ad3de25fd..73de6392afa 100755 --- a/pkg/skaffold/schema/v2beta20/config.go +++ b/pkg/skaffold/schema/v2beta20/config.go @@ -1397,7 +1397,7 @@ type ContainerHook struct { // NamedContainerHook describes a lifecycle hook definition to execute on a named container. type NamedContainerHook struct { // ContainerHook describes a lifecycle hook definition to execute on a container. - ContainerHook `yaml:",inline"` + ContainerHook `yaml:",inline" yamltags:"skipTrim"` // PodName is the name of the pod to execute the command in. PodName string `yaml:"podName" yamltags:"required"` // ContainerName is the name of the container to execute the command in.