Skip to content

Commit

Permalink
External loaded generators add KustTarget to PluginHelpers
Browse files Browse the repository at this point in the history
  • Loading branch information
LittleChimera committed Sep 7, 2024
1 parent 06e14a4 commit f8427e7
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 9 deletions.
16 changes: 9 additions & 7 deletions api/internal/plugins/loader/loader.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,10 @@ func (l *Loader) Config() *types.PluginConfig {
}

func (l *Loader) LoadGenerators(
ldr ifc.Loader, v ifc.Validator, rm resmap.ResMap) (
ldr ifc.Loader, v ifc.Validator, rm resmap.ResMap, kt resmap.KustTargetInterface) (
result []*resmap.GeneratorWithProperties, err error) {
for _, res := range rm.Resources() {
g, err := l.LoadGenerator(ldr, v, res)
g, err := l.LoadGenerator(ldr, v, res, kt)
if err != nil {
return nil, fmt.Errorf("failed to load generator: %w", err)
}
Expand All @@ -78,8 +78,8 @@ func (l *Loader) LoadGenerators(
}

func (l *Loader) LoadGenerator(
ldr ifc.Loader, v ifc.Validator, res *resource.Resource) (resmap.Generator, error) {
c, err := l.loadAndConfigurePlugin(ldr, v, res)
ldr ifc.Loader, v ifc.Validator, res *resource.Resource, kt resmap.KustTargetInterface) (resmap.Generator, error) {
c, err := l.loadAndConfigurePlugin(ldr, v, res, kt)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -109,7 +109,7 @@ func (l *Loader) LoadTransformers(

func (l *Loader) LoadTransformer(
ldr ifc.Loader, v ifc.Validator, res *resource.Resource) (*resmap.TransformerWithProperties, error) {
c, err := l.loadAndConfigurePlugin(ldr, v, res)
c, err := l.loadAndConfigurePlugin(ldr, v, res, nil)
if err != nil {
return nil, err
}
Expand Down Expand Up @@ -183,7 +183,9 @@ func isBuiltinPlugin(res *resource.Resource) bool {
func (l *Loader) loadAndConfigurePlugin(
ldr ifc.Loader,
v ifc.Validator,
res *resource.Resource) (c resmap.Configurable, err error) {
res *resource.Resource,
kt resmap.KustTargetInterface,
) (c resmap.Configurable, err error) {
if isBuiltinPlugin(res) {
switch l.pc.BpLoadingOptions {
case types.BploLoadFromFileSys:
Expand Down Expand Up @@ -218,7 +220,7 @@ func (l *Loader) loadAndConfigurePlugin(
if err != nil {
return nil, errors.WrapPrefixf(err, "marshalling yaml from res %s", res.OrgId())
}
err = c.Config(resmap.NewPluginHelpers(ldr, v, l.rf, l.pc), yaml)
err = c.Config(resmap.NewPluginHelpersWithKt(ldr, v, l.rf, l.pc, kt), yaml)
if err != nil {
return nil, errors.WrapPrefixf(
err, "plugin %s fails configuration", res.OrgId())
Expand Down
2 changes: 1 addition & 1 deletion api/internal/plugins/loader/loader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ func TestLoader(t *testing.T) {
t.Fatal("expect non-nil loader")
}
_, err = pLdr.LoadGenerators(
fLdr, valtest_test.MakeFakeValidator(), generatorConfigs)
fLdr, valtest_test.MakeFakeValidator(), generatorConfigs, nil)
if err != nil {
t.Fatal(err)
}
Expand Down
2 changes: 1 addition & 1 deletion api/internal/target/kusttarget.go
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ func (kt *KustTarget) configureExternalGenerators() (
if err != nil {
return nil, err
}
return kt.pLdr.LoadGenerators(kt.ldr, kt.validator, ra.ResMap())
return kt.pLdr.LoadGenerators(kt.ldr, kt.validator, ra.ResMap(), kt)
}

func (kt *KustTarget) runTransformers(ra *accumulator.ResAccumulator) error {
Expand Down

0 comments on commit f8427e7

Please sign in to comment.