Skip to content

Commit

Permalink
Merge pull request #940 from Vafilor/feat/full.node.resources
Browse files Browse the repository at this point in the history
feat: add optional logic to capture the entire node
  • Loading branch information
Vafilor authored Aug 3, 2021
2 parents 0021249 + e0f3f81 commit 147c937
Show file tree
Hide file tree
Showing 7 changed files with 270 additions and 244 deletions.
3 changes: 3 additions & 0 deletions api/api.swagger.json
Original file line number Diff line number Diff line change
Expand Up @@ -3305,6 +3305,9 @@
"items": {
"$ref": "#/definitions/KeyValue"
}
},
"captureNode": {
"type": "boolean"
}
}
},
Expand Down
490 changes: 250 additions & 240 deletions api/gen/workspace.pb.go

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions api/proto/workspace.proto
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ message CreateWorkspaceBody {

repeated Parameter parameters = 3;
repeated KeyValue labels = 4;
bool captureNode = 5;
}

message CreateWorkspaceRequest {
Expand Down
7 changes: 7 additions & 0 deletions db/sql/20210802222820_configurable_capture_workspace_node.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
-- +goose Up
-- SQL in this section is executed when the migration is applied.
ALTER TABLE workspaces ADD COLUMN capture_node boolean;
UPDATE workspaces SET capture_node = false;

-- +goose Down
ALTER TABLE workspaces DROP COLUMN capture_node;
5 changes: 3 additions & 2 deletions pkg/workspace.go
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,7 @@ func (c *Client) createWorkspace(namespace string, parameters []byte, workspace
"workspace_template_id": workspace.WorkspaceTemplate.ID,
"workspace_template_version": workspace.WorkspaceTemplate.Version,
"labels": workspace.Labels,
"capture_node": workspace.CaptureNode,
}).
Suffix("RETURNING id, created_at").
RunWith(c.DB).
Expand Down Expand Up @@ -311,9 +312,9 @@ func (c *Client) addRuntimeFieldsToWorkspaceTemplate(t wfv1.Template, workspace
if !ok {
return nil, errors.New("unable to type check statefulset manifest")
}
extraContainer := generateNodeCaptureContainer(workspace, config)

if extraContainer != nil {
if workspace.CaptureNode {
extraContainer := generateNodeCaptureContainer(workspace, config)
containers, ok := templateSpec["containers"].([]interface{})
if !ok {
return nil, errors.New("unable to type check statefulset manifest")
Expand Down
5 changes: 4 additions & 1 deletion pkg/workspace_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ type Workspace struct {
WorkspaceTemplateID uint64 `db:"workspace_template_id"`
WorkspaceTemplateVersion uint64 `db:"workspace_template_version"`
WorkflowTemplateVersion *WorkflowTemplateVersion `db:"workflow_template_version"` // helper to store data from workflow template version
CaptureNode bool `db:"capture_node"`
}

type WorkspaceSpec struct {
Expand Down Expand Up @@ -102,7 +103,7 @@ func GenerateWorkspaceUID(name string) (string, error) {
// getWorkspaceColumns returns all of the columns for workspace modified by alias, destination.
// see formatColumnSelect
func getWorkspaceColumns(aliasAndDestination ...string) []string {
columns := []string{"id", "created_at", "modified_at", "uid", "name", "namespace", "parameters", "workspace_template_id", "workspace_template_version", "labels"}
columns := []string{"id", "created_at", "modified_at", "uid", "name", "namespace", "parameters", "workspace_template_id", "workspace_template_version", "labels", "capture_node"}
return sql.FormatColumnSelect(columns, aliasAndDestination...)
}

Expand Down Expand Up @@ -145,9 +146,11 @@ func getWorkspaceColumnsMap(camelCase bool) map[string]string {
if camelCase {
result["createdAt"] = "created_at"
result["modifiedAt"] = "modified_at"
result["captureNode"] = "capture_node"
} else {
result["created_at"] = "created_at"
result["modified_at"] = "modified_at"
result["capture_node"] = "capture_node"
}

return result
Expand Down
3 changes: 2 additions & 1 deletion server/workspace_server.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,8 @@ func (s *WorkspaceServer) CreateWorkspace(ctx context.Context, req *api.CreateWo
UID: req.Body.WorkspaceTemplateUid,
Version: req.Body.WorkspaceTemplateVersion,
},
Labels: converter.APIKeyValueToLabel(req.Body.Labels),
Labels: converter.APIKeyValueToLabel(req.Body.Labels),
CaptureNode: req.Body.CaptureNode,
}

for _, param := range req.Body.Parameters {
Expand Down

0 comments on commit 147c937

Please sign in to comment.