Skip to content

Commit

Permalink
fix: poc
Browse files Browse the repository at this point in the history
  • Loading branch information
ericzzzzzzz committed Dec 5, 2023
1 parent 8cca856 commit 220351b
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 2 deletions.
2 changes: 2 additions & 0 deletions integration/examples/lifecycle-hooks/k8s-pod.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ apiVersion: v1
kind: Pod
metadata:
name: getting-started
labels:
tier: test-1
spec:
containers:
- name: getting-started
Expand Down
3 changes: 3 additions & 0 deletions integration/examples/lifecycle-hooks/post-render.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env bash

sed -e 's/test-1/test-2/g' < /dev/stdin
2 changes: 1 addition & 1 deletion integration/examples/lifecycle-hooks/skaffold.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ manifests:
command: ["sh", "-c", "echo pre-render host hook running on $(hostname)!"]
after:
- host:
command: ["sh", "-c", "echo post-render host hook running on $(hostname)!"]
command: ["sh", "post-render.sh", ]
build:
hooks:
before:
Expand Down
6 changes: 6 additions & 0 deletions pkg/skaffold/hooks/render.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"bytes"
"context"
"fmt"
"github.com/GoogleContainerTools/skaffold/v2/pkg/skaffold/output/log"
"io"
"strings"
"sync"
Expand Down Expand Up @@ -81,6 +82,9 @@ func (r renderRunner) RunPostHooks(ctx context.Context, list manifest.ManifestLi
if err := hook.run(ctx, in, &b); err != nil {
return manifest.ManifestList{}, err
}
if b.Len() == 0 {
return manifest.ManifestList{}, fmt.Errorf("the length of stdout should be greater than 0 when using render post hook with change")
}
in = &b
} else {
if err := hook.run(ctx, in, out); err != nil {
Expand All @@ -92,7 +96,9 @@ func (r renderRunner) RunPostHooks(ctx context.Context, list manifest.ManifestLi
if len(r.PostHooks) > 0 {
output.Default.Fprintln(out, fmt.Sprintf("Completed %s hooks", phases.PostRender))
}
log.Entry(context.TODO()).Debugf("Original manifests: %s\n", list.String())
updated, err := manifest.Load(in)
log.Entry(context.TODO()).Debugf("Updated manifests: %s\n", updated.String())
if err != nil {
return manifest.ManifestList{}, err
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/skaffold/render/renderer/render_mux.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ func (r RenderMux) Render(ctx context.Context, out io.Writer, artifacts []graph.
return allManifests, nil
}

updated := manifest.ManifestListByConfig{}
updated := manifest.NewManifestListByConfig()
for _, name := range allManifests.ConfigNames() {
list := allManifests.GetForConfig(name)
for _, hr := range r.gr.HookRunners {
Expand Down

0 comments on commit 220351b

Please sign in to comment.