Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added resourcegen #5205

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 47 additions & 0 deletions plugin/builtin/resourcegenerator/resourcegenerator.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package main


import (
"sigs.k8s.io/kustomize/api/kv"
"sigs.k8s.io/kustomize/api/resmap"
"sigs.k8s.io/kustomize/api/resource"
"sigs.k8s.io/kustomize/api/types"
"sigs.k8s.io/yaml"
)

type plugin struct {
h *resmap.PluginHelpers
types.ObjectMeta `json:"metadata,omitempty" yaml:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"`
Resources []string `json:"resources,omitempty" yaml:"resources,omitempty" protobuf:"bytes,2,opt,name=resources"`
}

var KustomizePlugin plugin //nolint:gochecknoglobals

func (p *plugin) Config(h *resmap.PluginHelpers, config []byte) (err error) {
p.Resources = []string{}
err = yaml.Unmarshal(config, p)
p.h = h
return
}

func (p *plugin) Generate() (resmap.ResMap, error) {
var resList []resmap.ResMap

for _, resourcePath := range p.Resources {
resources, err := p.h.ResmapFactory().FromFiles(resourcePath)
if err != nil {
return nil, err
}
resList = append(resList, resources)
}

mergedResMap := resmap.ResMap
for _, resMap := range resList {
err := mergedResMap.Append(resMap)
if err != nil {
return nil, err
}
}

return mergedResMap, nil
}