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

Add deploy target by plugin to deployment #5544

Merged
merged 2 commits into from
Feb 6, 2025
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
2 changes: 1 addition & 1 deletion pkg/app/piped/trigger/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@
GitPath: app.GitPath,
CloudProvider: app.CloudProvider,
PlatformProvider: app.PlatformProvider,
DeployTargets: app.GetDeployTargets(),
DeployTargetsByPlugin: app.GetDeployTargetsByPlugin(),

Check warning on line 98 in pkg/app/piped/trigger/deployment.go

View check run for this annotation

Codecov / codecov/patch

pkg/app/piped/trigger/deployment.go#L98

Added line #L98 was not covered by tests
Labels: app.Labels,
Status: model.DeploymentStatus_DEPLOYMENT_PENDING,
StatusReason: "The deployment is waiting to be planned",
Expand Down
7 changes: 6 additions & 1 deletion pkg/app/pipedv1/plugin/kubernetes/deployment/rollback.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,12 @@
}

// Get the deploy target config.
deployTargetConfig, err := kubeconfig.FindDeployTarget(a.pluginConfig, input.GetDeployment().GetDeployTargets()[0]) // TODO: check if there is a deploy target
deployTargets, err := input.GetDeployment().GetDeployTargets(a.pluginConfig.Name)
if err != nil {
lp.Errorf("Failed while finding deploy target config (%v)", err)
return model.StageStatus_STAGE_FAILURE
}
deployTargetConfig, err := kubeconfig.FindDeployTarget(a.pluginConfig, deployTargets[0]) // TODO: consider multiple targets

Check warning on line 81 in pkg/app/pipedv1/plugin/kubernetes/deployment/rollback.go

View check run for this annotation

Codecov / codecov/patch

pkg/app/pipedv1/plugin/kubernetes/deployment/rollback.go#L76-L81

Added lines #L76 - L81 were not covered by tests
if err != nil {
lp.Errorf("Failed while unmarshalling deploy target config (%v)", err)
return model.StageStatus_STAGE_FAILURE
Expand Down
7 changes: 6 additions & 1 deletion pkg/app/pipedv1/plugin/kubernetes/deployment/sync.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,12 @@
}

// Get the deploy target config.
deployTargetConfig, err := kubeconfig.FindDeployTarget(a.pluginConfig, input.GetDeployment().GetDeployTargets()[0]) // TODO: check if there is a deploy target
deployTargets, err := input.GetDeployment().GetDeployTargets(a.pluginConfig.Name)
if err != nil {
lp.Errorf("Failed while finding deploy target config (%v)", err)
return model.StageStatus_STAGE_FAILURE
}

Check warning on line 80 in pkg/app/pipedv1/plugin/kubernetes/deployment/sync.go

View check run for this annotation

Codecov / codecov/patch

pkg/app/pipedv1/plugin/kubernetes/deployment/sync.go#L78-L80

Added lines #L78 - L80 were not covered by tests
deployTargetConfig, err := kubeconfig.FindDeployTarget(a.pluginConfig, deployTargets[0]) // TODO: consider multiple targets
if err != nil {
lp.Errorf("Failed while unmarshalling deploy target config (%v)", err)
return model.StageStatus_STAGE_FAILURE
Expand Down
109 changes: 100 additions & 9 deletions pkg/app/pipedv1/plugin/kubernetes/deployment/sync_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import (
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
"go.uber.org/zap/zaptest"
"google.golang.org/protobuf/types/known/structpb"
apierrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/runtime/schema"
Expand Down Expand Up @@ -52,7 +53,17 @@ func TestDeploymentService_executeK8sSyncStage(t *testing.T) {
Deployment: &model.Deployment{
PipedId: "piped-id",
ApplicationId: "app-id",
DeployTargets: []string{"default"},
DeployTargetsByPlugin: map[string]*structpb.ListValue{
"kubernetes": &structpb.ListValue{
Values: []*structpb.Value{
{
Kind: &structpb.Value_StringValue{
StringValue: "default",
},
},
},
},
},
},
Stage: &model.PipelineStage{
Id: "stage-id",
Expand Down Expand Up @@ -125,7 +136,17 @@ func TestDeploymentService_executeK8sSyncStage_withInputNamespace(t *testing.T)
Deployment: &model.Deployment{
PipedId: "piped-id",
ApplicationId: "app-id",
DeployTargets: []string{"default"},
DeployTargetsByPlugin: map[string]*structpb.ListValue{
"kubernetes": &structpb.ListValue{
Values: []*structpb.Value{
{
Kind: &structpb.Value_StringValue{
StringValue: "default",
},
},
},
},
},
},
Stage: &model.PipelineStage{
Id: "stage-id",
Expand Down Expand Up @@ -199,7 +220,17 @@ func TestDeploymentService_executeK8sSyncStage_withPrune(t *testing.T) {
Deployment: &model.Deployment{
PipedId: "piped-id",
ApplicationId: "app-id",
DeployTargets: []string{"default"},
DeployTargetsByPlugin: map[string]*structpb.ListValue{
"kubernetes": &structpb.ListValue{
Values: []*structpb.Value{
{
Kind: &structpb.Value_StringValue{
StringValue: "default",
},
},
},
},
},
},
Stage: &model.PipelineStage{
Id: "stage-id",
Expand Down Expand Up @@ -255,7 +286,17 @@ func TestDeploymentService_executeK8sSyncStage_withPrune(t *testing.T) {
Deployment: &model.Deployment{
PipedId: "piped-id",
ApplicationId: "app-id",
DeployTargets: []string{"default"},
DeployTargetsByPlugin: map[string]*structpb.ListValue{
"kubernetes": &structpb.ListValue{
Values: []*structpb.Value{
{
Kind: &structpb.Value_StringValue{
StringValue: "default",
},
},
},
},
},
},
Stage: &model.PipelineStage{
Id: "stage-id",
Expand Down Expand Up @@ -314,7 +355,17 @@ func TestDeploymentService_executeK8sSyncStage_withPrune_changesNamespace(t *tes
Deployment: &model.Deployment{
PipedId: "piped-id",
ApplicationId: "app-id",
DeployTargets: []string{"default"},
DeployTargetsByPlugin: map[string]*structpb.ListValue{
"kubernetes": &structpb.ListValue{
Values: []*structpb.Value{
{
Kind: &structpb.Value_StringValue{
StringValue: "default",
},
},
},
},
},
},
Stage: &model.PipelineStage{
Id: "stage-id",
Expand Down Expand Up @@ -367,7 +418,17 @@ func TestDeploymentService_executeK8sSyncStage_withPrune_changesNamespace(t *tes
Deployment: &model.Deployment{
PipedId: "piped-id",
ApplicationId: "app-id",
DeployTargets: []string{"default"},
DeployTargetsByPlugin: map[string]*structpb.ListValue{
"kubernetes": &structpb.ListValue{
Values: []*structpb.Value{
{
Kind: &structpb.Value_StringValue{
StringValue: "default",
},
},
},
},
},
},
Stage: &model.PipelineStage{
Id: "stage-id",
Expand Down Expand Up @@ -443,7 +504,17 @@ func TestDeploymentService_executeK8sSyncStage_withPrune_clusterScoped(t *testin
Deployment: &model.Deployment{
PipedId: "piped-id",
ApplicationId: "prepare-app-id",
DeployTargets: []string{"default"},
DeployTargetsByPlugin: map[string]*structpb.ListValue{
"kubernetes": &structpb.ListValue{
Values: []*structpb.Value{
{
Kind: &structpb.Value_StringValue{
StringValue: "default",
},
},
},
},
},
},
Stage: &model.PipelineStage{
Id: "stage-id",
Expand Down Expand Up @@ -481,7 +552,17 @@ func TestDeploymentService_executeK8sSyncStage_withPrune_clusterScoped(t *testin
Deployment: &model.Deployment{
PipedId: "piped-id",
ApplicationId: "app-id",
DeployTargets: []string{"default"},
DeployTargetsByPlugin: map[string]*structpb.ListValue{
"kubernetes": &structpb.ListValue{
Values: []*structpb.Value{
{
Kind: &structpb.Value_StringValue{
StringValue: "default",
},
},
},
},
},
},
Stage: &model.PipelineStage{
Id: "stage-id",
Expand Down Expand Up @@ -527,7 +608,17 @@ func TestDeploymentService_executeK8sSyncStage_withPrune_clusterScoped(t *testin
Deployment: &model.Deployment{
PipedId: "piped-id",
ApplicationId: "app-id",
DeployTargets: []string{"default"},
DeployTargetsByPlugin: map[string]*structpb.ListValue{
"kubernetes": &structpb.ListValue{
Values: []*structpb.Value{
{
Kind: &structpb.Value_StringValue{
StringValue: "default",
},
},
},
},
},
},
Stage: &model.PipelineStage{
Id: "stage-id",
Expand Down
2 changes: 1 addition & 1 deletion pkg/app/pipedv1/trigger/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@
GitPath: app.GitPath,
CloudProvider: app.CloudProvider,
PlatformProvider: app.PlatformProvider,
DeployTargets: app.GetDeployTargets(),
DeployTargetsByPlugin: app.GetDeployTargetsByPlugin(),

Check warning on line 98 in pkg/app/pipedv1/trigger/deployment.go

View check run for this annotation

Codecov / codecov/patch

pkg/app/pipedv1/trigger/deployment.go#L98

Added line #L98 was not covered by tests
Labels: app.Labels,
Status: model.DeploymentStatus_DEPLOYMENT_PENDING,
StatusReason: "The deployment is waiting to be planned",
Expand Down
14 changes: 14 additions & 0 deletions pkg/model/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,20 @@
d.UpdatedAt = t
}

func (d *Deployment) GetDeployTargets(pluginName string) ([]string, error) {
dps, ok := d.GetDeployTargetsByPlugin()[pluginName]
if !ok || len(dps.GetValues()) == 0 {
return nil, fmt.Errorf("deploy target not found for plugin %v", pluginName)
}

Check warning on line 221 in pkg/model/deployment.go

View check run for this annotation

Codecov / codecov/patch

pkg/model/deployment.go#L217-L221

Added lines #L217 - L221 were not covered by tests

values := make([]string, 0, len(dps.GetValues()))
for _, v := range dps.GetValues() {
values = append(values, v.GetStringValue())
}

Check warning on line 226 in pkg/model/deployment.go

View check run for this annotation

Codecov / codecov/patch

pkg/model/deployment.go#L223-L226

Added lines #L223 - L226 were not covered by tests

return values, nil

Check warning on line 228 in pkg/model/deployment.go

View check run for this annotation

Codecov / codecov/patch

pkg/model/deployment.go#L228

Added line #L228 was not covered by tests
}

// Implement sort.Interface for PipelineStages.
type PipelineStages []*PipelineStage

Expand Down
Loading