From b291cc9fe5d7afc0e2df25b68c3d233305a79428 Mon Sep 17 00:00:00 2001 From: Erik Rasmussen Date: Sun, 28 Jul 2024 20:17:44 -0500 Subject: [PATCH] Happy path implementation (#50) --- .../unmango/baremetal/v1alpha1/command.pb.go | 108 ++++++++++-------- .../unmango/baremetal/v1alpha1/command.proto | 1 + provider/cmd/provisioner/main.go | 1 + provider/pkg/provider/cmd/tee.go | 1 + provider/pkg/provisioner/cmd/service.go | 41 ++++++- provider/pkg/provisioner/cmd/tee.go | 18 --- tests/logging.go | 2 +- tests/provider.go | 14 +++ tests/provider_suite_test.go | 4 +- tests/provider_test.go | 22 ---- tests/provisioner.go | 19 +++ tests/tee_test.go | 54 ++++++--- 12 files changed, 171 insertions(+), 114 deletions(-) delete mode 100644 provider/pkg/provisioner/cmd/tee.go delete mode 100644 tests/provider_test.go diff --git a/gen/go/unmango/baremetal/v1alpha1/command.pb.go b/gen/go/unmango/baremetal/v1alpha1/command.pb.go index 2febbd6f..e8af9181 100644 --- a/gen/go/unmango/baremetal/v1alpha1/command.pb.go +++ b/gen/go/unmango/baremetal/v1alpha1/command.pb.go @@ -127,6 +127,7 @@ type CommandRequest struct { Command Command `protobuf:"varint,2,opt,name=command,proto3,enum=unmango.baremetal.v1alpha1.Command" json:"command,omitempty"` Args []string `protobuf:"bytes,3,rep,name=args,proto3" json:"args,omitempty"` Flags map[string]*Flag `protobuf:"bytes,4,rep,name=flags,proto3" json:"flags,omitempty" protobuf_key:"bytes,1,opt,name=key,proto3" protobuf_val:"bytes,2,opt,name=value,proto3"` + Stdin string `protobuf:"bytes,5,opt,name=stdin,proto3" json:"stdin,omitempty"` } func (x *CommandRequest) Reset() { @@ -189,6 +190,13 @@ func (x *CommandRequest) GetFlags() map[string]*Flag { return nil } +func (x *CommandRequest) GetStdin() string { + if x != nil { + return x.Stdin + } + return "" +} + type CommandResponse struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache @@ -306,7 +314,7 @@ var file_unmango_baremetal_v1alpha1_command_proto_rawDesc = []byte{ 0x74, 0x61, 0x6c, 0x2f, 0x76, 0x31, 0x61, 0x6c, 0x70, 0x68, 0x61, 0x31, 0x2f, 0x63, 0x6f, 0x6d, 0x6d, 0x61, 0x6e, 0x64, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x1a, 0x75, 0x6e, 0x6d, 0x61, 0x6e, 0x67, 0x6f, 0x2e, 0x62, 0x61, 0x72, 0x65, 0x6d, 0x65, 0x74, 0x61, 0x6c, 0x2e, 0x76, 0x31, - 0x61, 0x6c, 0x70, 0x68, 0x61, 0x31, 0x22, 0xbc, 0x02, 0x0a, 0x0e, 0x43, 0x6f, 0x6d, 0x6d, 0x61, + 0x61, 0x6c, 0x70, 0x68, 0x61, 0x31, 0x22, 0xd2, 0x02, 0x0a, 0x0e, 0x43, 0x6f, 0x6d, 0x6d, 0x61, 0x6e, 0x64, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x2e, 0x0a, 0x02, 0x6f, 0x70, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0e, 0x32, 0x1e, 0x2e, 0x75, 0x6e, 0x6d, 0x61, 0x6e, 0x67, 0x6f, 0x2e, 0x62, 0x61, 0x72, 0x65, 0x6d, 0x65, 0x74, 0x61, 0x6c, 0x2e, 0x76, 0x31, 0x61, 0x6c, 0x70, 0x68, @@ -320,54 +328,56 @@ var file_unmango_baremetal_v1alpha1_command_proto_rawDesc = []byte{ 0x6d, 0x61, 0x6e, 0x67, 0x6f, 0x2e, 0x62, 0x61, 0x72, 0x65, 0x6d, 0x65, 0x74, 0x61, 0x6c, 0x2e, 0x76, 0x31, 0x61, 0x6c, 0x70, 0x68, 0x61, 0x31, 0x2e, 0x43, 0x6f, 0x6d, 0x6d, 0x61, 0x6e, 0x64, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x2e, 0x46, 0x6c, 0x61, 0x67, 0x73, 0x45, 0x6e, 0x74, - 0x72, 0x79, 0x52, 0x05, 0x66, 0x6c, 0x61, 0x67, 0x73, 0x1a, 0x5a, 0x0a, 0x0a, 0x46, 0x6c, 0x61, - 0x67, 0x73, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x12, 0x10, 0x0a, 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, - 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, 0x36, 0x0a, 0x05, 0x76, 0x61, 0x6c, - 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x20, 0x2e, 0x75, 0x6e, 0x6d, 0x61, 0x6e, - 0x67, 0x6f, 0x2e, 0x62, 0x61, 0x72, 0x65, 0x6d, 0x65, 0x74, 0x61, 0x6c, 0x2e, 0x76, 0x31, 0x61, - 0x6c, 0x70, 0x68, 0x61, 0x31, 0x2e, 0x46, 0x6c, 0x61, 0x67, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, - 0x65, 0x3a, 0x02, 0x38, 0x01, 0x22, 0x41, 0x0a, 0x0f, 0x43, 0x6f, 0x6d, 0x6d, 0x61, 0x6e, 0x64, - 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x16, 0x0a, 0x06, 0x73, 0x74, 0x64, 0x6f, - 0x75, 0x74, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x73, 0x74, 0x64, 0x6f, 0x75, 0x74, - 0x12, 0x16, 0x0a, 0x06, 0x73, 0x74, 0x64, 0x65, 0x72, 0x72, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, - 0x52, 0x06, 0x73, 0x74, 0x64, 0x65, 0x72, 0x72, 0x22, 0x45, 0x0a, 0x04, 0x46, 0x6c, 0x61, 0x67, - 0x12, 0x18, 0x0a, 0x07, 0x70, 0x72, 0x65, 0x73, 0x65, 0x6e, 0x74, 0x18, 0x01, 0x20, 0x01, 0x28, - 0x08, 0x52, 0x07, 0x70, 0x72, 0x65, 0x73, 0x65, 0x6e, 0x74, 0x12, 0x19, 0x0a, 0x05, 0x76, 0x61, - 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x48, 0x00, 0x52, 0x05, 0x76, 0x61, 0x6c, - 0x75, 0x65, 0x88, 0x01, 0x01, 0x42, 0x08, 0x0a, 0x06, 0x5f, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x2a, - 0x45, 0x0a, 0x02, 0x4f, 0x70, 0x12, 0x12, 0x0a, 0x0e, 0x4f, 0x50, 0x5f, 0x55, 0x4e, 0x53, 0x50, - 0x45, 0x43, 0x49, 0x46, 0x49, 0x45, 0x44, 0x10, 0x00, 0x12, 0x0d, 0x0a, 0x09, 0x4f, 0x50, 0x5f, - 0x43, 0x52, 0x45, 0x41, 0x54, 0x45, 0x10, 0x01, 0x12, 0x0d, 0x0a, 0x09, 0x4f, 0x50, 0x5f, 0x55, - 0x50, 0x44, 0x41, 0x54, 0x45, 0x10, 0x02, 0x12, 0x0d, 0x0a, 0x09, 0x4f, 0x50, 0x5f, 0x44, 0x45, - 0x4c, 0x45, 0x54, 0x45, 0x10, 0x03, 0x2a, 0x33, 0x0a, 0x07, 0x43, 0x6f, 0x6d, 0x6d, 0x61, 0x6e, - 0x64, 0x12, 0x17, 0x0a, 0x13, 0x43, 0x4f, 0x4d, 0x4d, 0x41, 0x4e, 0x44, 0x5f, 0x55, 0x4e, 0x53, - 0x50, 0x45, 0x43, 0x49, 0x46, 0x49, 0x45, 0x44, 0x10, 0x00, 0x12, 0x0f, 0x0a, 0x0b, 0x43, 0x4f, - 0x4d, 0x4d, 0x41, 0x4e, 0x44, 0x5f, 0x54, 0x45, 0x45, 0x10, 0x01, 0x32, 0x74, 0x0a, 0x0e, 0x43, - 0x6f, 0x6d, 0x6d, 0x61, 0x6e, 0x64, 0x53, 0x65, 0x72, 0x76, 0x69, 0x63, 0x65, 0x12, 0x62, 0x0a, - 0x07, 0x43, 0x6f, 0x6d, 0x6d, 0x61, 0x6e, 0x64, 0x12, 0x2a, 0x2e, 0x75, 0x6e, 0x6d, 0x61, 0x6e, - 0x67, 0x6f, 0x2e, 0x62, 0x61, 0x72, 0x65, 0x6d, 0x65, 0x74, 0x61, 0x6c, 0x2e, 0x76, 0x31, 0x61, - 0x6c, 0x70, 0x68, 0x61, 0x31, 0x2e, 0x43, 0x6f, 0x6d, 0x6d, 0x61, 0x6e, 0x64, 0x52, 0x65, 0x71, - 0x75, 0x65, 0x73, 0x74, 0x1a, 0x2b, 0x2e, 0x75, 0x6e, 0x6d, 0x61, 0x6e, 0x67, 0x6f, 0x2e, 0x62, - 0x61, 0x72, 0x65, 0x6d, 0x65, 0x74, 0x61, 0x6c, 0x2e, 0x76, 0x31, 0x61, 0x6c, 0x70, 0x68, 0x61, - 0x31, 0x2e, 0x43, 0x6f, 0x6d, 0x6d, 0x61, 0x6e, 0x64, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, - 0x65, 0x42, 0x91, 0x02, 0x0a, 0x1e, 0x63, 0x6f, 0x6d, 0x2e, 0x75, 0x6e, 0x6d, 0x61, 0x6e, 0x67, - 0x6f, 0x2e, 0x62, 0x61, 0x72, 0x65, 0x6d, 0x65, 0x74, 0x61, 0x6c, 0x2e, 0x76, 0x31, 0x61, 0x6c, - 0x70, 0x68, 0x61, 0x31, 0x42, 0x0c, 0x43, 0x6f, 0x6d, 0x6d, 0x61, 0x6e, 0x64, 0x50, 0x72, 0x6f, - 0x74, 0x6f, 0x50, 0x01, 0x5a, 0x57, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, - 0x2f, 0x75, 0x6e, 0x6d, 0x61, 0x6e, 0x67, 0x6f, 0x2f, 0x70, 0x75, 0x6c, 0x75, 0x6d, 0x69, 0x2d, - 0x62, 0x61, 0x72, 0x65, 0x6d, 0x65, 0x74, 0x61, 0x6c, 0x2f, 0x67, 0x65, 0x6e, 0x2f, 0x67, 0x6f, - 0x2f, 0x75, 0x6e, 0x6d, 0x61, 0x6e, 0x67, 0x6f, 0x2f, 0x62, 0x61, 0x72, 0x65, 0x6d, 0x65, 0x74, - 0x61, 0x6c, 0x2f, 0x76, 0x31, 0x61, 0x6c, 0x70, 0x68, 0x61, 0x31, 0x3b, 0x62, 0x61, 0x72, 0x65, - 0x6d, 0x65, 0x74, 0x61, 0x6c, 0x76, 0x31, 0x61, 0x6c, 0x70, 0x68, 0x61, 0x31, 0xa2, 0x02, 0x03, - 0x55, 0x42, 0x58, 0xaa, 0x02, 0x1a, 0x55, 0x6e, 0x6d, 0x61, 0x6e, 0x67, 0x6f, 0x2e, 0x42, 0x61, - 0x72, 0x65, 0x6d, 0x65, 0x74, 0x61, 0x6c, 0x2e, 0x56, 0x31, 0x61, 0x6c, 0x70, 0x68, 0x61, 0x31, - 0xca, 0x02, 0x1a, 0x55, 0x6e, 0x6d, 0x61, 0x6e, 0x67, 0x6f, 0x5c, 0x42, 0x61, 0x72, 0x65, 0x6d, - 0x65, 0x74, 0x61, 0x6c, 0x5c, 0x56, 0x31, 0x61, 0x6c, 0x70, 0x68, 0x61, 0x31, 0xe2, 0x02, 0x26, - 0x55, 0x6e, 0x6d, 0x61, 0x6e, 0x67, 0x6f, 0x5c, 0x42, 0x61, 0x72, 0x65, 0x6d, 0x65, 0x74, 0x61, - 0x6c, 0x5c, 0x56, 0x31, 0x61, 0x6c, 0x70, 0x68, 0x61, 0x31, 0x5c, 0x47, 0x50, 0x42, 0x4d, 0x65, - 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0xea, 0x02, 0x1c, 0x55, 0x6e, 0x6d, 0x61, 0x6e, 0x67, 0x6f, - 0x3a, 0x3a, 0x42, 0x61, 0x72, 0x65, 0x6d, 0x65, 0x74, 0x61, 0x6c, 0x3a, 0x3a, 0x56, 0x31, 0x61, - 0x6c, 0x70, 0x68, 0x61, 0x31, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x72, 0x79, 0x52, 0x05, 0x66, 0x6c, 0x61, 0x67, 0x73, 0x12, 0x14, 0x0a, 0x05, 0x73, 0x74, 0x64, + 0x69, 0x6e, 0x18, 0x05, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x73, 0x74, 0x64, 0x69, 0x6e, 0x1a, + 0x5a, 0x0a, 0x0a, 0x46, 0x6c, 0x61, 0x67, 0x73, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x12, 0x10, 0x0a, + 0x03, 0x6b, 0x65, 0x79, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x03, 0x6b, 0x65, 0x79, 0x12, + 0x36, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x20, + 0x2e, 0x75, 0x6e, 0x6d, 0x61, 0x6e, 0x67, 0x6f, 0x2e, 0x62, 0x61, 0x72, 0x65, 0x6d, 0x65, 0x74, + 0x61, 0x6c, 0x2e, 0x76, 0x31, 0x61, 0x6c, 0x70, 0x68, 0x61, 0x31, 0x2e, 0x46, 0x6c, 0x61, 0x67, + 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x3a, 0x02, 0x38, 0x01, 0x22, 0x41, 0x0a, 0x0f, 0x43, + 0x6f, 0x6d, 0x6d, 0x61, 0x6e, 0x64, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x16, + 0x0a, 0x06, 0x73, 0x74, 0x64, 0x6f, 0x75, 0x74, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, + 0x73, 0x74, 0x64, 0x6f, 0x75, 0x74, 0x12, 0x16, 0x0a, 0x06, 0x73, 0x74, 0x64, 0x65, 0x72, 0x72, + 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x06, 0x73, 0x74, 0x64, 0x65, 0x72, 0x72, 0x22, 0x45, + 0x0a, 0x04, 0x46, 0x6c, 0x61, 0x67, 0x12, 0x18, 0x0a, 0x07, 0x70, 0x72, 0x65, 0x73, 0x65, 0x6e, + 0x74, 0x18, 0x01, 0x20, 0x01, 0x28, 0x08, 0x52, 0x07, 0x70, 0x72, 0x65, 0x73, 0x65, 0x6e, 0x74, + 0x12, 0x19, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x48, + 0x00, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x88, 0x01, 0x01, 0x42, 0x08, 0x0a, 0x06, 0x5f, + 0x76, 0x61, 0x6c, 0x75, 0x65, 0x2a, 0x45, 0x0a, 0x02, 0x4f, 0x70, 0x12, 0x12, 0x0a, 0x0e, 0x4f, + 0x50, 0x5f, 0x55, 0x4e, 0x53, 0x50, 0x45, 0x43, 0x49, 0x46, 0x49, 0x45, 0x44, 0x10, 0x00, 0x12, + 0x0d, 0x0a, 0x09, 0x4f, 0x50, 0x5f, 0x43, 0x52, 0x45, 0x41, 0x54, 0x45, 0x10, 0x01, 0x12, 0x0d, + 0x0a, 0x09, 0x4f, 0x50, 0x5f, 0x55, 0x50, 0x44, 0x41, 0x54, 0x45, 0x10, 0x02, 0x12, 0x0d, 0x0a, + 0x09, 0x4f, 0x50, 0x5f, 0x44, 0x45, 0x4c, 0x45, 0x54, 0x45, 0x10, 0x03, 0x2a, 0x33, 0x0a, 0x07, + 0x43, 0x6f, 0x6d, 0x6d, 0x61, 0x6e, 0x64, 0x12, 0x17, 0x0a, 0x13, 0x43, 0x4f, 0x4d, 0x4d, 0x41, + 0x4e, 0x44, 0x5f, 0x55, 0x4e, 0x53, 0x50, 0x45, 0x43, 0x49, 0x46, 0x49, 0x45, 0x44, 0x10, 0x00, + 0x12, 0x0f, 0x0a, 0x0b, 0x43, 0x4f, 0x4d, 0x4d, 0x41, 0x4e, 0x44, 0x5f, 0x54, 0x45, 0x45, 0x10, + 0x01, 0x32, 0x74, 0x0a, 0x0e, 0x43, 0x6f, 0x6d, 0x6d, 0x61, 0x6e, 0x64, 0x53, 0x65, 0x72, 0x76, + 0x69, 0x63, 0x65, 0x12, 0x62, 0x0a, 0x07, 0x43, 0x6f, 0x6d, 0x6d, 0x61, 0x6e, 0x64, 0x12, 0x2a, + 0x2e, 0x75, 0x6e, 0x6d, 0x61, 0x6e, 0x67, 0x6f, 0x2e, 0x62, 0x61, 0x72, 0x65, 0x6d, 0x65, 0x74, + 0x61, 0x6c, 0x2e, 0x76, 0x31, 0x61, 0x6c, 0x70, 0x68, 0x61, 0x31, 0x2e, 0x43, 0x6f, 0x6d, 0x6d, + 0x61, 0x6e, 0x64, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x2b, 0x2e, 0x75, 0x6e, 0x6d, + 0x61, 0x6e, 0x67, 0x6f, 0x2e, 0x62, 0x61, 0x72, 0x65, 0x6d, 0x65, 0x74, 0x61, 0x6c, 0x2e, 0x76, + 0x31, 0x61, 0x6c, 0x70, 0x68, 0x61, 0x31, 0x2e, 0x43, 0x6f, 0x6d, 0x6d, 0x61, 0x6e, 0x64, 0x52, + 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x42, 0x91, 0x02, 0x0a, 0x1e, 0x63, 0x6f, 0x6d, 0x2e, + 0x75, 0x6e, 0x6d, 0x61, 0x6e, 0x67, 0x6f, 0x2e, 0x62, 0x61, 0x72, 0x65, 0x6d, 0x65, 0x74, 0x61, + 0x6c, 0x2e, 0x76, 0x31, 0x61, 0x6c, 0x70, 0x68, 0x61, 0x31, 0x42, 0x0c, 0x43, 0x6f, 0x6d, 0x6d, + 0x61, 0x6e, 0x64, 0x50, 0x72, 0x6f, 0x74, 0x6f, 0x50, 0x01, 0x5a, 0x57, 0x67, 0x69, 0x74, 0x68, + 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x75, 0x6e, 0x6d, 0x61, 0x6e, 0x67, 0x6f, 0x2f, 0x70, + 0x75, 0x6c, 0x75, 0x6d, 0x69, 0x2d, 0x62, 0x61, 0x72, 0x65, 0x6d, 0x65, 0x74, 0x61, 0x6c, 0x2f, + 0x67, 0x65, 0x6e, 0x2f, 0x67, 0x6f, 0x2f, 0x75, 0x6e, 0x6d, 0x61, 0x6e, 0x67, 0x6f, 0x2f, 0x62, + 0x61, 0x72, 0x65, 0x6d, 0x65, 0x74, 0x61, 0x6c, 0x2f, 0x76, 0x31, 0x61, 0x6c, 0x70, 0x68, 0x61, + 0x31, 0x3b, 0x62, 0x61, 0x72, 0x65, 0x6d, 0x65, 0x74, 0x61, 0x6c, 0x76, 0x31, 0x61, 0x6c, 0x70, + 0x68, 0x61, 0x31, 0xa2, 0x02, 0x03, 0x55, 0x42, 0x58, 0xaa, 0x02, 0x1a, 0x55, 0x6e, 0x6d, 0x61, + 0x6e, 0x67, 0x6f, 0x2e, 0x42, 0x61, 0x72, 0x65, 0x6d, 0x65, 0x74, 0x61, 0x6c, 0x2e, 0x56, 0x31, + 0x61, 0x6c, 0x70, 0x68, 0x61, 0x31, 0xca, 0x02, 0x1a, 0x55, 0x6e, 0x6d, 0x61, 0x6e, 0x67, 0x6f, + 0x5c, 0x42, 0x61, 0x72, 0x65, 0x6d, 0x65, 0x74, 0x61, 0x6c, 0x5c, 0x56, 0x31, 0x61, 0x6c, 0x70, + 0x68, 0x61, 0x31, 0xe2, 0x02, 0x26, 0x55, 0x6e, 0x6d, 0x61, 0x6e, 0x67, 0x6f, 0x5c, 0x42, 0x61, + 0x72, 0x65, 0x6d, 0x65, 0x74, 0x61, 0x6c, 0x5c, 0x56, 0x31, 0x61, 0x6c, 0x70, 0x68, 0x61, 0x31, + 0x5c, 0x47, 0x50, 0x42, 0x4d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0xea, 0x02, 0x1c, 0x55, + 0x6e, 0x6d, 0x61, 0x6e, 0x67, 0x6f, 0x3a, 0x3a, 0x42, 0x61, 0x72, 0x65, 0x6d, 0x65, 0x74, 0x61, + 0x6c, 0x3a, 0x3a, 0x56, 0x31, 0x61, 0x6c, 0x70, 0x68, 0x61, 0x31, 0x62, 0x06, 0x70, 0x72, 0x6f, + 0x74, 0x6f, 0x33, } var ( diff --git a/proto/unmango/baremetal/v1alpha1/command.proto b/proto/unmango/baremetal/v1alpha1/command.proto index 9f031cc9..7fb19cdd 100644 --- a/proto/unmango/baremetal/v1alpha1/command.proto +++ b/proto/unmango/baremetal/v1alpha1/command.proto @@ -11,6 +11,7 @@ message CommandRequest { Command command = 2; repeated string args = 3; map flags = 4; + string stdin = 5; } message CommandResponse { diff --git a/provider/cmd/provisioner/main.go b/provider/cmd/provisioner/main.go index 51b20c1b..705e5d39 100644 --- a/provider/cmd/provisioner/main.go +++ b/provider/cmd/provisioner/main.go @@ -28,6 +28,7 @@ var rootCmd = &cobra.Command{ return err } + slog.SetDefault(log) log.Info("serving", "network", network, "address", address, "verbose", verbose) return provisioner.Serve(lis) }, diff --git a/provider/pkg/provider/cmd/tee.go b/provider/pkg/provider/cmd/tee.go index e9021ab2..6eca34d1 100644 --- a/provider/pkg/provider/cmd/tee.go +++ b/provider/pkg/provider/cmd/tee.go @@ -58,6 +58,7 @@ func (state *TeeState) create(ctx context.Context, input TeeArgs) error { Command: pb.Command_COMMAND_TEE, Args: input.Create.Files, Flags: map[string]*pb.Flag{}, + Stdin: input.Stdin, }) if err != nil { return err diff --git a/provider/pkg/provisioner/cmd/service.go b/provider/pkg/provisioner/cmd/service.go index e0a5d6fe..4725dd0d 100644 --- a/provider/pkg/provisioner/cmd/service.go +++ b/provider/pkg/provisioner/cmd/service.go @@ -1,26 +1,59 @@ package cmd import ( + "bytes" "context" "fmt" + "log/slog" + "os/exec" + "strings" pb "github.com/unmango/pulumi-baremetal/gen/go/unmango/baremetal/v1alpha1" ) type service struct { pb.UnimplementedCommandServiceServer + log *slog.Logger } func NewServer() pb.CommandServiceServer { - return &service{} + return &service{log: slog.Default()} } // Command implements baremetalv1alpha1.CommandServiceServer. func (c *service) Command(ctx context.Context, req *pb.CommandRequest) (*pb.CommandResponse, error) { - switch req.Command { + log := c.log.With("op", req.Op) + bin, err := getBin(req.Command) + if err != nil { + return nil, err + } + + cmd := exec.CommandContext(ctx, bin, req.Args...) + log = log.With("bin", bin, "args", req.Args) + + stdout := &bytes.Buffer{} + stderr := &bytes.Buffer{} + cmd.Stdin = strings.NewReader(req.Stdin) + cmd.Stdout = stdout + cmd.Stderr = stderr + + log.Info("executing command") + err = cmd.Run() + if err != nil { + log.Error("command failed", "err", err) + } + + return &pb.CommandResponse{ + Stdout: stdout.String(), + Stderr: stderr.String(), + }, nil +} + +func getBin(cmd pb.Command) (string, error) { + switch cmd { case pb.Command_COMMAND_TEE: - return tee(ctx, req) + return "tee", nil } - return nil, fmt.Errorf("unrecognized command: %s", req.Command) + return "", fmt.Errorf("unrecognized command: %s", cmd) } diff --git a/provider/pkg/provisioner/cmd/tee.go b/provider/pkg/provisioner/cmd/tee.go deleted file mode 100644 index 3dc56db8..00000000 --- a/provider/pkg/provisioner/cmd/tee.go +++ /dev/null @@ -1,18 +0,0 @@ -package cmd - -import ( - "context" - "fmt" - - pb "github.com/unmango/pulumi-baremetal/gen/go/unmango/baremetal/v1alpha1" -) - -func tee(ctx context.Context, req *pb.CommandRequest) (*pb.CommandResponse, error) { - stdout := fmt.Sprintf("op: %s, cmd: %s, args: %#v, flags: %#v", - req.Op, req.Command, req.Args, req.Flags, - ) - - return &pb.CommandResponse{ - Stdout: stdout, - }, nil -} diff --git a/tests/logging.go b/tests/logging.go index 32140b4e..11036ba4 100644 --- a/tests/logging.go +++ b/tests/logging.go @@ -21,7 +21,7 @@ func NewLogger(w io.Writer) tc.Logging { // Accept implements testcontainers.LogConsumer. func (w *writerConsumer) Accept(log tc.Log) { - _, _ = w.Write(log.Content) + _, _ = w.Write(append(log.Content, '\n')) } // Printf implements testcontainers.Logging. diff --git a/tests/provider.go b/tests/provider.go index 52a77546..4cc525ed 100644 --- a/tests/provider.go +++ b/tests/provider.go @@ -1,8 +1,12 @@ package tests import ( + "strings" + "github.com/blang/semver" "github.com/pulumi/pulumi-go-provider/integration" + "github.com/pulumi/pulumi/sdk/v3/go/common/resource" + "github.com/pulumi/pulumi/sdk/v3/go/common/tokens" baremetal "github.com/unmango/pulumi-baremetal/provider" ) @@ -14,3 +18,13 @@ func NewIntegrationProvider() integration.Server { baremetal.Provider(), ) } + +func urn(typ string, mods ...string) resource.URN { + if len(mods) == 0 { + mods = []string{"index"} + } + + tok := strings.Join(append(mods, typ), ":") + return resource.NewURN("stack", "proj", "", + tokens.Type("test:"+tok), "name") +} diff --git a/tests/provider_suite_test.go b/tests/provider_suite_test.go index fd458a5b..3bb1b047 100644 --- a/tests/provider_suite_test.go +++ b/tests/provider_suite_test.go @@ -2,6 +2,7 @@ package tests import ( "context" + "os" "testing" . "github.com/onsi/ginkgo/v2" @@ -19,9 +20,10 @@ func TestProvider(t *testing.T) { var _ = BeforeSuite(func(ctx context.Context) { By("creating a provisioner") - prov, err := NewTestProvisioner(ctx, GinkgoWriter) + prov, err := NewTestProvisioner(ctx, os.Stdout) Expect(err).NotTo(HaveOccurred()) + By("starting the provisioner") err = prov.Start(ctx) Expect(err).NotTo(HaveOccurred()) provisioner = prov diff --git a/tests/provider_test.go b/tests/provider_test.go deleted file mode 100644 index dee8bcd6..00000000 --- a/tests/provider_test.go +++ /dev/null @@ -1,22 +0,0 @@ -package tests - -import ( - "strings" - - . "github.com/onsi/ginkgo/v2" - - "github.com/pulumi/pulumi/sdk/v3/go/common/resource" - "github.com/pulumi/pulumi/sdk/v3/go/common/tokens" -) - -var _ = Describe("Provider", Ordered, func() {}) - -func urn(typ string, mods ...string) resource.URN { - if len(mods) == 0 { - mods = []string{"index"} - } - - tok := strings.Join(append(mods, typ), ":") - return resource.NewURN("stack", "proj", "", - tokens.Type("test:"+tok), "name") -} diff --git a/tests/provisioner.go b/tests/provisioner.go index 7e7846dc..22d7b7de 100644 --- a/tests/provisioner.go +++ b/tests/provisioner.go @@ -47,6 +47,7 @@ func NewTestProvisioner(ctx context.Context, logger io.Writer) (testProvisioner, Cmd: []string{ "--network", defaultProtocol, "--address", fmt.Sprintf("%s:%d", "0.0.0.0", port.Int()), + "--verbose", }, ExposedPorts: []string{port.Port()}, WaitingFor: wait.ForListeningPort(port), @@ -74,6 +75,24 @@ func (p testProvisioner) Stop(ctx context.Context) error { return p.ct.Stop(ctx, &timeout) } +func (p testProvisioner) Exec(ctx context.Context, args ...string) error { + code, output, err := p.ct.Exec(ctx, args) + if err != nil { + return err + } + + out, err := io.ReadAll(output) + if err != nil { + return err + } + + if code != 0 { + return fmt.Errorf("unexpected return code: %d, output: %s", code, out) + } + + return nil +} + func (prov testProvisioner) ConfigureProvider(ctx context.Context, server integration.Server) error { ip, err := prov.ct.ContainerIP(ctx) if err != nil { diff --git a/tests/tee_test.go b/tests/tee_test.go index eb3556ef..b77c452d 100644 --- a/tests/tee_test.go +++ b/tests/tee_test.go @@ -2,6 +2,7 @@ package tests import ( "context" + "io" . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" @@ -14,6 +15,12 @@ import ( var _ = Describe("Tee", Ordered, func() { var server integration.Server + BeforeAll(func(ctx context.Context) { + By("creating a working directory for the tee test") + err := provisioner.Exec(ctx, "mkdir", "-p", "/tmp/tee") + Expect(err).NotTo(HaveOccurred()) + }) + BeforeEach(func(ctx context.Context) { By("creating a provider server") server = NewIntegrationProvider() @@ -23,26 +30,35 @@ var _ = Describe("Tee", Ordered, func() { Expect(err).NotTo(HaveOccurred()) }) - It("should create a tee", func() { - stdin := "Test stdin" - By("generating expected data") - - By("creating the resource") - response, err := server.Create(p.CreateRequest{ - Urn: urn("Tee", "cmd"), - Properties: resource.PropertyMap{ - "stdin": resource.NewStringProperty(stdin), - "create": resource.NewObjectProperty(resource.PropertyMap{ - "files": resource.NewArrayProperty([]resource.PropertyValue{ - resource.NewStringProperty("test"), + Describe("Create", func() { + It("should write stdin to a file", func(ctx context.Context) { + stdin := "Test stdin" + file := "/tmp/tee/create.txt" + + By("creating the resource") + response, err := server.Create(p.CreateRequest{ + Urn: urn("Tee", "cmd"), + Preview: false, + Properties: resource.PropertyMap{ + "stdin": resource.NewStringProperty(stdin), + "create": resource.NewObjectProperty(resource.PropertyMap{ + "files": resource.NewArrayProperty([]resource.PropertyValue{ + resource.NewStringProperty(file), + }), }), - }), - }, - Preview: false, - }) + }, + }) - Expect(err).NotTo(HaveOccurred()) - Expect(response).NotTo(BeNil()) - Expect(response.Properties["stdout"].V).To(Equal("op: OP_CREATE, cmd: COMMAND_TEE, args: []string{\"test\"}, flags: map[string]*baremetalv1alpha1.Flag(nil)")) + Expect(err).NotTo(HaveOccurred()) + Expect(response.Properties["stderr"].V).To(BeEmpty()) + Expect(response.Properties["stdout"].V).To(Equal(stdin)) + + By("attempting to copy the created file") + reader, err := provisioner.ct.CopyFileFromContainer(ctx, file) + Expect(err).NotTo(HaveOccurred()) + result, err := io.ReadAll(reader) + Expect(err).NotTo(HaveOccurred()) + Expect(string(result)).To(Equal(stdin)) + }) }) })