Skip to content
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
30 changes: 30 additions & 0 deletions pkg/app/api/grpcapi/piped_api.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,36 @@ func (a *PipedAPI) ReportApplicationSyncState(ctx context.Context, req *pipedser
return &pipedservice.ReportApplicationSyncStateResponse{}, nil
}

// ReportApplicationDeployingStatus is used to report whether the specified application is deploying or not.
func (a *PipedAPI) ReportApplicationDeployingStatus(ctx context.Context, req *pipedservice.ReportApplicationDeployingStatusRequest) (*pipedservice.ReportApplicationDeployingStatusResponse, error) {
_, pipedID, _, err := rpcauth.ExtractPipedToken(ctx)
if err != nil {
return nil, err
}
if err := a.validateAppBelongsToPiped(ctx, req.ApplicationId, pipedID); err != nil {
return nil, err
}

err = a.applicationStore.UpdateApplication(ctx, req.ApplicationId, func(app *model.Application) error {
app.Deploying = req.Deploying
return nil
})
switch err {
case datastore.ErrNotFound:
return nil, status.Error(codes.InvalidArgument, "application is not found")
case datastore.ErrInvalidArgument:
return nil, status.Error(codes.InvalidArgument, "invalid value for update")
default:
a.logger.Error("failed to update deploying status of application",
zap.String("application-id", req.ApplicationId),
zap.Error(err),
)
return nil, status.Error(codes.Internal, "failed to update deploying status of application")
}

return &pipedservice.ReportApplicationDeployingStatusResponse{}, nil
}

// ReportApplicationMostRecentDeployment is used to update the basic information about
// the most recent deployment of a specific application.
func (a *PipedAPI) ReportApplicationMostRecentDeployment(ctx context.Context, req *pipedservice.ReportApplicationMostRecentDeploymentRequest) (*pipedservice.ReportApplicationMostRecentDeploymentResponse, error) {
Expand Down
15 changes: 15 additions & 0 deletions pkg/app/api/service/pipedservice/pipedclientfake/fakeclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,21 @@ func (c *fakeClient) ReportApplicationSyncState(ctx context.Context, req *pipeds
return &pipedservice.ReportApplicationSyncStateResponse{}, nil
}

// ReportApplicationDeployingStatus is used to report whether the specified application is deploying or not.
func (c *fakeClient) ReportApplicationDeployingStatus(_ context.Context, req *pipedservice.ReportApplicationDeployingStatusRequest, _ ...grpc.CallOption) (*pipedservice.ReportApplicationDeployingStatusResponse, error) {
c.logger.Info("fake client received ReportApplicationDeployingStatus rpc", zap.Any("request", req))
c.mu.RLock()
defer c.mu.RUnlock()

app, ok := c.applications[req.ApplicationId]
if !ok {
return nil, status.Error(codes.NotFound, "application was not found")
}
app.Deploying = req.Deploying

return &pipedservice.ReportApplicationDeployingStatusResponse{}, nil
}

// ReportApplicationMostRecentDeployment is used to update the basic information about
// the most recent deployment of a specific application.
func (c *fakeClient) ReportApplicationMostRecentDeployment(ctx context.Context, req *pipedservice.ReportApplicationMostRecentDeploymentRequest, opts ...grpc.CallOption) (*pipedservice.ReportApplicationMostRecentDeploymentResponse, error) {
Expand Down
11 changes: 11 additions & 0 deletions pkg/app/api/service/pipedservice/service.proto
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ service PipedService {
// ReportApplicationSyncState is used to update the sync status of an application.
rpc ReportApplicationSyncState(ReportApplicationSyncStateRequest) returns (ReportApplicationSyncStateResponse) {}

// ReportApplicationDeployingStatus is used to report whether the specified application is deploying or not.
rpc ReportApplicationDeployingStatus(ReportApplicationDeployingStatusRequest) returns (ReportApplicationDeployingStatusResponse) {}

// ReportApplicationMostRecentDeployment is used to update the basic information about
// the most recent deployment of a specific application.
rpc ReportApplicationMostRecentDeployment(ReportApplicationMostRecentDeploymentRequest) returns (ReportApplicationMostRecentDeploymentResponse) {}
Expand Down Expand Up @@ -173,6 +176,14 @@ message ReportApplicationSyncStateRequest {
message ReportApplicationSyncStateResponse {
}

message ReportApplicationDeployingStatusRequest {
string application_id = 1 [(validate.rules).string.min_len = 1];
bool deploying = 2;
}

message ReportApplicationDeployingStatusResponse {
}

message ReportApplicationMostRecentDeploymentRequest {
string application_id = 1 [(validate.rules).string.min_len = 1];
pipe.model.DeploymentStatus status = 2 [(validate.rules).enum.defined_only = true];
Expand Down
22 changes: 21 additions & 1 deletion pkg/app/piped/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ import (

type apiClient interface {
GetApplicationMostRecentDeployment(ctx context.Context, req *pipedservice.GetApplicationMostRecentDeploymentRequest, opts ...grpc.CallOption) (*pipedservice.GetApplicationMostRecentDeploymentResponse, error)
ReportApplicationDeployingStatus(ctx context.Context, req *pipedservice.ReportApplicationDeployingStatusRequest, opts ...grpc.CallOption) (*pipedservice.ReportApplicationDeployingStatusResponse, error)
ReportDeploymentPlanned(ctx context.Context, req *pipedservice.ReportDeploymentPlannedRequest, opts ...grpc.CallOption) (*pipedservice.ReportDeploymentPlannedResponse, error)
ReportDeploymentStatusChanged(ctx context.Context, req *pipedservice.ReportDeploymentStatusChangedRequest, opts ...grpc.CallOption) (*pipedservice.ReportDeploymentStatusChangedResponse, error)
ReportDeploymentCompleted(ctx context.Context, req *pipedservice.ReportDeploymentCompletedRequest, opts ...grpc.CallOption) (*pipedservice.ReportDeploymentCompletedResponse, error)
Expand Down Expand Up @@ -192,7 +193,7 @@ func (c *controller) Run(ctx context.Context) error {
c.logger.Info("start running controller")

// Make sure the existence of the workspace directory.
// Each planner/scheduler will have an working directory inside this workspace.
// Each planner/scheduler will have a working directory inside this workspace.
dir, err := ioutil.TempDir("", "workspace")
if err != nil {
c.logger.Error("failed to create workspace directory", zap.Error(err))
Expand Down Expand Up @@ -589,6 +590,25 @@ func (c *controller) getMostRecentlySuccessfulDeployment(ctx context.Context, ap
return nil, err
}

func (c *controller) reportApplicationDeployingStatus(ctx context.Context, appID string, deploying bool) error {
var (
err error
retry = pipedservice.NewRetry(10)
req = &pipedservice.ReportApplicationDeployingStatusRequest{
ApplicationId: appID,
Deploying: deploying,
}
)

for retry.WaitNext(ctx) {
if _, err = c.apiClient.ReportApplicationDeployingStatus(ctx, req); err == nil {
return nil
}
err = fmt.Errorf("failed to report application deploying status to control-plane: %w", err)
}
return err
}

type appLiveResourceLister struct {
lister liveResourceLister
cloudProvider string
Expand Down