Skip to content

[SDK] Add type parameter for DeploymentSource and unmarshalling the spec #5740

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

Merged
merged 35 commits into from
Apr 17, 2025

Conversation

Warashi
Copy link
Contributor

@Warashi Warashi commented Apr 16, 2025

What this PR does:

This PR adds a type parameter to the DeploymentSource struct and Unmarshalling app.pipecd.yaml when invoking the plugins' methods.

Why we need it:

I realized we can do this, and I don't want each plugin developer to write config unmarshalling code.

Which issue(s) this PR fixes:

Part of #5530

Does this PR introduce a user-facing change?:

  • How are users affected by this change:
  • Is this breaking change:
  • How to migrate (if breaking change):

Warashi added 17 commits April 16, 2025 16:30
Signed-off-by: Shinnosuke Sawada-Dazai <[email protected]>
Signed-off-by: Shinnosuke Sawada-Dazai <[email protected]>
Signed-off-by: Shinnosuke Sawada-Dazai <[email protected]>
Signed-off-by: Shinnosuke Sawada-Dazai <[email protected]>
Signed-off-by: Shinnosuke Sawada-Dazai <[email protected]>
Signed-off-by: Shinnosuke Sawada-Dazai <[email protected]>
Signed-off-by: Shinnosuke Sawada-Dazai <[email protected]>
Signed-off-by: Shinnosuke Sawada-Dazai <[email protected]>
Signed-off-by: Shinnosuke Sawada-Dazai <[email protected]>
Signed-off-by: Shinnosuke Sawada-Dazai <[email protected]>
Signed-off-by: Shinnosuke Sawada-Dazai <[email protected]>
Warashi added 4 commits April 16, 2025 17:16
Signed-off-by: Shinnosuke Sawada-Dazai <[email protected]>
Signed-off-by: Shinnosuke Sawada-Dazai <[email protected]>
Signed-off-by: Shinnosuke Sawada-Dazai <[email protected]>
Warashi added 2 commits April 16, 2025 17:44
Signed-off-by: Shinnosuke Sawada-Dazai <[email protected]>
Signed-off-by: Shinnosuke Sawada-Dazai <[email protected]>
Copy link

codecov bot commented Apr 16, 2025

Codecov Report

Attention: Patch coverage is 34.73684% with 124 lines in your changes missing coverage. Please review.

Project coverage is 26.98%. Comparing base (4ca4a01) to head (4885a40).
Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
pkg/plugin/sdk/deployment.go 43.54% 30 Missing and 5 partials ⚠️
pkg/plugin/sdk/deployment_source.go 46.66% 18 Missing and 6 partials ⚠️
pkg/plugin/sdk/plugin.go 0.00% 15 Missing ⚠️
pkg/plugin/sdk/sdktest/config.go 0.00% 13 Missing ⚠️
...app/pipedv1/plugin/kubernetes/deployment/plugin.go 12.50% 7 Missing ⚠️
...lugin/kubernetes_multicluster/deployment/plugin.go 12.50% 7 Missing ⚠️
.../app/pipedv1/plugin/kubernetes/livestate/plugin.go 0.00% 4 Missing ⚠️
...plugin/kubernetes_multicluster/livestate/plugin.go 0.00% 4 Missing ⚠️
...p/pipedv1/plugin/kubernetes/deployment/baseline.go 0.00% 2 Missing ⚠️
...app/pipedv1/plugin/kubernetes/deployment/canary.go 0.00% 2 Missing ⚠️
... and 10 more
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #5740      +/-   ##
==========================================
- Coverage   26.98%   26.98%   -0.01%     
==========================================
  Files         503      504       +1     
  Lines       53047    53120      +73     
==========================================
+ Hits        14317    14335      +18     
- Misses      37665    37709      +44     
- Partials     1065     1076      +11     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@Warashi Warashi marked this pull request as ready for review April 16, 2025 08:50
khanhtc1202
khanhtc1202 previously approved these changes Apr 16, 2025
Copy link
Member

@khanhtc1202 khanhtc1202 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Got the point, looks neat 👍

Copy link
Member

@ffjlabo ffjlabo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you for the nice improvement! This is what I also expected.
I left some comments.

Comment on lines 62 to 65
type ApplicationConfig[Spec any] struct {
commonSpec *config.GenericApplicationSpec
Spec *Spec
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nit] plz add comment for the struct and fields 🙏

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added comments
c92050d

Comment on lines 93 to 95
cfgBytes, err := os.ReadFile(filepath.Join(examplesDir(), "kubernetes", "simple", "app.pipecd.yaml"))
require.NoError(t, err)
cfg, err := sdk.DecodeYAML[kubeConfigPkg.KubernetesApplicationSpec](cfgBytes)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[imo]
It would be nice to define a helper function to create ApplicationConfigSpec from a file or string.
I feel users don't need to be aware of sdk.DecodeYAML in the actual logic.
WDYT?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with you, so I added sdk.LoadApplicationConfig and removed sdk.DecodeYAML
5abbdd5

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Warashi
Thank you for adding the helper method!
I read the comment and think that we can make a test package sdk/sdktest . How about you?

/ LoadApplicationConfig loads the application config from the given filename.
// This is intended to use in the tests.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ffjlabo

It sounds good.
How about making the sdktest.LoadApplicationConfig 's first argument t *testing.T and automatically calling t.Fatal when it meets an unmarshalling error and making its return value only *ApplicationConfig[Spec]?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Warashi Sounds great!!! Let's go with that!

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Implemented and switched the usage.
30bd753
4885a40

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sounds nice! That's a nice improvement!

if err != nil {
logger.Error("Failed while decoding application config", zap.Error(err))
return nil, err
cfg := input.Request.TargetDeploymentSource.ApplicationConfig.Spec
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[imo] It would be nice to add a method into DeploySource to get ApplicationConfig from DeploySource, including a nil check because ApplicationConfig is a pointer.
WDYT?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with you and I added AppConfig method
53ef850

Copy link
Member

@ffjlabo ffjlabo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM!

@Warashi Warashi enabled auto-merge (squash) April 17, 2025 01:30
@Warashi
Copy link
Contributor Author

Warashi commented Apr 17, 2025

@khanhtc1202 Sorry, please re-review

Copy link
Member

@khanhtc1202 khanhtc1202 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LNeatTM 👌

@Warashi Warashi merged commit d7d637b into master Apr 17, 2025
21 of 22 checks passed
@Warashi Warashi deleted the plugin-sdk-app-spec-type-params branch April 17, 2025 03:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants