Skip to content

Commit

Permalink
[kpt deployer] Fix non-kustomize manifests not rendered issue (#5627)
Browse files Browse the repository at this point in the history
root cause: version changes. kpt-sourced manfiest cannot pipeline directly into the kpt function pipeline.
Fix: The sourced manifest is of type "ResourceList" and the raw manifests are stored in the ResourceList.Items.
  • Loading branch information
yuwenma authored Apr 8, 2021
1 parent cc262b4 commit bb89cbb
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions pkg/skaffold/deploy/kpt/kpt.go
Original file line number Diff line number Diff line change
Expand Up @@ -286,6 +286,8 @@ func (k *Deployer) renderManifests(ctx context.Context, _ io.Writer, builds []gr
}

// Hydrate the manifests source.
// Note: kustomize cannot be used as a kpt fn yet and thus we add a kustomize cmd step in the kpt pipeline:
// kpt source --> (workaround) kustomize build --> kpt run --> kpt sink.
_, err = kustomize.FindKustomizationConfig(k.Dir)
// Only run kustomize if kustomization.yaml is found.
if err == nil {
Expand All @@ -312,7 +314,31 @@ func (k *Deployer) renderManifests(ctx context.Context, _ io.Writer, builds []gr
if err != nil {
return nil, fmt.Errorf("kustomize build: %w", err)
}
} else {
// Note: Here we use kpt ResourceList as the media to store the config source.
// Eventually, skaffold should not need to construct a kpt inner resource but only use kpt commands and
// the new Kptfile(v1) to establish a hydration pipeline.
input := bytes.NewBufferString(string(buf))
rl := framework.ResourceList{
Reader: input,
}
// Manipulate the kustomize "Rnode"(Kustomize term) and pulls out the "Items"
// from ResourceLists.
if err := rl.Read(); err != nil {
return nil, fmt.Errorf("reading ResourceList %w", err)
}

var newBuf []byte
for i := range rl.Items {
item, err := rl.Items[i].String()
if err != nil {
return nil, fmt.Errorf("reading Item %w", err)
}
newBuf = append(newBuf, []byte(item)...)
}
buf = newBuf
}

// Run kpt functions against the hydrated manifests.
cmd = exec.CommandContext(ctx, "kpt", kptCommandArgs("", []string{"fn", "run"}, flags, nil)...)
buf = append(buf, []byte("---\n")...)
Expand Down

0 comments on commit bb89cbb

Please sign in to comment.