-
Notifications
You must be signed in to change notification settings - Fork 153
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
Conversation
pkg/config/piped.go
Outdated
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 | ||
} |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
addressed by f413a7e
pkg/config/piped.go
Outdated
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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 👍
There was a problem hiding this comment.
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)), |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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 🤔
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 🙏
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
addressed by 0272ba2
// 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 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice!
/hold |
pkg/config/piped.go
Outdated
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 | ||
} |
There was a problem hiding this comment.
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?
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 | |
} |
There was a problem hiding this comment.
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 🙏
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
addressed by a7a4767
…guration load as platformProviders
Co-authored-by: nghialv <[email protected]>
a7a4767
to
d91cf3e
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let's go
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?: