Skip to content
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

Make platformProviders works as piped deployment provider #3815

Merged
merged 9 commits into from Jul 25, 2022

Conversation

khanhtc1202
Copy link
Member

What this PR does / why we need it:

This PR adds logic to make PlatformProviders specified via piped configuration work as the current CloudProviders. The CloudProviders configuration is marked as deprecated and will be removed after a few releases.

Which issue(s) this PR fixes:

Fixes #

Does this PR introduce a user-facing change?:

Enable PlatformProviders as piped configuration

@khanhtc1202 khanhtc1202 enabled auto-merge (squash) July 21, 2022 06:10
knanao
knanao previously approved these changes Jul 21, 2022
Comment on lines 190 to 205
func (s *PipedSpec) HasPlatformProvider(name string, t model.ApplicationKind) bool {
requiredProviderType := t.CompatiblePlatformProviderType()
for _, cp := range s.PlatformProviders {
if cp.Name == name && cp.Type == requiredProviderType {
return true
}
if cp.Type != requiredProviderType {
continue
}
for _, pp := range s.CloudProviders {
if pp.Name == name && pp.Type == requiredProviderType {
return true
}
return true
}
return false
}
Copy link
Member

Choose a reason for hiding this comment

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

To avoid duplication how about removing this function and use FindCloudProvider instead?

Copy link
Member Author

Choose a reason for hiding this comment

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

addressed by f413a7e

Comment on lines 210 to 221
for _, p := range s.PlatformProviders {
if p.Name != name {
continue
}
if p.Type != requiredProviderType {
continue
}
return p, true
}
for _, p := range s.CloudProviders {
if p.Name != name {
continue
Copy link
Member

@nghialv nghialv Jul 21, 2022

Choose a reason for hiding this comment

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

I feel that instead of keeping both fields as this, converting all configuration ways to use only a single PlatformProviders field could be easier to maintain.
I mean we can remove the CloudProviders field immediately from the Piped config and customizing the Unmarhal function to allow accepting both cloudProviders and platformProviders specifications in YAML.

Copy link
Member

@nghialv nghialv Jul 21, 2022

Choose a reason for hiding this comment

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

And by that way, I guess that we can remove a lot of duplications that are being added via this PR.

Copy link
Member Author

Choose a reason for hiding this comment

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

Nice idea, lets me try this 👍

Copy link
Member Author

Choose a reason for hiding this comment

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

addressed by 63d4b7e 🙏

Version: version.Get().Version,
Config: string(maskedCfg),
Repositories: repos,
CloudProviders: make([]*model.Piped_CloudProvider, 0, len(cfg.CloudProviders)),
Copy link
Member

Choose a reason for hiding this comment

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

Is it ok to remove this field in gRPC?
As far as I see only CloudProvider is being used in the implementation of that RPC.
https://github.com/pipe-cd/pipecd/blob/master/pkg/app/server/grpcapi/piped_api.go#L167-L194

Copy link
Member Author

Choose a reason for hiding this comment

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

Nice catch, the current implementation pass from the test because I updated the ReportPipedMetaRequest previously (in here).

The API update for that is included by another PR

--- a/pkg/app/server/grpcapi/piped_api.go
+++ b/pkg/app/server/grpcapi/piped_api.go
@@ -69,7 +69,7 @@ type pipedApiDeploymentChainStore interface {
 
 type pipedApiPipedStore interface {
        Get(ctx context.Context, id string) (*model.Piped, error)
-       UpdateMetadata(ctx context.Context, id, version, config string, cps []*model.Piped_CloudProvider, repos []*model.ApplicationGitRepository, se *model.Piped_SecretEncryption, startedAt int64) error
+       UpdateMetadata(ctx context.Context, id, version, config string, pps []*model.Piped_PlatformProvider, repos []*model.ApplicationGitRepository, se *model.Piped_SecretEncryption, startedAt int64) error
 }
 
 type pipedApiEventStore interface {
@@ -176,7 +176,7 @@ func (a *PipedAPI) ReportPipedMeta(ctx context.Context, req *pipedservice.Report
                pipedID,
                req.Version,
                req.Config,
-               req.CloudProviders,
+               req.PlatformProviders,
                req.Repositories,
                req.SecretEncryption,
                now,

but you're right, maybe we should include the change for that in this PR as well 🤔

Copy link
Member

Choose a reason for hiding this comment

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

maybe we should include the change for that in this PR as well

Yes, that is better. Or the PR for that API change should be merged before this PR.

Copy link
Member Author

Choose a reason for hiding this comment

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

Okay, lets me revise this. Thank you 🙏

Copy link
Member Author

Choose a reason for hiding this comment

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

addressed by 0272ba2

knanao
knanao previously approved these changes Jul 24, 2022
// HasPlatformProvider checks whether the given provider is configured or not.
func (s *PipedSpec) HasPlatformProvider(name string, t model.ApplicationKind) bool {
_, contains := s.FindPlatformProvider(name, t)
return contains
Copy link
Member

Choose a reason for hiding this comment

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

Nice!

@khanhtc1202
Copy link
Member Author

/hold
Hold until PR #3817 be merged ⏱️

Comment on lines 87 to 100
func (s *PipedSpec) UnmarshalJSON(data []byte) error {
ps := pipedSpec{}
if err := json.Unmarshal(data, &ps); err != nil {
return err
}

s.ProjectID = ps.ProjectID
s.PipedID = ps.PipedID
s.PipedKeyFile = ps.PipedKeyFile
s.PipedKeyData = ps.PipedKeyData
s.Name = ps.Name
s.APIAddress = ps.APIAddress
s.WebAddress = ps.WebAddress
s.SyncInterval = ps.SyncInterval
s.AppConfigSyncInterval = ps.AppConfigSyncInterval
s.Git = ps.Git
s.Repositories = ps.Repositories
s.ChartRegistries = ps.ChartRegistries
s.ChartRepositories = ps.ChartRepositories
// Add all CloudProviders configuration as PlatformProviders configuration.
s.PlatformProviders = append(s.PlatformProviders, ps.PlatformProviders...)
s.PlatformProviders = append(s.PlatformProviders, ps.CloudProviders...)
s.AnalysisProviders = ps.AnalysisProviders
s.Notifications = ps.Notifications
s.SecretManagement = ps.SecretManagement
s.EventWatcher = ps.EventWatcher
s.AppSelector = ps.AppSelector

return nil
}
Copy link
Member

Choose a reason for hiding this comment

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

We should avoid this manual copy.
How about this?

Suggested change
func (s *PipedSpec) UnmarshalJSON(data []byte) error {
ps := pipedSpec{}
if err := json.Unmarshal(data, &ps); err != nil {
return err
}
s.ProjectID = ps.ProjectID
s.PipedID = ps.PipedID
s.PipedKeyFile = ps.PipedKeyFile
s.PipedKeyData = ps.PipedKeyData
s.Name = ps.Name
s.APIAddress = ps.APIAddress
s.WebAddress = ps.WebAddress
s.SyncInterval = ps.SyncInterval
s.AppConfigSyncInterval = ps.AppConfigSyncInterval
s.Git = ps.Git
s.Repositories = ps.Repositories
s.ChartRegistries = ps.ChartRegistries
s.ChartRepositories = ps.ChartRepositories
// Add all CloudProviders configuration as PlatformProviders configuration.
s.PlatformProviders = append(s.PlatformProviders, ps.PlatformProviders...)
s.PlatformProviders = append(s.PlatformProviders, ps.CloudProviders...)
s.AnalysisProviders = ps.AnalysisProviders
s.Notifications = ps.Notifications
s.SecretManagement = ps.SecretManagement
s.EventWatcher = ps.EventWatcher
s.AppSelector = ps.AppSelector
return nil
}
func (s *PipedSpec) UnmarshalJSON(data []byte) error {
type Alias PipedSpec
ps := &struct {
*Alias
}{
Alias: (*Alias)(s),
}
if err := json.Unmarshal(b, &ps); err != nil {
return err
}
// Add all CloudProviders configuration as PlatformProviders configuration.
s.PlatformProviders = append(s.PlatformProviders, ps.CloudProviders...)
s.CloudProviders = nil
return nil
}

Copy link
Member Author

Choose a reason for hiding this comment

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

Nice, thanks to teach me about that 🙏

Copy link
Member Author

Choose a reason for hiding this comment

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

addressed by a7a4767

@khanhtc1202 khanhtc1202 enabled auto-merge (squash) July 25, 2022 06:51
@khanhtc1202
Copy link
Member Author

@nghialv @knanao it's ready to review, ptal when you guys have time 🙏

Copy link
Member

@nghialv nghialv left a comment

Choose a reason for hiding this comment

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

Looks good.

Copy link
Member

@knanao knanao left a comment

Choose a reason for hiding this comment

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

let's go

@khanhtc1202 khanhtc1202 merged commit 0fb6e72 into master Jul 25, 2022
@khanhtc1202 khanhtc1202 deleted the platform-provider-logic branch July 25, 2022 09:11
@github-actions github-actions bot mentioned this pull request Aug 4, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants