-
Notifications
You must be signed in to change notification settings - Fork 151
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* [WIP] Add planner Signed-off-by: Yoshiki Fujikane <ffjlabo@gmail.com> * Not to use out.Version Signed-off-by: Yoshiki Fujikane <ffjlabo@gmail.com> * Use last_successful_commit_hash and last_successful_config_file_name Signed-off-by: Yoshiki Fujikane <ffjlabo@gmail.com> * Use in.WorkingDir Signed-off-by: Yoshiki Fujikane <ffjlabo@gmail.com> * Use in.PipedConfig Signed-off-by: Yoshiki Fujikane <ffjlabo@gmail.com> * Create git client Signed-off-by: Yoshiki Fujikane <ffjlabo@gmail.com> * Create secret encryptor Signed-off-by: Yoshiki Fujikane <ffjlabo@gmail.com> * Add startup server implementation Signed-off-by: Yoshiki Fujikane <ffjlabo@gmail.com> * Fix for relocation of proto api Signed-off-by: Yoshiki Fujikane <ffjlabo@gmail.com> * Add roughly implementation for planner plugin Signed-off-by: Yoshiki Fujikane <ffjlabo@gmail.com> * Rename pkg name Signed-off-by: Yoshiki Fujikane <ffjlabo@gmail.com> * Add licence Signed-off-by: Yoshiki Fujikane <ffjlabo@gmail.com> * Comment out for the testing code Signed-off-by: Yoshiki Fujikane <ffjlabo@gmail.com> --------- Signed-off-by: Yoshiki Fujikane <ffjlabo@gmail.com>
- Loading branch information
Showing
5 changed files
with
919 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// 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 main | ||
|
||
import ( | ||
"log" | ||
|
||
"github.com/pipe-cd/pipecd/pkg/cli" | ||
) | ||
|
||
func main() { | ||
app := cli.NewApp( | ||
"pipecd-plugin-kubernetes", | ||
"Plugin component to deploy Kubernetes Application.", | ||
) | ||
app.AddCommands( | ||
NewServerCommand(), | ||
) | ||
if err := app.Run(); err != nil { | ||
log.Fatal(err) | ||
} | ||
} |
146 changes: 146 additions & 0 deletions
146
pkg/app/pipedv1/plugin/platform/kubernetes/planner/pipeline.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,146 @@ | ||
// 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 planner | ||
|
||
import ( | ||
"encoding/json" | ||
"fmt" | ||
"time" | ||
|
||
"github.com/pipe-cd/pipecd/pkg/app/pipedv1/planner" | ||
"github.com/pipe-cd/pipecd/pkg/config" | ||
"github.com/pipe-cd/pipecd/pkg/model" | ||
) | ||
|
||
func buildQuickSyncPipeline(autoRollback bool, now time.Time) []*model.PipelineStage { | ||
var ( | ||
preStageID = "" | ||
stage, _ = planner.GetPredefinedStage(planner.PredefinedStageK8sSync) | ||
stages = []config.PipelineStage{stage} | ||
out = make([]*model.PipelineStage, 0, len(stages)) | ||
) | ||
|
||
for i, s := range stages { | ||
id := s.ID | ||
if id == "" { | ||
id = fmt.Sprintf("stage-%d", i) | ||
} | ||
stage := &model.PipelineStage{ | ||
Id: id, | ||
Name: s.Name.String(), | ||
Desc: s.Desc, | ||
Index: int32(i), | ||
Predefined: true, | ||
Visible: true, | ||
Status: model.StageStatus_STAGE_NOT_STARTED_YET, | ||
Metadata: planner.MakeInitialStageMetadata(s), | ||
CreatedAt: now.Unix(), | ||
UpdatedAt: now.Unix(), | ||
} | ||
if preStageID != "" { | ||
stage.Requires = []string{preStageID} | ||
} | ||
preStageID = id | ||
out = append(out, stage) | ||
} | ||
|
||
if autoRollback { | ||
s, _ := planner.GetPredefinedStage(planner.PredefinedStageRollback) | ||
out = append(out, &model.PipelineStage{ | ||
Id: s.ID, | ||
Name: s.Name.String(), | ||
Desc: s.Desc, | ||
Predefined: true, | ||
Visible: false, | ||
Status: model.StageStatus_STAGE_NOT_STARTED_YET, | ||
CreatedAt: now.Unix(), | ||
UpdatedAt: now.Unix(), | ||
}) | ||
} | ||
|
||
return out | ||
} | ||
|
||
func buildProgressivePipeline(pp *config.DeploymentPipeline, autoRollback bool, now time.Time) []*model.PipelineStage { | ||
var ( | ||
preStageID = "" | ||
out = make([]*model.PipelineStage, 0, len(pp.Stages)) | ||
) | ||
|
||
for i, s := range pp.Stages { | ||
id := s.ID | ||
if id == "" { | ||
id = fmt.Sprintf("stage-%d", i) | ||
} | ||
stage := &model.PipelineStage{ | ||
Id: id, | ||
Name: s.Name.String(), | ||
Desc: s.Desc, | ||
Index: int32(i), | ||
Predefined: false, | ||
Visible: true, | ||
Status: model.StageStatus_STAGE_NOT_STARTED_YET, | ||
Metadata: planner.MakeInitialStageMetadata(s), | ||
CreatedAt: now.Unix(), | ||
UpdatedAt: now.Unix(), | ||
} | ||
if preStageID != "" { | ||
stage.Requires = []string{preStageID} | ||
} | ||
preStageID = id | ||
out = append(out, stage) | ||
} | ||
|
||
if autoRollback { | ||
s, _ := planner.GetPredefinedStage(planner.PredefinedStageRollback) | ||
out = append(out, &model.PipelineStage{ | ||
Id: s.ID, | ||
Name: s.Name.String(), | ||
Desc: s.Desc, | ||
Predefined: true, | ||
Visible: false, | ||
Status: model.StageStatus_STAGE_NOT_STARTED_YET, | ||
CreatedAt: now.Unix(), | ||
UpdatedAt: now.Unix(), | ||
}) | ||
|
||
// Add a stage for rolling back script run stages. | ||
for i, s := range pp.Stages { | ||
if s.Name == model.StageScriptRun { | ||
// Use metadata as a way to pass parameters to the stage. | ||
envStr, _ := json.Marshal(s.ScriptRunStageOptions.Env) | ||
metadata := map[string]string{ | ||
"baseStageID": out[i].Id, | ||
"onRollback": s.ScriptRunStageOptions.OnRollback, | ||
"env": string(envStr), | ||
} | ||
ss, _ := planner.GetPredefinedStage(planner.PredefinedStageScriptRunRollback) | ||
out = append(out, &model.PipelineStage{ | ||
Id: ss.ID, | ||
Name: ss.Name.String(), | ||
Desc: ss.Desc, | ||
Predefined: true, | ||
Visible: false, | ||
Status: model.StageStatus_STAGE_NOT_STARTED_YET, | ||
Metadata: metadata, | ||
CreatedAt: now.Unix(), | ||
UpdatedAt: now.Unix(), | ||
}) | ||
} | ||
} | ||
} | ||
|
||
return out | ||
} |
Oops, something went wrong.