mirror of
https://github.com/kubernetes-sigs/kustomize.git
synced 2026-05-18 02:55:22 +00:00
39 lines
767 B
Go
39 lines
767 B
Go
// 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
|
|
}
|