Skip to content

Commit

Permalink
feat(ui): move image processing to backend (#2389)
Browse files Browse the repository at this point in the history
Signed-off-by: Remington Breeze <[email protected]>
  • Loading branch information
rbreeze authored Aug 22, 2024
1 parent 643d656 commit d1b1f02
Show file tree
Hide file tree
Showing 11 changed files with 2,192 additions and 1,616 deletions.
16 changes: 16 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -60,10 +60,17 @@ endif
.PHONY: lint
lint: lint-go lint-proto lint-charts lint-ui

.PHONY: format
format: format-go format-ui

.PHONY: lint-go
lint-go:
golangci-lint run --out-format=$(GO_LINT_ERROR_FORMAT)

.PHONY: format-go
format-go:
golangci-lint run --fix

.PHONY: lint-proto
lint-proto:
# Vendor go dependencies to build protobuf definitions
Expand All @@ -81,6 +88,11 @@ lint-ui:
pnpm --dir=ui install --dev
pnpm --dir=ui run lint

.PHONY: format-ui
format-ui:
pnpm --dir=ui install --dev
pnpm --dir=ui run lint:fix

.PHONY: test-unit
test-unit:
go test \
Expand Down Expand Up @@ -200,6 +212,10 @@ hack-build-dev-tools:
hack-lint: hack-build-dev-tools
$(DOCKER_CMD) make lint

.PHONY: hack-format
hack-format: hack-build-dev-tools
$(DOCKER_CMD) make format

.PHONY: hack-lint-go
hack-lint-go: hack-build-dev-tools
$(DOCKER_CMD) make lint-go
Expand Down
20 changes: 20 additions & 0 deletions api/service/v1alpha1/service.proto
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ service KargoService {
/* Stage APIs */

rpc ListStages(ListStagesRequest) returns (ListStagesResponse);
rpc ListImages(ListImagesRequest) returns (ListImagesResponse);
rpc GetStage(GetStageRequest) returns (GetStageResponse);
rpc WatchStages(WatchStagesRequest) returns (stream WatchStagesResponse);
rpc DeleteStage(DeleteStageRequest) returns (DeleteStageResponse);
Expand Down Expand Up @@ -229,6 +230,25 @@ message ListStagesResponse {
repeated github.com.akuity.kargo.api.v1alpha1.Stage stages = 1;
}

message ListImagesRequest {
string project = 1;
}

message ListImagesResponse {
// images maps image repository names to their tags
map<string, TagMap> images = 2;
}

message TagMap {
// tags maps image tag names to stages which have previously used that tag
map<string, ImageStageMap> tags = 1;
}

message ImageStageMap {
// stages maps stage names to the order which an image was promoted to that stage
map<string, int32> stages = 1;
}

message GetStageRequest {
string project = 1;
string name = 2;
Expand Down
72 changes: 72 additions & 0 deletions internal/api/list_images_v1alpha1.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
package api

import (
"context"
"fmt"

"connectrpc.com/connect"
"sigs.k8s.io/controller-runtime/pkg/client"

kargoapi "github.com/akuity/kargo/api/v1alpha1"
svcv1alpha1 "github.com/akuity/kargo/pkg/api/service/v1alpha1"
)

func (s *server) ListImages(
ctx context.Context,
req *connect.Request[svcv1alpha1.ListImagesRequest],
) (*connect.Response[svcv1alpha1.ListImagesResponse], error) {
project := req.Msg.GetProject()
if err := validateFieldNotEmpty("project", project); err != nil {
return nil, err
}

if err := s.validateProjectExists(ctx, project); err != nil {
return nil, err
}

var list kargoapi.StageList
if err := s.client.List(ctx, &list, client.InNamespace(project)); err != nil {
return nil, fmt.Errorf("list stages: %w", err)
}

stages := make([]*kargoapi.Stage, len(list.Items))
images := make(map[string]*svcv1alpha1.TagMap)

for idx, stage := range list.Items {
stages[idx] = &list.Items[idx]

for i, freightGroup := range stage.Status.FreightHistory {
for _, freight := range freightGroup.Freight {
for _, image := range freight.Images {
repo, ok := images[image.RepoURL]
if !ok || repo == nil {
repo = &svcv1alpha1.TagMap{}
images[image.RepoURL] = repo
}

if repo.Tags == nil {
repo.Tags = make(map[string]*svcv1alpha1.ImageStageMap)
}

stagemap, ok := repo.Tags[image.Tag]
if !ok || stagemap == nil {
repo.Tags[image.Tag] = &svcv1alpha1.ImageStageMap{}
stagemap = repo.Tags[image.Tag]
}

if stagemap.Stages == nil {
stagemap.Stages = make(map[string]int32)
}

if _, ok := stagemap.Stages[stage.Name]; !ok {
stagemap.Stages[stage.Name] = int32(i)
}
}
}
}
}

return connect.NewResponse(&svcv1alpha1.ListImagesResponse{
Images: images,
}), nil
}
6 changes: 3 additions & 3 deletions internal/controller/argocd/api/v1alpha1/application_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ type OperationState struct {
}

type SyncOperationResult struct {
Revision string `json:"revision,omitempty"`
Source ApplicationSource `json:"source,omitempty"`
Sources ApplicationSources `json:"sources,omitempty"`
Revision string `json:"revision,omitempty"`
Source ApplicationSource `json:"source,omitempty"`
Sources ApplicationSources `json:"sources,omitempty"`
}
Loading

0 comments on commit d1b1f02

Please sign in to comment.