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

chore: minor endpoint cleanup #1608

Merged
merged 1 commit into from
Mar 12, 2024
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
7 changes: 0 additions & 7 deletions internal/api/delete_project_v1alpha1.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ import (
"strings"

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

kargoapi "github.com/akuity/kargo/api/v1alpha1"
Expand All @@ -33,12 +32,6 @@ func (s *server) DeleteProject(
},
},
); err != nil {
if kubeerr.IsNotFound(err) {
return nil, connect.NewError(
connect.CodeNotFound,
fmt.Errorf("project %q not found", name),
)
}
return nil, fmt.Errorf("delete project: %w", err)
}
return connect.NewResponse(&svcv1alpha1.DeleteProjectResponse{}), nil
Expand Down
25 changes: 10 additions & 15 deletions internal/api/delete_stage_v1alpha1.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
"fmt"

"connectrpc.com/connect"
kubeerr "k8s.io/apimachinery/pkg/api/errors"
"sigs.k8s.io/controller-runtime/pkg/client"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

kargoapi "github.com/akuity/kargo/api/v1alpha1"
svcv1alpha1 "github.com/akuity/kargo/pkg/api/service/v1alpha1"
Expand All @@ -30,19 +29,15 @@
return nil, err
}

var stage kargoapi.Stage
key := client.ObjectKey{
Namespace: project,
Name: name,
}
if err := s.client.Get(ctx, key, &stage); err != nil {
if kubeerr.IsNotFound(err) {
return nil, connect.NewError(connect.CodeNotFound,
fmt.Errorf("stage %q not found", key.String()))
}
return nil, fmt.Errorf("get stage: %w", err)
}
if err := s.client.Delete(ctx, &stage); err != nil && !kubeerr.IsNotFound(err) {
if err := s.client.Delete(
ctx,
&kargoapi.Stage{
ObjectMeta: metav1.ObjectMeta{
Namespace: project,
Name: name,
},
},
); err != nil {

Check warning on line 40 in internal/api/delete_stage_v1alpha1.go

View check run for this annotation

Codecov / codecov/patch

internal/api/delete_stage_v1alpha1.go#L32-L40

Added lines #L32 - L40 were not covered by tests
return nil, fmt.Errorf("delete stage: %w", err)
}
return connect.NewResponse(&svcv1alpha1.DeleteStageResponse{}), nil
Expand Down
25 changes: 10 additions & 15 deletions internal/api/delete_warehouse_v1alpha1.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@
"fmt"

"connectrpc.com/connect"
kubeerr "k8s.io/apimachinery/pkg/api/errors"
"sigs.k8s.io/controller-runtime/pkg/client"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

kargoapi "github.com/akuity/kargo/api/v1alpha1"
svcv1alpha1 "github.com/akuity/kargo/pkg/api/service/v1alpha1"
Expand All @@ -30,19 +29,15 @@
return nil, err
}

var warehouse kargoapi.Warehouse
key := client.ObjectKey{
Namespace: project,
Name: name,
}
if err := s.client.Get(ctx, key, &warehouse); err != nil {
if kubeerr.IsNotFound(err) {
return nil, connect.NewError(connect.CodeNotFound,
fmt.Errorf("warehouse %q not found", key.String()))
}
return nil, fmt.Errorf("get warehouse: %w", err)
}
if err := s.client.Delete(ctx, &warehouse); err != nil && !kubeerr.IsNotFound(err) {
if err := s.client.Delete(
ctx,
&kargoapi.Warehouse{
ObjectMeta: metav1.ObjectMeta{
Namespace: project,
Name: name,
},
},
); err != nil {

Check warning on line 40 in internal/api/delete_warehouse_v1alpha1.go

View check run for this annotation

Codecov / codecov/patch

internal/api/delete_warehouse_v1alpha1.go#L32-L40

Added lines #L32 - L40 were not covered by tests
return nil, fmt.Errorf("delete warehouse: %w", err)
}
return connect.NewResponse(&svcv1alpha1.DeleteWarehouseResponse{}), nil
Expand Down
4 changes: 0 additions & 4 deletions internal/api/get_project_v1alpha1.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"fmt"

"connectrpc.com/connect"
kubeerr "k8s.io/apimachinery/pkg/api/errors"
"sigs.k8s.io/controller-runtime/pkg/client"

kargoapi "github.com/akuity/kargo/api/v1alpha1"
Expand All @@ -28,9 +27,6 @@ func (s *server) GetProject(
},
&project,
); err != nil {
if kubeerr.IsNotFound(err) {
return nil, connect.NewError(connect.CodeNotFound, err)
}
return nil, fmt.Errorf("get project: %w", err)
}

Expand Down
5 changes: 0 additions & 5 deletions internal/api/get_promotion_v1alpha1.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"fmt"

"connectrpc.com/connect"
kubeerr "k8s.io/apimachinery/pkg/api/errors"
"sigs.k8s.io/controller-runtime/pkg/client"

kargoapi "github.com/akuity/kargo/api/v1alpha1"
Expand Down Expand Up @@ -35,10 +34,6 @@ func (s *server) GetPromotion(
Namespace: project,
Name: name,
}, &promotion); err != nil {
if kubeerr.IsNotFound(err) {
return nil, connect.NewError(connect.CodeNotFound,
fmt.Errorf("promotion %q not found", name))
}
return nil, fmt.Errorf("get promotion: %w", err)
}
return connect.NewResponse(&svcv1alpha1.GetPromotionResponse{
Expand Down
4 changes: 0 additions & 4 deletions internal/api/get_stage_v1alpha1.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"fmt"

"connectrpc.com/connect"
kubeerr "k8s.io/apimachinery/pkg/api/errors"
"sigs.k8s.io/controller-runtime/pkg/client"

kargoapi "github.com/akuity/kargo/api/v1alpha1"
Expand Down Expand Up @@ -35,9 +34,6 @@ func (s *server) GetStage(
Namespace: project,
Name: name,
}, &stage); err != nil {
if kubeerr.IsNotFound(err) {
return nil, connect.NewError(connect.CodeNotFound, err)
}
return nil, fmt.Errorf("get stage: %w", err)
}
return connect.NewResponse(&svcv1alpha1.GetStageResponse{
Expand Down
4 changes: 0 additions & 4 deletions internal/api/get_warehouse_v1alpha1.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"fmt"

"connectrpc.com/connect"
kubeerr "k8s.io/apimachinery/pkg/api/errors"
"sigs.k8s.io/controller-runtime/pkg/client"

kargoapi "github.com/akuity/kargo/api/v1alpha1"
Expand Down Expand Up @@ -35,9 +34,6 @@ func (s *server) GetWarehouse(
Namespace: project,
Name: name,
}, &warehouse); err != nil {
if kubeerr.IsNotFound(err) {
return nil, connect.NewError(connect.CodeNotFound, err)
}
return nil, fmt.Errorf("get warehouse: %w", err)
}
return connect.NewResponse(&svcv1alpha1.GetWarehouseResponse{
Expand Down
4 changes: 0 additions & 4 deletions internal/api/watch_promotion_v1alpha1.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"fmt"

"connectrpc.com/connect"
kubeerr "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/fields"
Expand Down Expand Up @@ -39,9 +38,6 @@ func (s *server) WatchPromotion(
Namespace: project,
Name: name,
}, &kargoapi.Promotion{}); err != nil {
if kubeerr.IsNotFound(err) {
return connect.NewError(connect.CodeNotFound, err)
}
return fmt.Errorf("get promotion: %w", err)
}

Expand Down
4 changes: 0 additions & 4 deletions internal/api/watch_promotions_v1alpha1.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"fmt"

"connectrpc.com/connect"
kubeerr "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/runtime"
Expand Down Expand Up @@ -36,9 +35,6 @@ func (s *server) WatchPromotions(
Namespace: project,
Name: stage,
}, &kargoapi.Stage{}); err != nil {
if kubeerr.IsNotFound(err) {
return connect.NewError(connect.CodeNotFound, err)
}
return fmt.Errorf("get stage: %w", err)
}
}
Expand Down
4 changes: 0 additions & 4 deletions internal/api/watch_stages_v1alpha1.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"fmt"

"connectrpc.com/connect"
kubeerr "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/fields"
Expand Down Expand Up @@ -37,9 +36,6 @@ func (s *server) WatchStages(
Namespace: project,
Name: name,
}, &kargoapi.Stage{}); err != nil {
if kubeerr.IsNotFound(err) {
return connect.NewError(connect.CodeNotFound, err)
}
return fmt.Errorf("get stage: %w", err)
}
}
Expand Down
4 changes: 0 additions & 4 deletions internal/api/watch_warehouses_v1alpha1.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ import (
"fmt"

"connectrpc.com/connect"
kubeerr "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
"k8s.io/apimachinery/pkg/fields"
Expand Down Expand Up @@ -37,9 +36,6 @@ func (s *server) WatchWarehouses(
Namespace: project,
Name: name,
}, &kargoapi.Warehouse{}); err != nil {
if kubeerr.IsNotFound(err) {
return connect.NewError(connect.CodeNotFound, err)
}
return fmt.Errorf("get warehouse: %w", err)
}
}
Expand Down
Loading