Implement K8S_SYNC without prune feature by using plugin SDK#5624
Implement K8S_SYNC without prune feature by using plugin SDK#5624
Conversation
Signed-off-by: Yoshiki Fujikane <ffjlabo@gmail.com>
Signed-off-by: Yoshiki Fujikane <ffjlabo@gmail.com>
Signed-off-by: Yoshiki Fujikane <ffjlabo@gmail.com>
Signed-off-by: Yoshiki Fujikane <ffjlabo@gmail.com>
Signed-off-by: Yoshiki Fujikane <ffjlabo@gmail.com>
Signed-off-by: Yoshiki Fujikane <ffjlabo@gmail.com>
Signed-off-by: Yoshiki Fujikane <ffjlabo@gmail.com>
Signed-off-by: Yoshiki Fujikane <ffjlabo@gmail.com>
Signed-off-by: Yoshiki Fujikane <ffjlabo@gmail.com>
Signed-off-by: Yoshiki Fujikane <ffjlabo@gmail.com>
Signed-off-by: Yoshiki Fujikane <ffjlabo@gmail.com>
Signed-off-by: Yoshiki Fujikane <ffjlabo@gmail.com>
d6287cb to
24a5807
Compare
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #5624 +/- ##
==========================================
+ Coverage 26.57% 26.64% +0.07%
==========================================
Files 477 478 +1
Lines 50644 50780 +136
==========================================
+ Hits 13458 13530 +72
- Misses 36128 36184 +56
- Partials 1058 1066 +8 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
| } | ||
|
|
||
| // FIXME | ||
| func (p *Plugin) executeK8sSyncStage(ctx context.Context, input *sdk.ExecuteStageInput, dts []*sdk.DeployTarget[kubeconfig.KubernetesDeployTargetConfig]) sdk.StageStatus { |
There was a problem hiding this comment.
reference implementation:
pipecd/pkg/app/pipedv1/plugin/kubernetes/deployment/sync.go
Lines 31 to 170 in 424894c
| return sdk.StageStatusSuccess | ||
| } | ||
|
|
||
| func (p *Plugin) loadManifests(ctx context.Context, deploy *sdk.Deployment, spec *kubeconfig.KubernetesApplicationSpec, deploymentSource *sdk.DeploymentSource, loader loader) ([]provider.Manifest, error) { |
There was a problem hiding this comment.
reference implementation:
pipecd/pkg/app/pipedv1/plugin/kubernetes/deployment/server.go
Lines 183 to 203 in 424894c
| return deployTargetCfg, dynamicClient | ||
| } | ||
|
|
||
| func TestPlugin_executeK8sSyncStage(t *testing.T) { |
There was a problem hiding this comment.
reference implementation:
pipecd/pkg/app/pipedv1/plugin/kubernetes/deployment/sync_test.go
Lines 40 to 106 in 424894c
| assert.Equal(t, "0123456789", deployment.GetAnnotations()["pipecd.dev/commit-hash"]) | ||
| } | ||
|
|
||
| func TestPlugin_executeK8sSyncStage_withInputNamespace(t *testing.T) { |
There was a problem hiding this comment.
reference implementation:
pipecd/pkg/app/pipedv1/plugin/kubernetes/deployment/sync_test.go
Lines 108 to 180 in 424894c
| type toolRegistry interface { | ||
| Kubectl(ctx context.Context, version string) (string, error) | ||
| Kustomize(ctx context.Context, version string) (string, error) | ||
| Helm(ctx context.Context, version string) (string, error) | ||
| } | ||
|
|
||
| type loader interface { | ||
| // LoadManifests renders and loads all manifests for application. | ||
| LoadManifests(ctx context.Context, input provider.LoaderInput) ([]provider.Manifest, error) | ||
| } | ||
|
|
||
| type applier interface { | ||
| // ApplyManifest does applying the given manifest. | ||
| ApplyManifest(ctx context.Context, manifest provider.Manifest) error | ||
| // CreateManifest does creating resource from given manifest. | ||
| CreateManifest(ctx context.Context, manifest provider.Manifest) error | ||
| // ReplaceManifest does replacing resource from given manifest. | ||
| ReplaceManifest(ctx context.Context, manifest provider.Manifest) error | ||
| // ForceReplaceManifest does force replacing resource from given manifest. | ||
| ForceReplaceManifest(ctx context.Context, manifest provider.Manifest) error | ||
| } | ||
|
|
There was a problem hiding this comment.
Moved them to plugin.go to remove server.go at the end.
| func NewClient(base *pipedapi.PipedServiceClient, pluginName, applicationID, stageID string, lp StageLogPersister, tr *toolregistry.ToolRegistry) *Client { | ||
| return &Client{ | ||
| base: base, | ||
| pluginName: pluginName, | ||
| applicationID: applicationID, | ||
| stageID: stageID, | ||
| logPersister: lp, | ||
| toolRegistry: tr, | ||
| } |
There was a problem hiding this comment.
I implemented it to use sdk.Client in the test.
It might not be the best way but I want to prior to implement quick sync logic for now.
There was a problem hiding this comment.
// Currently, this is used to create the Client in the test for the plugin made by the SDK.
Let's emphasize this comment since the sdk package is visible to plugin developers.
for example:
// DO NOT USE this function except in tests.
// FIXME: ...... (Remove this function and make a better way for tests??)
// NewClient creates a new client.Signed-off-by: Yoshiki Fujikane <ffjlabo@gmail.com>
| func NewClient(base *pipedapi.PipedServiceClient, pluginName, applicationID, stageID string, lp StageLogPersister, tr *toolregistry.ToolRegistry) *Client { | ||
| return &Client{ | ||
| base: base, | ||
| pluginName: pluginName, | ||
| applicationID: applicationID, | ||
| stageID: stageID, | ||
| logPersister: lp, | ||
| toolRegistry: tr, | ||
| } |
There was a problem hiding this comment.
// Currently, this is used to create the Client in the test for the plugin made by the SDK.
Let's emphasize this comment since the sdk package is visible to plugin developers.
for example:
// DO NOT USE this function except in tests.
// FIXME: ...... (Remove this function and make a better way for tests??)
// NewClient creates a new client.Signed-off-by: Yoshiki Fujikane <ffjlabo@gmail.com>
What this PR does:
I implemented k8s sync without prune feature by using SDK.
The fix summary
deployment/plugin.go: Implementdeployment.Plugin, similar to thedeployment.DeploymentServiceto keep the current implementation working until finishing the re-implementation.deployment/plugin_test.go: Implement two tests for the quick sync features without pruning.Why we need it:
We want to implement plugins with SDK.
Which issue(s) this PR fixes:
Part of #4980 #5006
Does this PR introduce a user-facing change?: