Skip to content

Commit

Permalink
Move parsing GenericApplicationSpec to configv1
Browse files Browse the repository at this point in the history
Signed-off-by: Shinnosuke Sawada-Dazai <[email protected]>
  • Loading branch information
Warashi committed Oct 1, 2024
1 parent d9d098c commit b9e9261
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 3 deletions.
5 changes: 2 additions & 3 deletions pkg/app/pipedv1/controller/planner.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
package controller

import (
"bytes"
"context"
"encoding/json"
"fmt"
Expand Down Expand Up @@ -273,8 +272,8 @@ func (p *planner) buildPlan(ctx context.Context, runningDS, targetDS *model.Depl
}
}

cfg := new(config.GenericApplicationSpec)
if err := json.NewDecoder(bytes.NewReader(targetDS.ApplicationConfig)).Decode(cfg); err != nil {
cfg, err := config.ParseApplication(targetDS.GetApplicationConfig())
if err != nil {
p.logger.Error("unable to parse application config", zap.Error(err))
return nil, err
}

Check warning on line 279 in pkg/app/pipedv1/controller/planner.go

View check run for this annotation

Codecov / codecov/patch

pkg/app/pipedv1/controller/planner.go#L277-L279

Added lines #L277 - L279 were not covered by tests
Expand Down
11 changes: 11 additions & 0 deletions pkg/configv1/application.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
package config

import (
"bytes"
"encoding/json"
"fmt"
"os"
Expand Down Expand Up @@ -593,3 +594,13 @@ func LoadApplication(repoPath, configRelPath string, appKind model.ApplicationKi

return &spec, nil
}

// ParseApplication parses the given byte slice into a GenericApplicationSpec.
func ParseApplication(b []byte) (*GenericApplicationSpec, error) {
cfg := new(GenericApplicationSpec)
if err := json.NewDecoder(bytes.NewReader(b)).Decode(cfg); err != nil {
return nil, err
}

Check warning on line 603 in pkg/configv1/application.go

View check run for this annotation

Codecov / codecov/patch

pkg/configv1/application.go#L599-L603

Added lines #L599 - L603 were not covered by tests

return cfg, nil

Check warning on line 605 in pkg/configv1/application.go

View check run for this annotation

Codecov / codecov/patch

pkg/configv1/application.go#L605

Added line #L605 was not covered by tests
}

0 comments on commit b9e9261

Please sign in to comment.