-
Notifications
You must be signed in to change notification settings - Fork 239
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
16 changed files
with
813 additions
and
24 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
package cluster | ||
|
||
import ( | ||
"net/http" | ||
|
||
"connectrpc.com/connect" | ||
|
||
porterv1 "github.com/porter-dev/api-contracts/generated/go/porter/v1" | ||
"github.com/porter-dev/porter/internal/telemetry" | ||
|
||
"github.com/porter-dev/porter/api/server/authz" | ||
"github.com/porter-dev/porter/api/server/handlers" | ||
"github.com/porter-dev/porter/api/server/shared" | ||
"github.com/porter-dev/porter/api/server/shared/apierrors" | ||
"github.com/porter-dev/porter/api/server/shared/config" | ||
"github.com/porter-dev/porter/api/types" | ||
"github.com/porter-dev/porter/internal/models" | ||
) | ||
|
||
// DeleteNodeGroupHandler is the handler for the /delete-node-group endpoint | ||
type DeleteNodeGroupHandler struct { | ||
handlers.PorterHandlerReadWriter | ||
authz.KubernetesAgentGetter | ||
} | ||
|
||
// NewDeleteNodeGroupHandler returns a handler for handling node group requests | ||
func NewDeleteNodeGroupHandler( | ||
config *config.Config, | ||
decoderValidator shared.RequestDecoderValidator, | ||
writer shared.ResultWriter, | ||
) *DeleteNodeGroupHandler { | ||
return &DeleteNodeGroupHandler{ | ||
PorterHandlerReadWriter: handlers.NewDefaultPorterHandler(config, decoderValidator, writer), | ||
KubernetesAgentGetter: authz.NewOutOfClusterAgentGetter(config), | ||
} | ||
} | ||
|
||
// DeleteNodeGroupRequest represents the request to delete a node group | ||
type DeleteNodeGroupRequest struct { | ||
// NodeGroupId is the id of the node group to delete | ||
NodeGroupId string `json:"node_group_id"` | ||
} | ||
|
||
// DeleteNodeGroupResponse represents the response from deleting a node group | ||
type DeleteNodeGroupResponse struct { | ||
// ContractRevisionId is the id of the contract revision created by the deletion | ||
ContractRevisionId string `json:"contract_revision_id"` | ||
} | ||
|
||
// ServeHTTP handles GET requests to list node groups | ||
func (c *DeleteNodeGroupHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { | ||
ctx, span := telemetry.NewSpan(r.Context(), "serve-list-nodes") | ||
defer span.End() | ||
|
||
project, _ := r.Context().Value(types.ProjectScope).(*models.Project) | ||
cluster, _ := r.Context().Value(types.ClusterScope).(*models.Cluster) | ||
|
||
request := &DeleteNodeGroupRequest{} | ||
|
||
ok := c.DecodeAndValidate(w, r, request) | ||
if !ok { | ||
err := telemetry.Error(ctx, span, nil, "error decoding delete node group request") | ||
c.HandleAPIError(w, r, apierrors.NewErrPassThroughToClient(err, http.StatusBadRequest)) | ||
} | ||
|
||
if request.NodeGroupId == "" { | ||
err := telemetry.Error(ctx, span, nil, "node group id is empty") | ||
c.HandleAPIError(w, r, apierrors.NewErrPassThroughToClient(err, http.StatusBadRequest)) | ||
} | ||
|
||
userNodeGroupReq := connect.NewRequest(&porterv1.DeleteUserNodeGroupRequest{ | ||
ProjectId: int64(project.ID), | ||
ClusterId: int64(cluster.ID), | ||
UserNodeGroupId: request.NodeGroupId, | ||
}) | ||
|
||
ccpResp, err := c.Config().ClusterControlPlaneClient.DeleteUserNodeGroup(ctx, userNodeGroupReq) | ||
if err != nil { | ||
err := telemetry.Error(ctx, span, err, "error deleting user node group") | ||
c.HandleAPIError(w, r, apierrors.NewErrPassThroughToClient(err, http.StatusInternalServerError)) | ||
return | ||
} | ||
if ccpResp == nil || ccpResp.Msg == nil { | ||
err := telemetry.Error(ctx, span, err, "ccp resp msg is nil") | ||
c.HandleAPIError(w, r, apierrors.NewErrPassThroughToClient(err, http.StatusInternalServerError)) | ||
return | ||
} | ||
|
||
resp := &DeleteNodeGroupResponse{ | ||
ContractRevisionId: ccpResp.Msg.ContractRevisionId, | ||
} | ||
|
||
c.WriteResult(w, r, resp) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
package cluster | ||
|
||
import ( | ||
"net/http" | ||
|
||
"connectrpc.com/connect" | ||
|
||
porterv1 "github.com/porter-dev/api-contracts/generated/go/porter/v1" | ||
"github.com/porter-dev/porter/internal/telemetry" | ||
|
||
"github.com/porter-dev/porter/api/server/authz" | ||
"github.com/porter-dev/porter/api/server/handlers" | ||
"github.com/porter-dev/porter/api/server/shared" | ||
"github.com/porter-dev/porter/api/server/shared/apierrors" | ||
"github.com/porter-dev/porter/api/server/shared/config" | ||
"github.com/porter-dev/porter/api/types" | ||
"github.com/porter-dev/porter/internal/models" | ||
) | ||
|
||
// NodeGroupsHandler is the handler for the /node-groups endpoint | ||
type NodeGroupsHandler struct { | ||
handlers.PorterHandlerWriter | ||
authz.KubernetesAgentGetter | ||
} | ||
|
||
// NewNodeGroupsHandler returns a handler for handling node group requests | ||
func NewNodeGroupsHandler( | ||
config *config.Config, | ||
writer shared.ResultWriter, | ||
) *NodeGroupsHandler { | ||
return &NodeGroupsHandler{ | ||
PorterHandlerWriter: handlers.NewDefaultPorterHandler(config, nil, writer), | ||
KubernetesAgentGetter: authz.NewOutOfClusterAgentGetter(config), | ||
} | ||
} | ||
|
||
// NodeGroupsResponse represents the response to a list node groups request | ||
type NodeGroupsResponse struct { | ||
NodeGroups []NodeGroup `json:"node_groups"` | ||
} | ||
|
||
// NodeGroup represents a node group managed by a user | ||
type NodeGroup struct { | ||
Name string `json:"name"` | ||
Id string `json:"id"` | ||
InstanceType string `json:"instance_type"` | ||
RamMb int32 `json:"ram_mb"` | ||
CpuCores float32 `json:"cpu_cores"` | ||
GpuCores int32 `json:"gpu_cores"` | ||
} | ||
|
||
// ServeHTTP handles GET requests to list node groups | ||
func (c *NodeGroupsHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { | ||
ctx, span := telemetry.NewSpan(r.Context(), "serve-list-nodes") | ||
defer span.End() | ||
|
||
project, _ := r.Context().Value(types.ProjectScope).(*models.Project) | ||
cluster, _ := r.Context().Value(types.ClusterScope).(*models.Cluster) | ||
|
||
userNodeGroupReq := connect.NewRequest(&porterv1.UserNodeGroupsRequest{ | ||
ProjectId: int64(project.ID), | ||
ClusterId: int64(cluster.ID), | ||
}) | ||
|
||
ccpResp, err := c.Config().ClusterControlPlaneClient.UserNodeGroups(ctx, userNodeGroupReq) | ||
if err != nil { | ||
err := telemetry.Error(ctx, span, err, "error creating deployment target") | ||
c.HandleAPIError(w, r, apierrors.NewErrPassThroughToClient(err, http.StatusInternalServerError)) | ||
return | ||
} | ||
if ccpResp == nil || ccpResp.Msg == nil { | ||
err := telemetry.Error(ctx, span, err, "ccp resp msg is nil") | ||
c.HandleAPIError(w, r, apierrors.NewErrPassThroughToClient(err, http.StatusInternalServerError)) | ||
return | ||
} | ||
|
||
var nodeGroups []NodeGroup | ||
for _, ng := range ccpResp.Msg.UserNodeGroups { | ||
nodeGroups = append(nodeGroups, NodeGroup{ | ||
Name: ng.Name, | ||
Id: ng.Id, | ||
InstanceType: ng.InstanceType, | ||
RamMb: ng.RamMb, | ||
CpuCores: ng.CpuCores, | ||
GpuCores: ng.GpuCores, | ||
}) | ||
} | ||
|
||
res := &NodeGroupsResponse{ | ||
NodeGroups: nodeGroups, | ||
} | ||
|
||
c.WriteResult(w, r, res) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import React from "react"; | ||
import styled from "styled-components"; | ||
|
||
type Props = { | ||
handleDelete: () => void; | ||
}; | ||
|
||
const TrashDelete: React.FC<Props> = ({ handleDelete }) => { | ||
return ( | ||
<ActionButton | ||
onClick={(e) => { | ||
e.stopPropagation(); | ||
handleDelete(); | ||
}} | ||
type={"button"} | ||
> | ||
<span className="material-icons">delete</span> | ||
</ActionButton> | ||
); | ||
}; | ||
|
||
export default TrashDelete; | ||
|
||
const ActionButton = styled.button` | ||
position: relative; | ||
border: none; | ||
background: none; | ||
color: white; | ||
padding: 5px; | ||
display: flex; | ||
justify-content: center; | ||
align-items: center; | ||
border-radius: 50%; | ||
cursor: pointer; | ||
color: #aaaabb; | ||
:hover { | ||
color: white; | ||
} | ||
> span { | ||
font-size: 20px; | ||
} | ||
margin-right: 5px; | ||
`; |
Oops, something went wrong.