diff --git a/proto/alpine.proto b/proto/alpine.proto index aaeadb9f..820efc58 100644 --- a/proto/alpine.proto +++ b/proto/alpine.proto @@ -17,9 +17,26 @@ package alpine; option go_package = "github.com/openconfig/kne/proto/alpine"; +message Files { + // Mount point for the files inside the pod. + string mount_dir = 1; + + message FileData { + oneof file_data { + // Byte data for the startup configuration file. + bytes data = 101; + // File is always relative to the topology configuration file. + string file = 102; + } + } + + map files = 2; +} + // Alpine specific vendor data for KNE message AlpineConfig { repeated Container containers = 1; + Files files = 2; } message Container { diff --git a/proto/alpine/alpine.pb.go b/proto/alpine/alpine.pb.go index e79ed58c..ad2c1414 100644 --- a/proto/alpine/alpine.pb.go +++ b/proto/alpine/alpine.pb.go @@ -34,6 +34,62 @@ const ( _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) ) +type Files struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + // Mount point for the files inside the pod. + MountDir string `protobuf:"bytes,1,opt,name=mount_dir,json=mountDir,proto3" json:"mount_dir,omitempty"` + Files map[string]*Files_FileData `protobuf:"bytes,2,rep,name=files,proto3" json:"files,omitempty" protobuf_key:"bytes,1,opt,name=key,proto3" protobuf_val:"bytes,2,opt,name=value,proto3"` +} + +func (x *Files) Reset() { + *x = Files{} + if protoimpl.UnsafeEnabled { + mi := &file_alpine_proto_msgTypes[0] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *Files) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*Files) ProtoMessage() {} + +func (x *Files) ProtoReflect() protoreflect.Message { + mi := &file_alpine_proto_msgTypes[0] + 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 Files.ProtoReflect.Descriptor instead. +func (*Files) Descriptor() ([]byte, []int) { + return file_alpine_proto_rawDescGZIP(), []int{0} +} + +func (x *Files) GetMountDir() string { + if x != nil { + return x.MountDir + } + return "" +} + +func (x *Files) GetFiles() map[string]*Files_FileData { + if x != nil { + return x.Files + } + return nil +} + // Alpine specific vendor data for KNE type AlpineConfig struct { state protoimpl.MessageState @@ -41,12 +97,13 @@ type AlpineConfig struct { unknownFields protoimpl.UnknownFields Containers []*Container `protobuf:"bytes,1,rep,name=containers,proto3" json:"containers,omitempty"` + Files *Files `protobuf:"bytes,2,opt,name=files,proto3" json:"files,omitempty"` } func (x *AlpineConfig) Reset() { *x = AlpineConfig{} if protoimpl.UnsafeEnabled { - mi := &file_alpine_proto_msgTypes[0] + mi := &file_alpine_proto_msgTypes[1] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -59,7 +116,7 @@ func (x *AlpineConfig) String() string { func (*AlpineConfig) ProtoMessage() {} func (x *AlpineConfig) ProtoReflect() protoreflect.Message { - mi := &file_alpine_proto_msgTypes[0] + mi := &file_alpine_proto_msgTypes[1] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -72,7 +129,7 @@ func (x *AlpineConfig) ProtoReflect() protoreflect.Message { // Deprecated: Use AlpineConfig.ProtoReflect.Descriptor instead. func (*AlpineConfig) Descriptor() ([]byte, []int) { - return file_alpine_proto_rawDescGZIP(), []int{0} + return file_alpine_proto_rawDescGZIP(), []int{1} } func (x *AlpineConfig) GetContainers() []*Container { @@ -82,6 +139,13 @@ func (x *AlpineConfig) GetContainers() []*Container { return nil } +func (x *AlpineConfig) GetFiles() *Files { + if x != nil { + return x.Files + } + return nil +} + type Container struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache @@ -96,7 +160,7 @@ type Container struct { func (x *Container) Reset() { *x = Container{} if protoimpl.UnsafeEnabled { - mi := &file_alpine_proto_msgTypes[1] + mi := &file_alpine_proto_msgTypes[2] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -109,7 +173,7 @@ func (x *Container) String() string { func (*Container) ProtoMessage() {} func (x *Container) ProtoReflect() protoreflect.Message { - mi := &file_alpine_proto_msgTypes[1] + mi := &file_alpine_proto_msgTypes[2] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -122,7 +186,7 @@ func (x *Container) ProtoReflect() protoreflect.Message { // Deprecated: Use Container.ProtoReflect.Descriptor instead. func (*Container) Descriptor() ([]byte, []int) { - return file_alpine_proto_rawDescGZIP(), []int{1} + return file_alpine_proto_rawDescGZIP(), []int{2} } func (x *Container) GetName() string { @@ -153,24 +217,125 @@ func (x *Container) GetArgs() []string { return nil } +type Files_FileData struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + // Types that are assignable to FileData: + // + // *Files_FileData_Data + // *Files_FileData_File + FileData isFiles_FileData_FileData `protobuf_oneof:"file_data"` +} + +func (x *Files_FileData) Reset() { + *x = Files_FileData{} + if protoimpl.UnsafeEnabled { + mi := &file_alpine_proto_msgTypes[3] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *Files_FileData) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*Files_FileData) ProtoMessage() {} + +func (x *Files_FileData) ProtoReflect() protoreflect.Message { + mi := &file_alpine_proto_msgTypes[3] + 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 Files_FileData.ProtoReflect.Descriptor instead. +func (*Files_FileData) Descriptor() ([]byte, []int) { + return file_alpine_proto_rawDescGZIP(), []int{0, 0} +} + +func (m *Files_FileData) GetFileData() isFiles_FileData_FileData { + if m != nil { + return m.FileData + } + return nil +} + +func (x *Files_FileData) GetData() []byte { + if x, ok := x.GetFileData().(*Files_FileData_Data); ok { + return x.Data + } + return nil +} + +func (x *Files_FileData) GetFile() string { + if x, ok := x.GetFileData().(*Files_FileData_File); ok { + return x.File + } + return "" +} + +type isFiles_FileData_FileData interface { + isFiles_FileData_FileData() +} + +type Files_FileData_Data struct { + // Byte data for the startup configuration file. + Data []byte `protobuf:"bytes,101,opt,name=data,proto3,oneof"` +} + +type Files_FileData_File struct { + // File is always relative to the topology configuration file. + File string `protobuf:"bytes,102,opt,name=file,proto3,oneof"` +} + +func (*Files_FileData_Data) isFiles_FileData_FileData() {} + +func (*Files_FileData_File) isFiles_FileData_FileData() {} + var File_alpine_proto protoreflect.FileDescriptor var file_alpine_proto_rawDesc = []byte{ 0x0a, 0x0c, 0x61, 0x6c, 0x70, 0x69, 0x6e, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x06, - 0x61, 0x6c, 0x70, 0x69, 0x6e, 0x65, 0x22, 0x41, 0x0a, 0x0c, 0x41, 0x6c, 0x70, 0x69, 0x6e, 0x65, - 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x12, 0x31, 0x0a, 0x0a, 0x63, 0x6f, 0x6e, 0x74, 0x61, 0x69, - 0x6e, 0x65, 0x72, 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x11, 0x2e, 0x61, 0x6c, 0x70, - 0x69, 0x6e, 0x65, 0x2e, 0x43, 0x6f, 0x6e, 0x74, 0x61, 0x69, 0x6e, 0x65, 0x72, 0x52, 0x0a, 0x63, - 0x6f, 0x6e, 0x74, 0x61, 0x69, 0x6e, 0x65, 0x72, 0x73, 0x22, 0x63, 0x0a, 0x09, 0x43, 0x6f, 0x6e, - 0x74, 0x61, 0x69, 0x6e, 0x65, 0x72, 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x18, 0x01, - 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x12, 0x14, 0x0a, 0x05, 0x69, 0x6d, - 0x61, 0x67, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x69, 0x6d, 0x61, 0x67, 0x65, - 0x12, 0x18, 0x0a, 0x07, 0x63, 0x6f, 0x6d, 0x6d, 0x61, 0x6e, 0x64, 0x18, 0x03, 0x20, 0x03, 0x28, - 0x09, 0x52, 0x07, 0x63, 0x6f, 0x6d, 0x6d, 0x61, 0x6e, 0x64, 0x12, 0x12, 0x0a, 0x04, 0x61, 0x72, - 0x67, 0x73, 0x18, 0x04, 0x20, 0x03, 0x28, 0x09, 0x52, 0x04, 0x61, 0x72, 0x67, 0x73, 0x42, 0x28, - 0x5a, 0x26, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x6f, 0x70, 0x65, - 0x6e, 0x63, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x2f, 0x6b, 0x6e, 0x65, 0x2f, 0x70, 0x72, 0x6f, 0x74, - 0x6f, 0x2f, 0x61, 0x6c, 0x70, 0x69, 0x6e, 0x65, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, + 0x61, 0x6c, 0x70, 0x69, 0x6e, 0x65, 0x22, 0xeb, 0x01, 0x0a, 0x05, 0x46, 0x69, 0x6c, 0x65, 0x73, + 0x12, 0x1b, 0x0a, 0x09, 0x6d, 0x6f, 0x75, 0x6e, 0x74, 0x5f, 0x64, 0x69, 0x72, 0x18, 0x01, 0x20, + 0x01, 0x28, 0x09, 0x52, 0x08, 0x6d, 0x6f, 0x75, 0x6e, 0x74, 0x44, 0x69, 0x72, 0x12, 0x2e, 0x0a, + 0x05, 0x66, 0x69, 0x6c, 0x65, 0x73, 0x18, 0x02, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x18, 0x2e, 0x61, + 0x6c, 0x70, 0x69, 0x6e, 0x65, 0x2e, 0x46, 0x69, 0x6c, 0x65, 0x73, 0x2e, 0x46, 0x69, 0x6c, 0x65, + 0x73, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x52, 0x05, 0x66, 0x69, 0x6c, 0x65, 0x73, 0x1a, 0x43, 0x0a, + 0x08, 0x46, 0x69, 0x6c, 0x65, 0x44, 0x61, 0x74, 0x61, 0x12, 0x14, 0x0a, 0x04, 0x64, 0x61, 0x74, + 0x61, 0x18, 0x65, 0x20, 0x01, 0x28, 0x0c, 0x48, 0x00, 0x52, 0x04, 0x64, 0x61, 0x74, 0x61, 0x12, + 0x14, 0x0a, 0x04, 0x66, 0x69, 0x6c, 0x65, 0x18, 0x66, 0x20, 0x01, 0x28, 0x09, 0x48, 0x00, 0x52, + 0x04, 0x66, 0x69, 0x6c, 0x65, 0x42, 0x0b, 0x0a, 0x09, 0x66, 0x69, 0x6c, 0x65, 0x5f, 0x64, 0x61, + 0x74, 0x61, 0x1a, 0x50, 0x0a, 0x0a, 0x46, 0x69, 0x6c, 0x65, 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, 0x2c, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, + 0x0b, 0x32, 0x16, 0x2e, 0x61, 0x6c, 0x70, 0x69, 0x6e, 0x65, 0x2e, 0x46, 0x69, 0x6c, 0x65, 0x73, + 0x2e, 0x46, 0x69, 0x6c, 0x65, 0x44, 0x61, 0x74, 0x61, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, + 0x3a, 0x02, 0x38, 0x01, 0x22, 0x66, 0x0a, 0x0c, 0x41, 0x6c, 0x70, 0x69, 0x6e, 0x65, 0x43, 0x6f, + 0x6e, 0x66, 0x69, 0x67, 0x12, 0x31, 0x0a, 0x0a, 0x63, 0x6f, 0x6e, 0x74, 0x61, 0x69, 0x6e, 0x65, + 0x72, 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x11, 0x2e, 0x61, 0x6c, 0x70, 0x69, 0x6e, + 0x65, 0x2e, 0x43, 0x6f, 0x6e, 0x74, 0x61, 0x69, 0x6e, 0x65, 0x72, 0x52, 0x0a, 0x63, 0x6f, 0x6e, + 0x74, 0x61, 0x69, 0x6e, 0x65, 0x72, 0x73, 0x12, 0x23, 0x0a, 0x05, 0x66, 0x69, 0x6c, 0x65, 0x73, + 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x0d, 0x2e, 0x61, 0x6c, 0x70, 0x69, 0x6e, 0x65, 0x2e, + 0x46, 0x69, 0x6c, 0x65, 0x73, 0x52, 0x05, 0x66, 0x69, 0x6c, 0x65, 0x73, 0x22, 0x63, 0x0a, 0x09, + 0x43, 0x6f, 0x6e, 0x74, 0x61, 0x69, 0x6e, 0x65, 0x72, 0x12, 0x12, 0x0a, 0x04, 0x6e, 0x61, 0x6d, + 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x04, 0x6e, 0x61, 0x6d, 0x65, 0x12, 0x14, 0x0a, + 0x05, 0x69, 0x6d, 0x61, 0x67, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x69, 0x6d, + 0x61, 0x67, 0x65, 0x12, 0x18, 0x0a, 0x07, 0x63, 0x6f, 0x6d, 0x6d, 0x61, 0x6e, 0x64, 0x18, 0x03, + 0x20, 0x03, 0x28, 0x09, 0x52, 0x07, 0x63, 0x6f, 0x6d, 0x6d, 0x61, 0x6e, 0x64, 0x12, 0x12, 0x0a, + 0x04, 0x61, 0x72, 0x67, 0x73, 0x18, 0x04, 0x20, 0x03, 0x28, 0x09, 0x52, 0x04, 0x61, 0x72, 0x67, + 0x73, 0x42, 0x28, 0x5a, 0x26, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, + 0x6f, 0x70, 0x65, 0x6e, 0x63, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x2f, 0x6b, 0x6e, 0x65, 0x2f, 0x70, + 0x72, 0x6f, 0x74, 0x6f, 0x2f, 0x61, 0x6c, 0x70, 0x69, 0x6e, 0x65, 0x62, 0x06, 0x70, 0x72, 0x6f, + 0x74, 0x6f, 0x33, } var ( @@ -185,18 +350,24 @@ func file_alpine_proto_rawDescGZIP() []byte { return file_alpine_proto_rawDescData } -var file_alpine_proto_msgTypes = make([]protoimpl.MessageInfo, 2) +var file_alpine_proto_msgTypes = make([]protoimpl.MessageInfo, 5) var file_alpine_proto_goTypes = []interface{}{ - (*AlpineConfig)(nil), // 0: alpine.AlpineConfig - (*Container)(nil), // 1: alpine.Container + (*Files)(nil), // 0: alpine.Files + (*AlpineConfig)(nil), // 1: alpine.AlpineConfig + (*Container)(nil), // 2: alpine.Container + (*Files_FileData)(nil), // 3: alpine.Files.FileData + nil, // 4: alpine.Files.FilesEntry } var file_alpine_proto_depIdxs = []int32{ - 1, // 0: alpine.AlpineConfig.containers:type_name -> alpine.Container - 1, // [1:1] is the sub-list for method output_type - 1, // [1:1] is the sub-list for method input_type - 1, // [1:1] is the sub-list for extension type_name - 1, // [1:1] is the sub-list for extension extendee - 0, // [0:1] is the sub-list for field type_name + 4, // 0: alpine.Files.files:type_name -> alpine.Files.FilesEntry + 2, // 1: alpine.AlpineConfig.containers:type_name -> alpine.Container + 0, // 2: alpine.AlpineConfig.files:type_name -> alpine.Files + 3, // 3: alpine.Files.FilesEntry.value:type_name -> alpine.Files.FileData + 4, // [4:4] is the sub-list for method output_type + 4, // [4:4] is the sub-list for method input_type + 4, // [4:4] is the sub-list for extension type_name + 4, // [4:4] is the sub-list for extension extendee + 0, // [0:4] is the sub-list for field type_name } func init() { file_alpine_proto_init() } @@ -206,7 +377,7 @@ func file_alpine_proto_init() { } if !protoimpl.UnsafeEnabled { file_alpine_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*AlpineConfig); i { + switch v := v.(*Files); i { case 0: return &v.state case 1: @@ -218,6 +389,18 @@ func file_alpine_proto_init() { } } file_alpine_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*AlpineConfig); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_alpine_proto_msgTypes[2].Exporter = func(v interface{}, i int) interface{} { switch v := v.(*Container); i { case 0: return &v.state @@ -229,6 +412,22 @@ func file_alpine_proto_init() { return nil } } + file_alpine_proto_msgTypes[3].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*Files_FileData); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + } + file_alpine_proto_msgTypes[3].OneofWrappers = []interface{}{ + (*Files_FileData_Data)(nil), + (*Files_FileData_File)(nil), } type x struct{} out := protoimpl.TypeBuilder{ @@ -236,7 +435,7 @@ func file_alpine_proto_init() { GoPackagePath: reflect.TypeOf(x{}).PkgPath(), RawDescriptor: file_alpine_proto_rawDesc, NumEnums: 0, - NumMessages: 2, + NumMessages: 5, NumExtensions: 0, NumServices: 0, }, diff --git a/topo/node/alpine/alpine.go b/topo/node/alpine/alpine.go index 6c1c1ddf..09dca0f4 100644 --- a/topo/node/alpine/alpine.go +++ b/topo/node/alpine/alpine.go @@ -16,6 +16,8 @@ package alpine import ( "context" "fmt" + "os" + "path/filepath" "strings" apb "github.com/openconfig/kne/proto/alpine" @@ -99,10 +101,8 @@ func (n *Node) CreatePod(ctx context.Context) error { }, }} - var intfMap []string - for k, v := range pb.Interfaces { - intfMap = append(intfMap, fmt.Sprintf("%s:%s", v.IntName, k)) - } + var extraVolumes []corev1.Volume + var extraMounts []corev1.VolumeMount if vendorData := pb.Config.GetVendorData(); vendorData != nil { alpineConfig := &apb.AlpineConfig{} @@ -111,29 +111,67 @@ func (n *Node) CreatePod(ctx context.Context) error { return err } + if len(alpineConfig.GetFiles().GetFiles()) > 0 { + cm := &corev1.ConfigMap{ + ObjectMeta: metav1.ObjectMeta{ + Name: fmt.Sprintf("%s-files", n.Proto.Name), + }, + Data: map[string]string{}, + } + extraMounts = append(extraMounts, corev1.VolumeMount{ + Name: "files", + MountPath: alpineConfig.GetFiles().GetMountDir(), + }) + extraVolumes = append(extraVolumes, corev1.Volume{ + Name: "files", + VolumeSource: corev1.VolumeSource{ + ConfigMap: &corev1.ConfigMapVolumeSource{ + LocalObjectReference: corev1.LocalObjectReference{ + Name: fmt.Sprintf("%s-files", n.Proto.Name), + }, + }}, + }) + for name, data := range alpineConfig.GetFiles().GetFiles() { + var contents []byte + var err error + switch v := data.GetFileData().(type) { + case *apb.Files_FileData_File: + contents, err = os.ReadFile(filepath.Join(n.BasePath, v.File)) + case *apb.Files_FileData_Data: + contents, err = v.Data, nil + } + if err != nil { + return err + } + cm.Data[name] = string(contents) + } + + _, err := n.KubeClient.CoreV1().ConfigMaps(n.Namespace).Create(ctx, cm, metav1.CreateOptions{}) + if err != nil { + return err + } + } + switch numContainers := len(alpineConfig.Containers); numContainers { case 0: log.Infof("Alpine custom containers not found.") case 1: dpContainer := alpineConfig.Containers[0] - if len(intfMap) != 0 { - dpContainer.Args = append(dpContainer.Args, "--port_map="+strings.Join(intfMap, ",")) - } - alpineContainers = append(alpineContainers, - corev1.Container{ - Name: dpContainer.Name, - Image: dpContainer.Image, - Command: dpContainer.Command, - Args: dpContainer.Args, - Env: node.ToEnvVar(pb.Config.Env), - // TODO: Update resources to the containers as per the constraints - Resources: node.ToResourceRequirements(pb.Constraints), - ImagePullPolicy: "IfNotPresent", - SecurityContext: &corev1.SecurityContext{ - Privileged: pointer.Bool(true), - }, + containerSpec := corev1.Container{ + Name: dpContainer.Name, + Image: dpContainer.Image, + Command: dpContainer.Command, + Args: dpContainer.Args, + Env: node.ToEnvVar(pb.Config.Env), + // TODO: Update resources to the containers as per the constraints + Resources: node.ToResourceRequirements(pb.Constraints), + ImagePullPolicy: "IfNotPresent", + SecurityContext: &corev1.SecurityContext{ + Privileged: pointer.Bool(true), }, - ) + VolumeMounts: extraMounts, + } + alpineContainers = append(alpineContainers, containerSpec) default: // Only Dataplane container is supported as the custom container return fmt.Errorf("Alpine supports only 1 custom container, %d provided.", numContainers) @@ -187,6 +225,7 @@ func (n *Node) CreatePod(ctx context.Context) error { return err } pod.Spec.Volumes = append(pod.Spec.Volumes, *vol) + pod.Spec.Volumes = append(pod.Spec.Volumes, extraVolumes...) vm := corev1.VolumeMount{ Name: node.ConfigVolumeName, MountPath: pb.Config.ConfigPath + "/" + pb.Config.ConfigFile, diff --git a/topo/node/alpine/alpine_test.go b/topo/node/alpine/alpine_test.go index a04c424b..0cb46756 100644 --- a/topo/node/alpine/alpine_test.go +++ b/topo/node/alpine/alpine_test.go @@ -148,6 +148,14 @@ func TestCreatePod(t *testing.T) { Command: []string{"dpCommand"}, Args: []string{"dpArgs"}, }}, + Files: &apb.Files{ + MountDir: "/files", + Files: map[string]*apb.Files_FileData{ + "test.config": {FileData: &apb.Files_FileData_Data{ + Data: []byte{'t', 'e', 's', 't'}, + }}, + }, + }, }) if err != nil { t.Fatalf("cannot marshal AlpineConfig into \"any\" protobuf: %v", err) @@ -194,6 +202,7 @@ func TestCreatePod(t *testing.T) { SecurityContext: &corev1.SecurityContext{ Privileged: pointer.Bool(true), }, + VolumeMounts: []corev1.VolumeMount{{Name: "files", MountPath: "/files"}}, }, }, { desc: "get all containers with ports", @@ -238,7 +247,7 @@ func TestCreatePod(t *testing.T) { Name: "dp", Image: "dpImage", Command: []string{"dpCommand"}, - Args: []string{"dpArgs", "--port_map=Ethernet1/1/1:eth1", "--config_file=/etc/sonic/config_db.json"}, + Args: []string{"dpArgs", "--config_file=/etc/sonic/config_db.json"}, Resources: corev1.ResourceRequirements{ Requests: corev1.ResourceList{}}, ImagePullPolicy: "IfNotPresent", @@ -246,6 +255,9 @@ func TestCreatePod(t *testing.T) { Privileged: pointer.Bool(true), }, VolumeMounts: []corev1.VolumeMount{{ + Name: "files", + MountPath: "/files", + }, { Name: "startup-config-volume", ReadOnly: true, MountPath: "/etc/sonic/config_db.json",