diff --git a/pkg/model/application.go b/pkg/model/application.go index 803de6eff0..002e65f04c 100644 --- a/pkg/model/application.go +++ b/pkg/model/application.go @@ -78,6 +78,17 @@ func (a *Application) ContainLabels(labels map[string]string) bool { return true } +func (a *Application) 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 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 diff --git a/pkg/model/application_test.go b/pkg/model/application_test.go index 2f50e703d8..ff39ab4ba3 100644 --- a/pkg/model/application_test.go +++ b/pkg/model/application_test.go @@ -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 diff --git a/pkg/model/common.pb.go b/pkg/model/common.pb.go index bd76f7836a..23d27d3f26 100644 --- a/pkg/model/common.pb.go +++ b/pkg/model/common.pb.go @@ -38,11 +38,12 @@ const ( type ApplicationKind int32 const ( - ApplicationKind_KUBERNETES ApplicationKind = 0 - ApplicationKind_TERRAFORM ApplicationKind = 1 - ApplicationKind_LAMBDA ApplicationKind = 3 - ApplicationKind_CLOUDRUN ApplicationKind = 4 - ApplicationKind_ECS ApplicationKind = 5 + ApplicationKind_KUBERNETES ApplicationKind = 0 + ApplicationKind_TERRAFORM ApplicationKind = 1 + ApplicationKind_LAMBDA ApplicationKind = 3 + ApplicationKind_CLOUDRUN ApplicationKind = 4 + ApplicationKind_ECS ApplicationKind = 5 + ApplicationKind_APPLICATION ApplicationKind = 6 ) // Enum value maps for ApplicationKind. @@ -53,13 +54,15 @@ var ( 3: "LAMBDA", 4: "CLOUDRUN", 5: "ECS", + 6: "APPLICATION", } ApplicationKind_value = map[string]int32{ - "KUBERNETES": 0, - "TERRAFORM": 1, - "LAMBDA": 3, - "CLOUDRUN": 4, - "ECS": 5, + "KUBERNETES": 0, + "TERRAFORM": 1, + "LAMBDA": 3, + "CLOUDRUN": 4, + "ECS": 5, + "APPLICATION": 6, } ) @@ -689,32 +692,33 @@ var file_pkg_model_common_proto_rawDesc = []byte{ 0x53, 0x33, 0x5f, 0x4f, 0x42, 0x4a, 0x45, 0x43, 0x54, 0x10, 0x02, 0x12, 0x0e, 0x0a, 0x0a, 0x47, 0x49, 0x54, 0x5f, 0x53, 0x4f, 0x55, 0x52, 0x43, 0x45, 0x10, 0x03, 0x12, 0x14, 0x0a, 0x10, 0x54, 0x45, 0x52, 0x52, 0x41, 0x46, 0x4f, 0x52, 0x4d, 0x5f, 0x4d, 0x4f, 0x44, 0x55, 0x4c, 0x45, 0x10, - 0x04, 0x2a, 0x53, 0x0a, 0x0f, 0x41, 0x70, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, + 0x04, 0x2a, 0x64, 0x0a, 0x0f, 0x41, 0x70, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x4b, 0x69, 0x6e, 0x64, 0x12, 0x0e, 0x0a, 0x0a, 0x4b, 0x55, 0x42, 0x45, 0x52, 0x4e, 0x45, 0x54, 0x45, 0x53, 0x10, 0x00, 0x12, 0x0d, 0x0a, 0x09, 0x54, 0x45, 0x52, 0x52, 0x41, 0x46, 0x4f, 0x52, 0x4d, 0x10, 0x01, 0x12, 0x0a, 0x0a, 0x06, 0x4c, 0x41, 0x4d, 0x42, 0x44, 0x41, 0x10, 0x03, 0x12, 0x0c, 0x0a, 0x08, 0x43, 0x4c, 0x4f, 0x55, 0x44, 0x52, 0x55, 0x4e, 0x10, 0x04, 0x12, 0x07, 0x0a, - 0x03, 0x45, 0x43, 0x53, 0x10, 0x05, 0x2a, 0x97, 0x01, 0x0a, 0x0c, 0x52, 0x6f, 0x6c, 0x6c, 0x62, - 0x61, 0x63, 0x6b, 0x4b, 0x69, 0x6e, 0x64, 0x12, 0x17, 0x0a, 0x13, 0x52, 0x6f, 0x6c, 0x6c, 0x62, - 0x61, 0x63, 0x6b, 0x5f, 0x4b, 0x55, 0x42, 0x45, 0x52, 0x4e, 0x45, 0x54, 0x45, 0x53, 0x10, 0x00, - 0x12, 0x16, 0x0a, 0x12, 0x52, 0x6f, 0x6c, 0x6c, 0x62, 0x61, 0x63, 0x6b, 0x5f, 0x54, 0x45, 0x52, - 0x52, 0x41, 0x46, 0x4f, 0x52, 0x4d, 0x10, 0x01, 0x12, 0x13, 0x0a, 0x0f, 0x52, 0x6f, 0x6c, 0x6c, - 0x62, 0x61, 0x63, 0x6b, 0x5f, 0x4c, 0x41, 0x4d, 0x42, 0x44, 0x41, 0x10, 0x03, 0x12, 0x15, 0x0a, - 0x11, 0x52, 0x6f, 0x6c, 0x6c, 0x62, 0x61, 0x63, 0x6b, 0x5f, 0x43, 0x4c, 0x4f, 0x55, 0x44, 0x52, - 0x55, 0x4e, 0x10, 0x04, 0x12, 0x10, 0x0a, 0x0c, 0x52, 0x6f, 0x6c, 0x6c, 0x62, 0x61, 0x63, 0x6b, - 0x5f, 0x45, 0x43, 0x53, 0x10, 0x05, 0x12, 0x18, 0x0a, 0x14, 0x52, 0x6f, 0x6c, 0x6c, 0x62, 0x61, - 0x63, 0x6b, 0x5f, 0x43, 0x55, 0x53, 0x54, 0x4f, 0x4d, 0x5f, 0x53, 0x59, 0x4e, 0x43, 0x10, 0x0f, - 0x2a, 0x41, 0x0a, 0x17, 0x41, 0x70, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x41, - 0x63, 0x74, 0x69, 0x76, 0x65, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x12, 0x0b, 0x0a, 0x07, 0x45, - 0x4e, 0x41, 0x42, 0x4c, 0x45, 0x44, 0x10, 0x00, 0x12, 0x0c, 0x0a, 0x08, 0x44, 0x49, 0x53, 0x41, - 0x42, 0x4c, 0x45, 0x44, 0x10, 0x01, 0x12, 0x0b, 0x0a, 0x07, 0x44, 0x45, 0x4c, 0x45, 0x54, 0x45, - 0x44, 0x10, 0x02, 0x2a, 0x36, 0x0a, 0x0c, 0x53, 0x79, 0x6e, 0x63, 0x53, 0x74, 0x72, 0x61, 0x74, - 0x65, 0x67, 0x79, 0x12, 0x08, 0x0a, 0x04, 0x41, 0x55, 0x54, 0x4f, 0x10, 0x00, 0x12, 0x0e, 0x0a, - 0x0a, 0x51, 0x55, 0x49, 0x43, 0x4b, 0x5f, 0x53, 0x59, 0x4e, 0x43, 0x10, 0x01, 0x12, 0x0c, 0x0a, - 0x08, 0x50, 0x49, 0x50, 0x45, 0x4c, 0x49, 0x4e, 0x45, 0x10, 0x02, 0x42, 0x25, 0x5a, 0x23, 0x67, - 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x70, 0x69, 0x70, 0x65, 0x2d, 0x63, - 0x64, 0x2f, 0x70, 0x69, 0x70, 0x65, 0x63, 0x64, 0x2f, 0x70, 0x6b, 0x67, 0x2f, 0x6d, 0x6f, 0x64, - 0x65, 0x6c, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x03, 0x45, 0x43, 0x53, 0x10, 0x05, 0x12, 0x0f, 0x0a, 0x0b, 0x41, 0x50, 0x50, 0x4c, 0x49, 0x43, + 0x41, 0x54, 0x49, 0x4f, 0x4e, 0x10, 0x06, 0x2a, 0x97, 0x01, 0x0a, 0x0c, 0x52, 0x6f, 0x6c, 0x6c, + 0x62, 0x61, 0x63, 0x6b, 0x4b, 0x69, 0x6e, 0x64, 0x12, 0x17, 0x0a, 0x13, 0x52, 0x6f, 0x6c, 0x6c, + 0x62, 0x61, 0x63, 0x6b, 0x5f, 0x4b, 0x55, 0x42, 0x45, 0x52, 0x4e, 0x45, 0x54, 0x45, 0x53, 0x10, + 0x00, 0x12, 0x16, 0x0a, 0x12, 0x52, 0x6f, 0x6c, 0x6c, 0x62, 0x61, 0x63, 0x6b, 0x5f, 0x54, 0x45, + 0x52, 0x52, 0x41, 0x46, 0x4f, 0x52, 0x4d, 0x10, 0x01, 0x12, 0x13, 0x0a, 0x0f, 0x52, 0x6f, 0x6c, + 0x6c, 0x62, 0x61, 0x63, 0x6b, 0x5f, 0x4c, 0x41, 0x4d, 0x42, 0x44, 0x41, 0x10, 0x03, 0x12, 0x15, + 0x0a, 0x11, 0x52, 0x6f, 0x6c, 0x6c, 0x62, 0x61, 0x63, 0x6b, 0x5f, 0x43, 0x4c, 0x4f, 0x55, 0x44, + 0x52, 0x55, 0x4e, 0x10, 0x04, 0x12, 0x10, 0x0a, 0x0c, 0x52, 0x6f, 0x6c, 0x6c, 0x62, 0x61, 0x63, + 0x6b, 0x5f, 0x45, 0x43, 0x53, 0x10, 0x05, 0x12, 0x18, 0x0a, 0x14, 0x52, 0x6f, 0x6c, 0x6c, 0x62, + 0x61, 0x63, 0x6b, 0x5f, 0x43, 0x55, 0x53, 0x54, 0x4f, 0x4d, 0x5f, 0x53, 0x59, 0x4e, 0x43, 0x10, + 0x0f, 0x2a, 0x41, 0x0a, 0x17, 0x41, 0x70, 0x70, 0x6c, 0x69, 0x63, 0x61, 0x74, 0x69, 0x6f, 0x6e, + 0x41, 0x63, 0x74, 0x69, 0x76, 0x65, 0x53, 0x74, 0x61, 0x74, 0x75, 0x73, 0x12, 0x0b, 0x0a, 0x07, + 0x45, 0x4e, 0x41, 0x42, 0x4c, 0x45, 0x44, 0x10, 0x00, 0x12, 0x0c, 0x0a, 0x08, 0x44, 0x49, 0x53, + 0x41, 0x42, 0x4c, 0x45, 0x44, 0x10, 0x01, 0x12, 0x0b, 0x0a, 0x07, 0x44, 0x45, 0x4c, 0x45, 0x54, + 0x45, 0x44, 0x10, 0x02, 0x2a, 0x36, 0x0a, 0x0c, 0x53, 0x79, 0x6e, 0x63, 0x53, 0x74, 0x72, 0x61, + 0x74, 0x65, 0x67, 0x79, 0x12, 0x08, 0x0a, 0x04, 0x41, 0x55, 0x54, 0x4f, 0x10, 0x00, 0x12, 0x0e, + 0x0a, 0x0a, 0x51, 0x55, 0x49, 0x43, 0x4b, 0x5f, 0x53, 0x59, 0x4e, 0x43, 0x10, 0x01, 0x12, 0x0c, + 0x0a, 0x08, 0x50, 0x49, 0x50, 0x45, 0x4c, 0x49, 0x4e, 0x45, 0x10, 0x02, 0x42, 0x25, 0x5a, 0x23, + 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x70, 0x69, 0x70, 0x65, 0x2d, + 0x63, 0x64, 0x2f, 0x70, 0x69, 0x70, 0x65, 0x63, 0x64, 0x2f, 0x70, 0x6b, 0x67, 0x2f, 0x6d, 0x6f, + 0x64, 0x65, 0x6c, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, } var ( diff --git a/pkg/model/common.proto b/pkg/model/common.proto index b52636d6d9..792e700d25 100644 --- a/pkg/model/common.proto +++ b/pkg/model/common.proto @@ -25,6 +25,7 @@ enum ApplicationKind { LAMBDA = 3; CLOUDRUN = 4; ECS = 5; + APPLICATION = 6; } enum RollbackKind { diff --git a/pkg/model/deployment.go b/pkg/model/deployment.go index fb5c794347..519cebd00c 100644 --- a/pkg/model/deployment.go +++ b/pkg/model/deployment.go @@ -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 diff --git a/pkg/model/deployment_test.go b/pkg/model/deployment_test.go index 891f43cc6a..ce66f16fa8 100644 --- a/pkg/model/deployment_test.go +++ b/pkg/model/deployment_test.go @@ -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) + }) + } +} diff --git a/web/model/common_pb.d.ts b/web/model/common_pb.d.ts index 635cdcfaf9..b9154ecce7 100644 --- a/web/model/common_pb.d.ts +++ b/web/model/common_pb.d.ts @@ -155,6 +155,7 @@ export enum ApplicationKind { LAMBDA = 3, CLOUDRUN = 4, ECS = 5, + APPLICATION = 6, } export enum RollbackKind { ROLLBACK_KUBERNETES = 0, diff --git a/web/model/common_pb.js b/web/model/common_pb.js index 7e1fbcc06d..61130b71d7 100644 --- a/web/model/common_pb.js +++ b/web/model/common_pb.js @@ -1160,7 +1160,8 @@ proto.model.ApplicationKind = { TERRAFORM: 1, LAMBDA: 3, CLOUDRUN: 4, - ECS: 5 + ECS: 5, + APPLICATION: 6 }; /** diff --git a/web/src/__fixtures__/dummy-application-live-state.ts b/web/src/__fixtures__/dummy-application-live-state.ts index 565a40a156..cf04228ecc 100644 --- a/web/src/__fixtures__/dummy-application-live-state.ts +++ b/web/src/__fixtures__/dummy-application-live-state.ts @@ -98,6 +98,11 @@ export const dummyLiveStates: Record = { applicationId: dummyApps[ApplicationKind.ECS].id, kind: ApplicationKind.ECS, }, + [ApplicationKind.APPLICATION]: { + ...dummyApplicationLiveState, + applicationId: dummyApps[ApplicationKind.APPLICATION].id, + kind: ApplicationKind.APPLICATION, + }, }; function createKubernetesResourceStateFromObject( diff --git a/web/src/__fixtures__/dummy-application.ts b/web/src/__fixtures__/dummy-application.ts index b02bb37d92..f621fcb1b9 100644 --- a/web/src/__fixtures__/dummy-application.ts +++ b/web/src/__fixtures__/dummy-application.ts @@ -96,6 +96,13 @@ export const dummyApps: Record = { kind: ApplicationKind.ECS, platformProvider: "ecs-default", }, + [ApplicationKind.APPLICATION]: { + ...dummyApplication, + id: randomUUID(), + name: "Application App", + kind: ApplicationKind.APPLICATION, + platformProvider: "application-default", + }, }; function createAppSyncStateFromObject( diff --git a/web/src/constants/application-kind.ts b/web/src/constants/application-kind.ts index a0581c533b..197fbd4c08 100644 --- a/web/src/constants/application-kind.ts +++ b/web/src/constants/application-kind.ts @@ -6,6 +6,7 @@ export const APPLICATION_KIND_TEXT: Record = { [ApplicationKind.LAMBDA]: "LAMBDA", [ApplicationKind.CLOUDRUN]: "CLOUDRUN", [ApplicationKind.ECS]: "ECS", + [ApplicationKind.APPLICATION]: "APPLICATION", }; export const APPLICATION_KIND_BY_NAME: Record = { @@ -15,4 +16,6 @@ export const APPLICATION_KIND_BY_NAME: Record = { [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, };