-
Notifications
You must be signed in to change notification settings - Fork 208
Implement QuickSyncPlan for k8s plugin #5020
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
Changes from all commits
4b4ee33
2d03122
2203a1e
6d3a18a
0a9a0e9
355ce05
0b562e4
d845f7a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| // 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 plugin | ||
|
|
||
| import ( | ||
| "os/exec" | ||
|
|
||
| "github.com/pipe-cd/pipecd/pkg/app/pipedv1/deploysource" | ||
| "github.com/pipe-cd/pipecd/pkg/git" | ||
| "github.com/pipe-cd/pipecd/pkg/plugin/api/v1alpha1/platform" | ||
| ) | ||
|
|
||
| func GetPlanSourceCloner(input *platform.PlanPluginInput) (deploysource.SourceCloner, error) { | ||
|
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🤔 I wonder where we should place utilities like this function.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I got your point, let's find out later. In this PR, place it here is LGTM 👍 |
||
| gitPath, err := exec.LookPath("git") | ||
| if err != nil { | ||
| return nil, err | ||
| } | ||
|
|
||
| cloner := deploysource.NewLocalSourceCloner( | ||
| git.NewRepo(input.GetSourceRemoteUrl(), gitPath, input.GetSourceRemoteUrl(), input.GetDeployment().GetGitPath().GetRepo().GetBranch(), nil), | ||
| "target", | ||
| input.GetDeployment().GetGitPath().GetRepo().GetBranch(), | ||
| ) | ||
|
|
||
| return cloner, nil | ||
| } | ||
| Original file line number | Diff line number | Diff line change | ||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -17,17 +17,27 @@ package planner | |||||||||||||||
| import ( | ||||||||||||||||
| "context" | ||||||||||||||||
| "fmt" | ||||||||||||||||
| "io" | ||||||||||||||||
| "os" | ||||||||||||||||
| "time" | ||||||||||||||||
|
|
||||||||||||||||
| "github.com/pipe-cd/pipecd/pkg/app/pipedv1/deploysource" | ||||||||||||||||
| "github.com/pipe-cd/pipecd/pkg/app/pipedv1/plugin" | ||||||||||||||||
| "github.com/pipe-cd/pipecd/pkg/plugin/api/v1alpha1/platform" | ||||||||||||||||
| "github.com/pipe-cd/pipecd/pkg/regexpool" | ||||||||||||||||
|
|
||||||||||||||||
| "go.uber.org/zap" | ||||||||||||||||
| "google.golang.org/grpc" | ||||||||||||||||
| ) | ||||||||||||||||
|
|
||||||||||||||||
| type secretDecrypter interface { | ||||||||||||||||
| Decrypt(string) (string, error) | ||||||||||||||||
| } | ||||||||||||||||
|
|
||||||||||||||||
| type PlannerService struct { | ||||||||||||||||
| platform.UnimplementedPlannerServiceServer | ||||||||||||||||
|
|
||||||||||||||||
| Decrypter secretDecrypter | ||||||||||||||||
| RegexPool *regexpool.Pool | ||||||||||||||||
| Logger *zap.Logger | ||||||||||||||||
| } | ||||||||||||||||
|
|
@@ -38,8 +48,12 @@ func (a *PlannerService) Register(server *grpc.Server) { | |||||||||||||||
| } | ||||||||||||||||
|
|
||||||||||||||||
| // NewPlannerService creates a new planService. | ||||||||||||||||
| func NewPlannerService(logger *zap.Logger) *PlannerService { | ||||||||||||||||
| func NewPlannerService( | ||||||||||||||||
| decrypter secretDecrypter, | ||||||||||||||||
| logger *zap.Logger, | ||||||||||||||||
| ) *PlannerService { | ||||||||||||||||
| return &PlannerService{ | ||||||||||||||||
| Decrypter: decrypter, | ||||||||||||||||
| RegexPool: regexpool.DefaultPool(), | ||||||||||||||||
| Logger: logger.Named("planner"), | ||||||||||||||||
| } | ||||||||||||||||
|
|
@@ -63,7 +77,39 @@ func (ps *PlannerService) DetermineStrategy(ctx context.Context, in *platform.De | |||||||||||||||
| } | ||||||||||||||||
|
|
||||||||||||||||
| func (ps *PlannerService) QuickSyncPlan(ctx context.Context, in *platform.QuickSyncPlanRequest) (*platform.QuickSyncPlanResponse, error) { | ||||||||||||||||
| return nil, fmt.Errorf("not implemented yet") | ||||||||||||||||
| now := time.Now() | ||||||||||||||||
|
|
||||||||||||||||
| cloner, err := plugin.GetPlanSourceCloner(in.GetInput()) | ||||||||||||||||
| if err != nil { | ||||||||||||||||
| return nil, err | ||||||||||||||||
| } | ||||||||||||||||
|
|
||||||||||||||||
| d, err := os.MkdirTemp("", "") // TODO | ||||||||||||||||
| if err != nil { | ||||||||||||||||
| return nil, fmt.Errorf("failed to prepare temporary directory (%w)", err) | ||||||||||||||||
| } | ||||||||||||||||
| defer os.RemoveAll(d) | ||||||||||||||||
|
Comment on lines
+87
to
+91
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @Warashi Question: pipecd/pkg/app/piped/controller/controller.go Lines 438 to 443 in 6400c89
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If we make it that way, then the piped.planner object will create the workingDir then clone/pull the deploy source, then we pass the workingDir (which contains cloned source) to the planner plugin via PlanPluginInput.
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That sounds nice.
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok, let address it by another PR 👍 |
||||||||||||||||
|
|
||||||||||||||||
| p := deploysource.NewProvider( | ||||||||||||||||
| d, | ||||||||||||||||
| cloner, | ||||||||||||||||
| *in.GetInput().GetDeployment().GetGitPath(), | ||||||||||||||||
| ps.Decrypter, | ||||||||||||||||
| ) | ||||||||||||||||
|
|
||||||||||||||||
| ds, err := p.GetReadOnly(ctx, io.Discard /* TODO */) | ||||||||||||||||
| if err != nil { | ||||||||||||||||
| return nil, err | ||||||||||||||||
| } | ||||||||||||||||
|
|
||||||||||||||||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nits cfg := ds.ApplicationConfig.KubernetesApplicationSpec
if cfg == nil {
return nil, fmt.Errorf("missing KubernetesApplicationSpec in application configuration")
}Should check spec available to avoid nil pointer 👀
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I fixed it on this commit. |
||||||||||||||||
| cfg := ds.ApplicationConfig.KubernetesApplicationSpec | ||||||||||||||||
| if cfg == nil { | ||||||||||||||||
| return nil, fmt.Errorf("missing KubernetesApplicationSpec in application configuration") | ||||||||||||||||
| } | ||||||||||||||||
|
|
||||||||||||||||
| return &platform.QuickSyncPlanResponse{ | ||||||||||||||||
| Stages: buildQuickSyncPipeline(*cfg.Input.AutoRollback, now), | ||||||||||||||||
| }, nil | ||||||||||||||||
| } | ||||||||||||||||
|
|
||||||||||||||||
| func (ps *PlannerService) PipelineSyncPlan(ctx context.Context, in *platform.PipelineSyncPlanRequest) (*platform.PipelineSyncPlanResponse, error) { | ||||||||||||||||
|
|
||||||||||||||||
| 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 secrets | ||
|
|
||
| import ( | ||
| "context" | ||
| "fmt" | ||
|
|
||
| "github.com/pipe-cd/pipecd/pkg/app/pipedv1/cmd/piped/service" | ||
| ) | ||
|
|
||
| type Decrypter struct { | ||
| client service.PluginServiceClient | ||
| } | ||
|
|
||
| func (d *Decrypter) Decrypt(src string) (string, error) { | ||
| r, err := d.client.DecryptSecret(context.TODO(), &service.DecryptSecretRequest{Secret: src}) | ||
| if err != nil { | ||
| return "", fmt.Errorf("failed to decrypt secret: %w", err) | ||
| } | ||
| return r.GetDecryptedSecret(), nil | ||
| } |
Uh oh!
There was an error while loading. Please reload this page.