code cleanup

This commit is contained in:
rushtehrani
2019-12-10 11:49:27 -08:00
parent 0996aa830d
commit 7fd5a0b1fe
15 changed files with 73 additions and 63 deletions

2
.vscode/launch.json vendored
View File

@@ -9,7 +9,7 @@
"type": "go", "type": "go",
"request": "launch", "request": "launch",
"mode": "auto", "mode": "auto",
"program": "${fileDirname}", "program": "${workspaceRoot}/main.go",
"env": {}, "env": {},
"args": [] "args": []
} }

View File

@@ -4,4 +4,10 @@
}, },
"go.lintTool": "golangci-lint", "go.lintTool": "golangci-lint",
"go.useLanguageServer": true, "go.useLanguageServer": true,
"protoc": {
"path": "/usr/local/bin/protoc",
"options": [
"--proto_path=${workspaceRoot}/api"
]
}
} }

View File

@@ -73,7 +73,7 @@ func (m *CreateWorkflowRequest) GetWorkflow() *Workflow {
} }
type Workflow struct { type Workflow struct {
Uuid string `protobuf:"bytes,1,opt,name=uuid,proto3" json:"uuid,omitempty"` Uid string `protobuf:"bytes,1,opt,name=uid,proto3" json:"uid,omitempty"`
Name string `protobuf:"bytes,2,opt,name=name,proto3" json:"name,omitempty"` Name string `protobuf:"bytes,2,opt,name=name,proto3" json:"name,omitempty"`
Parameters []*Parameter `protobuf:"bytes,3,rep,name=parameters,proto3" json:"parameters,omitempty"` Parameters []*Parameter `protobuf:"bytes,3,rep,name=parameters,proto3" json:"parameters,omitempty"`
WorkflowTemplate *WorkflowTemplate `protobuf:"bytes,4,opt,name=workflowTemplate,proto3" json:"workflowTemplate,omitempty"` WorkflowTemplate *WorkflowTemplate `protobuf:"bytes,4,opt,name=workflowTemplate,proto3" json:"workflowTemplate,omitempty"`
@@ -107,9 +107,9 @@ func (m *Workflow) XXX_DiscardUnknown() {
var xxx_messageInfo_Workflow proto.InternalMessageInfo var xxx_messageInfo_Workflow proto.InternalMessageInfo
func (m *Workflow) GetUuid() string { func (m *Workflow) GetUid() string {
if m != nil { if m != nil {
return m.Uuid return m.Uid
} }
return "" return ""
} }
@@ -191,27 +191,27 @@ func init() {
func init() { proto.RegisterFile("workflow.proto", fileDescriptor_892c7f566756b0be) } func init() { proto.RegisterFile("workflow.proto", fileDescriptor_892c7f566756b0be) }
var fileDescriptor_892c7f566756b0be = []byte{ var fileDescriptor_892c7f566756b0be = []byte{
// 319 bytes of a gzipped FileDescriptorProto // 318 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x6c, 0x91, 0xc1, 0x4e, 0xf2, 0x40, 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0x6c, 0x91, 0xc1, 0x4e, 0xc2, 0x40,
0x14, 0x85, 0x53, 0xe0, 0x27, 0xf4, 0x92, 0x1f, 0xcd, 0x44, 0x62, 0xd3, 0xb0, 0x20, 0x75, 0x83, 0x10, 0x86, 0x53, 0x8a, 0x84, 0x0e, 0x11, 0xc9, 0x46, 0x62, 0xd3, 0x70, 0x20, 0xf5, 0x82, 0x97,
0x9b, 0x36, 0x60, 0xd8, 0xb8, 0x33, 0xbe, 0x80, 0xa9, 0x26, 0x2e, 0xf5, 0x82, 0x57, 0x52, 0x2d, 0x36, 0x60, 0xb8, 0x78, 0x33, 0xbe, 0x80, 0xa9, 0x26, 0x1e, 0x75, 0xc0, 0x91, 0x54, 0x4b, 0x77,
0x9d, 0x71, 0x66, 0x0a, 0x0b, 0xc3, 0xc6, 0x57, 0xf0, 0x19, 0x7c, 0x22, 0x5f, 0xc1, 0x07, 0x31, 0xdd, 0x5d, 0xe0, 0x60, 0xb8, 0xf8, 0x0a, 0x3e, 0x82, 0x8f, 0xe4, 0x2b, 0xf8, 0x20, 0x86, 0x2d,
0x4c, 0x3b, 0x23, 0x44, 0x77, 0xd3, 0x73, 0x4f, 0xbf, 0x7b, 0xe6, 0x0c, 0xf4, 0xd6, 0x5c, 0x3e, 0xbb, 0x42, 0xf4, 0x36, 0x9d, 0xf9, 0xfb, 0xcd, 0xbf, 0xff, 0x40, 0x7b, 0xc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fd, 0xc2, 0xa7, 0xc4, 0x9e, 0xa1, 0x51, 0x25, 0xca, 0x22, 0xb3, 0xfc, 0xdf, 0x78, 0xa3, 0xfd, 0xb8, 0xe2,
0xa2, 0xe9, 0xdb, 0xe7, 0xd7, 0x7b, 0x23, 0x89, 0x4e, 0xb6, 0x2f, 0xa8, 0x92, 0xd5, 0x78, 0x46, 0xf1, 0xfb, 0xd7, 0xf7, 0x47, 0x2d, 0x8d, 0x4f, 0x37, 0xf7, 0x53, 0xe9, 0x72, 0x38, 0x21, 0x8d,
0x1a, 0xc7, 0xc9, 0xab, 0xeb, 0x7c, 0x93, 0xd8, 0xc8, 0xea, 0xdc, 0xb5, 0x3b, 0x6b, 0x9b, 0x67, 0xc3, 0xf4, 0xcd, 0x25, 0xbe, 0x4e, 0xad, 0x65, 0x75, 0xe1, 0xb2, 0x9d, 0x34, 0xcc, 0x11, 0xcf,
0x3c, 0xfb, 0x0e, 0x00, 0x00, 0xff, 0xff, 0x33, 0xb5, 0x82, 0xa3, 0x14, 0x02, 0x00, 0x00, 0x7f, 0x02, 0x00, 0x00, 0xff, 0xff, 0x67, 0x35, 0xdb, 0xc1, 0x12, 0x02, 0x00, 0x00,
} }
// Reference imports to suppress errors if they are not otherwise used. // Reference imports to suppress errors if they are not otherwise used.

View File

@@ -21,7 +21,7 @@ message CreateWorkflowRequest {
} }
message Workflow { message Workflow {
string uuid = 1; string uid = 1;
string name = 2; string name = 2;
repeated Parameter parameters = 3; repeated Parameter parameters = 3;

View File

@@ -60,7 +60,7 @@
"apiWorkflow": { "apiWorkflow": {
"type": "object", "type": "object",
"properties": { "properties": {
"uuid": { "uid": {
"type": "string" "type": "string"
}, },
"name": { "name": {
@@ -80,7 +80,7 @@
"apiWorkflowTemplate": { "apiWorkflowTemplate": {
"type": "object", "type": "object",
"properties": { "properties": {
"uuid": { "uid": {
"type": "string" "type": "string"
}, },
"name": { "name": {

View File

@@ -21,7 +21,7 @@ var _ = math.Inf
const _ = proto.ProtoPackageIsVersion3 // please upgrade the proto package const _ = proto.ProtoPackageIsVersion3 // please upgrade the proto package
type WorkflowTemplate struct { type WorkflowTemplate struct {
Uuid string `protobuf:"bytes,1,opt,name=uuid,proto3" json:"uuid,omitempty"` Uid string `protobuf:"bytes,1,opt,name=uid,proto3" json:"uid,omitempty"`
Name string `protobuf:"bytes,2,opt,name=name,proto3" json:"name,omitempty"` Name string `protobuf:"bytes,2,opt,name=name,proto3" json:"name,omitempty"`
Manifest string `protobuf:"bytes,4,opt,name=manifest,proto3" json:"manifest,omitempty"` Manifest string `protobuf:"bytes,4,opt,name=manifest,proto3" json:"manifest,omitempty"`
XXX_NoUnkeyedLiteral struct{} `json:"-"` XXX_NoUnkeyedLiteral struct{} `json:"-"`
@@ -54,9 +54,9 @@ func (m *WorkflowTemplate) XXX_DiscardUnknown() {
var xxx_messageInfo_WorkflowTemplate proto.InternalMessageInfo var xxx_messageInfo_WorkflowTemplate proto.InternalMessageInfo
func (m *WorkflowTemplate) GetUuid() string { func (m *WorkflowTemplate) GetUid() string {
if m != nil { if m != nil {
return m.Uuid return m.Uid
} }
return "" return ""
} }
@@ -82,13 +82,13 @@ func init() {
func init() { proto.RegisterFile("workflow_template.proto", fileDescriptor_b9a07547748a96e8) } func init() { proto.RegisterFile("workflow_template.proto", fileDescriptor_b9a07547748a96e8) }
var fileDescriptor_b9a07547748a96e8 = []byte{ var fileDescriptor_b9a07547748a96e8 = []byte{
// 115 bytes of a gzipped FileDescriptorProto // 116 bytes of a gzipped FileDescriptorProto
0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x12, 0x2f, 0xcf, 0x2f, 0xca, 0x1f, 0x8b, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0xff, 0xe2, 0x12, 0x2f, 0xcf, 0x2f, 0xca,
0x4e, 0xcb, 0xc9, 0x2f, 0x8f, 0x2f, 0x49, 0xcd, 0x2d, 0xc8, 0x49, 0x2c, 0x49, 0xd5, 0x2b, 0x28, 0x4e, 0xcb, 0xc9, 0x2f, 0x8f, 0x2f, 0x49, 0xcd, 0x2d, 0xc8, 0x49, 0x2c, 0x49, 0xd5, 0x2b, 0x28,
0xca, 0x2f, 0xc9, 0x17, 0x62, 0x4e, 0x2c, 0xc8, 0x54, 0x0a, 0xe3, 0x12, 0x08, 0x87, 0xca, 0x87, 0xca, 0x2f, 0xc9, 0x17, 0x62, 0x4e, 0x2c, 0xc8, 0x54, 0x0a, 0xe1, 0x12, 0x08, 0x87, 0xca, 0x87,
0x40, 0xa5, 0x85, 0x84, 0xb8, 0x58, 0x4a, 0x4b, 0x33, 0x53, 0x24, 0x18, 0x15, 0x18, 0x35, 0x38, 0x40, 0xa5, 0x85, 0x04, 0xb8, 0x98, 0x4b, 0x33, 0x53, 0x24, 0x18, 0x15, 0x18, 0x35, 0x38, 0x83,
0x83, 0xc0, 0x6c, 0x90, 0x58, 0x5e, 0x62, 0x6e, 0xaa, 0x04, 0x13, 0x44, 0x0c, 0xc4, 0x16, 0x92, 0x40, 0x4c, 0x21, 0x21, 0x2e, 0x96, 0xbc, 0xc4, 0xdc, 0x54, 0x09, 0x26, 0xb0, 0x10, 0x98, 0x2d,
0xe2, 0xe2, 0xc8, 0x4d, 0xcc, 0xcb, 0x4c, 0x4b, 0x2d, 0x2e, 0x91, 0x60, 0x01, 0x8b, 0xc3, 0xf9, 0x24, 0xc5, 0xc5, 0x91, 0x9b, 0x98, 0x97, 0x99, 0x96, 0x5a, 0x5c, 0x22, 0xc1, 0x02, 0x16, 0x87,
0x49, 0x6c, 0x60, 0x3b, 0x8c, 0x01, 0x01, 0x00, 0x00, 0xff, 0xff, 0xe4, 0xe9, 0x1d, 0x6a, 0x7e, 0xf3, 0x93, 0xd8, 0xc0, 0x36, 0x18, 0x03, 0x02, 0x00, 0x00, 0xff, 0xff, 0xa0, 0x43, 0x79, 0x28,
0x00, 0x00, 0x00, 0x7c, 0x00, 0x00, 0x00,
} }

View File

@@ -3,7 +3,7 @@ syntax = "proto3";
package api; package api;
message WorkflowTemplate { message WorkflowTemplate {
string uuid = 1; string uid = 1;
string name = 2; string name = 2;
string manifest = 4; string manifest = 4;

View File

@@ -13,7 +13,7 @@ type Parameter = wfv1.Parameter
type Options struct { type Options struct {
Name string Name string
GenerateName string GeneratedName string
Entrypoint string Entrypoint string
Parameters []Parameter Parameters []Parameter
ServiceAccount string ServiceAccount string
@@ -45,8 +45,8 @@ func (c *Client) create(wf *Workflow, opts *Options) (createdWorkflow *Workflow,
if opts.Name != "" { if opts.Name != "" {
wf.ObjectMeta.Name = opts.Name wf.ObjectMeta.Name = opts.Name
} }
if opts.GenerateName != "" { if opts.GeneratedName != "" {
wf.ObjectMeta.GenerateName = opts.GenerateName wf.ObjectMeta.GenerateName = opts.GeneratedName
} }
if opts.Entrypoint != "" { if opts.Entrypoint != "" {
wf.Spec.Entrypoint = opts.Entrypoint wf.Spec.Entrypoint = opts.Entrypoint

View File

@@ -20,12 +20,13 @@ func (r *ResourceManager) CreateWorkflow(namespace string, workflow *model.Workf
}) })
} }
createdWorkflows, err := r.workflowClient.Create(workflow.WorkflowTemplate.ToBytes(), opts) createdWorkflows, err := r.workflowClient.Create(workflow.WorkflowTemplate.GetManifest(), opts)
if err != nil { if err != nil {
return return
} }
createdWorkflow = workflow createdWorkflow = workflow
createdWorkflow.Name = createdWorkflows[0].Name createdWorkflow.Name = createdWorkflows[0].Name
createdWorkflow.UID = string(createdWorkflows[0].ObjectMeta.UID)
return return
} }

View File

@@ -1,11 +1,10 @@
package model package model
import "github.com/google/uuid"
type Workflow struct { type Workflow struct {
ID uint64 ID uint64
UUID uuid.UUID UID string
Name string Name string
GeneratedName string
Parameters []Parameter Parameters []Parameter
WorkflowTemplate WorkflowTemplate WorkflowTemplate WorkflowTemplate
} }
@@ -14,14 +13,3 @@ type Parameter struct {
Name string Name string
Value *string Value *string
} }
type WorkflowTemplate struct {
ID uint64
UUID uuid.UUID
Name string
Manifest string
}
func (wt *WorkflowTemplate) ToBytes() []byte {
return []byte(wt.Manifest)
}

View File

@@ -0,0 +1,12 @@
package model
type WorkflowTemplate struct {
ID uint64
UID string
Name string
Manifest string
}
func (wt *WorkflowTemplate) GetManifest() []byte {
return []byte(wt.Manifest)
}

View File

@@ -6,5 +6,5 @@ func TestWorkflowTemplateToBytes(t *testing.T) {
w := &WorkflowTemplate{ w := &WorkflowTemplate{
Manifest: "test", Manifest: "test",
} }
t.Log(w.ToBytes()) t.Log(w.GetManifest())
} }

View File

@@ -21,7 +21,7 @@ func NewWorkflowRepository(db *DB) *WorkflowRepository {
func (w *WorkflowRepository) Create(workflow *model.Workflow) (err error) { func (w *WorkflowRepository) Create(workflow *model.Workflow) (err error) {
sql, _, err := sq.Insert("workflows"). sql, _, err := sq.Insert("workflows").
SetMap(sq.Eq{ SetMap(sq.Eq{
"UUID": workflow.UUID, "UID": workflow.UID,
}).ToSql() }).ToSql()
if err != nil { if err != nil {
return return

View File

@@ -9,18 +9,18 @@ import (
) )
func TestWorkflowRepositoryCreate(t *testing.T) { func TestWorkflowRepositoryCreate(t *testing.T) {
uuid, err := uuid.NewRandom() uid, err := uuid.NewRandom()
if err != nil { if err != nil {
t.Error(err) t.Error(err)
return return
} }
workflow := &model.Workflow{ workflow := &model.Workflow{
UUID: uuid, UID: uid.String(),
} }
sql, args, err := sq.Insert("workflows"). sql, args, err := sq.Insert("workflows").
SetMap(sq.Eq{ SetMap(sq.Eq{
"UUID": workflow.UUID, "UID": workflow.UID,
}).ToSql() }).ToSql()
if err != nil { if err != nil {
t.Error(err) t.Error(err)

View File

@@ -34,7 +34,10 @@ func (w *WorkflowServer) Create(ctx context.Context, req *api.CreateWorkflowRequ
if err != nil { if err != nil {
return nil, err return nil, err
} }
req.Workflow.Name = createdWorkflow.Name req.Workflow = &api.Workflow{
Name: createdWorkflow.Name,
Uid: createdWorkflow.UID,
}
return req.Workflow, nil return req.Workflow, nil
} }