Skip to content

Commit

Permalink
chore: change schema
Browse files Browse the repository at this point in the history
  • Loading branch information
ericzzzzzzz committed Dec 5, 2023
1 parent 220351b commit fe7076b
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 7 deletions.
10 changes: 7 additions & 3 deletions pkg/skaffold/hooks/render.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ import (
"bytes"
"context"
"fmt"
"github.com/GoogleContainerTools/skaffold/v2/pkg/skaffold/output/log"
"io"
"strings"
"sync"

"github.com/GoogleContainerTools/skaffold/v2/pkg/skaffold/kubernetes/manifest"
"github.com/GoogleContainerTools/skaffold/v2/pkg/skaffold/output"
"github.com/GoogleContainerTools/skaffold/v2/pkg/skaffold/output/log"
"github.com/GoogleContainerTools/skaffold/v2/pkg/skaffold/schema/latest"
)

Expand Down Expand Up @@ -76,8 +76,12 @@ func (r renderRunner) RunPostHooks(ctx context.Context, list manifest.ManifestLi
env := r.getEnv()
for _, h := range r.PostHooks {
if h.HostHook != nil {
hook := hostHook{*h.HostHook, env}
if h.WithChange {
hook := hostHook{latest.HostHook{
Command: h.HostHook.Command,
OS: h.HostHook.OS,
Dir: h.HostHook.Dir,
}, env}
if h.HostHook.WithChange {
var b bytes.Buffer
if err := hook.run(ctx, in, &b); err != nil {
return manifest.ManifestList{}, err
Expand Down
4 changes: 2 additions & 2 deletions pkg/skaffold/hooks/render_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,13 @@ func TestRenderHooks(t *testing.T) {
},
PostHooks: []latest.PostRenderHookItem{
{
HostHook: &latest.HostHook{
HostHook: &latest.PostRenderHostHook{
OS: []string{"linux", "darwin"},
Command: []string{"sh", "-c", "echo post-hook running with SKAFFOLD_KUBE_CONTEXT=$SKAFFOLD_KUBE_CONTEXT,SKAFFOLD_NAMESPACES=$SKAFFOLD_NAMESPACES"},
},
},
{
HostHook: &latest.HostHook{
HostHook: &latest.PostRenderHostHook{
OS: []string{"windows"},
Command: []string{"cmd.exe", "/C", "echo post-hook running with SKAFFOLD_KUBE_CONTEXT=%SKAFFOLD_KUBE_CONTEXT%,SKAFFOLD_NAMESPACES=%SKAFFOLD_NAMESPACES%"},
},
Expand Down
15 changes: 13 additions & 2 deletions pkg/skaffold/schema/latest/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -1668,8 +1668,19 @@ type RenderHookItem struct {

type PostRenderHookItem struct {
// HostHook describes a single lifecycle hook to run on the host machine.
HostHook *HostHook `yaml:"host,omitempty" yamltags:"oneOf=render_hook"`
// WithChange preserves changes made on the manifests by the HostHook.
HostHook *PostRenderHostHook `yaml:"host,omitempty" yamltags:"oneOf=render_hook"`
}

type PostRenderHostHook struct {
// Command is the command to execute.
Command []string `yaml:"command" yamltags:"required"`
// OS is an optional slice of operating system names. If the host machine OS is different, then it skips execution.
OS []string `yaml:"os,omitempty"`
// Dir specifies the working directory of the command.
// If empty, the command runs in the calling process's current directory.
Dir string `yaml:"dir,omitempty" skaffold:"filepath"`

// WithChange preserves changes made on the manifests by the hook.
WithChange bool `yaml:"withChange,omitempty"`
}

Expand Down

0 comments on commit fe7076b

Please sign in to comment.