Skip to content

Commit

Permalink
fix: the former module patchers are override by the latter one
Browse files Browse the repository at this point in the history
  • Loading branch information
SparkYuan committed Jun 11, 2024
1 parent 1df3c90 commit 99f9756
Showing 1 changed file with 19 additions and 13 deletions.
32 changes: 19 additions & 13 deletions pkg/modules/generators/app_configurations_generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,21 +141,23 @@ 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 {
return err
}
if err = JSONPatch(spec.Resources, patcher); err != nil {
return err
// patch workload with resource patchers
if patchers != nil {

Check failure on line 153 in pkg/modules/generators/app_configurations_generator.go

View workflow job for this annotation

GitHub Actions / Golang Lint

S1031: unnecessary nil check around range (gosimple)
for _, patcher := range patchers {
if err = PatchWorkload(&wl, &patcher); err != nil {
return err
}
if err = JSONPatch(spec.Resources, &patcher); err != nil {
return err
}
}
}

Expand Down Expand Up @@ -341,7 +343,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 +423,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

0 comments on commit 99f9756

Please sign in to comment.