Move hashing transformer out of k8sdeps.

This commit is contained in:
Jeffrey Regan
2019-05-29 10:01:52 -07:00
parent 4812ddff9f
commit fd2248e7c2
14 changed files with 205 additions and 201 deletions

View File

@@ -0,0 +1,38 @@
// Copyright 2019 The Kubernetes Authors.
// SPDX-License-Identifier: Apache-2.0
//go:generate go run sigs.k8s.io/kustomize/plugin/pluginator
package main
import (
"fmt"
"sigs.k8s.io/kustomize/pkg/ifc"
"sigs.k8s.io/kustomize/pkg/resmap"
)
type plugin struct {
hasher ifc.KunstructuredHasher
}
var KustomizePlugin plugin
func (p *plugin) Config(
ldr ifc.Loader, rf *resmap.Factory, config []byte) (err error) {
p.hasher = rf.RF().Hasher()
return nil
}
// Transform appends hash to generated resources.
func (p *plugin) Transform(m resmap.ResMap) error {
for _, res := range m {
if res.NeedHashSuffix() {
h, err := p.hasher.Hash(res)
if err != nil {
return err
}
res.SetName(fmt.Sprintf("%s-%s", res.GetName(), h))
}
}
return nil
}