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

Update plugin planner interface #5015

Merged
merged 2 commits into from
Jul 2, 2024
Merged
Show file tree
Hide file tree
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
417 changes: 56 additions & 361 deletions pkg/app/pipedv1/cmd/piped/service/service.pb.go

Large diffs are not rendered by default.

647 changes: 56 additions & 591 deletions pkg/app/pipedv1/cmd/piped/service/service.pb.validate.go

Large diffs are not rendered by default.

36 changes: 6 additions & 30 deletions pkg/app/pipedv1/cmd/piped/service/service.proto
Original file line number Diff line number Diff line change
Expand Up @@ -18,41 +18,17 @@ package grpc.piped.service;
option go_package = "github.com/pipe-cd/pipecd/pkg/app/pipedv1/cmd/piped/service";

import "validate/validate.proto";
import "pkg/model/command.proto";
import "pkg/model/analysis_result.proto";

// PluginService provides the ability to interact with plugins.
service PluginService {
// ListStageCommands returns the list requested commands to the given stage.
rpc ListStageCommands(ListStageCommandsRequest) returns (ListStageCommandsResponse) {}

// Put and Get the latest analysis result of a given application.
// Used by the analysis plugin to store and retrieve the latest analysis result.
rpc GetLatestAnalysisResult(GetLatestAnalysisResultRequest) returns (GetLatestAnalysisResultResponse) {}
rpc PutLatestAnalysisResult(PutLatestAnalysisResultRequest) returns (PutLatestAnalysisResultResponse) {}
}

message ListStageCommandsRequest {
string deployment_id = 1 [(validate.rules).string = {min_len: 1}];
string stage_id = 2 [(validate.rules).string = {min_len: 1}];
}

message ListStageCommandsResponse {
repeated model.Command commands = 1;
}

message GetLatestAnalysisResultRequest {
string application_id = 1 [(validate.rules).string = {min_len: 1}];
}

message GetLatestAnalysisResultResponse {
model.AnalysisResult analysis_result = 1;
// DecryptSecret decrypts the given secret.
rpc DecryptSecret(DecryptSecretRequest) returns (DecryptSecretResponse) {}
}

message PutLatestAnalysisResultRequest {
string application_id = 1 [(validate.rules).string = {min_len: 1}];
model.AnalysisResult analysis_result = 2;
message DecryptSecretRequest {
string secret = 1 [(validate.rules).string.min_len = 1];
}

message PutLatestAnalysisResultResponse {
message DecryptSecretResponse {
string decrypted_secret = 1;
}
108 changes: 16 additions & 92 deletions pkg/app/pipedv1/cmd/piped/service/service_grpc.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

150 changes: 76 additions & 74 deletions pkg/app/pipedv1/controller/planner.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,82 +150,84 @@
controllermetrics.UpdateDeploymentStatus(p.deployment, p.doneDeploymentStatus)
}()

in := &platform.BuildPlanRequest{
Deployment: p.deployment,
WorkingDir: p.workingDir,
LastSuccessfulCommitHash: p.lastSuccessfulCommitHash,
LastSuccessfulConfigFileName: p.lastSuccessfulConfigFilename,
PipedConfig: p.pipedConfig,
}

out, err := p.pluginClient.BuildPlan(ctx, in)

// If the deployment was already cancelled, we ignore the plan result.
select {
case cmd := <-p.cancelledCh:
if cmd != nil {
p.doneDeploymentStatus = model.DeploymentStatus_DEPLOYMENT_CANCELLED
desc := fmt.Sprintf("Deployment was cancelled by %s while planning", cmd.Commander)
p.reportDeploymentCancelled(ctx, cmd.Commander, desc)
return cmd.Report(ctx, model.CommandStatus_COMMAND_SUCCEEDED, nil, nil)
}
default:
}

if err != nil {
p.doneDeploymentStatus = model.DeploymentStatus_DEPLOYMENT_FAILURE
return p.reportDeploymentFailed(ctx, fmt.Sprintf("Unable to plan the deployment (%v)", err))
}

p.doneDeploymentStatus = model.DeploymentStatus_DEPLOYMENT_PLANNED
return p.reportDeploymentPlanned(ctx, out.Plan)
return nil

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

View check run for this annotation

Codecov / codecov/patch

pkg/app/pipedv1/controller/planner.go#L153

Added line #L153 was not covered by tests

// in := &platform.BuildPlanRequest{
// Deployment: p.deployment,
// WorkingDir: p.workingDir,
// LastSuccessfulCommitHash: p.lastSuccessfulCommitHash,
// LastSuccessfulConfigFileName: p.lastSuccessfulConfigFilename,
// PipedConfig: p.pipedConfig,
// }

// out, err := p.pluginClient.BuildPlan(ctx, in)

// // If the deployment was already cancelled, we ignore the plan result.
// select {
// case cmd := <-p.cancelledCh:
// if cmd != nil {
// p.doneDeploymentStatus = model.DeploymentStatus_DEPLOYMENT_CANCELLED
// desc := fmt.Sprintf("Deployment was cancelled by %s while planning", cmd.Commander)
// p.reportDeploymentCancelled(ctx, cmd.Commander, desc)
// return cmd.Report(ctx, model.CommandStatus_COMMAND_SUCCEEDED, nil, nil)
// }
// default:
// }

// if err != nil {
// p.doneDeploymentStatus = model.DeploymentStatus_DEPLOYMENT_FAILURE
// return p.reportDeploymentFailed(ctx, fmt.Sprintf("Unable to plan the deployment (%v)", err))
// }

// p.doneDeploymentStatus = model.DeploymentStatus_DEPLOYMENT_PLANNED
// return p.reportDeploymentPlanned(ctx, out.Plan)
}

func (p *planner) reportDeploymentPlanned(ctx context.Context, out *platform.DeploymentPlan) error {
var (
err error
retry = pipedservice.NewRetry(10)
req = &pipedservice.ReportDeploymentPlannedRequest{
DeploymentId: p.deployment.Id,
Summary: out.Summary,
StatusReason: "The deployment has been planned",
RunningCommitHash: p.lastSuccessfulCommitHash,
RunningConfigFilename: p.lastSuccessfulConfigFilename,
Versions: out.Versions,
Stages: out.Stages,
DeploymentChainId: p.deployment.DeploymentChainId,
DeploymentChainBlockIndex: p.deployment.DeploymentChainBlockIndex,
}
)

accounts, err := p.getMentionedAccounts(model.NotificationEventType_EVENT_DEPLOYMENT_PLANNED)
if err != nil {
p.logger.Error("failed to get the list of accounts", zap.Error(err))
}

defer func() {
p.notifier.Notify(model.NotificationEvent{
Type: model.NotificationEventType_EVENT_DEPLOYMENT_PLANNED,
Metadata: &model.NotificationEventDeploymentPlanned{
Deployment: p.deployment,
Summary: out.Summary,
MentionedAccounts: accounts,
},
})
}()

for retry.WaitNext(ctx) {
if _, err = p.apiClient.ReportDeploymentPlanned(ctx, req); err == nil {
return nil
}
err = fmt.Errorf("failed to report deployment status to control-plane: %v", err)
}

if err != nil {
p.logger.Error("failed to mark deployment to be planned", zap.Error(err))
}
return err
}
// func (p *planner) reportDeploymentPlanned(ctx context.Context, out *platform.DeploymentPlan) error {
// var (
// err error
// retry = pipedservice.NewRetry(10)
// req = &pipedservice.ReportDeploymentPlannedRequest{
// DeploymentId: p.deployment.Id,
// Summary: out.Summary,
// StatusReason: "The deployment has been planned",
// RunningCommitHash: p.lastSuccessfulCommitHash,
// RunningConfigFilename: p.lastSuccessfulConfigFilename,
// Versions: out.Versions,
// Stages: out.Stages,
// DeploymentChainId: p.deployment.DeploymentChainId,
// DeploymentChainBlockIndex: p.deployment.DeploymentChainBlockIndex,
// }
// )

// accounts, err := p.getMentionedAccounts(model.NotificationEventType_EVENT_DEPLOYMENT_PLANNED)
// if err != nil {
// p.logger.Error("failed to get the list of accounts", zap.Error(err))
// }

// defer func() {
// p.notifier.Notify(model.NotificationEvent{
// Type: model.NotificationEventType_EVENT_DEPLOYMENT_PLANNED,
// Metadata: &model.NotificationEventDeploymentPlanned{
// Deployment: p.deployment,
// Summary: out.Summary,
// MentionedAccounts: accounts,
// },
// })
// }()

// for retry.WaitNext(ctx) {
// if _, err = p.apiClient.ReportDeploymentPlanned(ctx, req); err == nil {
// return nil
// }
// err = fmt.Errorf("failed to report deployment status to control-plane: %v", err)
// }

// if err != nil {
// p.logger.Error("failed to mark deployment to be planned", zap.Error(err))
// }
// return err
// }

func (p *planner) reportDeploymentFailed(ctx context.Context, reason string) error {
var (
Expand Down
Loading
Loading