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

fix: the former module patchers are overridden by the latter one #1158

Merged
merged 1 commit into from
Jun 12, 2024
Merged
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
24 changes: 14 additions & 10 deletions pkg/modules/generators/app_configurations_generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,20 +141,20 @@ func (g *appConfigurationGenerator) Generate(spec *v1.Spec) error {
wl := spec.Resources[1]

// call modules to generate customized resources
resources, patcher, err := g.callModules(projectModuleConfigs)
resources, patchers, err := g.callModules(projectModuleConfigs)
if err != nil {
return err
}

// append the generated resources to the spec
spec.Resources = append(spec.Resources, resources...)

// patch workload with resource patcher
if patcher != nil {
if err = PatchWorkload(&wl, patcher); err != nil {
// patch workload with resource patchers
for _, patcher := range patchers {
if err = PatchWorkload(&wl, &patcher); err != nil {
return err
}
if err = JSONPatch(spec.Resources, patcher); err != nil {
if err = JSONPatch(spec.Resources, &patcher); err != nil {
return err
}
}
Expand Down Expand Up @@ -341,7 +341,7 @@ type moduleConfig struct {
ctx v1.GenericConfig
}

func (g *appConfigurationGenerator) callModules(projectModuleConfigs map[string]v1.GenericConfig) (resources []v1.Resource, patcher *v1.Patcher, err error) {
func (g *appConfigurationGenerator) callModules(projectModuleConfigs map[string]v1.GenericConfig) (resources []v1.Resource, patchers []v1.Patcher, err error) {
pluginMap := make(map[string]*modules.Plugin)
defer func() {
if e := recover(); e != nil {
Expand Down Expand Up @@ -421,13 +421,17 @@ func (g *appConfigurationGenerator) callModules(projectModuleConfigs map[string]
}

// parse patcher
err = yaml.Unmarshal(response.Patcher, &patcher)
if err != nil {
return nil, nil, err
temp := &v1.Patcher{}
if response.Patcher != nil {
err = yaml.Unmarshal(response.Patcher, temp)
if err != nil {
return nil, nil, err
}
patchers = append(patchers, *temp)
}
}

return resources, patcher, nil
return resources, patchers, nil
}

func (g *appConfigurationGenerator) buildModuleConfigIndex(platformModuleConfigs map[string]v1.GenericConfig) (map[string]moduleConfig, error) {
Expand Down
Loading