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

feat: add delete freight endpoint to api server #1177

Merged
merged 2 commits into from
Nov 29, 2023
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
10 changes: 10 additions & 0 deletions api/service/v1alpha1/service.proto
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ service KargoService {
/* Freight APIs */

rpc QueryFreight(QueryFreightRequest) returns (QueryFreightResponse);
rpc DeleteFreight(DeleteFreightRequest) returns (DeleteFreightResponse);

/* Warehouse APIs */

Expand Down Expand Up @@ -424,6 +425,15 @@ message QueryFreightResponse {
map<string, FreightList> groups = 1;
}

message DeleteFreightRequest {
string project = 1;
string name = 2;
}

message DeleteFreightResponse {
/* explicitly empty */
}

message FreightList {
repeated git.luolix.top.akuity.kargo.pkg.api.v1alpha1.Freight freight = 1;
}
Expand Down
1 change: 1 addition & 0 deletions charts/kargo/templates/api/cluster-role.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ rules:
- get
- list
- watch
- delete
- apiGroups:
- kargo.akuity.io
resources:
Expand Down
40 changes: 40 additions & 0 deletions internal/api/delete_freight_v1alpha1.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package api

import (
"context"

"connectrpc.com/connect"
"github.com/pkg/errors"
apierrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

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

func (s *server) DeleteFreight(
ctx context.Context,
req *connect.Request[svcv1alpha1.DeleteFreightRequest],
) (*connect.Response[svcv1alpha1.DeleteFreightResponse], error) {
if err := validateProjectAndFreightName(req.Msg.GetProject(), req.Msg.GetName()); err != nil {
return nil, err
}
if err := s.validateProject(ctx, req.Msg.GetProject()); err != nil {
return nil, err
}
if err := s.client.Delete(ctx, &kargoapi.Freight{
ObjectMeta: metav1.ObjectMeta{
Namespace: req.Msg.GetProject(),
Name: req.Msg.GetName(),
},
}); err != nil {
if apierrors.IsNotFound(err) {
return nil, connect.NewError(
connect.CodeNotFound,
errors.Errorf("freight %q not found", req.Msg.GetName()),
)
}
return nil, errors.Wrap(err, "delete freight")

Check warning on line 37 in internal/api/delete_freight_v1alpha1.go

View check run for this annotation

Codecov / codecov/patch

internal/api/delete_freight_v1alpha1.go#L18-L37

Added lines #L18 - L37 were not covered by tests
}
return connect.NewResponse(&svcv1alpha1.DeleteFreightResponse{}), nil

Check warning on line 39 in internal/api/delete_freight_v1alpha1.go

View check run for this annotation

Codecov / codecov/patch

internal/api/delete_freight_v1alpha1.go#L39

Added line #L39 was not covered by tests
}
10 changes: 10 additions & 0 deletions internal/api/validators.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,16 @@
return nil
}

func validateProjectAndFreightName(project, name string) error {
if project == "" {
return connect.NewError(connect.CodeInvalidArgument, errors.New("project should not be empty"))
}
if name == "" {
return connect.NewError(connect.CodeInvalidArgument, errors.New("freight should not be empty"))
}
return nil

Check warning on line 54 in internal/api/validators.go

View check run for this annotation

Codecov / codecov/patch

internal/api/validators.go#L47-L54

Added lines #L47 - L54 were not covered by tests
}

func validateGroupByOrderBy(group string, groupBy string, orderBy string) error {
if group != "" && groupBy == "" {
return connect.NewError(
Expand Down
Loading
Loading