Skip to content

Commit

Permalink
Implement k8s plugin's FetchDefinedStages and BuildQuickSyncStages (#…
Browse files Browse the repository at this point in the history
…5223)

* Pass the deployment source directory to the plugins

Signed-off-by: Shinnosuke Sawada-Dazai <[email protected]>

* Add Deploysource

Signed-off-by: Shinnosuke Sawada-Dazai <[email protected]>

* Remove GenericApplicationSpec from DeploymentSource

Signed-off-by: Shinnosuke Sawada-Dazai <[email protected]>

* Do make gen/code

Signed-off-by: Shinnosuke Sawada-Dazai <[email protected]>

* Rename planner plugin to deployment plugin

Signed-off-by: Shinnosuke Sawada-Dazai <[email protected]>

* Implement FetchDefinedStages

Signed-off-by: Shinnosuke Sawada-Dazai <[email protected]>

* Implement BuildQuickSyncStages

Signed-off-by: Shinnosuke Sawada-Dazai <[email protected]>

* Add TODO comment at DetermineVersions

Signed-off-by: Shinnosuke Sawada-Dazai <[email protected]>

---------

Signed-off-by: Shinnosuke Sawada-Dazai <[email protected]>
  • Loading branch information
Warashi authored Sep 25, 2024
1 parent 90f6a1f commit fb46bdb
Show file tree
Hide file tree
Showing 4 changed files with 127 additions and 71 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

package planner
package deployment

import (
"fmt"
Expand All @@ -23,11 +23,47 @@ import (
"github.com/pipe-cd/pipecd/pkg/model"
)

type Stage string

const (
// StageK8sSync represents the state where
// all resources should be synced with the Git state.
StageK8sSync Stage = "K8S_SYNC"
// StageK8sPrimaryRollout represents the state where
// the PRIMARY variant resources has been updated to the new version/configuration.
StageK8sPrimaryRollout Stage = "K8S_PRIMARY_ROLLOUT"
// StageK8sCanaryRollout represents the state where
// the CANARY variant resources has been rolled out with the new version/configuration.
StageK8sCanaryRollout Stage = "K8S_CANARY_ROLLOUT"
// StageK8sCanaryClean represents the state where
// the CANARY variant resources has been cleaned.
StageK8sCanaryClean Stage = "K8S_CANARY_CLEAN"
// StageK8sBaselineRollout represents the state where
// the BASELINE variant resources has been rolled out.
StageK8sBaselineRollout Stage = "K8S_BASELINE_ROLLOUT"
// StageK8sBaselineClean represents the state where
// the BASELINE variant resources has been cleaned.
StageK8sBaselineClean Stage = "K8S_BASELINE_CLEAN"
// StageK8sTrafficRouting represents the state where the traffic to application
// should be splitted as the specified percentage to PRIMARY, CANARY, BASELINE variants.
StageK8sTrafficRouting Stage = "K8S_TRAFFIC_ROUTING"
)

var AllStages = []Stage{
StageK8sSync,
StageK8sPrimaryRollout,
StageK8sCanaryRollout,
StageK8sCanaryClean,
StageK8sBaselineRollout,
StageK8sBaselineClean,
StageK8sTrafficRouting,
}

const (
PredefinedStageK8sSync = "K8sSync"
PredefinedStageRollback = "Rollback"
PredefinedStageK8sSync = "K8sSync"
PredefinedStageRollback = "Rollback"
)

var predefinedStages = map[string]config.PipelineStage{
PredefinedStageK8sSync: {
ID: PredefinedStageK8sSync,
Expand All @@ -54,7 +90,6 @@ func MakeInitialStageMetadata(cfg config.PipelineStage) map[string]string {
}
}


func buildQuickSyncPipeline(autoRollback bool, now time.Time) []*model.PipelineStage {
var (
preStageID = ""
Expand Down
85 changes: 85 additions & 0 deletions pkg/app/pipedv1/plugin/kubernetes/deployment/server.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
// Copyright 2024 The PipeCD Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

package deployment

import (
"context"
"time"

"github.com/pipe-cd/pipecd/pkg/plugin/api/v1alpha1/deployment"
"github.com/pipe-cd/pipecd/pkg/regexpool"

"go.uber.org/zap"
"google.golang.org/grpc"
)

type DeploymentService struct {
deployment.UnimplementedDeploymentServiceServer

RegexPool *regexpool.Pool
Logger *zap.Logger
}

// NewDeploymentService creates a new planService.
func NewDeploymentService(
logger *zap.Logger,
) *DeploymentService {
return &DeploymentService{
RegexPool: regexpool.DefaultPool(),
Logger: logger.Named("planner"),
}
}

// Register registers all handling of this service into the specified gRPC server.
func (a *DeploymentService) Register(server *grpc.Server) {
deployment.RegisterDeploymentServiceServer(server, a)
}

// DetermineStrategy implements deployment.DeploymentServiceServer.
func (a *DeploymentService) DetermineStrategy(context.Context, *deployment.DetermineStrategyRequest) (*deployment.DetermineStrategyResponse, error) {
panic("unimplemented")
}

// DetermineVersions implements deployment.DeploymentServiceServer.
func (a *DeploymentService) DetermineVersions(context.Context, *deployment.DetermineVersionsRequest) (*deployment.DetermineVersionsResponse, error) {
// TODO: how to determine whether the runnning or target deployment to use?
panic("unimplemented")
}

// BuildPipelineSyncStages implements deployment.DeploymentServiceServer.
func (a *DeploymentService) BuildPipelineSyncStages(context.Context, *deployment.BuildPipelineSyncStagesRequest) (*deployment.BuildPipelineSyncStagesResponse, error) {
panic("unimplemented")
}

// BuildQuickSyncStages implements deployment.DeploymentServiceServer.
func (a *DeploymentService) BuildQuickSyncStages(ctx context.Context, request *deployment.BuildQuickSyncStagesRequest) (*deployment.BuildQuickSyncStagesResponse, error) {
now := time.Now()
stages := buildQuickSyncPipeline(request.GetRollback(), now)
return &deployment.BuildQuickSyncStagesResponse{
Stages: stages,
}, nil
}

// FetchDefinedStages implements deployment.DeploymentServiceServer.
func (a *DeploymentService) FetchDefinedStages(context.Context, *deployment.FetchDefinedStagesRequest) (*deployment.FetchDefinedStagesResponse, error) {
stages := make([]string, 0, len(AllStages))
for _, s := range AllStages {
stages = append(stages, string(s))
}

return &deployment.FetchDefinedStagesResponse{
Stages: stages,
}, nil
}
63 changes: 0 additions & 63 deletions pkg/app/pipedv1/plugin/kubernetes/planner/server.go

This file was deleted.

5 changes: 2 additions & 3 deletions pkg/app/pipedv1/plugin/kubernetes/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (
"context"
"time"

"github.com/pipe-cd/pipecd/pkg/app/pipedv1/plugin/kubernetes/planner"
"github.com/pipe-cd/pipecd/pkg/app/pipedv1/plugin/kubernetes/deployment"
"github.com/pipe-cd/pipecd/pkg/cli"
"github.com/pipe-cd/pipecd/pkg/rpc"
"github.com/spf13/cobra"
Expand Down Expand Up @@ -71,8 +71,7 @@ func (s *server) run(ctx context.Context, input cli.Input) (runErr error) {
// Start a gRPC server for handling external API requests.
{
var (
service = planner.NewPlannerService(
nil, // TODO: Inject the real secret decrypter. It should be a instance of pipedv1/plugin/secrets.Decrypter.
service = deployment.NewDeploymentService(
input.Logger,
)
opts = []rpc.Option{
Expand Down

0 comments on commit fb46bdb

Please sign in to comment.