mirror of
https://github.com/coder/coder.git
synced 2026-09-24 15:04:27 +08:00
feat: integrate Acquirer for provisioner jobs (#9717)
* chore: add Acquirer to provisionerdserver pkg Signed-off-by: Spike Curtis <spike@coder.com> * code review improvements & fixes Signed-off-by: Spike Curtis <spike@coder.com> * feat: integrate Acquirer for provisioner jobs Signed-off-by: Spike Curtis <spike@coder.com> * Fix imports, whitespace Signed-off-by: Spike Curtis <spike@coder.com> * provisionerdserver always closes; remove poll interval from playwright Signed-off-by: Spike Curtis <spike@coder.com> * post jobs outside transactions Signed-off-by: Spike Curtis <spike@coder.com> * graceful shutdown in test Signed-off-by: Spike Curtis <spike@coder.com> * Mark AcquireJob deprecated Signed-off-by: Spike Curtis <spike@coder.com> * Graceful shutdown on all provisionerd tests Signed-off-by: Spike Curtis <spike@coder.com> * Deprecate, not remove CLI flags Signed-off-by: Spike Curtis <spike@coder.com> --------- Signed-off-by: Spike Curtis <spike@coder.com>
This commit is contained in:
Generated
+176
-116
@@ -809,6 +809,44 @@ func (x *CommitQuotaResponse) GetBudget() int32 {
|
||||
return 0
|
||||
}
|
||||
|
||||
type CancelAcquire struct {
|
||||
state protoimpl.MessageState
|
||||
sizeCache protoimpl.SizeCache
|
||||
unknownFields protoimpl.UnknownFields
|
||||
}
|
||||
|
||||
func (x *CancelAcquire) Reset() {
|
||||
*x = CancelAcquire{}
|
||||
if protoimpl.UnsafeEnabled {
|
||||
mi := &file_provisionerd_proto_provisionerd_proto_msgTypes[9]
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
ms.StoreMessageInfo(mi)
|
||||
}
|
||||
}
|
||||
|
||||
func (x *CancelAcquire) String() string {
|
||||
return protoimpl.X.MessageStringOf(x)
|
||||
}
|
||||
|
||||
func (*CancelAcquire) ProtoMessage() {}
|
||||
|
||||
func (x *CancelAcquire) ProtoReflect() protoreflect.Message {
|
||||
mi := &file_provisionerd_proto_provisionerd_proto_msgTypes[9]
|
||||
if protoimpl.UnsafeEnabled && x != nil {
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
if ms.LoadMessageInfo() == nil {
|
||||
ms.StoreMessageInfo(mi)
|
||||
}
|
||||
return ms
|
||||
}
|
||||
return mi.MessageOf(x)
|
||||
}
|
||||
|
||||
// Deprecated: Use CancelAcquire.ProtoReflect.Descriptor instead.
|
||||
func (*CancelAcquire) Descriptor() ([]byte, []int) {
|
||||
return file_provisionerd_proto_provisionerd_proto_rawDescGZIP(), []int{9}
|
||||
}
|
||||
|
||||
type AcquiredJob_WorkspaceBuild struct {
|
||||
state protoimpl.MessageState
|
||||
sizeCache protoimpl.SizeCache
|
||||
@@ -827,7 +865,7 @@ type AcquiredJob_WorkspaceBuild struct {
|
||||
func (x *AcquiredJob_WorkspaceBuild) Reset() {
|
||||
*x = AcquiredJob_WorkspaceBuild{}
|
||||
if protoimpl.UnsafeEnabled {
|
||||
mi := &file_provisionerd_proto_provisionerd_proto_msgTypes[9]
|
||||
mi := &file_provisionerd_proto_provisionerd_proto_msgTypes[10]
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
ms.StoreMessageInfo(mi)
|
||||
}
|
||||
@@ -840,7 +878,7 @@ func (x *AcquiredJob_WorkspaceBuild) String() string {
|
||||
func (*AcquiredJob_WorkspaceBuild) ProtoMessage() {}
|
||||
|
||||
func (x *AcquiredJob_WorkspaceBuild) ProtoReflect() protoreflect.Message {
|
||||
mi := &file_provisionerd_proto_provisionerd_proto_msgTypes[9]
|
||||
mi := &file_provisionerd_proto_provisionerd_proto_msgTypes[10]
|
||||
if protoimpl.UnsafeEnabled && x != nil {
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
if ms.LoadMessageInfo() == nil {
|
||||
@@ -924,7 +962,7 @@ type AcquiredJob_TemplateImport struct {
|
||||
func (x *AcquiredJob_TemplateImport) Reset() {
|
||||
*x = AcquiredJob_TemplateImport{}
|
||||
if protoimpl.UnsafeEnabled {
|
||||
mi := &file_provisionerd_proto_provisionerd_proto_msgTypes[10]
|
||||
mi := &file_provisionerd_proto_provisionerd_proto_msgTypes[11]
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
ms.StoreMessageInfo(mi)
|
||||
}
|
||||
@@ -937,7 +975,7 @@ func (x *AcquiredJob_TemplateImport) String() string {
|
||||
func (*AcquiredJob_TemplateImport) ProtoMessage() {}
|
||||
|
||||
func (x *AcquiredJob_TemplateImport) ProtoReflect() protoreflect.Message {
|
||||
mi := &file_provisionerd_proto_provisionerd_proto_msgTypes[10]
|
||||
mi := &file_provisionerd_proto_provisionerd_proto_msgTypes[11]
|
||||
if protoimpl.UnsafeEnabled && x != nil {
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
if ms.LoadMessageInfo() == nil {
|
||||
@@ -980,7 +1018,7 @@ type AcquiredJob_TemplateDryRun struct {
|
||||
func (x *AcquiredJob_TemplateDryRun) Reset() {
|
||||
*x = AcquiredJob_TemplateDryRun{}
|
||||
if protoimpl.UnsafeEnabled {
|
||||
mi := &file_provisionerd_proto_provisionerd_proto_msgTypes[11]
|
||||
mi := &file_provisionerd_proto_provisionerd_proto_msgTypes[12]
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
ms.StoreMessageInfo(mi)
|
||||
}
|
||||
@@ -993,7 +1031,7 @@ func (x *AcquiredJob_TemplateDryRun) String() string {
|
||||
func (*AcquiredJob_TemplateDryRun) ProtoMessage() {}
|
||||
|
||||
func (x *AcquiredJob_TemplateDryRun) ProtoReflect() protoreflect.Message {
|
||||
mi := &file_provisionerd_proto_provisionerd_proto_msgTypes[11]
|
||||
mi := &file_provisionerd_proto_provisionerd_proto_msgTypes[12]
|
||||
if protoimpl.UnsafeEnabled && x != nil {
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
if ms.LoadMessageInfo() == nil {
|
||||
@@ -1041,7 +1079,7 @@ type FailedJob_WorkspaceBuild struct {
|
||||
func (x *FailedJob_WorkspaceBuild) Reset() {
|
||||
*x = FailedJob_WorkspaceBuild{}
|
||||
if protoimpl.UnsafeEnabled {
|
||||
mi := &file_provisionerd_proto_provisionerd_proto_msgTypes[13]
|
||||
mi := &file_provisionerd_proto_provisionerd_proto_msgTypes[14]
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
ms.StoreMessageInfo(mi)
|
||||
}
|
||||
@@ -1054,7 +1092,7 @@ func (x *FailedJob_WorkspaceBuild) String() string {
|
||||
func (*FailedJob_WorkspaceBuild) ProtoMessage() {}
|
||||
|
||||
func (x *FailedJob_WorkspaceBuild) ProtoReflect() protoreflect.Message {
|
||||
mi := &file_provisionerd_proto_provisionerd_proto_msgTypes[13]
|
||||
mi := &file_provisionerd_proto_provisionerd_proto_msgTypes[14]
|
||||
if protoimpl.UnsafeEnabled && x != nil {
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
if ms.LoadMessageInfo() == nil {
|
||||
@@ -1086,7 +1124,7 @@ type FailedJob_TemplateImport struct {
|
||||
func (x *FailedJob_TemplateImport) Reset() {
|
||||
*x = FailedJob_TemplateImport{}
|
||||
if protoimpl.UnsafeEnabled {
|
||||
mi := &file_provisionerd_proto_provisionerd_proto_msgTypes[14]
|
||||
mi := &file_provisionerd_proto_provisionerd_proto_msgTypes[15]
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
ms.StoreMessageInfo(mi)
|
||||
}
|
||||
@@ -1099,7 +1137,7 @@ func (x *FailedJob_TemplateImport) String() string {
|
||||
func (*FailedJob_TemplateImport) ProtoMessage() {}
|
||||
|
||||
func (x *FailedJob_TemplateImport) ProtoReflect() protoreflect.Message {
|
||||
mi := &file_provisionerd_proto_provisionerd_proto_msgTypes[14]
|
||||
mi := &file_provisionerd_proto_provisionerd_proto_msgTypes[15]
|
||||
if protoimpl.UnsafeEnabled && x != nil {
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
if ms.LoadMessageInfo() == nil {
|
||||
@@ -1124,7 +1162,7 @@ type FailedJob_TemplateDryRun struct {
|
||||
func (x *FailedJob_TemplateDryRun) Reset() {
|
||||
*x = FailedJob_TemplateDryRun{}
|
||||
if protoimpl.UnsafeEnabled {
|
||||
mi := &file_provisionerd_proto_provisionerd_proto_msgTypes[15]
|
||||
mi := &file_provisionerd_proto_provisionerd_proto_msgTypes[16]
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
ms.StoreMessageInfo(mi)
|
||||
}
|
||||
@@ -1137,7 +1175,7 @@ func (x *FailedJob_TemplateDryRun) String() string {
|
||||
func (*FailedJob_TemplateDryRun) ProtoMessage() {}
|
||||
|
||||
func (x *FailedJob_TemplateDryRun) ProtoReflect() protoreflect.Message {
|
||||
mi := &file_provisionerd_proto_provisionerd_proto_msgTypes[15]
|
||||
mi := &file_provisionerd_proto_provisionerd_proto_msgTypes[16]
|
||||
if protoimpl.UnsafeEnabled && x != nil {
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
if ms.LoadMessageInfo() == nil {
|
||||
@@ -1165,7 +1203,7 @@ type CompletedJob_WorkspaceBuild struct {
|
||||
func (x *CompletedJob_WorkspaceBuild) Reset() {
|
||||
*x = CompletedJob_WorkspaceBuild{}
|
||||
if protoimpl.UnsafeEnabled {
|
||||
mi := &file_provisionerd_proto_provisionerd_proto_msgTypes[16]
|
||||
mi := &file_provisionerd_proto_provisionerd_proto_msgTypes[17]
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
ms.StoreMessageInfo(mi)
|
||||
}
|
||||
@@ -1178,7 +1216,7 @@ func (x *CompletedJob_WorkspaceBuild) String() string {
|
||||
func (*CompletedJob_WorkspaceBuild) ProtoMessage() {}
|
||||
|
||||
func (x *CompletedJob_WorkspaceBuild) ProtoReflect() protoreflect.Message {
|
||||
mi := &file_provisionerd_proto_provisionerd_proto_msgTypes[16]
|
||||
mi := &file_provisionerd_proto_provisionerd_proto_msgTypes[17]
|
||||
if protoimpl.UnsafeEnabled && x != nil {
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
if ms.LoadMessageInfo() == nil {
|
||||
@@ -1222,7 +1260,7 @@ type CompletedJob_TemplateImport struct {
|
||||
func (x *CompletedJob_TemplateImport) Reset() {
|
||||
*x = CompletedJob_TemplateImport{}
|
||||
if protoimpl.UnsafeEnabled {
|
||||
mi := &file_provisionerd_proto_provisionerd_proto_msgTypes[17]
|
||||
mi := &file_provisionerd_proto_provisionerd_proto_msgTypes[18]
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
ms.StoreMessageInfo(mi)
|
||||
}
|
||||
@@ -1235,7 +1273,7 @@ func (x *CompletedJob_TemplateImport) String() string {
|
||||
func (*CompletedJob_TemplateImport) ProtoMessage() {}
|
||||
|
||||
func (x *CompletedJob_TemplateImport) ProtoReflect() protoreflect.Message {
|
||||
mi := &file_provisionerd_proto_provisionerd_proto_msgTypes[17]
|
||||
mi := &file_provisionerd_proto_provisionerd_proto_msgTypes[18]
|
||||
if protoimpl.UnsafeEnabled && x != nil {
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
if ms.LoadMessageInfo() == nil {
|
||||
@@ -1290,7 +1328,7 @@ type CompletedJob_TemplateDryRun struct {
|
||||
func (x *CompletedJob_TemplateDryRun) Reset() {
|
||||
*x = CompletedJob_TemplateDryRun{}
|
||||
if protoimpl.UnsafeEnabled {
|
||||
mi := &file_provisionerd_proto_provisionerd_proto_msgTypes[18]
|
||||
mi := &file_provisionerd_proto_provisionerd_proto_msgTypes[19]
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
ms.StoreMessageInfo(mi)
|
||||
}
|
||||
@@ -1303,7 +1341,7 @@ func (x *CompletedJob_TemplateDryRun) String() string {
|
||||
func (*CompletedJob_TemplateDryRun) ProtoMessage() {}
|
||||
|
||||
func (x *CompletedJob_TemplateDryRun) ProtoReflect() protoreflect.Message {
|
||||
mi := &file_provisionerd_proto_provisionerd_proto_msgTypes[18]
|
||||
mi := &file_provisionerd_proto_provisionerd_proto_msgTypes[19]
|
||||
if protoimpl.UnsafeEnabled && x != nil {
|
||||
ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x))
|
||||
if ms.LoadMessageInfo() == nil {
|
||||
@@ -1543,37 +1581,44 @@ var file_provisionerd_proto_provisionerd_proto_rawDesc = []byte{
|
||||
0x69, 0x74, 0x73, 0x5f, 0x63, 0x6f, 0x6e, 0x73, 0x75, 0x6d, 0x65, 0x64, 0x18, 0x02, 0x20, 0x01,
|
||||
0x28, 0x05, 0x52, 0x0f, 0x63, 0x72, 0x65, 0x64, 0x69, 0x74, 0x73, 0x43, 0x6f, 0x6e, 0x73, 0x75,
|
||||
0x6d, 0x65, 0x64, 0x12, 0x16, 0x0a, 0x06, 0x62, 0x75, 0x64, 0x67, 0x65, 0x74, 0x18, 0x03, 0x20,
|
||||
0x01, 0x28, 0x05, 0x52, 0x06, 0x62, 0x75, 0x64, 0x67, 0x65, 0x74, 0x2a, 0x34, 0x0a, 0x09, 0x4c,
|
||||
0x6f, 0x67, 0x53, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x12, 0x16, 0x0a, 0x12, 0x50, 0x52, 0x4f, 0x56,
|
||||
0x49, 0x53, 0x49, 0x4f, 0x4e, 0x45, 0x52, 0x5f, 0x44, 0x41, 0x45, 0x4d, 0x4f, 0x4e, 0x10, 0x00,
|
||||
0x12, 0x0f, 0x0a, 0x0b, 0x50, 0x52, 0x4f, 0x56, 0x49, 0x53, 0x49, 0x4f, 0x4e, 0x45, 0x52, 0x10,
|
||||
0x01, 0x32, 0xec, 0x02, 0x0a, 0x11, 0x50, 0x72, 0x6f, 0x76, 0x69, 0x73, 0x69, 0x6f, 0x6e, 0x65,
|
||||
0x72, 0x44, 0x61, 0x65, 0x6d, 0x6f, 0x6e, 0x12, 0x3c, 0x0a, 0x0a, 0x41, 0x63, 0x71, 0x75, 0x69,
|
||||
0x72, 0x65, 0x4a, 0x6f, 0x62, 0x12, 0x13, 0x2e, 0x70, 0x72, 0x6f, 0x76, 0x69, 0x73, 0x69, 0x6f,
|
||||
0x6e, 0x65, 0x72, 0x64, 0x2e, 0x45, 0x6d, 0x70, 0x74, 0x79, 0x1a, 0x19, 0x2e, 0x70, 0x72, 0x6f,
|
||||
0x76, 0x69, 0x73, 0x69, 0x6f, 0x6e, 0x65, 0x72, 0x64, 0x2e, 0x41, 0x63, 0x71, 0x75, 0x69, 0x72,
|
||||
0x65, 0x64, 0x4a, 0x6f, 0x62, 0x12, 0x52, 0x0a, 0x0b, 0x43, 0x6f, 0x6d, 0x6d, 0x69, 0x74, 0x51,
|
||||
0x75, 0x6f, 0x74, 0x61, 0x12, 0x20, 0x2e, 0x70, 0x72, 0x6f, 0x76, 0x69, 0x73, 0x69, 0x6f, 0x6e,
|
||||
0x65, 0x72, 0x64, 0x2e, 0x43, 0x6f, 0x6d, 0x6d, 0x69, 0x74, 0x51, 0x75, 0x6f, 0x74, 0x61, 0x52,
|
||||
0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x21, 0x2e, 0x70, 0x72, 0x6f, 0x76, 0x69, 0x73, 0x69,
|
||||
0x6f, 0x6e, 0x65, 0x72, 0x64, 0x2e, 0x43, 0x6f, 0x6d, 0x6d, 0x69, 0x74, 0x51, 0x75, 0x6f, 0x74,
|
||||
0x61, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x4c, 0x0a, 0x09, 0x55, 0x70, 0x64,
|
||||
0x61, 0x74, 0x65, 0x4a, 0x6f, 0x62, 0x12, 0x1e, 0x2e, 0x70, 0x72, 0x6f, 0x76, 0x69, 0x73, 0x69,
|
||||
0x6f, 0x6e, 0x65, 0x72, 0x64, 0x2e, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x4a, 0x6f, 0x62, 0x52,
|
||||
0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1f, 0x2e, 0x70, 0x72, 0x6f, 0x76, 0x69, 0x73, 0x69,
|
||||
0x6f, 0x6e, 0x65, 0x72, 0x64, 0x2e, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x4a, 0x6f, 0x62, 0x52,
|
||||
0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x37, 0x0a, 0x07, 0x46, 0x61, 0x69, 0x6c, 0x4a,
|
||||
0x6f, 0x62, 0x12, 0x17, 0x2e, 0x70, 0x72, 0x6f, 0x76, 0x69, 0x73, 0x69, 0x6f, 0x6e, 0x65, 0x72,
|
||||
0x64, 0x2e, 0x46, 0x61, 0x69, 0x6c, 0x65, 0x64, 0x4a, 0x6f, 0x62, 0x1a, 0x13, 0x2e, 0x70, 0x72,
|
||||
0x6f, 0x76, 0x69, 0x73, 0x69, 0x6f, 0x6e, 0x65, 0x72, 0x64, 0x2e, 0x45, 0x6d, 0x70, 0x74, 0x79,
|
||||
0x12, 0x3e, 0x0a, 0x0b, 0x43, 0x6f, 0x6d, 0x70, 0x6c, 0x65, 0x74, 0x65, 0x4a, 0x6f, 0x62, 0x12,
|
||||
0x1a, 0x2e, 0x70, 0x72, 0x6f, 0x76, 0x69, 0x73, 0x69, 0x6f, 0x6e, 0x65, 0x72, 0x64, 0x2e, 0x43,
|
||||
0x6f, 0x6d, 0x70, 0x6c, 0x65, 0x74, 0x65, 0x64, 0x4a, 0x6f, 0x62, 0x1a, 0x13, 0x2e, 0x70, 0x72,
|
||||
0x6f, 0x76, 0x69, 0x73, 0x69, 0x6f, 0x6e, 0x65, 0x72, 0x64, 0x2e, 0x45, 0x6d, 0x70, 0x74, 0x79,
|
||||
0x42, 0x2e, 0x5a, 0x2c, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x63,
|
||||
0x6f, 0x64, 0x65, 0x72, 0x2f, 0x63, 0x6f, 0x64, 0x65, 0x72, 0x2f, 0x76, 0x32, 0x2f, 0x70, 0x72,
|
||||
0x6f, 0x76, 0x69, 0x73, 0x69, 0x6f, 0x6e, 0x65, 0x72, 0x64, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f,
|
||||
0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
|
||||
0x01, 0x28, 0x05, 0x52, 0x06, 0x62, 0x75, 0x64, 0x67, 0x65, 0x74, 0x22, 0x0f, 0x0a, 0x0d, 0x43,
|
||||
0x61, 0x6e, 0x63, 0x65, 0x6c, 0x41, 0x63, 0x71, 0x75, 0x69, 0x72, 0x65, 0x2a, 0x34, 0x0a, 0x09,
|
||||
0x4c, 0x6f, 0x67, 0x53, 0x6f, 0x75, 0x72, 0x63, 0x65, 0x12, 0x16, 0x0a, 0x12, 0x50, 0x52, 0x4f,
|
||||
0x56, 0x49, 0x53, 0x49, 0x4f, 0x4e, 0x45, 0x52, 0x5f, 0x44, 0x41, 0x45, 0x4d, 0x4f, 0x4e, 0x10,
|
||||
0x00, 0x12, 0x0f, 0x0a, 0x0b, 0x50, 0x52, 0x4f, 0x56, 0x49, 0x53, 0x49, 0x4f, 0x4e, 0x45, 0x52,
|
||||
0x10, 0x01, 0x32, 0xc5, 0x03, 0x0a, 0x11, 0x50, 0x72, 0x6f, 0x76, 0x69, 0x73, 0x69, 0x6f, 0x6e,
|
||||
0x65, 0x72, 0x44, 0x61, 0x65, 0x6d, 0x6f, 0x6e, 0x12, 0x41, 0x0a, 0x0a, 0x41, 0x63, 0x71, 0x75,
|
||||
0x69, 0x72, 0x65, 0x4a, 0x6f, 0x62, 0x12, 0x13, 0x2e, 0x70, 0x72, 0x6f, 0x76, 0x69, 0x73, 0x69,
|
||||
0x6f, 0x6e, 0x65, 0x72, 0x64, 0x2e, 0x45, 0x6d, 0x70, 0x74, 0x79, 0x1a, 0x19, 0x2e, 0x70, 0x72,
|
||||
0x6f, 0x76, 0x69, 0x73, 0x69, 0x6f, 0x6e, 0x65, 0x72, 0x64, 0x2e, 0x41, 0x63, 0x71, 0x75, 0x69,
|
||||
0x72, 0x65, 0x64, 0x4a, 0x6f, 0x62, 0x22, 0x03, 0x88, 0x02, 0x01, 0x12, 0x52, 0x0a, 0x14, 0x41,
|
||||
0x63, 0x71, 0x75, 0x69, 0x72, 0x65, 0x4a, 0x6f, 0x62, 0x57, 0x69, 0x74, 0x68, 0x43, 0x61, 0x6e,
|
||||
0x63, 0x65, 0x6c, 0x12, 0x1b, 0x2e, 0x70, 0x72, 0x6f, 0x76, 0x69, 0x73, 0x69, 0x6f, 0x6e, 0x65,
|
||||
0x72, 0x64, 0x2e, 0x43, 0x61, 0x6e, 0x63, 0x65, 0x6c, 0x41, 0x63, 0x71, 0x75, 0x69, 0x72, 0x65,
|
||||
0x1a, 0x19, 0x2e, 0x70, 0x72, 0x6f, 0x76, 0x69, 0x73, 0x69, 0x6f, 0x6e, 0x65, 0x72, 0x64, 0x2e,
|
||||
0x41, 0x63, 0x71, 0x75, 0x69, 0x72, 0x65, 0x64, 0x4a, 0x6f, 0x62, 0x28, 0x01, 0x30, 0x01, 0x12,
|
||||
0x52, 0x0a, 0x0b, 0x43, 0x6f, 0x6d, 0x6d, 0x69, 0x74, 0x51, 0x75, 0x6f, 0x74, 0x61, 0x12, 0x20,
|
||||
0x2e, 0x70, 0x72, 0x6f, 0x76, 0x69, 0x73, 0x69, 0x6f, 0x6e, 0x65, 0x72, 0x64, 0x2e, 0x43, 0x6f,
|
||||
0x6d, 0x6d, 0x69, 0x74, 0x51, 0x75, 0x6f, 0x74, 0x61, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74,
|
||||
0x1a, 0x21, 0x2e, 0x70, 0x72, 0x6f, 0x76, 0x69, 0x73, 0x69, 0x6f, 0x6e, 0x65, 0x72, 0x64, 0x2e,
|
||||
0x43, 0x6f, 0x6d, 0x6d, 0x69, 0x74, 0x51, 0x75, 0x6f, 0x74, 0x61, 0x52, 0x65, 0x73, 0x70, 0x6f,
|
||||
0x6e, 0x73, 0x65, 0x12, 0x4c, 0x0a, 0x09, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x4a, 0x6f, 0x62,
|
||||
0x12, 0x1e, 0x2e, 0x70, 0x72, 0x6f, 0x76, 0x69, 0x73, 0x69, 0x6f, 0x6e, 0x65, 0x72, 0x64, 0x2e,
|
||||
0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x4a, 0x6f, 0x62, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74,
|
||||
0x1a, 0x1f, 0x2e, 0x70, 0x72, 0x6f, 0x76, 0x69, 0x73, 0x69, 0x6f, 0x6e, 0x65, 0x72, 0x64, 0x2e,
|
||||
0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x4a, 0x6f, 0x62, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73,
|
||||
0x65, 0x12, 0x37, 0x0a, 0x07, 0x46, 0x61, 0x69, 0x6c, 0x4a, 0x6f, 0x62, 0x12, 0x17, 0x2e, 0x70,
|
||||
0x72, 0x6f, 0x76, 0x69, 0x73, 0x69, 0x6f, 0x6e, 0x65, 0x72, 0x64, 0x2e, 0x46, 0x61, 0x69, 0x6c,
|
||||
0x65, 0x64, 0x4a, 0x6f, 0x62, 0x1a, 0x13, 0x2e, 0x70, 0x72, 0x6f, 0x76, 0x69, 0x73, 0x69, 0x6f,
|
||||
0x6e, 0x65, 0x72, 0x64, 0x2e, 0x45, 0x6d, 0x70, 0x74, 0x79, 0x12, 0x3e, 0x0a, 0x0b, 0x43, 0x6f,
|
||||
0x6d, 0x70, 0x6c, 0x65, 0x74, 0x65, 0x4a, 0x6f, 0x62, 0x12, 0x1a, 0x2e, 0x70, 0x72, 0x6f, 0x76,
|
||||
0x69, 0x73, 0x69, 0x6f, 0x6e, 0x65, 0x72, 0x64, 0x2e, 0x43, 0x6f, 0x6d, 0x70, 0x6c, 0x65, 0x74,
|
||||
0x65, 0x64, 0x4a, 0x6f, 0x62, 0x1a, 0x13, 0x2e, 0x70, 0x72, 0x6f, 0x76, 0x69, 0x73, 0x69, 0x6f,
|
||||
0x6e, 0x65, 0x72, 0x64, 0x2e, 0x45, 0x6d, 0x70, 0x74, 0x79, 0x42, 0x2e, 0x5a, 0x2c, 0x67, 0x69,
|
||||
0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x63, 0x6f, 0x64, 0x65, 0x72, 0x2f, 0x63,
|
||||
0x6f, 0x64, 0x65, 0x72, 0x2f, 0x76, 0x32, 0x2f, 0x70, 0x72, 0x6f, 0x76, 0x69, 0x73, 0x69, 0x6f,
|
||||
0x6e, 0x65, 0x72, 0x64, 0x2f, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74,
|
||||
0x6f, 0x33,
|
||||
}
|
||||
|
||||
var (
|
||||
@@ -1589,7 +1634,7 @@ func file_provisionerd_proto_provisionerd_proto_rawDescGZIP() []byte {
|
||||
}
|
||||
|
||||
var file_provisionerd_proto_provisionerd_proto_enumTypes = make([]protoimpl.EnumInfo, 1)
|
||||
var file_provisionerd_proto_provisionerd_proto_msgTypes = make([]protoimpl.MessageInfo, 19)
|
||||
var file_provisionerd_proto_provisionerd_proto_msgTypes = make([]protoimpl.MessageInfo, 20)
|
||||
var file_provisionerd_proto_provisionerd_proto_goTypes = []interface{}{
|
||||
(LogSource)(0), // 0: provisionerd.LogSource
|
||||
(*Empty)(nil), // 1: provisionerd.Empty
|
||||
@@ -1601,68 +1646,71 @@ var file_provisionerd_proto_provisionerd_proto_goTypes = []interface{}{
|
||||
(*UpdateJobResponse)(nil), // 7: provisionerd.UpdateJobResponse
|
||||
(*CommitQuotaRequest)(nil), // 8: provisionerd.CommitQuotaRequest
|
||||
(*CommitQuotaResponse)(nil), // 9: provisionerd.CommitQuotaResponse
|
||||
(*AcquiredJob_WorkspaceBuild)(nil), // 10: provisionerd.AcquiredJob.WorkspaceBuild
|
||||
(*AcquiredJob_TemplateImport)(nil), // 11: provisionerd.AcquiredJob.TemplateImport
|
||||
(*AcquiredJob_TemplateDryRun)(nil), // 12: provisionerd.AcquiredJob.TemplateDryRun
|
||||
nil, // 13: provisionerd.AcquiredJob.TraceMetadataEntry
|
||||
(*FailedJob_WorkspaceBuild)(nil), // 14: provisionerd.FailedJob.WorkspaceBuild
|
||||
(*FailedJob_TemplateImport)(nil), // 15: provisionerd.FailedJob.TemplateImport
|
||||
(*FailedJob_TemplateDryRun)(nil), // 16: provisionerd.FailedJob.TemplateDryRun
|
||||
(*CompletedJob_WorkspaceBuild)(nil), // 17: provisionerd.CompletedJob.WorkspaceBuild
|
||||
(*CompletedJob_TemplateImport)(nil), // 18: provisionerd.CompletedJob.TemplateImport
|
||||
(*CompletedJob_TemplateDryRun)(nil), // 19: provisionerd.CompletedJob.TemplateDryRun
|
||||
(proto.LogLevel)(0), // 20: provisioner.LogLevel
|
||||
(*proto.TemplateVariable)(nil), // 21: provisioner.TemplateVariable
|
||||
(*proto.VariableValue)(nil), // 22: provisioner.VariableValue
|
||||
(*proto.RichParameterValue)(nil), // 23: provisioner.RichParameterValue
|
||||
(*proto.GitAuthProvider)(nil), // 24: provisioner.GitAuthProvider
|
||||
(*proto.Metadata)(nil), // 25: provisioner.Metadata
|
||||
(*proto.Resource)(nil), // 26: provisioner.Resource
|
||||
(*proto.RichParameter)(nil), // 27: provisioner.RichParameter
|
||||
(*CancelAcquire)(nil), // 10: provisionerd.CancelAcquire
|
||||
(*AcquiredJob_WorkspaceBuild)(nil), // 11: provisionerd.AcquiredJob.WorkspaceBuild
|
||||
(*AcquiredJob_TemplateImport)(nil), // 12: provisionerd.AcquiredJob.TemplateImport
|
||||
(*AcquiredJob_TemplateDryRun)(nil), // 13: provisionerd.AcquiredJob.TemplateDryRun
|
||||
nil, // 14: provisionerd.AcquiredJob.TraceMetadataEntry
|
||||
(*FailedJob_WorkspaceBuild)(nil), // 15: provisionerd.FailedJob.WorkspaceBuild
|
||||
(*FailedJob_TemplateImport)(nil), // 16: provisionerd.FailedJob.TemplateImport
|
||||
(*FailedJob_TemplateDryRun)(nil), // 17: provisionerd.FailedJob.TemplateDryRun
|
||||
(*CompletedJob_WorkspaceBuild)(nil), // 18: provisionerd.CompletedJob.WorkspaceBuild
|
||||
(*CompletedJob_TemplateImport)(nil), // 19: provisionerd.CompletedJob.TemplateImport
|
||||
(*CompletedJob_TemplateDryRun)(nil), // 20: provisionerd.CompletedJob.TemplateDryRun
|
||||
(proto.LogLevel)(0), // 21: provisioner.LogLevel
|
||||
(*proto.TemplateVariable)(nil), // 22: provisioner.TemplateVariable
|
||||
(*proto.VariableValue)(nil), // 23: provisioner.VariableValue
|
||||
(*proto.RichParameterValue)(nil), // 24: provisioner.RichParameterValue
|
||||
(*proto.GitAuthProvider)(nil), // 25: provisioner.GitAuthProvider
|
||||
(*proto.Metadata)(nil), // 26: provisioner.Metadata
|
||||
(*proto.Resource)(nil), // 27: provisioner.Resource
|
||||
(*proto.RichParameter)(nil), // 28: provisioner.RichParameter
|
||||
}
|
||||
var file_provisionerd_proto_provisionerd_proto_depIdxs = []int32{
|
||||
10, // 0: provisionerd.AcquiredJob.workspace_build:type_name -> provisionerd.AcquiredJob.WorkspaceBuild
|
||||
11, // 1: provisionerd.AcquiredJob.template_import:type_name -> provisionerd.AcquiredJob.TemplateImport
|
||||
12, // 2: provisionerd.AcquiredJob.template_dry_run:type_name -> provisionerd.AcquiredJob.TemplateDryRun
|
||||
13, // 3: provisionerd.AcquiredJob.trace_metadata:type_name -> provisionerd.AcquiredJob.TraceMetadataEntry
|
||||
14, // 4: provisionerd.FailedJob.workspace_build:type_name -> provisionerd.FailedJob.WorkspaceBuild
|
||||
15, // 5: provisionerd.FailedJob.template_import:type_name -> provisionerd.FailedJob.TemplateImport
|
||||
16, // 6: provisionerd.FailedJob.template_dry_run:type_name -> provisionerd.FailedJob.TemplateDryRun
|
||||
17, // 7: provisionerd.CompletedJob.workspace_build:type_name -> provisionerd.CompletedJob.WorkspaceBuild
|
||||
18, // 8: provisionerd.CompletedJob.template_import:type_name -> provisionerd.CompletedJob.TemplateImport
|
||||
19, // 9: provisionerd.CompletedJob.template_dry_run:type_name -> provisionerd.CompletedJob.TemplateDryRun
|
||||
11, // 0: provisionerd.AcquiredJob.workspace_build:type_name -> provisionerd.AcquiredJob.WorkspaceBuild
|
||||
12, // 1: provisionerd.AcquiredJob.template_import:type_name -> provisionerd.AcquiredJob.TemplateImport
|
||||
13, // 2: provisionerd.AcquiredJob.template_dry_run:type_name -> provisionerd.AcquiredJob.TemplateDryRun
|
||||
14, // 3: provisionerd.AcquiredJob.trace_metadata:type_name -> provisionerd.AcquiredJob.TraceMetadataEntry
|
||||
15, // 4: provisionerd.FailedJob.workspace_build:type_name -> provisionerd.FailedJob.WorkspaceBuild
|
||||
16, // 5: provisionerd.FailedJob.template_import:type_name -> provisionerd.FailedJob.TemplateImport
|
||||
17, // 6: provisionerd.FailedJob.template_dry_run:type_name -> provisionerd.FailedJob.TemplateDryRun
|
||||
18, // 7: provisionerd.CompletedJob.workspace_build:type_name -> provisionerd.CompletedJob.WorkspaceBuild
|
||||
19, // 8: provisionerd.CompletedJob.template_import:type_name -> provisionerd.CompletedJob.TemplateImport
|
||||
20, // 9: provisionerd.CompletedJob.template_dry_run:type_name -> provisionerd.CompletedJob.TemplateDryRun
|
||||
0, // 10: provisionerd.Log.source:type_name -> provisionerd.LogSource
|
||||
20, // 11: provisionerd.Log.level:type_name -> provisioner.LogLevel
|
||||
21, // 11: provisionerd.Log.level:type_name -> provisioner.LogLevel
|
||||
5, // 12: provisionerd.UpdateJobRequest.logs:type_name -> provisionerd.Log
|
||||
21, // 13: provisionerd.UpdateJobRequest.template_variables:type_name -> provisioner.TemplateVariable
|
||||
22, // 14: provisionerd.UpdateJobRequest.user_variable_values:type_name -> provisioner.VariableValue
|
||||
22, // 15: provisionerd.UpdateJobResponse.variable_values:type_name -> provisioner.VariableValue
|
||||
23, // 16: provisionerd.AcquiredJob.WorkspaceBuild.rich_parameter_values:type_name -> provisioner.RichParameterValue
|
||||
22, // 17: provisionerd.AcquiredJob.WorkspaceBuild.variable_values:type_name -> provisioner.VariableValue
|
||||
24, // 18: provisionerd.AcquiredJob.WorkspaceBuild.git_auth_providers:type_name -> provisioner.GitAuthProvider
|
||||
25, // 19: provisionerd.AcquiredJob.WorkspaceBuild.metadata:type_name -> provisioner.Metadata
|
||||
25, // 20: provisionerd.AcquiredJob.TemplateImport.metadata:type_name -> provisioner.Metadata
|
||||
22, // 21: provisionerd.AcquiredJob.TemplateImport.user_variable_values:type_name -> provisioner.VariableValue
|
||||
23, // 22: provisionerd.AcquiredJob.TemplateDryRun.rich_parameter_values:type_name -> provisioner.RichParameterValue
|
||||
22, // 23: provisionerd.AcquiredJob.TemplateDryRun.variable_values:type_name -> provisioner.VariableValue
|
||||
25, // 24: provisionerd.AcquiredJob.TemplateDryRun.metadata:type_name -> provisioner.Metadata
|
||||
26, // 25: provisionerd.CompletedJob.WorkspaceBuild.resources:type_name -> provisioner.Resource
|
||||
26, // 26: provisionerd.CompletedJob.TemplateImport.start_resources:type_name -> provisioner.Resource
|
||||
26, // 27: provisionerd.CompletedJob.TemplateImport.stop_resources:type_name -> provisioner.Resource
|
||||
27, // 28: provisionerd.CompletedJob.TemplateImport.rich_parameters:type_name -> provisioner.RichParameter
|
||||
26, // 29: provisionerd.CompletedJob.TemplateDryRun.resources:type_name -> provisioner.Resource
|
||||
22, // 13: provisionerd.UpdateJobRequest.template_variables:type_name -> provisioner.TemplateVariable
|
||||
23, // 14: provisionerd.UpdateJobRequest.user_variable_values:type_name -> provisioner.VariableValue
|
||||
23, // 15: provisionerd.UpdateJobResponse.variable_values:type_name -> provisioner.VariableValue
|
||||
24, // 16: provisionerd.AcquiredJob.WorkspaceBuild.rich_parameter_values:type_name -> provisioner.RichParameterValue
|
||||
23, // 17: provisionerd.AcquiredJob.WorkspaceBuild.variable_values:type_name -> provisioner.VariableValue
|
||||
25, // 18: provisionerd.AcquiredJob.WorkspaceBuild.git_auth_providers:type_name -> provisioner.GitAuthProvider
|
||||
26, // 19: provisionerd.AcquiredJob.WorkspaceBuild.metadata:type_name -> provisioner.Metadata
|
||||
26, // 20: provisionerd.AcquiredJob.TemplateImport.metadata:type_name -> provisioner.Metadata
|
||||
23, // 21: provisionerd.AcquiredJob.TemplateImport.user_variable_values:type_name -> provisioner.VariableValue
|
||||
24, // 22: provisionerd.AcquiredJob.TemplateDryRun.rich_parameter_values:type_name -> provisioner.RichParameterValue
|
||||
23, // 23: provisionerd.AcquiredJob.TemplateDryRun.variable_values:type_name -> provisioner.VariableValue
|
||||
26, // 24: provisionerd.AcquiredJob.TemplateDryRun.metadata:type_name -> provisioner.Metadata
|
||||
27, // 25: provisionerd.CompletedJob.WorkspaceBuild.resources:type_name -> provisioner.Resource
|
||||
27, // 26: provisionerd.CompletedJob.TemplateImport.start_resources:type_name -> provisioner.Resource
|
||||
27, // 27: provisionerd.CompletedJob.TemplateImport.stop_resources:type_name -> provisioner.Resource
|
||||
28, // 28: provisionerd.CompletedJob.TemplateImport.rich_parameters:type_name -> provisioner.RichParameter
|
||||
27, // 29: provisionerd.CompletedJob.TemplateDryRun.resources:type_name -> provisioner.Resource
|
||||
1, // 30: provisionerd.ProvisionerDaemon.AcquireJob:input_type -> provisionerd.Empty
|
||||
8, // 31: provisionerd.ProvisionerDaemon.CommitQuota:input_type -> provisionerd.CommitQuotaRequest
|
||||
6, // 32: provisionerd.ProvisionerDaemon.UpdateJob:input_type -> provisionerd.UpdateJobRequest
|
||||
3, // 33: provisionerd.ProvisionerDaemon.FailJob:input_type -> provisionerd.FailedJob
|
||||
4, // 34: provisionerd.ProvisionerDaemon.CompleteJob:input_type -> provisionerd.CompletedJob
|
||||
2, // 35: provisionerd.ProvisionerDaemon.AcquireJob:output_type -> provisionerd.AcquiredJob
|
||||
9, // 36: provisionerd.ProvisionerDaemon.CommitQuota:output_type -> provisionerd.CommitQuotaResponse
|
||||
7, // 37: provisionerd.ProvisionerDaemon.UpdateJob:output_type -> provisionerd.UpdateJobResponse
|
||||
1, // 38: provisionerd.ProvisionerDaemon.FailJob:output_type -> provisionerd.Empty
|
||||
1, // 39: provisionerd.ProvisionerDaemon.CompleteJob:output_type -> provisionerd.Empty
|
||||
35, // [35:40] is the sub-list for method output_type
|
||||
30, // [30:35] is the sub-list for method input_type
|
||||
10, // 31: provisionerd.ProvisionerDaemon.AcquireJobWithCancel:input_type -> provisionerd.CancelAcquire
|
||||
8, // 32: provisionerd.ProvisionerDaemon.CommitQuota:input_type -> provisionerd.CommitQuotaRequest
|
||||
6, // 33: provisionerd.ProvisionerDaemon.UpdateJob:input_type -> provisionerd.UpdateJobRequest
|
||||
3, // 34: provisionerd.ProvisionerDaemon.FailJob:input_type -> provisionerd.FailedJob
|
||||
4, // 35: provisionerd.ProvisionerDaemon.CompleteJob:input_type -> provisionerd.CompletedJob
|
||||
2, // 36: provisionerd.ProvisionerDaemon.AcquireJob:output_type -> provisionerd.AcquiredJob
|
||||
2, // 37: provisionerd.ProvisionerDaemon.AcquireJobWithCancel:output_type -> provisionerd.AcquiredJob
|
||||
9, // 38: provisionerd.ProvisionerDaemon.CommitQuota:output_type -> provisionerd.CommitQuotaResponse
|
||||
7, // 39: provisionerd.ProvisionerDaemon.UpdateJob:output_type -> provisionerd.UpdateJobResponse
|
||||
1, // 40: provisionerd.ProvisionerDaemon.FailJob:output_type -> provisionerd.Empty
|
||||
1, // 41: provisionerd.ProvisionerDaemon.CompleteJob:output_type -> provisionerd.Empty
|
||||
36, // [36:42] is the sub-list for method output_type
|
||||
30, // [30:36] is the sub-list for method input_type
|
||||
30, // [30:30] is the sub-list for extension type_name
|
||||
30, // [30:30] is the sub-list for extension extendee
|
||||
0, // [0:30] is the sub-list for field type_name
|
||||
@@ -1783,7 +1831,7 @@ func file_provisionerd_proto_provisionerd_proto_init() {
|
||||
}
|
||||
}
|
||||
file_provisionerd_proto_provisionerd_proto_msgTypes[9].Exporter = func(v interface{}, i int) interface{} {
|
||||
switch v := v.(*AcquiredJob_WorkspaceBuild); i {
|
||||
switch v := v.(*CancelAcquire); i {
|
||||
case 0:
|
||||
return &v.state
|
||||
case 1:
|
||||
@@ -1795,7 +1843,7 @@ func file_provisionerd_proto_provisionerd_proto_init() {
|
||||
}
|
||||
}
|
||||
file_provisionerd_proto_provisionerd_proto_msgTypes[10].Exporter = func(v interface{}, i int) interface{} {
|
||||
switch v := v.(*AcquiredJob_TemplateImport); i {
|
||||
switch v := v.(*AcquiredJob_WorkspaceBuild); i {
|
||||
case 0:
|
||||
return &v.state
|
||||
case 1:
|
||||
@@ -1807,6 +1855,18 @@ func file_provisionerd_proto_provisionerd_proto_init() {
|
||||
}
|
||||
}
|
||||
file_provisionerd_proto_provisionerd_proto_msgTypes[11].Exporter = func(v interface{}, i int) interface{} {
|
||||
switch v := v.(*AcquiredJob_TemplateImport); i {
|
||||
case 0:
|
||||
return &v.state
|
||||
case 1:
|
||||
return &v.sizeCache
|
||||
case 2:
|
||||
return &v.unknownFields
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
}
|
||||
file_provisionerd_proto_provisionerd_proto_msgTypes[12].Exporter = func(v interface{}, i int) interface{} {
|
||||
switch v := v.(*AcquiredJob_TemplateDryRun); i {
|
||||
case 0:
|
||||
return &v.state
|
||||
@@ -1818,7 +1878,7 @@ func file_provisionerd_proto_provisionerd_proto_init() {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
file_provisionerd_proto_provisionerd_proto_msgTypes[13].Exporter = func(v interface{}, i int) interface{} {
|
||||
file_provisionerd_proto_provisionerd_proto_msgTypes[14].Exporter = func(v interface{}, i int) interface{} {
|
||||
switch v := v.(*FailedJob_WorkspaceBuild); i {
|
||||
case 0:
|
||||
return &v.state
|
||||
@@ -1830,7 +1890,7 @@ func file_provisionerd_proto_provisionerd_proto_init() {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
file_provisionerd_proto_provisionerd_proto_msgTypes[14].Exporter = func(v interface{}, i int) interface{} {
|
||||
file_provisionerd_proto_provisionerd_proto_msgTypes[15].Exporter = func(v interface{}, i int) interface{} {
|
||||
switch v := v.(*FailedJob_TemplateImport); i {
|
||||
case 0:
|
||||
return &v.state
|
||||
@@ -1842,7 +1902,7 @@ func file_provisionerd_proto_provisionerd_proto_init() {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
file_provisionerd_proto_provisionerd_proto_msgTypes[15].Exporter = func(v interface{}, i int) interface{} {
|
||||
file_provisionerd_proto_provisionerd_proto_msgTypes[16].Exporter = func(v interface{}, i int) interface{} {
|
||||
switch v := v.(*FailedJob_TemplateDryRun); i {
|
||||
case 0:
|
||||
return &v.state
|
||||
@@ -1854,7 +1914,7 @@ func file_provisionerd_proto_provisionerd_proto_init() {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
file_provisionerd_proto_provisionerd_proto_msgTypes[16].Exporter = func(v interface{}, i int) interface{} {
|
||||
file_provisionerd_proto_provisionerd_proto_msgTypes[17].Exporter = func(v interface{}, i int) interface{} {
|
||||
switch v := v.(*CompletedJob_WorkspaceBuild); i {
|
||||
case 0:
|
||||
return &v.state
|
||||
@@ -1866,7 +1926,7 @@ func file_provisionerd_proto_provisionerd_proto_init() {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
file_provisionerd_proto_provisionerd_proto_msgTypes[17].Exporter = func(v interface{}, i int) interface{} {
|
||||
file_provisionerd_proto_provisionerd_proto_msgTypes[18].Exporter = func(v interface{}, i int) interface{} {
|
||||
switch v := v.(*CompletedJob_TemplateImport); i {
|
||||
case 0:
|
||||
return &v.state
|
||||
@@ -1878,7 +1938,7 @@ func file_provisionerd_proto_provisionerd_proto_init() {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
file_provisionerd_proto_provisionerd_proto_msgTypes[18].Exporter = func(v interface{}, i int) interface{} {
|
||||
file_provisionerd_proto_provisionerd_proto_msgTypes[19].Exporter = func(v interface{}, i int) interface{} {
|
||||
switch v := v.(*CompletedJob_TemplateDryRun); i {
|
||||
case 0:
|
||||
return &v.state
|
||||
@@ -1912,7 +1972,7 @@ func file_provisionerd_proto_provisionerd_proto_init() {
|
||||
GoPackagePath: reflect.TypeOf(x{}).PkgPath(),
|
||||
RawDescriptor: file_provisionerd_proto_provisionerd_proto_rawDesc,
|
||||
NumEnums: 1,
|
||||
NumMessages: 19,
|
||||
NumMessages: 20,
|
||||
NumExtensions: 0,
|
||||
NumServices: 1,
|
||||
},
|
||||
|
||||
@@ -135,11 +135,22 @@ message CommitQuotaResponse {
|
||||
int32 budget = 3;
|
||||
}
|
||||
|
||||
message CancelAcquire {}
|
||||
|
||||
service ProvisionerDaemon {
|
||||
// AcquireJob requests a job. Implementations should
|
||||
// hold a lock on the job until CompleteJob() is
|
||||
// called with the matching ID.
|
||||
rpc AcquireJob(Empty) returns (AcquiredJob);
|
||||
rpc AcquireJob(Empty) returns (AcquiredJob) {
|
||||
option deprecated = true;
|
||||
};
|
||||
// AcquireJobWithCancel requests a job, blocking until
|
||||
// a job is available or the client sends CancelAcquire.
|
||||
// Server will send exactly one AcquiredJob, which is
|
||||
// empty if a cancel was successful. This RPC is a bidirectional
|
||||
// stream since both messages are asynchronous with no implied
|
||||
// ordering.
|
||||
rpc AcquireJobWithCancel(stream CancelAcquire) returns (stream AcquiredJob);
|
||||
|
||||
rpc CommitQuota(CommitQuotaRequest) returns (CommitQuotaResponse);
|
||||
|
||||
|
||||
+83
-4
@@ -39,6 +39,7 @@ type DRPCProvisionerDaemonClient interface {
|
||||
DRPCConn() drpc.Conn
|
||||
|
||||
AcquireJob(ctx context.Context, in *Empty) (*AcquiredJob, error)
|
||||
AcquireJobWithCancel(ctx context.Context) (DRPCProvisionerDaemon_AcquireJobWithCancelClient, error)
|
||||
CommitQuota(ctx context.Context, in *CommitQuotaRequest) (*CommitQuotaResponse, error)
|
||||
UpdateJob(ctx context.Context, in *UpdateJobRequest) (*UpdateJobResponse, error)
|
||||
FailJob(ctx context.Context, in *FailedJob) (*Empty, error)
|
||||
@@ -64,6 +65,45 @@ func (c *drpcProvisionerDaemonClient) AcquireJob(ctx context.Context, in *Empty)
|
||||
return out, nil
|
||||
}
|
||||
|
||||
func (c *drpcProvisionerDaemonClient) AcquireJobWithCancel(ctx context.Context) (DRPCProvisionerDaemon_AcquireJobWithCancelClient, error) {
|
||||
stream, err := c.cc.NewStream(ctx, "/provisionerd.ProvisionerDaemon/AcquireJobWithCancel", drpcEncoding_File_provisionerd_proto_provisionerd_proto{})
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
x := &drpcProvisionerDaemon_AcquireJobWithCancelClient{stream}
|
||||
return x, nil
|
||||
}
|
||||
|
||||
type DRPCProvisionerDaemon_AcquireJobWithCancelClient interface {
|
||||
drpc.Stream
|
||||
Send(*CancelAcquire) error
|
||||
Recv() (*AcquiredJob, error)
|
||||
}
|
||||
|
||||
type drpcProvisionerDaemon_AcquireJobWithCancelClient struct {
|
||||
drpc.Stream
|
||||
}
|
||||
|
||||
func (x *drpcProvisionerDaemon_AcquireJobWithCancelClient) GetStream() drpc.Stream {
|
||||
return x.Stream
|
||||
}
|
||||
|
||||
func (x *drpcProvisionerDaemon_AcquireJobWithCancelClient) Send(m *CancelAcquire) error {
|
||||
return x.MsgSend(m, drpcEncoding_File_provisionerd_proto_provisionerd_proto{})
|
||||
}
|
||||
|
||||
func (x *drpcProvisionerDaemon_AcquireJobWithCancelClient) Recv() (*AcquiredJob, error) {
|
||||
m := new(AcquiredJob)
|
||||
if err := x.MsgRecv(m, drpcEncoding_File_provisionerd_proto_provisionerd_proto{}); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return m, nil
|
||||
}
|
||||
|
||||
func (x *drpcProvisionerDaemon_AcquireJobWithCancelClient) RecvMsg(m *AcquiredJob) error {
|
||||
return x.MsgRecv(m, drpcEncoding_File_provisionerd_proto_provisionerd_proto{})
|
||||
}
|
||||
|
||||
func (c *drpcProvisionerDaemonClient) CommitQuota(ctx context.Context, in *CommitQuotaRequest) (*CommitQuotaResponse, error) {
|
||||
out := new(CommitQuotaResponse)
|
||||
err := c.cc.Invoke(ctx, "/provisionerd.ProvisionerDaemon/CommitQuota", drpcEncoding_File_provisionerd_proto_provisionerd_proto{}, in, out)
|
||||
@@ -102,6 +142,7 @@ func (c *drpcProvisionerDaemonClient) CompleteJob(ctx context.Context, in *Compl
|
||||
|
||||
type DRPCProvisionerDaemonServer interface {
|
||||
AcquireJob(context.Context, *Empty) (*AcquiredJob, error)
|
||||
AcquireJobWithCancel(DRPCProvisionerDaemon_AcquireJobWithCancelStream) error
|
||||
CommitQuota(context.Context, *CommitQuotaRequest) (*CommitQuotaResponse, error)
|
||||
UpdateJob(context.Context, *UpdateJobRequest) (*UpdateJobResponse, error)
|
||||
FailJob(context.Context, *FailedJob) (*Empty, error)
|
||||
@@ -114,6 +155,10 @@ func (s *DRPCProvisionerDaemonUnimplementedServer) AcquireJob(context.Context, *
|
||||
return nil, drpcerr.WithCode(errors.New("Unimplemented"), drpcerr.Unimplemented)
|
||||
}
|
||||
|
||||
func (s *DRPCProvisionerDaemonUnimplementedServer) AcquireJobWithCancel(DRPCProvisionerDaemon_AcquireJobWithCancelStream) error {
|
||||
return drpcerr.WithCode(errors.New("Unimplemented"), drpcerr.Unimplemented)
|
||||
}
|
||||
|
||||
func (s *DRPCProvisionerDaemonUnimplementedServer) CommitQuota(context.Context, *CommitQuotaRequest) (*CommitQuotaResponse, error) {
|
||||
return nil, drpcerr.WithCode(errors.New("Unimplemented"), drpcerr.Unimplemented)
|
||||
}
|
||||
@@ -132,7 +177,7 @@ func (s *DRPCProvisionerDaemonUnimplementedServer) CompleteJob(context.Context,
|
||||
|
||||
type DRPCProvisionerDaemonDescription struct{}
|
||||
|
||||
func (DRPCProvisionerDaemonDescription) NumMethods() int { return 5 }
|
||||
func (DRPCProvisionerDaemonDescription) NumMethods() int { return 6 }
|
||||
|
||||
func (DRPCProvisionerDaemonDescription) Method(n int) (string, drpc.Encoding, drpc.Receiver, interface{}, bool) {
|
||||
switch n {
|
||||
@@ -146,6 +191,14 @@ func (DRPCProvisionerDaemonDescription) Method(n int) (string, drpc.Encoding, dr
|
||||
)
|
||||
}, DRPCProvisionerDaemonServer.AcquireJob, true
|
||||
case 1:
|
||||
return "/provisionerd.ProvisionerDaemon/AcquireJobWithCancel", drpcEncoding_File_provisionerd_proto_provisionerd_proto{},
|
||||
func(srv interface{}, ctx context.Context, in1, in2 interface{}) (drpc.Message, error) {
|
||||
return nil, srv.(DRPCProvisionerDaemonServer).
|
||||
AcquireJobWithCancel(
|
||||
&drpcProvisionerDaemon_AcquireJobWithCancelStream{in1.(drpc.Stream)},
|
||||
)
|
||||
}, DRPCProvisionerDaemonServer.AcquireJobWithCancel, true
|
||||
case 2:
|
||||
return "/provisionerd.ProvisionerDaemon/CommitQuota", drpcEncoding_File_provisionerd_proto_provisionerd_proto{},
|
||||
func(srv interface{}, ctx context.Context, in1, in2 interface{}) (drpc.Message, error) {
|
||||
return srv.(DRPCProvisionerDaemonServer).
|
||||
@@ -154,7 +207,7 @@ func (DRPCProvisionerDaemonDescription) Method(n int) (string, drpc.Encoding, dr
|
||||
in1.(*CommitQuotaRequest),
|
||||
)
|
||||
}, DRPCProvisionerDaemonServer.CommitQuota, true
|
||||
case 2:
|
||||
case 3:
|
||||
return "/provisionerd.ProvisionerDaemon/UpdateJob", drpcEncoding_File_provisionerd_proto_provisionerd_proto{},
|
||||
func(srv interface{}, ctx context.Context, in1, in2 interface{}) (drpc.Message, error) {
|
||||
return srv.(DRPCProvisionerDaemonServer).
|
||||
@@ -163,7 +216,7 @@ func (DRPCProvisionerDaemonDescription) Method(n int) (string, drpc.Encoding, dr
|
||||
in1.(*UpdateJobRequest),
|
||||
)
|
||||
}, DRPCProvisionerDaemonServer.UpdateJob, true
|
||||
case 3:
|
||||
case 4:
|
||||
return "/provisionerd.ProvisionerDaemon/FailJob", drpcEncoding_File_provisionerd_proto_provisionerd_proto{},
|
||||
func(srv interface{}, ctx context.Context, in1, in2 interface{}) (drpc.Message, error) {
|
||||
return srv.(DRPCProvisionerDaemonServer).
|
||||
@@ -172,7 +225,7 @@ func (DRPCProvisionerDaemonDescription) Method(n int) (string, drpc.Encoding, dr
|
||||
in1.(*FailedJob),
|
||||
)
|
||||
}, DRPCProvisionerDaemonServer.FailJob, true
|
||||
case 4:
|
||||
case 5:
|
||||
return "/provisionerd.ProvisionerDaemon/CompleteJob", drpcEncoding_File_provisionerd_proto_provisionerd_proto{},
|
||||
func(srv interface{}, ctx context.Context, in1, in2 interface{}) (drpc.Message, error) {
|
||||
return srv.(DRPCProvisionerDaemonServer).
|
||||
@@ -206,6 +259,32 @@ func (x *drpcProvisionerDaemon_AcquireJobStream) SendAndClose(m *AcquiredJob) er
|
||||
return x.CloseSend()
|
||||
}
|
||||
|
||||
type DRPCProvisionerDaemon_AcquireJobWithCancelStream interface {
|
||||
drpc.Stream
|
||||
Send(*AcquiredJob) error
|
||||
Recv() (*CancelAcquire, error)
|
||||
}
|
||||
|
||||
type drpcProvisionerDaemon_AcquireJobWithCancelStream struct {
|
||||
drpc.Stream
|
||||
}
|
||||
|
||||
func (x *drpcProvisionerDaemon_AcquireJobWithCancelStream) Send(m *AcquiredJob) error {
|
||||
return x.MsgSend(m, drpcEncoding_File_provisionerd_proto_provisionerd_proto{})
|
||||
}
|
||||
|
||||
func (x *drpcProvisionerDaemon_AcquireJobWithCancelStream) Recv() (*CancelAcquire, error) {
|
||||
m := new(CancelAcquire)
|
||||
if err := x.MsgRecv(m, drpcEncoding_File_provisionerd_proto_provisionerd_proto{}); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
return m, nil
|
||||
}
|
||||
|
||||
func (x *drpcProvisionerDaemon_AcquireJobWithCancelStream) RecvMsg(m *CancelAcquire) error {
|
||||
return x.MsgRecv(m, drpcEncoding_File_provisionerd_proto_provisionerd_proto{})
|
||||
}
|
||||
|
||||
type DRPCProvisionerDaemon_CommitQuotaStream interface {
|
||||
drpc.Stream
|
||||
SendAndClose(*CommitQuotaResponse) error
|
||||
|
||||
+155
-188
@@ -16,13 +16,10 @@ import (
|
||||
"go.opentelemetry.io/otel/attribute"
|
||||
semconv "go.opentelemetry.io/otel/semconv/v1.14.0"
|
||||
"go.opentelemetry.io/otel/trace"
|
||||
"go.uber.org/atomic"
|
||||
"golang.org/x/xerrors"
|
||||
|
||||
"cdr.dev/slog"
|
||||
"github.com/coder/coder/v2/coderd/tracing"
|
||||
"github.com/coder/coder/v2/coderd/util/ptr"
|
||||
"github.com/coder/coder/v2/cryptorand"
|
||||
"github.com/coder/coder/v2/provisionerd/proto"
|
||||
"github.com/coder/coder/v2/provisionerd/runner"
|
||||
sdkproto "github.com/coder/coder/v2/provisionersdk/proto"
|
||||
@@ -60,9 +57,6 @@ type Options struct {
|
||||
ForceCancelInterval time.Duration
|
||||
UpdateInterval time.Duration
|
||||
LogBufferInterval time.Duration
|
||||
JobPollInterval time.Duration
|
||||
JobPollJitter time.Duration
|
||||
JobPollDebounce time.Duration
|
||||
Connector Connector
|
||||
}
|
||||
|
||||
@@ -71,12 +65,6 @@ func New(clientDialer Dialer, opts *Options) *Server {
|
||||
if opts == nil {
|
||||
opts = &Options{}
|
||||
}
|
||||
if opts.JobPollInterval == 0 {
|
||||
opts.JobPollInterval = 5 * time.Second
|
||||
}
|
||||
if opts.JobPollJitter == 0 {
|
||||
opts.JobPollJitter = time.Second
|
||||
}
|
||||
if opts.UpdateInterval == 0 {
|
||||
opts.UpdateInterval = 5 * time.Second
|
||||
}
|
||||
@@ -101,14 +89,18 @@ func New(clientDialer Dialer, opts *Options) *Server {
|
||||
tracer: opts.TracerProvider.Tracer(tracing.TracerName),
|
||||
|
||||
clientDialer: clientDialer,
|
||||
clientCh: make(chan proto.DRPCProvisionerDaemonClient),
|
||||
|
||||
closeContext: ctx,
|
||||
closeCancel: ctxCancel,
|
||||
|
||||
shutdown: make(chan struct{}),
|
||||
closeContext: ctx,
|
||||
closeCancel: ctxCancel,
|
||||
closedCh: make(chan struct{}),
|
||||
shuttingDownCh: make(chan struct{}),
|
||||
acquireDoneCh: make(chan struct{}),
|
||||
}
|
||||
|
||||
go daemon.connect(ctx)
|
||||
daemon.wg.Add(2)
|
||||
go daemon.connect()
|
||||
go daemon.acquireLoop()
|
||||
return daemon
|
||||
}
|
||||
|
||||
@@ -117,15 +109,28 @@ type Server struct {
|
||||
tracer trace.Tracer
|
||||
|
||||
clientDialer Dialer
|
||||
clientValue atomic.Pointer[proto.DRPCProvisionerDaemonClient]
|
||||
clientCh chan proto.DRPCProvisionerDaemonClient
|
||||
|
||||
// Locked when closing the daemon, shutting down, or starting a new job.
|
||||
mutex sync.Mutex
|
||||
wg sync.WaitGroup
|
||||
|
||||
// mutex protects all subsequent fields
|
||||
mutex sync.Mutex
|
||||
// closeContext is canceled when we start closing.
|
||||
closeContext context.Context
|
||||
closeCancel context.CancelFunc
|
||||
closeError error
|
||||
shutdown chan struct{}
|
||||
activeJob *runner.Runner
|
||||
// closeError stores the error when closing to return to subsequent callers
|
||||
closeError error
|
||||
// closingB is set to true when we start closing
|
||||
closingB bool
|
||||
// closedCh will receive when we complete closing
|
||||
closedCh chan struct{}
|
||||
// shuttingDownB is set to true when we start graceful shutdown
|
||||
shuttingDownB bool
|
||||
// shuttingDownCh will receive when we start graceful shutdown
|
||||
shuttingDownCh chan struct{}
|
||||
// acquireDoneCh will receive when the acquireLoop exits
|
||||
acquireDoneCh chan struct{}
|
||||
activeJob *runner.Runner
|
||||
}
|
||||
|
||||
type Metrics struct {
|
||||
@@ -176,16 +181,20 @@ func NewMetrics(reg prometheus.Registerer) Metrics {
|
||||
}
|
||||
|
||||
// Connect establishes a connection to coderd.
|
||||
func (p *Server) connect(ctx context.Context) {
|
||||
func (p *Server) connect() {
|
||||
defer p.opts.Logger.Debug(p.closeContext, "connect loop exited")
|
||||
defer p.wg.Done()
|
||||
// An exponential back-off occurs when the connection is failing to dial.
|
||||
// This is to prevent server spam in case of a coderd outage.
|
||||
for retrier := retry.New(50*time.Millisecond, 10*time.Second); retrier.Wait(ctx); {
|
||||
connectLoop:
|
||||
for retrier := retry.New(50*time.Millisecond, 10*time.Second); retrier.Wait(p.closeContext); {
|
||||
// It's possible for the provisioner daemon to be shut down
|
||||
// before the wait is complete!
|
||||
if p.isClosed() {
|
||||
return
|
||||
}
|
||||
client, err := p.clientDialer(ctx)
|
||||
p.opts.Logger.Debug(p.closeContext, "dialing coderd")
|
||||
client, err := p.clientDialer(p.closeContext)
|
||||
if err != nil {
|
||||
if errors.Is(err, context.Canceled) {
|
||||
return
|
||||
@@ -193,144 +202,75 @@ func (p *Server) connect(ctx context.Context) {
|
||||
if p.isClosed() {
|
||||
return
|
||||
}
|
||||
p.opts.Logger.Warn(context.Background(), "coderd client failed to dial", slog.Error(err))
|
||||
p.opts.Logger.Warn(p.closeContext, "coderd client failed to dial", slog.Error(err))
|
||||
continue
|
||||
}
|
||||
// Ensure connection is not left hanging during a race between
|
||||
// close and dial succeeding.
|
||||
p.mutex.Lock()
|
||||
if p.isClosed() {
|
||||
client.DRPCConn().Close()
|
||||
p.mutex.Unlock()
|
||||
break
|
||||
p.opts.Logger.Info(p.closeContext, "successfully connected to coderd")
|
||||
retrier.Reset()
|
||||
|
||||
// serve the client until we are closed or it disconnects
|
||||
for {
|
||||
select {
|
||||
case <-p.closeContext.Done():
|
||||
client.DRPCConn().Close()
|
||||
return
|
||||
case <-client.DRPCConn().Closed():
|
||||
p.opts.Logger.Info(p.closeContext, "connection to coderd closed")
|
||||
continue connectLoop
|
||||
case p.clientCh <- client:
|
||||
continue
|
||||
}
|
||||
}
|
||||
p.clientValue.Store(ptr.Ref(client))
|
||||
p.mutex.Unlock()
|
||||
|
||||
p.opts.Logger.Debug(ctx, "successfully connected to coderd")
|
||||
break
|
||||
}
|
||||
}
|
||||
|
||||
func (p *Server) client() (proto.DRPCProvisionerDaemonClient, bool) {
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
return
|
||||
default:
|
||||
case <-p.closeContext.Done():
|
||||
return nil, false
|
||||
case client := <-p.clientCh:
|
||||
return client, true
|
||||
}
|
||||
}
|
||||
|
||||
go func() {
|
||||
if p.isClosed() {
|
||||
func (p *Server) acquireLoop() {
|
||||
defer p.opts.Logger.Debug(p.closeContext, "acquire loop exited")
|
||||
defer p.wg.Done()
|
||||
defer func() { close(p.acquireDoneCh) }()
|
||||
ctx := p.closeContext
|
||||
for {
|
||||
if p.acquireExit() {
|
||||
return
|
||||
}
|
||||
client, ok := p.client()
|
||||
if !ok {
|
||||
p.opts.Logger.Debug(ctx, "shut down before client (re) connected")
|
||||
return
|
||||
}
|
||||
select {
|
||||
case <-p.closeContext.Done():
|
||||
return
|
||||
case <-client.DRPCConn().Closed():
|
||||
// We use the update stream to detect when the connection
|
||||
// has been interrupted. This works well, because logs need
|
||||
// to buffer if a job is running in the background.
|
||||
p.opts.Logger.Debug(context.Background(), "client stream ended")
|
||||
p.connect(ctx)
|
||||
}
|
||||
}()
|
||||
|
||||
go func() {
|
||||
if p.isClosed() {
|
||||
return
|
||||
}
|
||||
timer := time.NewTimer(p.opts.JobPollInterval)
|
||||
defer timer.Stop()
|
||||
for {
|
||||
client, ok := p.client()
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
select {
|
||||
case <-p.closeContext.Done():
|
||||
return
|
||||
case <-client.DRPCConn().Closed():
|
||||
return
|
||||
case <-timer.C:
|
||||
p.acquireJob(ctx)
|
||||
timer.Reset(p.nextInterval())
|
||||
}
|
||||
}
|
||||
}()
|
||||
}
|
||||
|
||||
func (p *Server) nextInterval() time.Duration {
|
||||
r, err := cryptorand.Float64()
|
||||
if err != nil {
|
||||
panic("get random float:" + err.Error())
|
||||
}
|
||||
|
||||
return p.opts.JobPollInterval + time.Duration(float64(p.opts.JobPollJitter)*r)
|
||||
}
|
||||
|
||||
func (p *Server) client() (proto.DRPCProvisionerDaemonClient, bool) {
|
||||
client := p.clientValue.Load()
|
||||
if client == nil {
|
||||
return nil, false
|
||||
}
|
||||
return *client, true
|
||||
}
|
||||
|
||||
// isRunningJob returns true if a job is running. Caller must hold the mutex.
|
||||
func (p *Server) isRunningJob() bool {
|
||||
if p.activeJob == nil {
|
||||
return false
|
||||
}
|
||||
select {
|
||||
case <-p.activeJob.Done():
|
||||
return false
|
||||
default:
|
||||
return true
|
||||
p.acquireAndRunOne(client)
|
||||
}
|
||||
}
|
||||
|
||||
var (
|
||||
lastAcquire time.Time
|
||||
lastAcquireMutex sync.RWMutex
|
||||
)
|
||||
|
||||
// Locks a job in the database, and runs it!
|
||||
func (p *Server) acquireJob(ctx context.Context) {
|
||||
// acquireExit returns true if the acquire loop should exit
|
||||
func (p *Server) acquireExit() bool {
|
||||
p.mutex.Lock()
|
||||
defer p.mutex.Unlock()
|
||||
if p.isClosed() {
|
||||
return
|
||||
if p.closingB {
|
||||
p.opts.Logger.Debug(p.closeContext, "exiting acquire; provisionerd is closing")
|
||||
return true
|
||||
}
|
||||
if p.isRunningJob() {
|
||||
return
|
||||
}
|
||||
if p.isShutdown() {
|
||||
p.opts.Logger.Debug(context.Background(), "skipping acquire; provisionerd is shutting down")
|
||||
return
|
||||
if p.shuttingDownB {
|
||||
p.opts.Logger.Debug(p.closeContext, "exiting acquire; provisionerd is shutting down")
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
// This prevents loads of provisioner daemons from consistently sending
|
||||
// requests when no jobs are available.
|
||||
//
|
||||
// The debounce only occurs when no job is returned, so if loads of jobs are
|
||||
// added at once, they will start after at most this duration.
|
||||
lastAcquireMutex.RLock()
|
||||
if !lastAcquire.IsZero() && time.Since(lastAcquire) < p.opts.JobPollDebounce {
|
||||
lastAcquireMutex.RUnlock()
|
||||
p.opts.Logger.Debug(ctx, "debounce acquire job")
|
||||
return
|
||||
}
|
||||
lastAcquireMutex.RUnlock()
|
||||
|
||||
var err error
|
||||
client, ok := p.client()
|
||||
if !ok {
|
||||
return
|
||||
}
|
||||
|
||||
job, err := client.AcquireJob(ctx, &proto.Empty{})
|
||||
p.opts.Logger.Debug(ctx, "called AcquireJob on client", slog.F("job_id", job.GetJobId()), slog.Error(err))
|
||||
func (p *Server) acquireAndRunOne(client proto.DRPCProvisionerDaemonClient) {
|
||||
ctx := p.closeContext
|
||||
p.opts.Logger.Debug(ctx, "start of acquireAndRunOne")
|
||||
job, err := p.acquireGraceful(client)
|
||||
p.opts.Logger.Debug(ctx, "graceful acquire done", slog.F("job_id", job.GetJobId()), slog.Error(err))
|
||||
if err != nil {
|
||||
if errors.Is(err, context.Canceled) ||
|
||||
errors.Is(err, yamux.ErrSessionShutdown) ||
|
||||
@@ -342,9 +282,7 @@ func (p *Server) acquireJob(ctx context.Context) {
|
||||
return
|
||||
}
|
||||
if job.JobId == "" {
|
||||
lastAcquireMutex.Lock()
|
||||
lastAcquire = time.Now()
|
||||
lastAcquireMutex.Unlock()
|
||||
p.opts.Logger.Debug(ctx, "acquire job successfully canceled")
|
||||
return
|
||||
}
|
||||
|
||||
@@ -405,6 +343,7 @@ func (p *Server) acquireJob(ctx context.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
p.mutex.Lock()
|
||||
p.activeJob = runner.New(
|
||||
ctx,
|
||||
job,
|
||||
@@ -420,8 +359,39 @@ func (p *Server) acquireJob(ctx context.Context) {
|
||||
Metrics: p.opts.Metrics.Runner,
|
||||
},
|
||||
)
|
||||
p.mutex.Unlock()
|
||||
p.activeJob.Run()
|
||||
p.mutex.Lock()
|
||||
p.activeJob = nil
|
||||
p.mutex.Unlock()
|
||||
}
|
||||
|
||||
go p.activeJob.Run()
|
||||
// acquireGraceful attempts to acquire a job from the server, handling canceling the acquisition if we gracefully shut
|
||||
// down.
|
||||
func (p *Server) acquireGraceful(client proto.DRPCProvisionerDaemonClient) (*proto.AcquiredJob, error) {
|
||||
stream, err := client.AcquireJobWithCancel(p.closeContext)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
acquireDone := make(chan struct{})
|
||||
go func() {
|
||||
select {
|
||||
case <-p.closeContext.Done():
|
||||
return
|
||||
case <-p.shuttingDownCh:
|
||||
p.opts.Logger.Debug(p.closeContext, "sending acquire job cancel")
|
||||
err := stream.Send(&proto.CancelAcquire{})
|
||||
if err != nil {
|
||||
p.opts.Logger.Warn(p.closeContext, "failed to gracefully cancel acquire job")
|
||||
}
|
||||
return
|
||||
case <-acquireDone:
|
||||
return
|
||||
}
|
||||
}()
|
||||
job, err := stream.Recv()
|
||||
close(acquireDone)
|
||||
return job, err
|
||||
}
|
||||
|
||||
func retryable(err error) bool {
|
||||
@@ -496,36 +466,23 @@ func (p *Server) isClosed() bool {
|
||||
}
|
||||
}
|
||||
|
||||
// isShutdown returns whether the API is shutdown or not.
|
||||
func (p *Server) isShutdown() bool {
|
||||
select {
|
||||
case <-p.shutdown:
|
||||
return true
|
||||
default:
|
||||
return false
|
||||
}
|
||||
}
|
||||
|
||||
// Shutdown triggers a graceful exit of each registered provisioner.
|
||||
// It exits when an active job stops.
|
||||
func (p *Server) Shutdown(ctx context.Context) error {
|
||||
p.mutex.Lock()
|
||||
defer p.mutex.Unlock()
|
||||
if !p.isRunningJob() {
|
||||
return nil
|
||||
}
|
||||
p.opts.Logger.Info(ctx, "attempting graceful shutdown")
|
||||
close(p.shutdown)
|
||||
if p.activeJob == nil {
|
||||
return nil
|
||||
if !p.shuttingDownB {
|
||||
close(p.shuttingDownCh)
|
||||
p.shuttingDownB = true
|
||||
}
|
||||
// wait for active job
|
||||
p.activeJob.Cancel()
|
||||
if p.activeJob != nil {
|
||||
p.activeJob.Cancel()
|
||||
}
|
||||
p.mutex.Unlock()
|
||||
select {
|
||||
case <-ctx.Done():
|
||||
p.opts.Logger.Warn(ctx, "graceful shutdown failed", slog.Error(ctx.Err()))
|
||||
return ctx.Err()
|
||||
case <-p.activeJob.Done():
|
||||
case <-p.acquireDoneCh:
|
||||
p.opts.Logger.Info(ctx, "gracefully shutdown")
|
||||
return nil
|
||||
}
|
||||
@@ -533,41 +490,51 @@ func (p *Server) Shutdown(ctx context.Context) error {
|
||||
|
||||
// Close ends the provisioner. It will mark any running jobs as failed.
|
||||
func (p *Server) Close() error {
|
||||
p.opts.Logger.Info(p.closeContext, "closing provisionerd")
|
||||
return p.closeWithError(nil)
|
||||
}
|
||||
|
||||
// closeWithError closes the provisioner; subsequent reads/writes will return the error err.
|
||||
func (p *Server) closeWithError(err error) error {
|
||||
p.mutex.Lock()
|
||||
defer p.mutex.Unlock()
|
||||
if p.isClosed() {
|
||||
return p.closeError
|
||||
var activeJob *runner.Runner
|
||||
first := false
|
||||
if !p.closingB {
|
||||
first = true
|
||||
p.closingB = true
|
||||
// only the first caller to close should attempt to fail the active job
|
||||
activeJob = p.activeJob
|
||||
}
|
||||
p.closeError = err
|
||||
|
||||
errMsg := "provisioner daemon was shutdown gracefully"
|
||||
if err != nil {
|
||||
errMsg = err.Error()
|
||||
}
|
||||
if p.activeJob != nil {
|
||||
// don't hold the mutex while doing I/O.
|
||||
p.mutex.Unlock()
|
||||
if activeJob != nil {
|
||||
errMsg := "provisioner daemon was shutdown gracefully"
|
||||
if err != nil {
|
||||
errMsg = err.Error()
|
||||
}
|
||||
p.opts.Logger.Debug(p.closeContext, "failing active job because of close")
|
||||
ctx, cancel := context.WithTimeout(context.Background(), time.Second)
|
||||
defer cancel()
|
||||
failErr := p.activeJob.Fail(ctx, &proto.FailedJob{Error: errMsg})
|
||||
failErr := activeJob.Fail(ctx, &proto.FailedJob{Error: errMsg})
|
||||
if failErr != nil {
|
||||
p.activeJob.ForceStop()
|
||||
activeJob.ForceStop()
|
||||
}
|
||||
if err == nil {
|
||||
err = failErr
|
||||
}
|
||||
}
|
||||
|
||||
p.closeCancel()
|
||||
|
||||
p.opts.Logger.Debug(context.Background(), "closing server with error", slog.Error(err))
|
||||
|
||||
if c, ok := p.client(); ok {
|
||||
_ = c.DRPCConn().Close()
|
||||
if first {
|
||||
p.closeCancel()
|
||||
p.opts.Logger.Debug(context.Background(), "waiting for goroutines to exit")
|
||||
p.wg.Wait()
|
||||
p.opts.Logger.Debug(context.Background(), "closing server with error", slog.Error(err))
|
||||
p.closeError = err
|
||||
close(p.closedCh)
|
||||
return err
|
||||
}
|
||||
|
||||
return err
|
||||
p.opts.Logger.Debug(p.closeContext, "waiting for first closer to complete")
|
||||
<-p.closedCh
|
||||
p.opts.Logger.Debug(p.closeContext, "first closer completed")
|
||||
return p.closeError
|
||||
}
|
||||
|
||||
+228
-233
@@ -59,7 +59,7 @@ func TestProvisionerd(t *testing.T) {
|
||||
close(done)
|
||||
})
|
||||
closer := createProvisionerd(t, func(ctx context.Context) (proto.DRPCProvisionerDaemonClient, error) {
|
||||
return createProvisionerDaemonClient(ctx, t, done, provisionerDaemonTestServer{}), nil
|
||||
return createProvisionerDaemonClient(t, done, provisionerDaemonTestServer{}), nil
|
||||
}, provisionerd.LocalProvisioners{})
|
||||
require.NoError(t, closer.Close())
|
||||
})
|
||||
@@ -79,33 +79,6 @@ func TestProvisionerd(t *testing.T) {
|
||||
require.NoError(t, closer.Close())
|
||||
})
|
||||
|
||||
t.Run("AcquireEmptyJob", func(t *testing.T) {
|
||||
// The provisioner daemon is supposed to skip the job acquire if
|
||||
// the job provided is empty. This is to show it successfully
|
||||
// tried to get a job, but none were available.
|
||||
t.Parallel()
|
||||
done := make(chan struct{})
|
||||
t.Cleanup(func() {
|
||||
close(done)
|
||||
})
|
||||
completeChan := make(chan struct{})
|
||||
closer := createProvisionerd(t, func(ctx context.Context) (proto.DRPCProvisionerDaemonClient, error) {
|
||||
acquireJobAttempt := 0
|
||||
return createProvisionerDaemonClient(ctx, t, done, provisionerDaemonTestServer{
|
||||
acquireJob: func(ctx context.Context, _ *proto.Empty) (*proto.AcquiredJob, error) {
|
||||
if acquireJobAttempt == 1 {
|
||||
close(completeChan)
|
||||
}
|
||||
acquireJobAttempt++
|
||||
return &proto.AcquiredJob{}, nil
|
||||
},
|
||||
updateJob: noopUpdateJob,
|
||||
}), nil
|
||||
}, provisionerd.LocalProvisioners{})
|
||||
require.Condition(t, closedWithin(completeChan, testutil.WaitShort))
|
||||
require.NoError(t, closer.Close())
|
||||
})
|
||||
|
||||
t.Run("CloseCancelsJob", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
done := make(chan struct{})
|
||||
@@ -118,9 +91,9 @@ func TestProvisionerd(t *testing.T) {
|
||||
var closerMutex sync.Mutex
|
||||
closerMutex.Lock()
|
||||
closer = createProvisionerd(t, func(ctx context.Context) (proto.DRPCProvisionerDaemonClient, error) {
|
||||
return createProvisionerDaemonClient(ctx, t, done, provisionerDaemonTestServer{
|
||||
acquireJob: func(ctx context.Context, _ *proto.Empty) (*proto.AcquiredJob, error) {
|
||||
return &proto.AcquiredJob{
|
||||
return createProvisionerDaemonClient(t, done, provisionerDaemonTestServer{
|
||||
acquireJobWithCancel: func(stream proto.DRPCProvisionerDaemon_AcquireJobWithCancelStream) error {
|
||||
err := stream.Send(&proto.AcquiredJob{
|
||||
JobId: "test",
|
||||
Provisioner: "someprovisioner",
|
||||
TemplateSourceArchive: createTar(t, map[string]string{
|
||||
@@ -131,7 +104,9 @@ func TestProvisionerd(t *testing.T) {
|
||||
Metadata: &sdkproto.Metadata{},
|
||||
},
|
||||
},
|
||||
}, nil
|
||||
})
|
||||
assert.NoError(t, err)
|
||||
return nil
|
||||
},
|
||||
updateJob: noopUpdateJob,
|
||||
failJob: func(ctx context.Context, job *proto.FailedJob) (*proto.Empty, error) {
|
||||
@@ -174,9 +149,9 @@ func TestProvisionerd(t *testing.T) {
|
||||
)
|
||||
|
||||
closer := createProvisionerd(t, func(ctx context.Context) (proto.DRPCProvisionerDaemonClient, error) {
|
||||
return createProvisionerDaemonClient(ctx, t, done, provisionerDaemonTestServer{
|
||||
acquireJob: func(ctx context.Context, _ *proto.Empty) (*proto.AcquiredJob, error) {
|
||||
return &proto.AcquiredJob{
|
||||
return createProvisionerDaemonClient(t, done, provisionerDaemonTestServer{
|
||||
acquireJobWithCancel: func(stream proto.DRPCProvisionerDaemon_AcquireJobWithCancelStream) error {
|
||||
err := stream.Send(&proto.AcquiredJob{
|
||||
JobId: "test",
|
||||
Provisioner: "someprovisioner",
|
||||
TemplateSourceArchive: createTar(t, map[string]string{
|
||||
@@ -187,7 +162,9 @@ func TestProvisionerd(t *testing.T) {
|
||||
Metadata: &sdkproto.Metadata{},
|
||||
},
|
||||
},
|
||||
}, nil
|
||||
})
|
||||
assert.NoError(t, err)
|
||||
return nil
|
||||
},
|
||||
updateJob: noopUpdateJob,
|
||||
failJob: func(ctx context.Context, job *proto.FailedJob) (*proto.Empty, error) {
|
||||
@@ -214,9 +191,9 @@ func TestProvisionerd(t *testing.T) {
|
||||
)
|
||||
|
||||
closer := createProvisionerd(t, func(ctx context.Context) (proto.DRPCProvisionerDaemonClient, error) {
|
||||
return createProvisionerDaemonClient(ctx, t, done, provisionerDaemonTestServer{
|
||||
acquireJob: func(ctx context.Context, _ *proto.Empty) (*proto.AcquiredJob, error) {
|
||||
return &proto.AcquiredJob{
|
||||
return createProvisionerDaemonClient(t, done, provisionerDaemonTestServer{
|
||||
acquireJobWithCancel: func(stream proto.DRPCProvisionerDaemon_AcquireJobWithCancelStream) error {
|
||||
err := stream.Send(&proto.AcquiredJob{
|
||||
JobId: "test",
|
||||
Provisioner: "someprovisioner",
|
||||
TemplateSourceArchive: createTar(t, map[string]string{
|
||||
@@ -227,7 +204,9 @@ func TestProvisionerd(t *testing.T) {
|
||||
Metadata: &sdkproto.Metadata{},
|
||||
},
|
||||
},
|
||||
}, nil
|
||||
})
|
||||
assert.NoError(t, err)
|
||||
return nil
|
||||
},
|
||||
updateJob: func(ctx context.Context, update *proto.UpdateJobRequest) (*proto.UpdateJobResponse, error) {
|
||||
completeOnce.Do(func() { close(completeChan) })
|
||||
@@ -260,36 +239,27 @@ func TestProvisionerd(t *testing.T) {
|
||||
close(done)
|
||||
})
|
||||
var (
|
||||
didComplete atomic.Bool
|
||||
didLog atomic.Bool
|
||||
didAcquireJob atomic.Bool
|
||||
didReadme atomic.Bool
|
||||
completeChan = make(chan struct{})
|
||||
completeOnce sync.Once
|
||||
didComplete atomic.Bool
|
||||
didLog atomic.Bool
|
||||
didReadme atomic.Bool
|
||||
acq = newAcquireOne(t, &proto.AcquiredJob{
|
||||
JobId: "test",
|
||||
Provisioner: "someprovisioner",
|
||||
TemplateSourceArchive: createTar(t, map[string]string{
|
||||
"test.txt": "content",
|
||||
provisionersdk.ReadmeFile: "# A cool template 😎\n",
|
||||
}),
|
||||
Type: &proto.AcquiredJob_TemplateImport_{
|
||||
TemplateImport: &proto.AcquiredJob_TemplateImport{
|
||||
Metadata: &sdkproto.Metadata{},
|
||||
},
|
||||
},
|
||||
})
|
||||
)
|
||||
|
||||
closer := createProvisionerd(t, func(ctx context.Context) (proto.DRPCProvisionerDaemonClient, error) {
|
||||
return createProvisionerDaemonClient(ctx, t, done, provisionerDaemonTestServer{
|
||||
acquireJob: func(ctx context.Context, _ *proto.Empty) (*proto.AcquiredJob, error) {
|
||||
if !didAcquireJob.CAS(false, true) {
|
||||
completeOnce.Do(func() { close(completeChan) })
|
||||
return &proto.AcquiredJob{}, nil
|
||||
}
|
||||
|
||||
return &proto.AcquiredJob{
|
||||
JobId: "test",
|
||||
Provisioner: "someprovisioner",
|
||||
TemplateSourceArchive: createTar(t, map[string]string{
|
||||
"test.txt": "content",
|
||||
provisionersdk.ReadmeFile: "# A cool template 😎\n",
|
||||
}),
|
||||
Type: &proto.AcquiredJob_TemplateImport_{
|
||||
TemplateImport: &proto.AcquiredJob_TemplateImport{
|
||||
Metadata: &sdkproto.Metadata{},
|
||||
},
|
||||
},
|
||||
}, nil
|
||||
},
|
||||
return createProvisionerDaemonClient(t, done, provisionerDaemonTestServer{
|
||||
acquireJobWithCancel: acq.acquireWithCancel,
|
||||
updateJob: func(ctx context.Context, update *proto.UpdateJobRequest) (*proto.UpdateJobResponse, error) {
|
||||
if len(update.Logs) > 0 {
|
||||
didLog.Store(true)
|
||||
@@ -338,7 +308,7 @@ func TestProvisionerd(t *testing.T) {
|
||||
}),
|
||||
})
|
||||
|
||||
require.Condition(t, closedWithin(completeChan, testutil.WaitShort))
|
||||
require.Condition(t, closedWithin(acq.complete, testutil.WaitShort))
|
||||
require.NoError(t, closer.Close())
|
||||
assert.True(t, didLog.Load(), "should log some updates")
|
||||
assert.True(t, didComplete.Load(), "should complete the job")
|
||||
@@ -351,36 +321,26 @@ func TestProvisionerd(t *testing.T) {
|
||||
close(done)
|
||||
})
|
||||
var (
|
||||
didComplete atomic.Bool
|
||||
didLog atomic.Bool
|
||||
didAcquireJob atomic.Bool
|
||||
completeChan = make(chan struct{})
|
||||
completeOnce sync.Once
|
||||
|
||||
metadata = &sdkproto.Metadata{}
|
||||
didComplete atomic.Bool
|
||||
didLog atomic.Bool
|
||||
metadata = &sdkproto.Metadata{}
|
||||
acq = newAcquireOne(t, &proto.AcquiredJob{
|
||||
JobId: "test",
|
||||
Provisioner: "someprovisioner",
|
||||
TemplateSourceArchive: createTar(t, map[string]string{
|
||||
"test.txt": "content",
|
||||
}),
|
||||
Type: &proto.AcquiredJob_TemplateDryRun_{
|
||||
TemplateDryRun: &proto.AcquiredJob_TemplateDryRun{
|
||||
Metadata: metadata,
|
||||
},
|
||||
},
|
||||
})
|
||||
)
|
||||
|
||||
closer := createProvisionerd(t, func(ctx context.Context) (proto.DRPCProvisionerDaemonClient, error) {
|
||||
return createProvisionerDaemonClient(ctx, t, done, provisionerDaemonTestServer{
|
||||
acquireJob: func(ctx context.Context, _ *proto.Empty) (*proto.AcquiredJob, error) {
|
||||
if !didAcquireJob.CAS(false, true) {
|
||||
completeOnce.Do(func() { close(completeChan) })
|
||||
return &proto.AcquiredJob{}, nil
|
||||
}
|
||||
|
||||
return &proto.AcquiredJob{
|
||||
JobId: "test",
|
||||
Provisioner: "someprovisioner",
|
||||
TemplateSourceArchive: createTar(t, map[string]string{
|
||||
"test.txt": "content",
|
||||
}),
|
||||
Type: &proto.AcquiredJob_TemplateDryRun_{
|
||||
TemplateDryRun: &proto.AcquiredJob_TemplateDryRun{
|
||||
Metadata: metadata,
|
||||
},
|
||||
},
|
||||
}, nil
|
||||
},
|
||||
return createProvisionerDaemonClient(t, done, provisionerDaemonTestServer{
|
||||
acquireJobWithCancel: acq.acquireWithCancel,
|
||||
updateJob: func(ctx context.Context, update *proto.UpdateJobRequest) (*proto.UpdateJobResponse, error) {
|
||||
if len(update.Logs) == 0 {
|
||||
t.Log("provisionerDaemonTestServer: no log messages")
|
||||
@@ -420,7 +380,7 @@ func TestProvisionerd(t *testing.T) {
|
||||
}),
|
||||
})
|
||||
|
||||
require.Condition(t, closedWithin(completeChan, testutil.WaitShort))
|
||||
require.Condition(t, closedWithin(acq.complete, testutil.WaitShort))
|
||||
require.NoError(t, closer.Close())
|
||||
assert.True(t, didLog.Load(), "should log some updates")
|
||||
assert.True(t, didComplete.Load(), "should complete the job")
|
||||
@@ -433,34 +393,25 @@ func TestProvisionerd(t *testing.T) {
|
||||
close(done)
|
||||
})
|
||||
var (
|
||||
didComplete atomic.Bool
|
||||
didLog atomic.Bool
|
||||
didAcquireJob atomic.Bool
|
||||
completeChan = make(chan struct{})
|
||||
completeOnce sync.Once
|
||||
didComplete atomic.Bool
|
||||
didLog atomic.Bool
|
||||
acq = newAcquireOne(t, &proto.AcquiredJob{
|
||||
JobId: "test",
|
||||
Provisioner: "someprovisioner",
|
||||
TemplateSourceArchive: createTar(t, map[string]string{
|
||||
"test.txt": "content",
|
||||
}),
|
||||
Type: &proto.AcquiredJob_WorkspaceBuild_{
|
||||
WorkspaceBuild: &proto.AcquiredJob_WorkspaceBuild{
|
||||
Metadata: &sdkproto.Metadata{},
|
||||
},
|
||||
},
|
||||
})
|
||||
)
|
||||
|
||||
closer := createProvisionerd(t, func(ctx context.Context) (proto.DRPCProvisionerDaemonClient, error) {
|
||||
return createProvisionerDaemonClient(ctx, t, done, provisionerDaemonTestServer{
|
||||
acquireJob: func(ctx context.Context, _ *proto.Empty) (*proto.AcquiredJob, error) {
|
||||
if !didAcquireJob.CAS(false, true) {
|
||||
completeOnce.Do(func() { close(completeChan) })
|
||||
return &proto.AcquiredJob{}, nil
|
||||
}
|
||||
|
||||
return &proto.AcquiredJob{
|
||||
JobId: "test",
|
||||
Provisioner: "someprovisioner",
|
||||
TemplateSourceArchive: createTar(t, map[string]string{
|
||||
"test.txt": "content",
|
||||
}),
|
||||
Type: &proto.AcquiredJob_WorkspaceBuild_{
|
||||
WorkspaceBuild: &proto.AcquiredJob_WorkspaceBuild{
|
||||
Metadata: &sdkproto.Metadata{},
|
||||
},
|
||||
},
|
||||
}, nil
|
||||
},
|
||||
return createProvisionerDaemonClient(t, done, provisionerDaemonTestServer{
|
||||
acquireJobWithCancel: acq.acquireWithCancel,
|
||||
updateJob: func(ctx context.Context, update *proto.UpdateJobRequest) (*proto.UpdateJobResponse, error) {
|
||||
if len(update.Logs) != 0 {
|
||||
didLog.Store(true)
|
||||
@@ -491,7 +442,7 @@ func TestProvisionerd(t *testing.T) {
|
||||
},
|
||||
}),
|
||||
})
|
||||
require.Condition(t, closedWithin(completeChan, testutil.WaitShort))
|
||||
require.Condition(t, closedWithin(acq.complete, testutil.WaitShort))
|
||||
require.NoError(t, closer.Close())
|
||||
assert.True(t, didLog.Load(), "should log some updates")
|
||||
assert.True(t, didComplete.Load(), "should complete the job")
|
||||
@@ -504,35 +455,26 @@ func TestProvisionerd(t *testing.T) {
|
||||
close(done)
|
||||
})
|
||||
var (
|
||||
didComplete atomic.Bool
|
||||
didLog atomic.Bool
|
||||
didAcquireJob atomic.Bool
|
||||
didFail atomic.Bool
|
||||
completeChan = make(chan struct{})
|
||||
completeOnce sync.Once
|
||||
didComplete atomic.Bool
|
||||
didLog atomic.Bool
|
||||
didFail atomic.Bool
|
||||
acq = newAcquireOne(t, &proto.AcquiredJob{
|
||||
JobId: "test",
|
||||
Provisioner: "someprovisioner",
|
||||
TemplateSourceArchive: createTar(t, map[string]string{
|
||||
"test.txt": "content",
|
||||
}),
|
||||
Type: &proto.AcquiredJob_WorkspaceBuild_{
|
||||
WorkspaceBuild: &proto.AcquiredJob_WorkspaceBuild{
|
||||
Metadata: &sdkproto.Metadata{},
|
||||
},
|
||||
},
|
||||
})
|
||||
)
|
||||
|
||||
closer := createProvisionerd(t, func(ctx context.Context) (proto.DRPCProvisionerDaemonClient, error) {
|
||||
return createProvisionerDaemonClient(ctx, t, done, provisionerDaemonTestServer{
|
||||
acquireJob: func(ctx context.Context, _ *proto.Empty) (*proto.AcquiredJob, error) {
|
||||
if !didAcquireJob.CAS(false, true) {
|
||||
completeOnce.Do(func() { close(completeChan) })
|
||||
return &proto.AcquiredJob{}, nil
|
||||
}
|
||||
|
||||
return &proto.AcquiredJob{
|
||||
JobId: "test",
|
||||
Provisioner: "someprovisioner",
|
||||
TemplateSourceArchive: createTar(t, map[string]string{
|
||||
"test.txt": "content",
|
||||
}),
|
||||
Type: &proto.AcquiredJob_WorkspaceBuild_{
|
||||
WorkspaceBuild: &proto.AcquiredJob_WorkspaceBuild{
|
||||
Metadata: &sdkproto.Metadata{},
|
||||
},
|
||||
},
|
||||
}, nil
|
||||
},
|
||||
return createProvisionerDaemonClient(t, done, provisionerDaemonTestServer{
|
||||
acquireJobWithCancel: acq.acquireWithCancel,
|
||||
updateJob: func(ctx context.Context, update *proto.UpdateJobRequest) (*proto.UpdateJobResponse, error) {
|
||||
if len(update.Logs) != 0 {
|
||||
didLog.Store(true)
|
||||
@@ -591,7 +533,7 @@ func TestProvisionerd(t *testing.T) {
|
||||
},
|
||||
}),
|
||||
})
|
||||
require.Condition(t, closedWithin(completeChan, testutil.WaitShort))
|
||||
require.Condition(t, closedWithin(acq.complete, testutil.WaitShort))
|
||||
require.NoError(t, closer.Close())
|
||||
assert.True(t, didLog.Load(), "should log some updates")
|
||||
assert.False(t, didComplete.Load(), "should not complete the job")
|
||||
@@ -605,34 +547,25 @@ func TestProvisionerd(t *testing.T) {
|
||||
close(done)
|
||||
})
|
||||
var (
|
||||
didFail atomic.Bool
|
||||
didAcquireJob atomic.Bool
|
||||
completeChan = make(chan struct{})
|
||||
completeOnce sync.Once
|
||||
didFail atomic.Bool
|
||||
acq = newAcquireOne(t, &proto.AcquiredJob{
|
||||
JobId: "test",
|
||||
Provisioner: "someprovisioner",
|
||||
TemplateSourceArchive: createTar(t, map[string]string{
|
||||
"test.txt": "content",
|
||||
}),
|
||||
Type: &proto.AcquiredJob_WorkspaceBuild_{
|
||||
WorkspaceBuild: &proto.AcquiredJob_WorkspaceBuild{
|
||||
Metadata: &sdkproto.Metadata{},
|
||||
},
|
||||
},
|
||||
})
|
||||
)
|
||||
|
||||
closer := createProvisionerd(t, func(ctx context.Context) (proto.DRPCProvisionerDaemonClient, error) {
|
||||
return createProvisionerDaemonClient(ctx, t, done, provisionerDaemonTestServer{
|
||||
acquireJob: func(ctx context.Context, _ *proto.Empty) (*proto.AcquiredJob, error) {
|
||||
if !didAcquireJob.CAS(false, true) {
|
||||
completeOnce.Do(func() { close(completeChan) })
|
||||
return &proto.AcquiredJob{}, nil
|
||||
}
|
||||
|
||||
return &proto.AcquiredJob{
|
||||
JobId: "test",
|
||||
Provisioner: "someprovisioner",
|
||||
TemplateSourceArchive: createTar(t, map[string]string{
|
||||
"test.txt": "content",
|
||||
}),
|
||||
Type: &proto.AcquiredJob_WorkspaceBuild_{
|
||||
WorkspaceBuild: &proto.AcquiredJob_WorkspaceBuild{
|
||||
Metadata: &sdkproto.Metadata{},
|
||||
},
|
||||
},
|
||||
}, nil
|
||||
},
|
||||
updateJob: noopUpdateJob,
|
||||
return createProvisionerDaemonClient(t, done, provisionerDaemonTestServer{
|
||||
acquireJobWithCancel: acq.acquireWithCancel,
|
||||
updateJob: noopUpdateJob,
|
||||
failJob: func(ctx context.Context, job *proto.FailedJob) (*proto.Empty, error) {
|
||||
didFail.Store(true)
|
||||
return &proto.Empty{}, nil
|
||||
@@ -661,7 +594,7 @@ func TestProvisionerd(t *testing.T) {
|
||||
},
|
||||
}),
|
||||
})
|
||||
require.Condition(t, closedWithin(completeChan, testutil.WaitShort))
|
||||
require.Condition(t, closedWithin(acq.complete, testutil.WaitShort))
|
||||
require.NoError(t, closer.Close())
|
||||
assert.True(t, didFail.Load(), "should fail the job")
|
||||
})
|
||||
@@ -677,9 +610,9 @@ func TestProvisionerd(t *testing.T) {
|
||||
updateChan := make(chan struct{})
|
||||
completeChan := make(chan struct{})
|
||||
server := createProvisionerd(t, func(ctx context.Context) (proto.DRPCProvisionerDaemonClient, error) {
|
||||
return createProvisionerDaemonClient(ctx, t, done, provisionerDaemonTestServer{
|
||||
acquireJob: func(ctx context.Context, _ *proto.Empty) (*proto.AcquiredJob, error) {
|
||||
return &proto.AcquiredJob{
|
||||
return createProvisionerDaemonClient(t, done, provisionerDaemonTestServer{
|
||||
acquireJobWithCancel: func(stream proto.DRPCProvisionerDaemon_AcquireJobWithCancelStream) error {
|
||||
err := stream.Send(&proto.AcquiredJob{
|
||||
JobId: "test",
|
||||
Provisioner: "someprovisioner",
|
||||
TemplateSourceArchive: createTar(t, map[string]string{
|
||||
@@ -690,7 +623,9 @@ func TestProvisionerd(t *testing.T) {
|
||||
Metadata: &sdkproto.Metadata{},
|
||||
},
|
||||
},
|
||||
}, nil
|
||||
})
|
||||
assert.NoError(t, err)
|
||||
return nil
|
||||
},
|
||||
updateJob: func(ctx context.Context, update *proto.UpdateJobRequest) (*proto.UpdateJobResponse, error) {
|
||||
if len(update.Logs) > 0 {
|
||||
@@ -755,9 +690,9 @@ func TestProvisionerd(t *testing.T) {
|
||||
updateChan := make(chan struct{})
|
||||
completeChan := make(chan struct{})
|
||||
server := createProvisionerd(t, func(ctx context.Context) (proto.DRPCProvisionerDaemonClient, error) {
|
||||
return createProvisionerDaemonClient(ctx, t, done, provisionerDaemonTestServer{
|
||||
acquireJob: func(ctx context.Context, _ *proto.Empty) (*proto.AcquiredJob, error) {
|
||||
return &proto.AcquiredJob{
|
||||
return createProvisionerDaemonClient(t, done, provisionerDaemonTestServer{
|
||||
acquireJobWithCancel: func(stream proto.DRPCProvisionerDaemon_AcquireJobWithCancelStream) error {
|
||||
err := stream.Send(&proto.AcquiredJob{
|
||||
JobId: "test",
|
||||
Provisioner: "someprovisioner",
|
||||
TemplateSourceArchive: createTar(t, map[string]string{
|
||||
@@ -768,7 +703,9 @@ func TestProvisionerd(t *testing.T) {
|
||||
Metadata: &sdkproto.Metadata{},
|
||||
},
|
||||
},
|
||||
}, nil
|
||||
})
|
||||
assert.NoError(t, err)
|
||||
return nil
|
||||
},
|
||||
updateJob: func(ctx context.Context, update *proto.UpdateJobRequest) (*proto.UpdateJobResponse, error) {
|
||||
resp := &proto.UpdateJobResponse{}
|
||||
@@ -825,6 +762,9 @@ func TestProvisionerd(t *testing.T) {
|
||||
})
|
||||
require.Condition(t, closedWithin(updateChan, testutil.WaitShort))
|
||||
require.Condition(t, closedWithin(completeChan, testutil.WaitShort))
|
||||
ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitShort)
|
||||
defer cancel()
|
||||
require.NoError(t, server.Shutdown(ctx))
|
||||
require.NoError(t, server.Close())
|
||||
})
|
||||
|
||||
@@ -844,12 +784,9 @@ func TestProvisionerd(t *testing.T) {
|
||||
completeOnce sync.Once
|
||||
)
|
||||
server := createProvisionerd(t, func(ctx context.Context) (proto.DRPCProvisionerDaemonClient, error) {
|
||||
client := createProvisionerDaemonClient(ctx, t, done, provisionerDaemonTestServer{
|
||||
acquireJob: func(ctx context.Context, _ *proto.Empty) (*proto.AcquiredJob, error) {
|
||||
if second.Load() {
|
||||
return &proto.AcquiredJob{}, nil
|
||||
}
|
||||
return &proto.AcquiredJob{
|
||||
client := createProvisionerDaemonClient(t, done, provisionerDaemonTestServer{
|
||||
acquireJobWithCancel: func(stream proto.DRPCProvisionerDaemon_AcquireJobWithCancelStream) error {
|
||||
job := &proto.AcquiredJob{
|
||||
JobId: "test",
|
||||
Provisioner: "someprovisioner",
|
||||
TemplateSourceArchive: createTar(t, map[string]string{
|
||||
@@ -860,7 +797,15 @@ func TestProvisionerd(t *testing.T) {
|
||||
Metadata: &sdkproto.Metadata{},
|
||||
},
|
||||
},
|
||||
}, nil
|
||||
}
|
||||
if second.Load() {
|
||||
job = &proto.AcquiredJob{}
|
||||
_, err := stream.Recv()
|
||||
assert.NoError(t, err)
|
||||
}
|
||||
err := stream.Send(job)
|
||||
assert.NoError(t, err)
|
||||
return nil
|
||||
},
|
||||
updateJob: func(ctx context.Context, update *proto.UpdateJobRequest) (*proto.UpdateJobResponse, error) {
|
||||
return &proto.UpdateJobResponse{}, nil
|
||||
@@ -908,6 +853,9 @@ func TestProvisionerd(t *testing.T) {
|
||||
}),
|
||||
})
|
||||
require.Condition(t, closedWithin(completeChan, testutil.WaitShort))
|
||||
ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitShort)
|
||||
defer cancel()
|
||||
require.NoError(t, server.Shutdown(ctx))
|
||||
require.NoError(t, server.Close())
|
||||
})
|
||||
|
||||
@@ -927,13 +875,15 @@ func TestProvisionerd(t *testing.T) {
|
||||
completeOnce sync.Once
|
||||
)
|
||||
server := createProvisionerd(t, func(ctx context.Context) (proto.DRPCProvisionerDaemonClient, error) {
|
||||
client := createProvisionerDaemonClient(ctx, t, done, provisionerDaemonTestServer{
|
||||
acquireJob: func(ctx context.Context, _ *proto.Empty) (*proto.AcquiredJob, error) {
|
||||
client := createProvisionerDaemonClient(t, done, provisionerDaemonTestServer{
|
||||
acquireJobWithCancel: func(stream proto.DRPCProvisionerDaemon_AcquireJobWithCancelStream) error {
|
||||
if second.Load() {
|
||||
completeOnce.Do(func() { close(completeChan) })
|
||||
return &proto.AcquiredJob{}, nil
|
||||
_, err := stream.Recv()
|
||||
assert.NoError(t, err)
|
||||
return nil
|
||||
}
|
||||
return &proto.AcquiredJob{
|
||||
job := &proto.AcquiredJob{
|
||||
JobId: "test",
|
||||
Provisioner: "someprovisioner",
|
||||
TemplateSourceArchive: createTar(t, map[string]string{
|
||||
@@ -944,7 +894,10 @@ func TestProvisionerd(t *testing.T) {
|
||||
Metadata: &sdkproto.Metadata{},
|
||||
},
|
||||
},
|
||||
}, nil
|
||||
}
|
||||
err := stream.Send(job)
|
||||
assert.NoError(t, err)
|
||||
return nil
|
||||
},
|
||||
failJob: func(ctx context.Context, job *proto.FailedJob) (*proto.Empty, error) {
|
||||
return nil, yamux.ErrSessionShutdown
|
||||
@@ -990,6 +943,10 @@ func TestProvisionerd(t *testing.T) {
|
||||
}),
|
||||
})
|
||||
require.Condition(t, closedWithin(completeChan, testutil.WaitShort))
|
||||
t.Log("completeChan closed")
|
||||
ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitShort)
|
||||
defer cancel()
|
||||
require.NoError(t, server.Shutdown(ctx))
|
||||
require.NoError(t, server.Close())
|
||||
})
|
||||
|
||||
@@ -1006,17 +963,21 @@ func TestProvisionerd(t *testing.T) {
|
||||
completeOnce := sync.Once{}
|
||||
|
||||
server := createProvisionerd(t, func(ctx context.Context) (proto.DRPCProvisionerDaemonClient, error) {
|
||||
return createProvisionerDaemonClient(ctx, t, done, provisionerDaemonTestServer{
|
||||
acquireJob: func(ctx context.Context, _ *proto.Empty) (*proto.AcquiredJob, error) {
|
||||
return createProvisionerDaemonClient(t, done, provisionerDaemonTestServer{
|
||||
acquireJobWithCancel: func(stream proto.DRPCProvisionerDaemon_AcquireJobWithCancelStream) error {
|
||||
m.Lock()
|
||||
defer m.Unlock()
|
||||
logger.Info(ctx, "provisioner stage: AcquiredJob")
|
||||
if len(ops) > 0 {
|
||||
return &proto.AcquiredJob{}, nil
|
||||
_, err := stream.Recv()
|
||||
assert.NoError(t, err)
|
||||
err = stream.Send(&proto.AcquiredJob{})
|
||||
assert.NoError(t, err)
|
||||
return nil
|
||||
}
|
||||
ops = append(ops, "AcquireJob")
|
||||
|
||||
return &proto.AcquiredJob{
|
||||
err := stream.Send(&proto.AcquiredJob{
|
||||
JobId: "test",
|
||||
Provisioner: "someprovisioner",
|
||||
TemplateSourceArchive: createTar(t, map[string]string{
|
||||
@@ -1027,7 +988,9 @@ func TestProvisionerd(t *testing.T) {
|
||||
Metadata: &sdkproto.Metadata{},
|
||||
},
|
||||
},
|
||||
}, nil
|
||||
})
|
||||
assert.NoError(t, err)
|
||||
return nil
|
||||
},
|
||||
updateJob: func(ctx context.Context, update *proto.UpdateJobRequest) (*proto.UpdateJobResponse, error) {
|
||||
m.Lock()
|
||||
@@ -1076,6 +1039,9 @@ func TestProvisionerd(t *testing.T) {
|
||||
}),
|
||||
})
|
||||
require.Condition(t, closedWithin(completeChan, testutil.WaitShort))
|
||||
ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitShort)
|
||||
defer cancel()
|
||||
require.NoError(t, server.Shutdown(ctx))
|
||||
require.NoError(t, server.Close())
|
||||
assert.Equal(t, ops[len(ops)-1], "CompleteJob")
|
||||
assert.Contains(t, ops[0:len(ops)-1], "Log: Cleaning Up | ")
|
||||
@@ -1105,12 +1071,14 @@ func createTar(t *testing.T, files map[string]string) []byte {
|
||||
// Creates a provisionerd implementation with the provided dialer and provisioners.
|
||||
func createProvisionerd(t *testing.T, dialer provisionerd.Dialer, connector provisionerd.LocalProvisioners) *provisionerd.Server {
|
||||
server := provisionerd.New(dialer, &provisionerd.Options{
|
||||
Logger: slogtest.Make(t, &slogtest.Options{IgnoreErrors: true}).Named("provisionerd").Leveled(slog.LevelDebug),
|
||||
JobPollInterval: 50 * time.Millisecond,
|
||||
UpdateInterval: 50 * time.Millisecond,
|
||||
Connector: connector,
|
||||
Logger: slogtest.Make(t, &slogtest.Options{IgnoreErrors: true}).Named("provisionerd").Leveled(slog.LevelDebug),
|
||||
UpdateInterval: 50 * time.Millisecond,
|
||||
Connector: connector,
|
||||
})
|
||||
t.Cleanup(func() {
|
||||
ctx, cancel := context.WithTimeout(context.Background(), testutil.WaitShort)
|
||||
defer cancel()
|
||||
_ = server.Shutdown(ctx)
|
||||
_ = server.Close()
|
||||
})
|
||||
return server
|
||||
@@ -1118,7 +1086,7 @@ func createProvisionerd(t *testing.T, dialer provisionerd.Dialer, connector prov
|
||||
|
||||
// Creates a provisionerd protobuf client that's connected
|
||||
// to the server implementation provided.
|
||||
func createProvisionerDaemonClient(ctx context.Context, t *testing.T, done <-chan struct{}, server provisionerDaemonTestServer) proto.DRPCProvisionerDaemonClient {
|
||||
func createProvisionerDaemonClient(t *testing.T, done <-chan struct{}, server provisionerDaemonTestServer) proto.DRPCProvisionerDaemonClient {
|
||||
t.Helper()
|
||||
if server.failJob == nil {
|
||||
// Default to asserting the error from the failure, otherwise
|
||||
@@ -1137,7 +1105,7 @@ func createProvisionerDaemonClient(ctx context.Context, t *testing.T, done <-cha
|
||||
err := proto.DRPCRegisterProvisionerDaemon(mux, &server)
|
||||
require.NoError(t, err)
|
||||
srv := drpcserver.New(mux)
|
||||
ctx, cancelFunc := context.WithCancel(ctx)
|
||||
ctx, cancelFunc := context.WithCancel(context.Background())
|
||||
closed := make(chan struct{})
|
||||
go func() {
|
||||
defer close(closed)
|
||||
@@ -1148,31 +1116,13 @@ func createProvisionerDaemonClient(ctx context.Context, t *testing.T, done <-cha
|
||||
<-closed
|
||||
select {
|
||||
case <-done:
|
||||
// It's possible to get unlucky since the dialer is run in a retry in a goroutine.
|
||||
// The following can occur:
|
||||
// 1. The provisionerd.connect goroutine checks if we're closed prior to attempting to establish a connection
|
||||
// with coderd, sees that we're not.
|
||||
// 2. A test closes the server.
|
||||
// 3. The provisionerd.connect goroutine calls the dialer to establish a connection. This
|
||||
// function detects that someone has tried to create a client after the test finishes.
|
||||
if ctx.Err() == nil {
|
||||
t.Error("createProvisionerDaemonClient cleanup after test was done!")
|
||||
}
|
||||
t.Error("createProvisionerDaemonClient cleanup after test was done!")
|
||||
default:
|
||||
}
|
||||
})
|
||||
select {
|
||||
case <-done:
|
||||
// It's possible to get unlucky since the dialer is run in a retry in a goroutine.
|
||||
// The following can occur:
|
||||
// 1. The provisionerd.connect goroutine checks if we're closed prior to attempting to establish a connection
|
||||
// with coderd, sees that we're not.
|
||||
// 2. A test closes the server.
|
||||
// 3. The provisionerd.connect goroutine calls the dialer to establish a connection. This
|
||||
// function detects that someone has tried to create a client after the test finishes.
|
||||
if ctx.Err() == nil {
|
||||
t.Error("createProvisionerDaemonClient cleanup after test was done!")
|
||||
}
|
||||
t.Error("called createProvisionerDaemonClient after test was done!")
|
||||
default:
|
||||
}
|
||||
return proto.NewDRPCProvisionerDaemonClient(clientPipe)
|
||||
@@ -1235,15 +1185,25 @@ func (p *provisionerTestServer) Apply(s *provisionersdk.Session, r *sdkproto.App
|
||||
// Fulfills the protobuf interface for a ProvisionerDaemon with
|
||||
// passable functions for dynamic functionality.
|
||||
type provisionerDaemonTestServer struct {
|
||||
acquireJob func(ctx context.Context, _ *proto.Empty) (*proto.AcquiredJob, error)
|
||||
commitQuota func(ctx context.Context, com *proto.CommitQuotaRequest) (*proto.CommitQuotaResponse, error)
|
||||
updateJob func(ctx context.Context, update *proto.UpdateJobRequest) (*proto.UpdateJobResponse, error)
|
||||
failJob func(ctx context.Context, job *proto.FailedJob) (*proto.Empty, error)
|
||||
completeJob func(ctx context.Context, job *proto.CompletedJob) (*proto.Empty, error)
|
||||
acquireJobWithCancel func(stream proto.DRPCProvisionerDaemon_AcquireJobWithCancelStream) error
|
||||
commitQuota func(ctx context.Context, com *proto.CommitQuotaRequest) (*proto.CommitQuotaResponse, error)
|
||||
updateJob func(ctx context.Context, update *proto.UpdateJobRequest) (*proto.UpdateJobResponse, error)
|
||||
failJob func(ctx context.Context, job *proto.FailedJob) (*proto.Empty, error)
|
||||
completeJob func(ctx context.Context, job *proto.CompletedJob) (*proto.Empty, error)
|
||||
}
|
||||
|
||||
func (p *provisionerDaemonTestServer) AcquireJob(ctx context.Context, empty *proto.Empty) (*proto.AcquiredJob, error) {
|
||||
return p.acquireJob(ctx, empty)
|
||||
func (*provisionerDaemonTestServer) AcquireJob(context.Context, *proto.Empty) (*proto.AcquiredJob, error) {
|
||||
return nil, xerrors.New("deprecated!")
|
||||
}
|
||||
|
||||
func (p *provisionerDaemonTestServer) AcquireJobWithCancel(stream proto.DRPCProvisionerDaemon_AcquireJobWithCancelStream) error {
|
||||
if p.acquireJobWithCancel != nil {
|
||||
return p.acquireJobWithCancel(stream)
|
||||
}
|
||||
// default behavior is to wait for cancel
|
||||
_, _ = stream.Recv()
|
||||
_ = stream.Send(&proto.AcquiredJob{})
|
||||
return nil
|
||||
}
|
||||
|
||||
func (p *provisionerDaemonTestServer) CommitQuota(ctx context.Context, com *proto.CommitQuotaRequest) (*proto.CommitQuotaResponse, error) {
|
||||
@@ -1266,3 +1226,38 @@ func (p *provisionerDaemonTestServer) FailJob(ctx context.Context, job *proto.Fa
|
||||
func (p *provisionerDaemonTestServer) CompleteJob(ctx context.Context, job *proto.CompletedJob) (*proto.Empty, error) {
|
||||
return p.completeJob(ctx, job)
|
||||
}
|
||||
|
||||
// acquireOne provides a function that returns a single provisioner job, then subsequent calls block until canceled.
|
||||
// The complete channel is closed on the 2nd call.
|
||||
type acquireOne struct {
|
||||
t *testing.T
|
||||
mu sync.Mutex
|
||||
job *proto.AcquiredJob
|
||||
called int
|
||||
complete chan struct{}
|
||||
}
|
||||
|
||||
func newAcquireOne(t *testing.T, job *proto.AcquiredJob) *acquireOne {
|
||||
return &acquireOne{
|
||||
t: t,
|
||||
job: job,
|
||||
complete: make(chan struct{}),
|
||||
}
|
||||
}
|
||||
|
||||
func (a *acquireOne) acquireWithCancel(stream proto.DRPCProvisionerDaemon_AcquireJobWithCancelStream) error {
|
||||
a.mu.Lock()
|
||||
defer a.mu.Unlock()
|
||||
a.called++
|
||||
if a.called == 2 {
|
||||
close(a.complete)
|
||||
}
|
||||
if a.called > 1 {
|
||||
_, _ = stream.Recv()
|
||||
_ = stream.Send(&proto.AcquiredJob{})
|
||||
return nil
|
||||
}
|
||||
err := stream.Send(a.job)
|
||||
assert.NoError(a.t, err)
|
||||
return nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user