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 kind APPLICATION #5358

Closed
wants to merge 4 commits into from
Closed
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
11 changes: 11 additions & 0 deletions pkg/model/application.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,17 @@ func (a *Application) ContainLabels(labels map[string]string) bool {
return true
}

func (a *Application) GetKindString() string {
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 wanted to use GetKind. But there is the same name method generated by protobuf.

// First, check the application is supported by the plugin architecture. It means that the kind is set to "Application".
// If so, return the kind from the labels.
if a.Kind == ApplicationKind_APPLICATION {
return a.Labels["kind"]
}

// For backward compatibility, return the kind as string
return a.Kind.String()
}

func (a *Application) IsOutOfSync() bool {
if a.SyncState == nil {
return false
Expand Down
51 changes: 51 additions & 0 deletions pkg/model/application_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,57 @@ func TestApplication_ContainLabels(t *testing.T) {
}
}

func TestGetKindString(t *testing.T) {
tests := []struct {
name string
app *Application
expected string
}{
{
name: "Kubernetes Application",
app: &Application{Kind: ApplicationKind_KUBERNETES},
expected: "KUBERNETES",
},
{
name: "Terraform Application",
app: &Application{Kind: ApplicationKind_TERRAFORM},
expected: "TERRAFORM",
},
{
name: "Lambda Application",
app: &Application{Kind: ApplicationKind_LAMBDA},
expected: "LAMBDA",
},
{
name: "CloudRun Application",
app: &Application{Kind: ApplicationKind_CLOUDRUN},
expected: "CLOUDRUN",
},
{
name: "ECS Application",
app: &Application{Kind: ApplicationKind_ECS},
expected: "ECS",
},
{
name: "Application",
app: &Application{Kind: ApplicationKind_APPLICATION, Labels: map[string]string{"kind": "KUBERNETES"}},
expected: "KUBERNETES",
},
{
name: "Application with no kind label",
app: &Application{Kind: ApplicationKind_APPLICATION, Labels: map[string]string{}},
expected: "",
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
actual := tt.app.GetKindString()
assert.Equal(t, tt.expected, actual)
})
}
}

func TestCompatiblePlatformProviderType(t *testing.T) {
tests := []struct {
name string
Expand Down
68 changes: 36 additions & 32 deletions pkg/model/common.pb.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions pkg/model/common.proto
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ enum ApplicationKind {
LAMBDA = 3;
CLOUDRUN = 4;
ECS = 5;
APPLICATION = 6;
}

enum RollbackKind {
Expand Down
11 changes: 11 additions & 0 deletions pkg/model/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,17 @@ func (d *Deployment) SetUpdatedAt(t int64) {
d.UpdatedAt = t
}

func (d *Deployment) GetKindString() string {
// First, check the application is supported by the plugin architecture. It means that the kind is set to "Application".
// If so, return the kind from the labels.
if d.Kind == ApplicationKind_APPLICATION {
return d.Labels["kind"]
}

// For backward compatibility, return the kind as string
return d.Kind.String()
}

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

Expand Down
51 changes: 51 additions & 0 deletions pkg/model/deployment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -658,3 +658,54 @@ func TestSortPipelineStagesByIndex(t *testing.T) {
{Index: 4},
}, stages)
}

func TestDeployment_GetKindString(t *testing.T) {
tests := []struct {
name string
deployment *Deployment
expected string
}{
{
name: "Kubernetes Deployment",
deployment: &Deployment{Kind: ApplicationKind_KUBERNETES},
expected: "KUBERNETES",
},
{
name: "Terraform Deployment",
deployment: &Deployment{Kind: ApplicationKind_TERRAFORM},
expected: "TERRAFORM",
},
{
name: "Lambda Deployment",
deployment: &Deployment{Kind: ApplicationKind_LAMBDA},
expected: "LAMBDA",
},
{
name: "CloudRun Deployment",
deployment: &Deployment{Kind: ApplicationKind_CLOUDRUN},
expected: "CLOUDRUN",
},
{
name: "ECS Deployment",
deployment: &Deployment{Kind: ApplicationKind_ECS},
expected: "ECS",
},
{
name: "Application",
deployment: &Deployment{Kind: ApplicationKind_APPLICATION, Labels: map[string]string{"kind": "KUBERNETES"}},
expected: "KUBERNETES",
},
{
name: "Application with no kind label",
deployment: &Deployment{Kind: ApplicationKind_APPLICATION, Labels: map[string]string{}},
expected: "",
},
}

for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
actual := tt.deployment.GetKindString()
assert.Equal(t, tt.expected, actual)
})
}
}
1 change: 1 addition & 0 deletions web/model/common_pb.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ export enum ApplicationKind {
LAMBDA = 3,
CLOUDRUN = 4,
ECS = 5,
APPLICATION = 6,
}
export enum RollbackKind {
ROLLBACK_KUBERNETES = 0,
Expand Down
3 changes: 2 additions & 1 deletion web/model/common_pb.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions web/src/__fixtures__/dummy-application-live-state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,11 @@ export const dummyLiveStates: Record<ApplicationKind, ApplicationLiveState> = {
applicationId: dummyApps[ApplicationKind.ECS].id,
kind: ApplicationKind.ECS,
},
[ApplicationKind.APPLICATION]: {
...dummyApplicationLiveState,
applicationId: dummyApps[ApplicationKind.APPLICATION].id,
kind: ApplicationKind.APPLICATION,
},
};

function createKubernetesResourceStateFromObject(
Expand Down
7 changes: 7 additions & 0 deletions web/src/__fixtures__/dummy-application.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,13 @@ export const dummyApps: Record<ApplicationKind, Application.AsObject> = {
kind: ApplicationKind.ECS,
platformProvider: "ecs-default",
},
[ApplicationKind.APPLICATION]: {
...dummyApplication,
id: randomUUID(),
name: "Application App",
kind: ApplicationKind.APPLICATION,
platformProvider: "application-default",
},
};

function createAppSyncStateFromObject(
Expand Down
3 changes: 3 additions & 0 deletions web/src/constants/application-kind.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ export const APPLICATION_KIND_TEXT: Record<ApplicationKind, string> = {
[ApplicationKind.LAMBDA]: "LAMBDA",
[ApplicationKind.CLOUDRUN]: "CLOUDRUN",
[ApplicationKind.ECS]: "ECS",
[ApplicationKind.APPLICATION]: "APPLICATION",
};

export const APPLICATION_KIND_BY_NAME: Record<string, ApplicationKind> = {
Expand All @@ -15,4 +16,6 @@ export const APPLICATION_KIND_BY_NAME: Record<string, ApplicationKind> = {
[APPLICATION_KIND_TEXT[ApplicationKind.LAMBDA]]: ApplicationKind.LAMBDA,
[APPLICATION_KIND_TEXT[ApplicationKind.CLOUDRUN]]: ApplicationKind.CLOUDRUN,
[APPLICATION_KIND_TEXT[ApplicationKind.ECS]]: ApplicationKind.ECS,
[APPLICATION_KIND_TEXT[ApplicationKind.APPLICATION]]:
ApplicationKind.APPLICATION,
};
Loading