Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions pkg/app/piped/cloudprovider/lambda/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ go_test(
],
embed = [":go_default_library"],
deps = [
"//pkg/model:go_default_library",
"@com_github_stretchr_testify//assert:go_default_library",
],
)
2 changes: 1 addition & 1 deletion pkg/app/piped/controller/scheduler.go
Original file line number Diff line number Diff line change
Expand Up @@ -434,7 +434,7 @@ func (s *scheduler) executeStage(sig executor.StopSignal, ps model.PipelineStage
}

// Check the existence of the specified cloud provider.
if !s.pipedConfig.HasCloudProvider(s.deployment.CloudProvider, s.deployment.CloudProviderType()) {
if !s.pipedConfig.HasCloudProvider(s.deployment.CloudProvider, s.deployment.Kind) {
lp.Errorf("This piped is not having the specified cloud provider in this deployment: %v", s.deployment.CloudProvider)
if err := s.reportStageStatus(ctx, ps.Id, model.StageStatus_STAGE_FAILURE, ps.Requires); err != nil {
s.logger.Error("failed to report stage status", zap.Error(err))
Expand Down
4 changes: 2 additions & 2 deletions pkg/app/piped/driftdetector/detector.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ func NewDetector(

for _, cp := range cfg.CloudProviders {
switch cp.Type {
case model.CloudProviderKubernetes:
case model.ApplicationKind_KUBERNETES:
sg, ok := stateGetter.KubernetesGetter(cp.Name)
if !ok {
return nil, fmt.Errorf(format, cp.Name)
Expand All @@ -113,7 +113,7 @@ func NewDetector(
logger,
))

case model.CloudProviderCloudRun:
case model.ApplicationKind_CLOUDRUN:
sg, ok := stateGetter.CloudRunGetter(cp.Name)
if !ok {
return nil, fmt.Errorf(format, cp.Name)
Expand Down
2 changes: 1 addition & 1 deletion pkg/app/piped/executor/cloudrun/cloudrun.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func findCloudProvider(in *executor.Input) (name string, cfg *config.CloudProvid
return
}

cp, ok := in.PipedConfig.FindCloudProvider(name, model.CloudProviderCloudRun)
cp, ok := in.PipedConfig.FindCloudProvider(name, model.ApplicationKind_CLOUDRUN)
if !ok {
in.LogPersister.Errorf("The specified cloud provider %q was not found in piped configuration", name)
return
Expand Down
2 changes: 1 addition & 1 deletion pkg/app/piped/executor/ecs/ecs.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ func findCloudProvider(in *executor.Input) (name string, cfg *config.CloudProvid
return
}

cp, ok := in.PipedConfig.FindCloudProvider(name, model.CloudProviderECS)
cp, ok := in.PipedConfig.FindCloudProvider(name, model.ApplicationKind_ECS)
if !ok {
in.LogPersister.Errorf("The specified cloud provider %q was not found in piped configuration", name)
return
Expand Down
2 changes: 1 addition & 1 deletion pkg/app/piped/executor/lambda/lambda.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ func findCloudProvider(in *executor.Input) (name string, cfg *config.CloudProvid
return
}

cp, ok := in.PipedConfig.FindCloudProvider(name, model.CloudProviderLambda)
cp, ok := in.PipedConfig.FindCloudProvider(name, model.ApplicationKind_LAMBDA)
if !ok {
in.LogPersister.Errorf("The specified cloud provider %q was not found in piped configuration", name)
return
Expand Down
2 changes: 1 addition & 1 deletion pkg/app/piped/executor/terraform/terraform.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ func findCloudProvider(in *executor.Input) (name string, cfg *config.CloudProvid
return
}

cp, ok := in.PipedConfig.FindCloudProvider(name, model.CloudProviderTerraform)
cp, ok := in.PipedConfig.FindCloudProvider(name, model.ApplicationKind_TERRAFORM)
if !ok {
in.LogPersister.Errorf("The specified cloud provider %q was not found in piped configuration", name)
return
Expand Down
4 changes: 2 additions & 2 deletions pkg/app/piped/livestatereporter/reporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,14 @@ func NewReporter(appLister applicationLister, stateGetter livestatestore.Getter,
for _, cp := range cfg.CloudProviders {
errFmt := fmt.Sprintf("unable to find live state getter for cloud provider: %s", cp.Name)
switch cp.Type {
case model.CloudProviderKubernetes:
case model.ApplicationKind_KUBERNETES:
sg, ok := stateGetter.KubernetesGetter(cp.Name)
if !ok {
r.logger.Error(errFmt)
continue
}
r.reporters = append(r.reporters, kubernetes.NewReporter(cp, appLister, sg, apiClient, logger))
case model.CloudProviderCloudRun:
case model.ApplicationKind_CLOUDRUN:
sg, ok := stateGetter.CloudRunGetter(cp.Name)
if !ok {
r.logger.Error(errFmt)
Expand Down
10 changes: 5 additions & 5 deletions pkg/app/piped/livestatestore/livestatestore.go
Original file line number Diff line number Diff line change
Expand Up @@ -105,27 +105,27 @@ func NewStore(ctx context.Context, cfg *config.PipedSpec, appLister applicationL
}
for _, cp := range cfg.CloudProviders {
switch cp.Type {
case model.CloudProviderKubernetes:
case model.ApplicationKind_KUBERNETES:
store := kubernetes.NewStore(cp.KubernetesConfig, cfg, cp.Name, logger)
s.kubernetesStores[cp.Name] = store

case model.CloudProviderTerraform:
case model.ApplicationKind_TERRAFORM:
store := terraform.NewStore(cp.TerraformConfig, cp.Name, appLister, logger)
s.terraformStores[cp.Name] = store

case model.CloudProviderCloudRun:
case model.ApplicationKind_CLOUDRUN:
store, err := cloudrun.NewStore(ctx, cp.CloudRunConfig, cp.Name, logger)
if err != nil {
logger.Error("failed to create a new cloudrun's livestatestore", zap.Error(err))
continue
}
s.cloudrunStores[cp.Name] = store

case model.CloudProviderLambda:
case model.ApplicationKind_LAMBDA:
store := lambda.NewStore(cp.LambdaConfig, cp.Name, appLister, logger)
s.lambdaStores[cp.Name] = store

case model.CloudProviderECS:
case model.ApplicationKind_ECS:
store := ecs.NewStore(cp.ECSConfig, cp.Name, appLister, logger)
s.ecsStores[cp.Name] = store
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/app/piped/planpreview/terraformdiff.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func (b *builder) terraformDiff(
buf *bytes.Buffer,
) (*diffResult, error) {

cp, ok := b.pipedCfg.FindCloudProvider(app.CloudProvider, model.CloudProviderTerraform)
cp, ok := b.pipedCfg.FindCloudProvider(app.CloudProvider, model.ApplicationKind_TERRAFORM)
if !ok {
err := fmt.Errorf("cloud provider %s was not found in Piped config", app.CloudProvider)
fmt.Fprintln(buf, err.Error())
Expand Down
32 changes: 16 additions & 16 deletions pkg/config/piped.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ import (
"github.com/pipe-cd/pipecd/pkg/model"
)

var DefaultKubernetesCloudProvider = PipedCloudProvider{
var defaultKubernetesCloudProvider = PipedCloudProvider{
Name: "kubernetes-default",
Type: model.CloudProviderKubernetes,
Type: model.ApplicationKind_KUBERNETES,
KubernetesConfig: &CloudProviderKubernetesConfig{},
}

Expand Down Expand Up @@ -116,15 +116,15 @@ func (s *PipedSpec) Validate() error {
// EnableDefaultKubernetesCloudProvider adds the default kubernetes cloud provider if it was not specified.
func (s *PipedSpec) EnableDefaultKubernetesCloudProvider() {
for _, cp := range s.CloudProviders {
if cp.Name == DefaultKubernetesCloudProvider.Name {
if cp.Name == defaultKubernetesCloudProvider.Name {
return
}
}
s.CloudProviders = append(s.CloudProviders, DefaultKubernetesCloudProvider)
s.CloudProviders = append(s.CloudProviders, defaultKubernetesCloudProvider)
}

// HasCloudProvider checks whether the given provider is configured or not.
func (s *PipedSpec) HasCloudProvider(name string, t model.CloudProviderType) bool {
func (s *PipedSpec) HasCloudProvider(name string, t model.ApplicationKind) bool {
for _, cp := range s.CloudProviders {
if cp.Name != name {
continue
Expand All @@ -138,7 +138,7 @@ func (s *PipedSpec) HasCloudProvider(name string, t model.CloudProviderType) boo
}

// FindCloudProvider finds and returns a Cloud Provider by name and type.
func (s *PipedSpec) FindCloudProvider(name string, t model.CloudProviderType) (PipedCloudProvider, bool) {
func (s *PipedSpec) FindCloudProvider(name string, t model.ApplicationKind) (PipedCloudProvider, bool) {
for _, p := range s.CloudProviders {
if p.Name != name {
continue
Expand Down Expand Up @@ -335,7 +335,7 @@ func (s *PipedSpec) GitHelmChartRepositories() []HelmChartRepository {

type PipedCloudProvider struct {
Name string
Type model.CloudProviderType
Type model.ApplicationKind

KubernetesConfig *CloudProviderKubernetesConfig
TerraformConfig *CloudProviderTerraformConfig
Expand All @@ -345,9 +345,9 @@ type PipedCloudProvider struct {
}

type genericPipedCloudProvider struct {
Name string `json:"name"`
Type model.CloudProviderType `json:"type"`
Config json.RawMessage `json:"config"`
Name string `json:"name"`
Type string `json:"type"`
Copy link
Member

Choose a reason for hiding this comment

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

nits, should we do the same thing we did at L338, instead of using type string, should we use type model.ApplicationKind?

Copy link
Member Author

Choose a reason for hiding this comment

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

I think it will not work since model.ApplicationKind is int32 not a string.
Or we have to add a custom Marshal function.

Copy link
Member

Choose a reason for hiding this comment

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

Yes, I mean to that since currently, we convert it at L360. But you're right, add a custom marshal function is not worth doing here. Thanks for clarification 🙏

Config json.RawMessage `json:"config"`
}

func (p *PipedCloudProvider) UnmarshalJSON(data []byte) error {
Expand All @@ -357,30 +357,30 @@ func (p *PipedCloudProvider) UnmarshalJSON(data []byte) error {
return err
}
p.Name = gp.Name
p.Type = gp.Type
p.Type = model.ApplicationKind(model.ApplicationKind_value[gp.Type])

switch p.Type {
case model.CloudProviderKubernetes:
case model.ApplicationKind_KUBERNETES:
p.KubernetesConfig = &CloudProviderKubernetesConfig{}
if len(gp.Config) > 0 {
err = json.Unmarshal(gp.Config, p.KubernetesConfig)
}
case model.CloudProviderTerraform:
case model.ApplicationKind_TERRAFORM:
p.TerraformConfig = &CloudProviderTerraformConfig{}
if len(gp.Config) > 0 {
err = json.Unmarshal(gp.Config, p.TerraformConfig)
}
case model.CloudProviderCloudRun:
case model.ApplicationKind_CLOUDRUN:
p.CloudRunConfig = &CloudProviderCloudRunConfig{}
if len(gp.Config) > 0 {
err = json.Unmarshal(gp.Config, p.CloudRunConfig)
}
case model.CloudProviderLambda:
case model.ApplicationKind_LAMBDA:
p.LambdaConfig = &CloudProviderLambdaConfig{}
if len(gp.Config) > 0 {
err = json.Unmarshal(gp.Config, p.LambdaConfig)
}
case model.CloudProviderECS:
case model.ApplicationKind_ECS:
p.ECSConfig = &CloudProviderECSConfig{}
if len(gp.Config) > 0 {
err = json.Unmarshal(gp.Config, p.ECSConfig)
Expand Down
10 changes: 5 additions & 5 deletions pkg/config/piped_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ func TestPipedConfig(t *testing.T) {
CloudProviders: []PipedCloudProvider{
{
Name: "kubernetes-default",
Type: model.CloudProviderKubernetes,
Type: model.ApplicationKind_KUBERNETES,
KubernetesConfig: &CloudProviderKubernetesConfig{
AppStateInformer: KubernetesAppStateInformer{
IncludeResources: []KubernetesResourceMatcher{
Expand All @@ -102,12 +102,12 @@ func TestPipedConfig(t *testing.T) {
},
{
Name: "kubernetes-dev",
Type: model.CloudProviderKubernetes,
Type: model.ApplicationKind_KUBERNETES,
KubernetesConfig: &CloudProviderKubernetesConfig{},
},
{
Name: "terraform",
Type: model.CloudProviderTerraform,
Type: model.ApplicationKind_TERRAFORM,
TerraformConfig: &CloudProviderTerraformConfig{
Vars: []string{
"project=gcp-project",
Expand All @@ -117,7 +117,7 @@ func TestPipedConfig(t *testing.T) {
},
{
Name: "cloudrun",
Type: model.CloudProviderCloudRun,
Type: model.ApplicationKind_CLOUDRUN,
CloudRunConfig: &CloudProviderCloudRunConfig{
Project: "gcp-project-id",
Region: "cloud-run-region",
Expand All @@ -126,7 +126,7 @@ func TestPipedConfig(t *testing.T) {
},
{
Name: "lambda",
Type: model.CloudProviderLambda,
Type: model.ApplicationKind_LAMBDA,
LambdaConfig: &CloudProviderLambdaConfig{
Region: "us-east-1",
},
Expand Down
1 change: 0 additions & 1 deletion pkg/model/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@ go_library(
"application_live_state.go",
"application_live_state.pb.go",
"application_live_state.pb.validate.go",
"cloudprovider.go",
"command.go",
"command.pb.go",
"command.pb.validate.go",
Expand Down
29 changes: 0 additions & 29 deletions pkg/model/cloudprovider.go

This file was deleted.

18 changes: 0 additions & 18 deletions pkg/model/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,24 +152,6 @@ func (d *Deployment) TriggerBefore(other *Deployment) bool {

}

// CloudProviderType determines the cloud provider type from application kind.
func (d *Deployment) CloudProviderType() CloudProviderType {
switch d.Kind {
case ApplicationKind_KUBERNETES:
return CloudProviderKubernetes
case ApplicationKind_TERRAFORM:
return CloudProviderTerraform
case ApplicationKind_CLOUDRUN:
return CloudProviderCloudRun
case ApplicationKind_LAMBDA:
return CloudProviderLambda
case ApplicationKind_ECS:
return CloudProviderECS
default:
return CloudProviderType(d.Kind.String())
}
}

// FindRollbackStage finds the rollback stage in stage list.
func (d *Deployment) FindRollbackStage() (*PipelineStage, bool) {
for i := len(d.Stages) - 1; i >= 0; i-- {
Expand Down