Skip to content

Commit

Permalink
Implement deploy source preparation in scheduler
Browse files Browse the repository at this point in the history
Signed-off-by: Shinnosuke Sawada-Dazai <[email protected]>
  • Loading branch information
Warashi committed Dec 11, 2024
1 parent ab7ad15 commit 862b76b
Showing 1 changed file with 34 additions and 3 deletions.
37 changes: 34 additions & 3 deletions pkg/app/pipedv1/controller/scheduler.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ import (
"context"
"encoding/json"
"fmt"
"io"
"path/filepath"
"time"

"go.opentelemetry.io/otel/attribute"
Expand All @@ -27,6 +29,7 @@ import (
"go.uber.org/zap"

"github.com/pipe-cd/pipecd/pkg/app/pipedv1/controller/controllermetrics"
"github.com/pipe-cd/pipecd/pkg/app/pipedv1/deploysource"
"github.com/pipe-cd/pipecd/pkg/app/pipedv1/metadatastore"
"github.com/pipe-cd/pipecd/pkg/app/server/service/pipedservice"
config "github.com/pipe-cd/pipecd/pkg/configv1"
Expand Down Expand Up @@ -214,9 +217,37 @@ func (s *scheduler) Run(ctx context.Context) error {
)
deploymentStatus = model.DeploymentStatus_DEPLOYMENT_SUCCESS

/// TODO: prepare the targetDS and runningDS
var targetDS *deployment.DeploymentSource
cfg, err := config.DecodeYAML[*config.GenericApplicationSpec](targetDS.GetApplicationConfig())
repoCfg := config.PipedRepository{
RepoID: s.deployment.GitPath.Repo.Id,
Remote: s.deployment.GitPath.Repo.Remote,
Branch: s.deployment.GitPath.Repo.Branch,
}

runningDSP := deploysource.NewProvider(
filepath.Join(s.workingDir, "running-deploysource"),
deploysource.NewGitSourceCloner(s.gitClient, repoCfg, "running", s.deployment.RunningCommitHash),
s.deployment.GetGitPath(), nil, // TODO: pass secret decrypter?
)
rds, err := runningDSP.Get(ctx, io.Discard) // TODO: pass not io.Discard
if err != nil {
// TODO: log error
return fmt.Errorf("error while preparing deploy source data (%v)", err)
}
s.runningDS = rds.ToPluginDeploySource()

targetDSP := deploysource.NewProvider(
filepath.Join(s.workingDir, "target-deploysource"),
deploysource.NewGitSourceCloner(s.gitClient, repoCfg, "target", s.deployment.Trigger.Commit.Hash),
s.deployment.GetGitPath(), nil, // TODO: pass secret decrypter?
)
tds, err := targetDSP.Get(ctx, io.Discard) // TODO: pass not io.Discard
if err != nil {
// TODO: log error
return fmt.Errorf("error while preparing deploy source data (%v)", err)
}
s.targetDS = tds.ToPluginDeploySource()

cfg, err := config.DecodeYAML[*config.GenericApplicationSpec](s.targetDS.GetApplicationConfig())

Check warning on line 250 in pkg/app/pipedv1/controller/scheduler.go

View check run for this annotation

Codecov / codecov/patch

pkg/app/pipedv1/controller/scheduler.go#L220-L250

Added lines #L220 - L250 were not covered by tests
if err != nil {
deploymentStatus = model.DeploymentStatus_DEPLOYMENT_FAILURE
statusReason = fmt.Sprintf("Failed to decode application configuration at target commit (%v)", err)
Expand Down

0 comments on commit 862b76b

Please sign in to comment.