diff --git a/Dockerfile b/Dockerfile index 9399bc6..f4f519d 100644 --- a/Dockerfile +++ b/Dockerfile @@ -14,9 +14,11 @@ RUN go mod download # Copy the go source COPY cmd/manager/main.go cmd/manager/main.go COPY cmd/metalprobe/main.go cmd/metalprobe/main.go +COPY cmd/fmiserver/main.go cmd/fmiserver/main.go COPY api/ api/ COPY internal/ internal/ COPY bmc/ bmc/ +COPY fmi/ fmi/ # Build # the GOARCH has not a default value to allow the binary be built according to the host where the command @@ -26,10 +28,15 @@ COPY bmc/ bmc/ RUN --mount=type=cache,target=/root/.cache/go-build \ --mount=type=cache,target=/go/pkg \ CGO_ENABLED=0 GOOS=${TARGETOS:-linux} GOARCH=${TARGETARCH} go build -a -o manager cmd/manager/main.go + RUN --mount=type=cache,target=/root/.cache/go-build \ --mount=type=cache,target=/go/pkg \ CGO_ENABLED=0 GOOS=${TARGETOS:-linux} GOARCH=${TARGETARCH} go build -a -o metalprobe cmd/metalprobe/main.go +RUN --mount=type=cache,target=/root/.cache/go-build \ + --mount=type=cache,target=/go/pkg \ + CGO_ENABLED=0 GOOS=${TARGETOS:-linux} GOARCH=${TARGETARCH} go build -a -o fmi-server cmd/fmiserver/main.go + # Use distroless as minimal base image to package the manager binary # Refer to https://github.com/GoogleContainerTools/distroless for more details @@ -48,3 +55,11 @@ COPY --from=builder /workspace/metalprobe . USER 65532:65532 ENTRYPOINT ["/metalprobe"] + +FROM gcr.io/distroless/static:nonroot AS fmi-server +LABEL source_repository="https://github.com/ironcore-dev/metal-operator" +WORKDIR / +COPY --from=builder /workspace/fmi-server . +USER 65532:65532 + +ENTRYPOINT ["/fmi-server"] diff --git a/Makefile b/Makefile index 340228e..5b49212 100644 --- a/Makefile +++ b/Makefile @@ -62,6 +62,10 @@ manifests: controller-gen ## Generate WebhookConfiguration, ClusterRole and Cust generate: controller-gen ## Generate code containing DeepCopy, DeepCopyInto, and DeepCopyObject method implementations. $(CONTROLLER_GEN) object:headerFile="hack/boilerplate.go.txt" paths="./..." +.PHONY: gen-proto +gen-proto: buf + $(BUF) generate + .PHONY: fmt fmt: goimports ## Run goimports against code. $(GOIMPORTS) -w . @@ -208,6 +212,7 @@ ENVTEST ?= $(LOCALBIN)/setup-envtest-$(ENVTEST_VERSION) GOLANGCI_LINT = $(LOCALBIN)/golangci-lint-$(GOLANGCI_LINT_VERSION) GOIMPORTS ?= $(LOCALBIN)/goimports-$(GOIMPORTS_VERSION) GEN_CRD_API_REFERENCE_DOCS ?= $(LOCALBIN)/gen-crd-api-reference-docs-$(GEN_CRD_API_REFERENCE_DOCS_VERSION) +BUF ?= $(LOCALBIN)/buf-$(BUF_VERSION) ## Tool Versions KUSTOMIZE_VERSION ?= v5.3.0 @@ -216,6 +221,7 @@ ENVTEST_VERSION ?= latest GOLANGCI_LINT_VERSION ?= v1.61.0 GOIMPORTS_VERSION ?= v0.25.0 GEN_CRD_API_REFERENCE_DOCS_VERSION ?= v0.3.0 +BUF_VERSION ?= v1.46.0 .PHONY: kustomize kustomize: $(KUSTOMIZE) ## Download kustomize locally if necessary. @@ -254,6 +260,11 @@ gen-crd-api-reference-docs: $(GEN_CRD_API_REFERENCE_DOCS) ## Download gen-crd-ap $(GEN_CRD_API_REFERENCE_DOCS): $(LOCALBIN) $(call go-install-tool,$(GEN_CRD_API_REFERENCE_DOCS),github.com/ahmetb/gen-crd-api-reference-docs,$(GEN_CRD_API_REFERENCE_DOCS_VERSION)) +.PHONY: buf +buf: $(BUF) ## Download buf locally if necessary. +$(BUF): $(LOCALBIN) + $(call go-install-tool,$(BUF),github.com/bufbuild/buf/cmd/buf,$(BUF_VERSION)) + # go-install-tool will 'go install' any package with custom target and name of binary, if it doesn't exist # $1 - target path with name of binary (ideally with version) # $2 - package url which can be installed diff --git a/Tiltfile b/Tiltfile index 92b51bc..7de3fb7 100644 --- a/Tiltfile +++ b/Tiltfile @@ -81,6 +81,7 @@ def waitforsystem(): deploy_cert_manager() docker_build('controller', '.', target = 'manager') +docker_build('fmi-server', '.', target = 'fmi-server') deploy_boot() diff --git a/api/gen/common/v1alpha1/api.pb.go b/api/gen/common/v1alpha1/api.pb.go new file mode 100644 index 0000000..493404b --- /dev/null +++ b/api/gen/common/v1alpha1/api.pb.go @@ -0,0 +1,149 @@ +// Code generated by protoc-gen-go. DO NOT EDIT. +// versions: +// protoc-gen-go v1.32.0 +// protoc (unknown) +// source: common/v1alpha1/api.proto + +package v1alpha1 + +import ( + reflect "reflect" + sync "sync" + + protoreflect "google.golang.org/protobuf/reflect/protoreflect" + protoimpl "google.golang.org/protobuf/runtime/protoimpl" +) + +const ( + // Verify that this generated code is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) + // Verify that runtime/protoimpl is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) +) + +type RequestResult int32 + +const ( + RequestResult_REQUEST_RESULT_UNSPECIFIED RequestResult = 0 + RequestResult_REQUEST_RESULT_SCHEDULED RequestResult = 1 + RequestResult_REQUEST_RESULT_SUCCESS RequestResult = 2 + RequestResult_REQUEST_RESULT_FAILURE RequestResult = 3 +) + +// Enum value maps for RequestResult. +var ( + RequestResult_name = map[int32]string{ + 0: "REQUEST_RESULT_UNSPECIFIED", + 1: "REQUEST_RESULT_SCHEDULED", + 2: "REQUEST_RESULT_SUCCESS", + 3: "REQUEST_RESULT_FAILURE", + } + RequestResult_value = map[string]int32{ + "REQUEST_RESULT_UNSPECIFIED": 0, + "REQUEST_RESULT_SCHEDULED": 1, + "REQUEST_RESULT_SUCCESS": 2, + "REQUEST_RESULT_FAILURE": 3, + } +) + +func (x RequestResult) Enum() *RequestResult { + p := new(RequestResult) + *p = x + return p +} + +func (x RequestResult) String() string { + return protoimpl.X.EnumStringOf(x.Descriptor(), protoreflect.EnumNumber(x)) +} + +func (RequestResult) Descriptor() protoreflect.EnumDescriptor { + return file_common_v1alpha1_api_proto_enumTypes[0].Descriptor() +} + +func (RequestResult) Type() protoreflect.EnumType { + return &file_common_v1alpha1_api_proto_enumTypes[0] +} + +func (x RequestResult) Number() protoreflect.EnumNumber { + return protoreflect.EnumNumber(x) +} + +// Deprecated: Use RequestResult.Descriptor instead. +func (RequestResult) EnumDescriptor() ([]byte, []int) { + return file_common_v1alpha1_api_proto_rawDescGZIP(), []int{0} +} + +var File_common_v1alpha1_api_proto protoreflect.FileDescriptor + +var file_common_v1alpha1_api_proto_rawDesc = []byte{ + 0x0a, 0x19, 0x63, 0x6f, 0x6d, 0x6d, 0x6f, 0x6e, 0x2f, 0x76, 0x31, 0x61, 0x6c, 0x70, 0x68, 0x61, + 0x31, 0x2f, 0x61, 0x70, 0x69, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x08, 0x76, 0x31, 0x61, + 0x6c, 0x70, 0x68, 0x61, 0x31, 0x2a, 0x85, 0x01, 0x0a, 0x0d, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, + 0x74, 0x52, 0x65, 0x73, 0x75, 0x6c, 0x74, 0x12, 0x1e, 0x0a, 0x1a, 0x52, 0x45, 0x51, 0x55, 0x45, + 0x53, 0x54, 0x5f, 0x52, 0x45, 0x53, 0x55, 0x4c, 0x54, 0x5f, 0x55, 0x4e, 0x53, 0x50, 0x45, 0x43, + 0x49, 0x46, 0x49, 0x45, 0x44, 0x10, 0x00, 0x12, 0x1c, 0x0a, 0x18, 0x52, 0x45, 0x51, 0x55, 0x45, + 0x53, 0x54, 0x5f, 0x52, 0x45, 0x53, 0x55, 0x4c, 0x54, 0x5f, 0x53, 0x43, 0x48, 0x45, 0x44, 0x55, + 0x4c, 0x45, 0x44, 0x10, 0x01, 0x12, 0x1a, 0x0a, 0x16, 0x52, 0x45, 0x51, 0x55, 0x45, 0x53, 0x54, + 0x5f, 0x52, 0x45, 0x53, 0x55, 0x4c, 0x54, 0x5f, 0x53, 0x55, 0x43, 0x43, 0x45, 0x53, 0x53, 0x10, + 0x02, 0x12, 0x1a, 0x0a, 0x16, 0x52, 0x45, 0x51, 0x55, 0x45, 0x53, 0x54, 0x5f, 0x52, 0x45, 0x53, + 0x55, 0x4c, 0x54, 0x5f, 0x46, 0x41, 0x49, 0x4c, 0x55, 0x52, 0x45, 0x10, 0x03, 0x42, 0x98, 0x01, + 0x0a, 0x0c, 0x63, 0x6f, 0x6d, 0x2e, 0x76, 0x31, 0x61, 0x6c, 0x70, 0x68, 0x61, 0x31, 0x42, 0x08, + 0x41, 0x70, 0x69, 0x50, 0x72, 0x6f, 0x74, 0x6f, 0x50, 0x01, 0x5a, 0x3e, 0x67, 0x69, 0x74, 0x68, + 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x69, 0x72, 0x6f, 0x6e, 0x63, 0x6f, 0x72, 0x65, 0x2d, + 0x64, 0x65, 0x76, 0x2f, 0x6d, 0x65, 0x74, 0x61, 0x6c, 0x2d, 0x6f, 0x70, 0x65, 0x72, 0x61, 0x74, + 0x6f, 0x72, 0x2f, 0x61, 0x70, 0x69, 0x2f, 0x67, 0x65, 0x6e, 0x2f, 0x63, 0x6f, 0x6d, 0x6d, 0x6f, + 0x6e, 0x2f, 0x76, 0x31, 0x61, 0x6c, 0x70, 0x68, 0x61, 0x31, 0xa2, 0x02, 0x03, 0x56, 0x58, 0x58, + 0xaa, 0x02, 0x08, 0x56, 0x31, 0x61, 0x6c, 0x70, 0x68, 0x61, 0x31, 0xca, 0x02, 0x08, 0x56, 0x31, + 0x61, 0x6c, 0x70, 0x68, 0x61, 0x31, 0xe2, 0x02, 0x14, 0x56, 0x31, 0x61, 0x6c, 0x70, 0x68, 0x61, + 0x31, 0x5c, 0x47, 0x50, 0x42, 0x4d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0xea, 0x02, 0x08, + 0x56, 0x31, 0x61, 0x6c, 0x70, 0x68, 0x61, 0x31, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, +} + +var ( + file_common_v1alpha1_api_proto_rawDescOnce sync.Once + file_common_v1alpha1_api_proto_rawDescData = file_common_v1alpha1_api_proto_rawDesc +) + +func file_common_v1alpha1_api_proto_rawDescGZIP() []byte { + file_common_v1alpha1_api_proto_rawDescOnce.Do(func() { + file_common_v1alpha1_api_proto_rawDescData = protoimpl.X.CompressGZIP(file_common_v1alpha1_api_proto_rawDescData) + }) + return file_common_v1alpha1_api_proto_rawDescData +} + +var file_common_v1alpha1_api_proto_enumTypes = make([]protoimpl.EnumInfo, 1) +var file_common_v1alpha1_api_proto_goTypes = []interface{}{ + (RequestResult)(0), // 0: v1alpha1.RequestResult +} +var file_common_v1alpha1_api_proto_depIdxs = []int32{ + 0, // [0:0] is the sub-list for method output_type + 0, // [0:0] is the sub-list for method input_type + 0, // [0:0] is the sub-list for extension type_name + 0, // [0:0] is the sub-list for extension extendee + 0, // [0:0] is the sub-list for field type_name +} + +func init() { file_common_v1alpha1_api_proto_init() } +func file_common_v1alpha1_api_proto_init() { + if File_common_v1alpha1_api_proto != nil { + return + } + type x struct{} + out := protoimpl.TypeBuilder{ + File: protoimpl.DescBuilder{ + GoPackagePath: reflect.TypeOf(x{}).PkgPath(), + RawDescriptor: file_common_v1alpha1_api_proto_rawDesc, + NumEnums: 1, + NumMessages: 0, + NumExtensions: 0, + NumServices: 0, + }, + GoTypes: file_common_v1alpha1_api_proto_goTypes, + DependencyIndexes: file_common_v1alpha1_api_proto_depIdxs, + EnumInfos: file_common_v1alpha1_api_proto_enumTypes, + }.Build() + File_common_v1alpha1_api_proto = out.File + file_common_v1alpha1_api_proto_rawDesc = nil + file_common_v1alpha1_api_proto_goTypes = nil + file_common_v1alpha1_api_proto_depIdxs = nil +} diff --git a/api/gen/serverbios/v1alpha1/api.pb.go b/api/gen/serverbios/v1alpha1/api.pb.go new file mode 100644 index 0000000..46fc909 --- /dev/null +++ b/api/gen/serverbios/v1alpha1/api.pb.go @@ -0,0 +1,545 @@ +// Code generated by protoc-gen-go. DO NOT EDIT. +// versions: +// protoc-gen-go v1.32.0 +// protoc (unknown) +// source: serverbios/v1alpha1/api.proto + +package v1alpha1 + +import ( + reflect "reflect" + sync "sync" + + v1alpha1 "github.com/ironcore-dev/metal-operator/api/gen/common/v1alpha1" + protoreflect "google.golang.org/protobuf/reflect/protoreflect" + protoimpl "google.golang.org/protobuf/runtime/protoimpl" +) + +const ( + // Verify that this generated code is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(20 - protoimpl.MinVersion) + // Verify that runtime/protoimpl is sufficiently up-to-date. + _ = protoimpl.EnforceVersion(protoimpl.MaxVersion - 20) +) + +type BIOSScanRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + ServerBiosRef string `protobuf:"bytes,1,opt,name=server_bios_ref,json=serverBiosRef,proto3" json:"server_bios_ref,omitempty"` +} + +func (x *BIOSScanRequest) Reset() { + *x = BIOSScanRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_serverbios_v1alpha1_api_proto_msgTypes[0] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *BIOSScanRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*BIOSScanRequest) ProtoMessage() {} + +func (x *BIOSScanRequest) ProtoReflect() protoreflect.Message { + mi := &file_serverbios_v1alpha1_api_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 BIOSScanRequest.ProtoReflect.Descriptor instead. +func (*BIOSScanRequest) Descriptor() ([]byte, []int) { + return file_serverbios_v1alpha1_api_proto_rawDescGZIP(), []int{0} +} + +func (x *BIOSScanRequest) GetServerBiosRef() string { + if x != nil { + return x.ServerBiosRef + } + return "" +} + +type BIOSScanResponse struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Result v1alpha1.RequestResult `protobuf:"varint,1,opt,name=result,proto3,enum=v1alpha1.RequestResult" json:"result,omitempty"` + Version string `protobuf:"bytes,2,opt,name=version,proto3" json:"version,omitempty"` + Settings map[string]string `protobuf:"bytes,3,rep,name=settings,proto3" json:"settings,omitempty" protobuf_key:"bytes,1,opt,name=key,proto3" protobuf_val:"bytes,2,opt,name=value,proto3"` +} + +func (x *BIOSScanResponse) Reset() { + *x = BIOSScanResponse{} + if protoimpl.UnsafeEnabled { + mi := &file_serverbios_v1alpha1_api_proto_msgTypes[1] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *BIOSScanResponse) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*BIOSScanResponse) ProtoMessage() {} + +func (x *BIOSScanResponse) ProtoReflect() protoreflect.Message { + mi := &file_serverbios_v1alpha1_api_proto_msgTypes[1] + 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 BIOSScanResponse.ProtoReflect.Descriptor instead. +func (*BIOSScanResponse) Descriptor() ([]byte, []int) { + return file_serverbios_v1alpha1_api_proto_rawDescGZIP(), []int{1} +} + +func (x *BIOSScanResponse) GetResult() v1alpha1.RequestResult { + if x != nil { + return x.Result + } + return v1alpha1.RequestResult(0) +} + +func (x *BIOSScanResponse) GetVersion() string { + if x != nil { + return x.Version + } + return "" +} + +func (x *BIOSScanResponse) GetSettings() map[string]string { + if x != nil { + return x.Settings + } + return nil +} + +type BIOSSettingsApplyRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + ServerBiosRef string `protobuf:"bytes,1,opt,name=server_bios_ref,json=serverBiosRef,proto3" json:"server_bios_ref,omitempty"` +} + +func (x *BIOSSettingsApplyRequest) Reset() { + *x = BIOSSettingsApplyRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_serverbios_v1alpha1_api_proto_msgTypes[2] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *BIOSSettingsApplyRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*BIOSSettingsApplyRequest) ProtoMessage() {} + +func (x *BIOSSettingsApplyRequest) ProtoReflect() protoreflect.Message { + mi := &file_serverbios_v1alpha1_api_proto_msgTypes[2] + 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 BIOSSettingsApplyRequest.ProtoReflect.Descriptor instead. +func (*BIOSSettingsApplyRequest) Descriptor() ([]byte, []int) { + return file_serverbios_v1alpha1_api_proto_rawDescGZIP(), []int{2} +} + +func (x *BIOSSettingsApplyRequest) GetServerBiosRef() string { + if x != nil { + return x.ServerBiosRef + } + return "" +} + +type BIOSSettingsApplyResponse struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Result v1alpha1.RequestResult `protobuf:"varint,1,opt,name=result,proto3,enum=v1alpha1.RequestResult" json:"result,omitempty"` + RebootRequired bool `protobuf:"varint,2,opt,name=reboot_required,json=rebootRequired,proto3" json:"reboot_required,omitempty"` +} + +func (x *BIOSSettingsApplyResponse) Reset() { + *x = BIOSSettingsApplyResponse{} + if protoimpl.UnsafeEnabled { + mi := &file_serverbios_v1alpha1_api_proto_msgTypes[3] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *BIOSSettingsApplyResponse) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*BIOSSettingsApplyResponse) ProtoMessage() {} + +func (x *BIOSSettingsApplyResponse) ProtoReflect() protoreflect.Message { + mi := &file_serverbios_v1alpha1_api_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 BIOSSettingsApplyResponse.ProtoReflect.Descriptor instead. +func (*BIOSSettingsApplyResponse) Descriptor() ([]byte, []int) { + return file_serverbios_v1alpha1_api_proto_rawDescGZIP(), []int{3} +} + +func (x *BIOSSettingsApplyResponse) GetResult() v1alpha1.RequestResult { + if x != nil { + return x.Result + } + return v1alpha1.RequestResult(0) +} + +func (x *BIOSSettingsApplyResponse) GetRebootRequired() bool { + if x != nil { + return x.RebootRequired + } + return false +} + +type BIOSVersionUpdateRequest struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + ServerBiosRef string `protobuf:"bytes,1,opt,name=server_bios_ref,json=serverBiosRef,proto3" json:"server_bios_ref,omitempty"` +} + +func (x *BIOSVersionUpdateRequest) Reset() { + *x = BIOSVersionUpdateRequest{} + if protoimpl.UnsafeEnabled { + mi := &file_serverbios_v1alpha1_api_proto_msgTypes[4] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *BIOSVersionUpdateRequest) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*BIOSVersionUpdateRequest) ProtoMessage() {} + +func (x *BIOSVersionUpdateRequest) ProtoReflect() protoreflect.Message { + mi := &file_serverbios_v1alpha1_api_proto_msgTypes[4] + 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 BIOSVersionUpdateRequest.ProtoReflect.Descriptor instead. +func (*BIOSVersionUpdateRequest) Descriptor() ([]byte, []int) { + return file_serverbios_v1alpha1_api_proto_rawDescGZIP(), []int{4} +} + +func (x *BIOSVersionUpdateRequest) GetServerBiosRef() string { + if x != nil { + return x.ServerBiosRef + } + return "" +} + +type BIOSVersionUpdateResponse struct { + state protoimpl.MessageState + sizeCache protoimpl.SizeCache + unknownFields protoimpl.UnknownFields + + Result v1alpha1.RequestResult `protobuf:"varint,1,opt,name=result,proto3,enum=v1alpha1.RequestResult" json:"result,omitempty"` +} + +func (x *BIOSVersionUpdateResponse) Reset() { + *x = BIOSVersionUpdateResponse{} + if protoimpl.UnsafeEnabled { + mi := &file_serverbios_v1alpha1_api_proto_msgTypes[5] + ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) + ms.StoreMessageInfo(mi) + } +} + +func (x *BIOSVersionUpdateResponse) String() string { + return protoimpl.X.MessageStringOf(x) +} + +func (*BIOSVersionUpdateResponse) ProtoMessage() {} + +func (x *BIOSVersionUpdateResponse) ProtoReflect() protoreflect.Message { + mi := &file_serverbios_v1alpha1_api_proto_msgTypes[5] + 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 BIOSVersionUpdateResponse.ProtoReflect.Descriptor instead. +func (*BIOSVersionUpdateResponse) Descriptor() ([]byte, []int) { + return file_serverbios_v1alpha1_api_proto_rawDescGZIP(), []int{5} +} + +func (x *BIOSVersionUpdateResponse) GetResult() v1alpha1.RequestResult { + if x != nil { + return x.Result + } + return v1alpha1.RequestResult(0) +} + +var File_serverbios_v1alpha1_api_proto protoreflect.FileDescriptor + +var file_serverbios_v1alpha1_api_proto_rawDesc = []byte{ + 0x0a, 0x1d, 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x62, 0x69, 0x6f, 0x73, 0x2f, 0x76, 0x31, 0x61, + 0x6c, 0x70, 0x68, 0x61, 0x31, 0x2f, 0x61, 0x70, 0x69, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, + 0x08, 0x76, 0x31, 0x61, 0x6c, 0x70, 0x68, 0x61, 0x31, 0x1a, 0x19, 0x63, 0x6f, 0x6d, 0x6d, 0x6f, + 0x6e, 0x2f, 0x76, 0x31, 0x61, 0x6c, 0x70, 0x68, 0x61, 0x31, 0x2f, 0x61, 0x70, 0x69, 0x2e, 0x70, + 0x72, 0x6f, 0x74, 0x6f, 0x22, 0x39, 0x0a, 0x0f, 0x42, 0x49, 0x4f, 0x53, 0x53, 0x63, 0x61, 0x6e, + 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x26, 0x0a, 0x0f, 0x73, 0x65, 0x72, 0x76, 0x65, + 0x72, 0x5f, 0x62, 0x69, 0x6f, 0x73, 0x5f, 0x72, 0x65, 0x66, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, + 0x52, 0x0d, 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x42, 0x69, 0x6f, 0x73, 0x52, 0x65, 0x66, 0x22, + 0xe0, 0x01, 0x0a, 0x10, 0x42, 0x49, 0x4f, 0x53, 0x53, 0x63, 0x61, 0x6e, 0x52, 0x65, 0x73, 0x70, + 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x2f, 0x0a, 0x06, 0x72, 0x65, 0x73, 0x75, 0x6c, 0x74, 0x18, 0x01, + 0x20, 0x01, 0x28, 0x0e, 0x32, 0x17, 0x2e, 0x76, 0x31, 0x61, 0x6c, 0x70, 0x68, 0x61, 0x31, 0x2e, + 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x52, 0x65, 0x73, 0x75, 0x6c, 0x74, 0x52, 0x06, 0x72, + 0x65, 0x73, 0x75, 0x6c, 0x74, 0x12, 0x18, 0x0a, 0x07, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, + 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x12, + 0x44, 0x0a, 0x08, 0x73, 0x65, 0x74, 0x74, 0x69, 0x6e, 0x67, 0x73, 0x18, 0x03, 0x20, 0x03, 0x28, + 0x0b, 0x32, 0x28, 0x2e, 0x76, 0x31, 0x61, 0x6c, 0x70, 0x68, 0x61, 0x31, 0x2e, 0x42, 0x49, 0x4f, + 0x53, 0x53, 0x63, 0x61, 0x6e, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x2e, 0x53, 0x65, + 0x74, 0x74, 0x69, 0x6e, 0x67, 0x73, 0x45, 0x6e, 0x74, 0x72, 0x79, 0x52, 0x08, 0x73, 0x65, 0x74, + 0x74, 0x69, 0x6e, 0x67, 0x73, 0x1a, 0x3b, 0x0a, 0x0d, 0x53, 0x65, 0x74, 0x74, 0x69, 0x6e, 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, 0x14, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, + 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x3a, 0x02, + 0x38, 0x01, 0x22, 0x42, 0x0a, 0x18, 0x42, 0x49, 0x4f, 0x53, 0x53, 0x65, 0x74, 0x74, 0x69, 0x6e, + 0x67, 0x73, 0x41, 0x70, 0x70, 0x6c, 0x79, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x26, + 0x0a, 0x0f, 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x5f, 0x62, 0x69, 0x6f, 0x73, 0x5f, 0x72, 0x65, + 0x66, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0d, 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x42, + 0x69, 0x6f, 0x73, 0x52, 0x65, 0x66, 0x22, 0x75, 0x0a, 0x19, 0x42, 0x49, 0x4f, 0x53, 0x53, 0x65, + 0x74, 0x74, 0x69, 0x6e, 0x67, 0x73, 0x41, 0x70, 0x70, 0x6c, 0x79, 0x52, 0x65, 0x73, 0x70, 0x6f, + 0x6e, 0x73, 0x65, 0x12, 0x2f, 0x0a, 0x06, 0x72, 0x65, 0x73, 0x75, 0x6c, 0x74, 0x18, 0x01, 0x20, + 0x01, 0x28, 0x0e, 0x32, 0x17, 0x2e, 0x76, 0x31, 0x61, 0x6c, 0x70, 0x68, 0x61, 0x31, 0x2e, 0x52, + 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x52, 0x65, 0x73, 0x75, 0x6c, 0x74, 0x52, 0x06, 0x72, 0x65, + 0x73, 0x75, 0x6c, 0x74, 0x12, 0x27, 0x0a, 0x0f, 0x72, 0x65, 0x62, 0x6f, 0x6f, 0x74, 0x5f, 0x72, + 0x65, 0x71, 0x75, 0x69, 0x72, 0x65, 0x64, 0x18, 0x02, 0x20, 0x01, 0x28, 0x08, 0x52, 0x0e, 0x72, + 0x65, 0x62, 0x6f, 0x6f, 0x74, 0x52, 0x65, 0x71, 0x75, 0x69, 0x72, 0x65, 0x64, 0x22, 0x42, 0x0a, + 0x18, 0x42, 0x49, 0x4f, 0x53, 0x56, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x55, 0x70, 0x64, 0x61, + 0x74, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x26, 0x0a, 0x0f, 0x73, 0x65, 0x72, + 0x76, 0x65, 0x72, 0x5f, 0x62, 0x69, 0x6f, 0x73, 0x5f, 0x72, 0x65, 0x66, 0x18, 0x01, 0x20, 0x01, + 0x28, 0x09, 0x52, 0x0d, 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x42, 0x69, 0x6f, 0x73, 0x52, 0x65, + 0x66, 0x22, 0x4c, 0x0a, 0x19, 0x42, 0x49, 0x4f, 0x53, 0x56, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, + 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x2f, + 0x0a, 0x06, 0x72, 0x65, 0x73, 0x75, 0x6c, 0x74, 0x18, 0x01, 0x20, 0x01, 0x28, 0x0e, 0x32, 0x17, + 0x2e, 0x76, 0x31, 0x61, 0x6c, 0x70, 0x68, 0x61, 0x31, 0x2e, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, + 0x74, 0x52, 0x65, 0x73, 0x75, 0x6c, 0x74, 0x52, 0x06, 0x72, 0x65, 0x73, 0x75, 0x6c, 0x74, 0x32, + 0x92, 0x02, 0x0a, 0x11, 0x53, 0x65, 0x72, 0x76, 0x65, 0x72, 0x42, 0x49, 0x4f, 0x53, 0x53, 0x65, + 0x72, 0x76, 0x69, 0x63, 0x65, 0x12, 0x41, 0x0a, 0x08, 0x42, 0x49, 0x4f, 0x53, 0x53, 0x63, 0x61, + 0x6e, 0x12, 0x19, 0x2e, 0x76, 0x31, 0x61, 0x6c, 0x70, 0x68, 0x61, 0x31, 0x2e, 0x42, 0x49, 0x4f, + 0x53, 0x53, 0x63, 0x61, 0x6e, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1a, 0x2e, 0x76, + 0x31, 0x61, 0x6c, 0x70, 0x68, 0x61, 0x31, 0x2e, 0x42, 0x49, 0x4f, 0x53, 0x53, 0x63, 0x61, 0x6e, + 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x5c, 0x0a, 0x11, 0x42, 0x49, 0x4f, 0x53, + 0x53, 0x65, 0x74, 0x74, 0x69, 0x6e, 0x67, 0x73, 0x41, 0x70, 0x70, 0x6c, 0x79, 0x12, 0x22, 0x2e, + 0x76, 0x31, 0x61, 0x6c, 0x70, 0x68, 0x61, 0x31, 0x2e, 0x42, 0x49, 0x4f, 0x53, 0x53, 0x65, 0x74, + 0x74, 0x69, 0x6e, 0x67, 0x73, 0x41, 0x70, 0x70, 0x6c, 0x79, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, + 0x74, 0x1a, 0x23, 0x2e, 0x76, 0x31, 0x61, 0x6c, 0x70, 0x68, 0x61, 0x31, 0x2e, 0x42, 0x49, 0x4f, + 0x53, 0x53, 0x65, 0x74, 0x74, 0x69, 0x6e, 0x67, 0x73, 0x41, 0x70, 0x70, 0x6c, 0x79, 0x52, 0x65, + 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x5c, 0x0a, 0x11, 0x42, 0x49, 0x4f, 0x53, 0x56, 0x65, + 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x12, 0x22, 0x2e, 0x76, 0x31, + 0x61, 0x6c, 0x70, 0x68, 0x61, 0x31, 0x2e, 0x42, 0x49, 0x4f, 0x53, 0x56, 0x65, 0x72, 0x73, 0x69, + 0x6f, 0x6e, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, + 0x23, 0x2e, 0x76, 0x31, 0x61, 0x6c, 0x70, 0x68, 0x61, 0x31, 0x2e, 0x42, 0x49, 0x4f, 0x53, 0x56, + 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x52, 0x65, 0x73, 0x70, + 0x6f, 0x6e, 0x73, 0x65, 0x42, 0x9c, 0x01, 0x0a, 0x0c, 0x63, 0x6f, 0x6d, 0x2e, 0x76, 0x31, 0x61, + 0x6c, 0x70, 0x68, 0x61, 0x31, 0x42, 0x08, 0x41, 0x70, 0x69, 0x50, 0x72, 0x6f, 0x74, 0x6f, 0x50, + 0x01, 0x5a, 0x42, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x69, 0x72, + 0x6f, 0x6e, 0x63, 0x6f, 0x72, 0x65, 0x2d, 0x64, 0x65, 0x76, 0x2f, 0x6d, 0x65, 0x74, 0x61, 0x6c, + 0x2d, 0x6f, 0x70, 0x65, 0x72, 0x61, 0x74, 0x6f, 0x72, 0x2f, 0x61, 0x70, 0x69, 0x2f, 0x67, 0x65, + 0x6e, 0x2f, 0x73, 0x65, 0x72, 0x76, 0x65, 0x72, 0x62, 0x69, 0x6f, 0x73, 0x2f, 0x76, 0x31, 0x61, + 0x6c, 0x70, 0x68, 0x61, 0x31, 0xa2, 0x02, 0x03, 0x56, 0x58, 0x58, 0xaa, 0x02, 0x08, 0x56, 0x31, + 0x61, 0x6c, 0x70, 0x68, 0x61, 0x31, 0xca, 0x02, 0x08, 0x56, 0x31, 0x61, 0x6c, 0x70, 0x68, 0x61, + 0x31, 0xe2, 0x02, 0x14, 0x56, 0x31, 0x61, 0x6c, 0x70, 0x68, 0x61, 0x31, 0x5c, 0x47, 0x50, 0x42, + 0x4d, 0x65, 0x74, 0x61, 0x64, 0x61, 0x74, 0x61, 0xea, 0x02, 0x08, 0x56, 0x31, 0x61, 0x6c, 0x70, + 0x68, 0x61, 0x31, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33, +} + +var ( + file_serverbios_v1alpha1_api_proto_rawDescOnce sync.Once + file_serverbios_v1alpha1_api_proto_rawDescData = file_serverbios_v1alpha1_api_proto_rawDesc +) + +func file_serverbios_v1alpha1_api_proto_rawDescGZIP() []byte { + file_serverbios_v1alpha1_api_proto_rawDescOnce.Do(func() { + file_serverbios_v1alpha1_api_proto_rawDescData = protoimpl.X.CompressGZIP(file_serverbios_v1alpha1_api_proto_rawDescData) + }) + return file_serverbios_v1alpha1_api_proto_rawDescData +} + +var file_serverbios_v1alpha1_api_proto_msgTypes = make([]protoimpl.MessageInfo, 7) +var file_serverbios_v1alpha1_api_proto_goTypes = []interface{}{ + (*BIOSScanRequest)(nil), // 0: v1alpha1.BIOSScanRequest + (*BIOSScanResponse)(nil), // 1: v1alpha1.BIOSScanResponse + (*BIOSSettingsApplyRequest)(nil), // 2: v1alpha1.BIOSSettingsApplyRequest + (*BIOSSettingsApplyResponse)(nil), // 3: v1alpha1.BIOSSettingsApplyResponse + (*BIOSVersionUpdateRequest)(nil), // 4: v1alpha1.BIOSVersionUpdateRequest + (*BIOSVersionUpdateResponse)(nil), // 5: v1alpha1.BIOSVersionUpdateResponse + nil, // 6: v1alpha1.BIOSScanResponse.SettingsEntry + (v1alpha1.RequestResult)(0), // 7: v1alpha1.RequestResult +} +var file_serverbios_v1alpha1_api_proto_depIdxs = []int32{ + 7, // 0: v1alpha1.BIOSScanResponse.result:type_name -> v1alpha1.RequestResult + 6, // 1: v1alpha1.BIOSScanResponse.settings:type_name -> v1alpha1.BIOSScanResponse.SettingsEntry + 7, // 2: v1alpha1.BIOSSettingsApplyResponse.result:type_name -> v1alpha1.RequestResult + 7, // 3: v1alpha1.BIOSVersionUpdateResponse.result:type_name -> v1alpha1.RequestResult + 0, // 4: v1alpha1.ServerBIOSService.BIOSScan:input_type -> v1alpha1.BIOSScanRequest + 2, // 5: v1alpha1.ServerBIOSService.BIOSSettingsApply:input_type -> v1alpha1.BIOSSettingsApplyRequest + 4, // 6: v1alpha1.ServerBIOSService.BIOSVersionUpdate:input_type -> v1alpha1.BIOSVersionUpdateRequest + 1, // 7: v1alpha1.ServerBIOSService.BIOSScan:output_type -> v1alpha1.BIOSScanResponse + 3, // 8: v1alpha1.ServerBIOSService.BIOSSettingsApply:output_type -> v1alpha1.BIOSSettingsApplyResponse + 5, // 9: v1alpha1.ServerBIOSService.BIOSVersionUpdate:output_type -> v1alpha1.BIOSVersionUpdateResponse + 7, // [7:10] is the sub-list for method output_type + 4, // [4:7] 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_serverbios_v1alpha1_api_proto_init() } +func file_serverbios_v1alpha1_api_proto_init() { + if File_serverbios_v1alpha1_api_proto != nil { + return + } + if !protoimpl.UnsafeEnabled { + file_serverbios_v1alpha1_api_proto_msgTypes[0].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*BIOSScanRequest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_serverbios_v1alpha1_api_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*BIOSScanResponse); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_serverbios_v1alpha1_api_proto_msgTypes[2].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*BIOSSettingsApplyRequest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_serverbios_v1alpha1_api_proto_msgTypes[3].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*BIOSSettingsApplyResponse); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_serverbios_v1alpha1_api_proto_msgTypes[4].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*BIOSVersionUpdateRequest); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + file_serverbios_v1alpha1_api_proto_msgTypes[5].Exporter = func(v interface{}, i int) interface{} { + switch v := v.(*BIOSVersionUpdateResponse); i { + case 0: + return &v.state + case 1: + return &v.sizeCache + case 2: + return &v.unknownFields + default: + return nil + } + } + } + type x struct{} + out := protoimpl.TypeBuilder{ + File: protoimpl.DescBuilder{ + GoPackagePath: reflect.TypeOf(x{}).PkgPath(), + RawDescriptor: file_serverbios_v1alpha1_api_proto_rawDesc, + NumEnums: 0, + NumMessages: 7, + NumExtensions: 0, + NumServices: 1, + }, + GoTypes: file_serverbios_v1alpha1_api_proto_goTypes, + DependencyIndexes: file_serverbios_v1alpha1_api_proto_depIdxs, + MessageInfos: file_serverbios_v1alpha1_api_proto_msgTypes, + }.Build() + File_serverbios_v1alpha1_api_proto = out.File + file_serverbios_v1alpha1_api_proto_rawDesc = nil + file_serverbios_v1alpha1_api_proto_goTypes = nil + file_serverbios_v1alpha1_api_proto_depIdxs = nil +} diff --git a/api/gen/serverbios/v1alpha1/api_grpc.pb.go b/api/gen/serverbios/v1alpha1/api_grpc.pb.go new file mode 100644 index 0000000..789f524 --- /dev/null +++ b/api/gen/serverbios/v1alpha1/api_grpc.pb.go @@ -0,0 +1,196 @@ +// Code generated by protoc-gen-go-grpc. DO NOT EDIT. +// versions: +// - protoc-gen-go-grpc v1.5.1 +// - protoc (unknown) +// source: serverbios/v1alpha1/api.proto + +package v1alpha1 + +import ( + context "context" + + grpc "google.golang.org/grpc" + codes "google.golang.org/grpc/codes" + status "google.golang.org/grpc/status" +) + +// This is a compile-time assertion to ensure that this generated file +// is compatible with the grpc package it is being compiled against. +// Requires gRPC-Go v1.64.0 or later. +const _ = grpc.SupportPackageIsVersion9 + +const ( + ServerBIOSService_BIOSScan_FullMethodName = "/v1alpha1.ServerBIOSService/BIOSScan" + ServerBIOSService_BIOSSettingsApply_FullMethodName = "/v1alpha1.ServerBIOSService/BIOSSettingsApply" + ServerBIOSService_BIOSVersionUpdate_FullMethodName = "/v1alpha1.ServerBIOSService/BIOSVersionUpdate" +) + +// ServerBIOSServiceClient is the client API for ServerBIOSService service. +// +// For semantics around ctx use and closing/ending streaming RPCs, please refer to https://pkg.go.dev/google.golang.org/grpc/?tab=doc#ClientConn.NewStream. +type ServerBIOSServiceClient interface { + BIOSScan(ctx context.Context, in *BIOSScanRequest, opts ...grpc.CallOption) (*BIOSScanResponse, error) + BIOSSettingsApply(ctx context.Context, in *BIOSSettingsApplyRequest, opts ...grpc.CallOption) (*BIOSSettingsApplyResponse, error) + BIOSVersionUpdate(ctx context.Context, in *BIOSVersionUpdateRequest, opts ...grpc.CallOption) (*BIOSVersionUpdateResponse, error) +} + +type serverBIOSServiceClient struct { + cc grpc.ClientConnInterface +} + +func NewServerBIOSServiceClient(cc grpc.ClientConnInterface) ServerBIOSServiceClient { + return &serverBIOSServiceClient{cc} +} + +func (c *serverBIOSServiceClient) BIOSScan(ctx context.Context, in *BIOSScanRequest, opts ...grpc.CallOption) (*BIOSScanResponse, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) + out := new(BIOSScanResponse) + err := c.cc.Invoke(ctx, ServerBIOSService_BIOSScan_FullMethodName, in, out, cOpts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *serverBIOSServiceClient) BIOSSettingsApply(ctx context.Context, in *BIOSSettingsApplyRequest, opts ...grpc.CallOption) (*BIOSSettingsApplyResponse, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) + out := new(BIOSSettingsApplyResponse) + err := c.cc.Invoke(ctx, ServerBIOSService_BIOSSettingsApply_FullMethodName, in, out, cOpts...) + if err != nil { + return nil, err + } + return out, nil +} + +func (c *serverBIOSServiceClient) BIOSVersionUpdate(ctx context.Context, in *BIOSVersionUpdateRequest, opts ...grpc.CallOption) (*BIOSVersionUpdateResponse, error) { + cOpts := append([]grpc.CallOption{grpc.StaticMethod()}, opts...) + out := new(BIOSVersionUpdateResponse) + err := c.cc.Invoke(ctx, ServerBIOSService_BIOSVersionUpdate_FullMethodName, in, out, cOpts...) + if err != nil { + return nil, err + } + return out, nil +} + +// ServerBIOSServiceServer is the server API for ServerBIOSService service. +// All implementations should embed UnimplementedServerBIOSServiceServer +// for forward compatibility. +type ServerBIOSServiceServer interface { + BIOSScan(context.Context, *BIOSScanRequest) (*BIOSScanResponse, error) + BIOSSettingsApply(context.Context, *BIOSSettingsApplyRequest) (*BIOSSettingsApplyResponse, error) + BIOSVersionUpdate(context.Context, *BIOSVersionUpdateRequest) (*BIOSVersionUpdateResponse, error) +} + +// UnimplementedServerBIOSServiceServer should be embedded to have +// forward compatible implementations. +// +// NOTE: this should be embedded by value instead of pointer to avoid a nil +// pointer dereference when methods are called. +type UnimplementedServerBIOSServiceServer struct{} + +func (UnimplementedServerBIOSServiceServer) BIOSScan(context.Context, *BIOSScanRequest) (*BIOSScanResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method BIOSScan not implemented") +} +func (UnimplementedServerBIOSServiceServer) BIOSSettingsApply(context.Context, *BIOSSettingsApplyRequest) (*BIOSSettingsApplyResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method BIOSSettingsApply not implemented") +} +func (UnimplementedServerBIOSServiceServer) BIOSVersionUpdate(context.Context, *BIOSVersionUpdateRequest) (*BIOSVersionUpdateResponse, error) { + return nil, status.Errorf(codes.Unimplemented, "method BIOSVersionUpdate not implemented") +} +func (UnimplementedServerBIOSServiceServer) testEmbeddedByValue() {} + +// UnsafeServerBIOSServiceServer may be embedded to opt out of forward compatibility for this service. +// Use of this interface is not recommended, as added methods to ServerBIOSServiceServer will +// result in compilation errors. +type UnsafeServerBIOSServiceServer interface { + mustEmbedUnimplementedServerBIOSServiceServer() +} + +func RegisterServerBIOSServiceServer(s grpc.ServiceRegistrar, srv ServerBIOSServiceServer) { + // If the following call pancis, it indicates UnimplementedServerBIOSServiceServer was + // embedded by pointer and is nil. This will cause panics if an + // unimplemented method is ever invoked, so we test this at initialization + // time to prevent it from happening at runtime later due to I/O. + if t, ok := srv.(interface{ testEmbeddedByValue() }); ok { + t.testEmbeddedByValue() + } + s.RegisterService(&ServerBIOSService_ServiceDesc, srv) +} + +func _ServerBIOSService_BIOSScan_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(BIOSScanRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(ServerBIOSServiceServer).BIOSScan(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: ServerBIOSService_BIOSScan_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(ServerBIOSServiceServer).BIOSScan(ctx, req.(*BIOSScanRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _ServerBIOSService_BIOSSettingsApply_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(BIOSSettingsApplyRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(ServerBIOSServiceServer).BIOSSettingsApply(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: ServerBIOSService_BIOSSettingsApply_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(ServerBIOSServiceServer).BIOSSettingsApply(ctx, req.(*BIOSSettingsApplyRequest)) + } + return interceptor(ctx, in, info, handler) +} + +func _ServerBIOSService_BIOSVersionUpdate_Handler(srv interface{}, ctx context.Context, dec func(interface{}) error, interceptor grpc.UnaryServerInterceptor) (interface{}, error) { + in := new(BIOSVersionUpdateRequest) + if err := dec(in); err != nil { + return nil, err + } + if interceptor == nil { + return srv.(ServerBIOSServiceServer).BIOSVersionUpdate(ctx, in) + } + info := &grpc.UnaryServerInfo{ + Server: srv, + FullMethod: ServerBIOSService_BIOSVersionUpdate_FullMethodName, + } + handler := func(ctx context.Context, req interface{}) (interface{}, error) { + return srv.(ServerBIOSServiceServer).BIOSVersionUpdate(ctx, req.(*BIOSVersionUpdateRequest)) + } + return interceptor(ctx, in, info, handler) +} + +// ServerBIOSService_ServiceDesc is the grpc.ServiceDesc for ServerBIOSService service. +// It's only intended for direct use with grpc.RegisterService, +// and not to be introspected or modified (even as a copy) +var ServerBIOSService_ServiceDesc = grpc.ServiceDesc{ + ServiceName: "v1alpha1.ServerBIOSService", + HandlerType: (*ServerBIOSServiceServer)(nil), + Methods: []grpc.MethodDesc{ + { + MethodName: "BIOSScan", + Handler: _ServerBIOSService_BIOSScan_Handler, + }, + { + MethodName: "BIOSSettingsApply", + Handler: _ServerBIOSService_BIOSSettingsApply_Handler, + }, + { + MethodName: "BIOSVersionUpdate", + Handler: _ServerBIOSService_BIOSVersionUpdate_Handler, + }, + }, + Streams: []grpc.StreamDesc{}, + Metadata: "serverbios/v1alpha1/api.proto", +} diff --git a/api/proto/buf.yaml b/api/proto/buf.yaml new file mode 100644 index 0000000..98208c1 --- /dev/null +++ b/api/proto/buf.yaml @@ -0,0 +1,8 @@ +version: v1 +breaking: + use: + - FILE +lint: + use: + - DEFAULT +deps: [] diff --git a/api/proto/common/v1alpha1/api.proto b/api/proto/common/v1alpha1/api.proto new file mode 100644 index 0000000..0fdf3e1 --- /dev/null +++ b/api/proto/common/v1alpha1/api.proto @@ -0,0 +1,12 @@ +syntax = "proto3"; + +package v1alpha1; + +option go_package = "github.com/ironcore-dev/metal-operator/api/gen/common/v1alpha1"; + +enum RequestResult { + REQUEST_RESULT_UNSPECIFIED = 0; + REQUEST_RESULT_SCHEDULED = 1; + REQUEST_RESULT_SUCCESS = 2; + REQUEST_RESULT_FAILURE = 3; +} diff --git a/api/proto/serverbios/v1alpha1/api.proto b/api/proto/serverbios/v1alpha1/api.proto new file mode 100644 index 0000000..6eb2083 --- /dev/null +++ b/api/proto/serverbios/v1alpha1/api.proto @@ -0,0 +1,40 @@ +syntax = "proto3"; + +package v1alpha1; + +import "common/v1alpha1/api.proto"; + +option go_package = "github.com/ironcore-dev/metal-operator/api/gen/serverbios/v1alpha1"; + +message BIOSScanRequest { + string server_bios_ref = 1; +} + +message BIOSScanResponse { + v1alpha1.RequestResult result = 1; + string version = 2; + map settings = 3; +} + +message BIOSSettingsApplyRequest { + string server_bios_ref = 1; +} + +message BIOSSettingsApplyResponse { + v1alpha1.RequestResult result = 1; + bool reboot_required = 2; +} + +message BIOSVersionUpdateRequest { + string server_bios_ref = 1; +} + +message BIOSVersionUpdateResponse { + v1alpha1.RequestResult result = 1; +} + +service ServerBIOSService { + rpc BIOSScan(BIOSScanRequest) returns (BIOSScanResponse); + rpc BIOSSettingsApply(BIOSSettingsApplyRequest) returns (BIOSSettingsApplyResponse); + rpc BIOSVersionUpdate(BIOSVersionUpdateRequest) returns (BIOSVersionUpdateResponse); +} diff --git a/api/v1alpha1/server_types.go b/api/v1alpha1/server_types.go index 0b826b5..2f3b9c0 100644 --- a/api/v1alpha1/server_types.go +++ b/api/v1alpha1/server_types.go @@ -98,7 +98,7 @@ type ServerSpec struct { BootOrder []BootOrder `json:"bootOrder,omitempty"` // BIOSSettingsRef is a reference to a ServerBIOS object. - BIOSSettingsRef v1.LocalObjectReference `json:"biOSSettingsRef,omitempty"` + BIOSSettingsRef v1.LocalObjectReference `json:"biosSettingsRef,omitempty"` } // ServerState defines the possible states of a server. diff --git a/api/v1alpha1/serverbios_types.go b/api/v1alpha1/serverbios_types.go index fe7aac8..ab74b8e 100644 --- a/api/v1alpha1/serverbios_types.go +++ b/api/v1alpha1/serverbios_types.go @@ -13,11 +13,6 @@ import ( // ServerBIOSSpec defines the desired state of ServerBIOS type ServerBIOSSpec struct { - // ScanPeriodMinutes defines the period in minutes after which scanned data is considered obsolete. - // +kubebuilder:default=30 - // +optional - ScanPeriodMinutes int32 `json:"scanPeriodMinutes,omitempty"` - // ServerRef is a reference to Server object // +optional ServerRef v1.LocalObjectReference `json:"serverRef,omitempty"` diff --git a/buf.gen.yaml b/buf.gen.yaml new file mode 100644 index 0000000..d0065d6 --- /dev/null +++ b/buf.gen.yaml @@ -0,0 +1,15 @@ +version: v2 +managed: + enabled: true +plugins: + - remote: buf.build/protocolbuffers/go:v1.32.0 + out: api/gen + opt: + - paths=source_relative + - local: ["go", "run", "google.golang.org/grpc/cmd/protoc-gen-go-grpc@v1.5.1"] + out: api/gen + opt: + - paths=source_relative + - require_unimplemented_servers=false +inputs: + - directory: api/proto diff --git a/cmd/fmiserver/main.go b/cmd/fmiserver/main.go new file mode 100644 index 0000000..bb6fe88 --- /dev/null +++ b/cmd/fmiserver/main.go @@ -0,0 +1,71 @@ +package main + +import ( + "context" + "flag" + "log/slog" + "os" + "os/signal" + "time" + + metalv1alpha1 "github.com/ironcore-dev/metal-operator/api/v1alpha1" + "github.com/ironcore-dev/metal-operator/fmi" + "k8s.io/apimachinery/pkg/runtime" + utilruntime "k8s.io/apimachinery/pkg/util/runtime" + clientgoscheme "k8s.io/client-go/kubernetes/scheme" + ctrl "sigs.k8s.io/controller-runtime" + "sigs.k8s.io/controller-runtime/pkg/client" +) + +var ( + scheme = runtime.NewScheme() + setupLog = slog.Default().WithGroup("setup") +) + +func init() { + utilruntime.Must(clientgoscheme.AddToScheme(scheme)) + utilruntime.Must(metalv1alpha1.AddToScheme(scheme)) + // +kubebuilder:scaffold:scheme +} + +func main() { + var ( + port int + shutdownTimeoutSeconds int + insecureBMC bool + taskRunnerType string + ) + + flag.IntVar(&port, "port", 9080, "The port to listen on") + flag.IntVar(&shutdownTimeoutSeconds, "shutdown-timeout-seconds", 10, "The timeout to wait for the server to shutdown") + flag.BoolVar(&insecureBMC, "insecure-bmc", true, "Whether to use insecure connection to BMC") + flag.StringVar(&taskRunnerType, "task-runner-type", "default", "The type of task runner to use") + flag.Parse() + + cfg := ctrl.GetConfigOrDie() + c, err := client.New(cfg, client.Options{Scheme: scheme}) + if err != nil { + setupLog.Error("unable to create client", slog.Any("err", err)) + os.Exit(1) + } + + setupLog.Info("starting fmi server") + config := fmi.ServerConfig{ + Port: port, + ShutdownTimeout: time.Second * time.Duration(shutdownTimeoutSeconds), + KubeClient: c, + TaskRunnerType: taskRunnerType, + } + server, err := fmi.NewServerGRPC(config, insecureBMC) + if err != nil { + setupLog.Error("failed to create server", slog.Any("err", err)) + os.Exit(1) + } + ctx, cancel := signal.NotifyContext(context.Background(), os.Interrupt) + defer cancel() + + if err := server.Start(ctx); err != nil { + setupLog.Error("failed to start server", slog.Any("err", err)) + os.Exit(1) + } +} diff --git a/cmd/manager/main.go b/cmd/manager/main.go index 58c71bb..52fa345 100644 --- a/cmd/manager/main.go +++ b/cmd/manager/main.go @@ -66,27 +66,24 @@ func main() { powerPollingInterval time.Duration powerPollingTimeout time.Duration discoveryTimeout time.Duration + fmiClientType string fmiServerAddress string - fmiServerProtocol string - fmiClientCAFile string + fmiCACertFile string fmiClientCertFile string fmiClientKeyFile string - fmiClientInsecure bool - fmiServerShutdownTimeout time.Duration + fmiInsecureSkipVerify bool + fmiRequestTimeout time.Duration serverBIOSResyncInterval time.Duration ) + flag.StringVar(&fmiClientType, "fmi-client-type", "grpc", "The type of FMI client to use. Values: 'grpc', 'http'.") flag.StringVar(&fmiServerAddress, "fmi-server-address", "localhost:11000", "The address the BIOS task runner binds to.") - flag.StringVar(&fmiServerProtocol, "fmi-server-protocol", "http", "The protocol of the BIOS task runner.") - flag.StringVar(&fmiClientCAFile, "fmi-client-ca-file", "", "File containing the CA to verify the BIOS task runner.") - flag.StringVar(&fmiClientCertFile, "fmi-client-cert-file", "", - "File containing the client certificate for the BIOS task runner.") - flag.StringVar(&fmiClientKeyFile, "fmi-client-key-file", "", - "File containing the client key for the BIOS task runner.") - flag.BoolVar(&fmiClientInsecure, "fmi-client-insecure", true, "Skip TLS verification for the BIOS task runner.") - flag.DurationVar(&fmiServerShutdownTimeout, "fmi-server-shutdown-timeout", 5*time.Second, - "Timeout for FMI server graceful shutdown") + flag.StringVar(&fmiCACertFile, "fmi-ca-cert-file", "", "Path to the CA certificate file.") + flag.StringVar(&fmiClientCertFile, "fmi-client-cert-file", "", "Path to the client certificate file.") + flag.StringVar(&fmiClientKeyFile, "fmi-client-key-file", "", "Path to the client key file.") + flag.BoolVar(&fmiInsecureSkipVerify, "fmi-insecure-skip-verify", false, "Skip TLS verification for FMI client.") + flag.DurationVar(&fmiRequestTimeout, "fmi-request-timeout", 5*time.Second, "Timeout for BIOS task runner requests.") flag.DurationVar(&serverBIOSResyncInterval, "server-bios-resync-interval", 10*time.Second, "Timeout for BIOS resync") flag.DurationVar(&discoveryTimeout, "discovery-timeout", 30*time.Minute, "Timeout for discovery boot") flag.DurationVar(&powerPollingInterval, "power-polling-interval", 5*time.Second, @@ -177,6 +174,19 @@ func main() { TLSOpts: tlsOpts, }) + fmiClient, err := fmi.NewClientForConfig(fmiClientType, fmi.ClientConfig{ + ServerURL: fmiServerAddress, + CAFile: fmiCACertFile, + CertFile: fmiClientCertFile, + KeyFile: fmiClientKeyFile, + InsecureSkipVerify: fmiInsecureSkipVerify, + RequestTimeout: fmiRequestTimeout, + }) + if err != nil { + setupLog.Error(err, "failed to create FMI client") + os.Exit(1) + } + mgr, err := ctrl.NewManager(ctrl.GetConfigOrDie(), ctrl.Options{ Scheme: scheme, Metrics: metricsserver.Options{ @@ -205,21 +215,6 @@ func main() { os.Exit(1) } - biosTaskRunnerClient, err := fmi.NewClientForConfig(fmi.ClientConfig{ - ServerURL: fmt.Sprintf("%s://%s", fmiServerProtocol, fmiServerAddress), - ScanEndpoint: "scan", - SettingsApplyEndpoint: "settings-apply", - VersionUpdateEndpoint: "version-update", - CAFile: fmiClientCAFile, - CertFile: fmiClientCertFile, - KeyFile: fmiClientKeyFile, - InsecureSkipVerify: fmiClientInsecure, - }) - if err != nil { - setupLog.Error(err, "unable to create FMI client") - os.Exit(1) - } - if err = (&controller.EndpointReconciler{ Client: mgr.GetClient(), Scheme: mgr.GetScheme(), @@ -278,10 +273,10 @@ func main() { os.Exit(1) } if err = (&controller.ServerBIOSReconciler{ - Client: mgr.GetClient(), - Scheme: mgr.GetScheme(), - TaskExecutor: biosTaskRunnerClient, - RequeueInterval: serverBIOSResyncInterval, + Client: mgr.GetClient(), + Scheme: mgr.GetScheme(), + TaskRunnerClient: fmiClient, + RequeueInterval: serverBIOSResyncInterval, }).SetupWithManager(mgr); err != nil { setupLog.Error(err, "unable to create controller", "controller", "ServerBIOS") os.Exit(1) @@ -320,15 +315,6 @@ func main() { } }() - setupLog.Info("starting FMI server", "FMIServerAddress", fmiServerAddress) - biosTaskRunner := fmi.NewDefaultFMIServer(fmiServerAddress, mgr.GetClient(), fmiServerShutdownTimeout, insecure) - go func() { - if err := biosTaskRunner.Start(ctx); err != nil { - setupLog.Error(err, "problem running FMI server") - os.Exit(1) - } - }() - setupLog.Info("starting manager") if err := mgr.Start(ctx); err != nil { setupLog.Error(err, "problem running manager") diff --git a/config/crd/bases/metal.ironcore.dev_serverbioses.yaml b/config/crd/bases/metal.ironcore.dev_serverbioses.yaml index 3631c16..a1c0adc 100644 --- a/config/crd/bases/metal.ironcore.dev_serverbioses.yaml +++ b/config/crd/bases/metal.ironcore.dev_serverbioses.yaml @@ -62,12 +62,6 @@ spec: required: - version type: object - scanPeriodMinutes: - default: 30 - description: ScanPeriodMinutes defines the period in minutes after - which scanned data is considered obsolete. - format: int32 - type: integer serverRef: description: ServerRef is a reference to Server object properties: diff --git a/config/crd/bases/metal.ironcore.dev_servers.yaml b/config/crd/bases/metal.ironcore.dev_servers.yaml index 59e0cdd..dca3e5d 100644 --- a/config/crd/bases/metal.ironcore.dev_servers.yaml +++ b/config/crd/bases/metal.ironcore.dev_servers.yaml @@ -70,7 +70,7 @@ spec: spec: description: ServerSpec defines the desired state of a Server. properties: - biOSSettingsRef: + biosSettingsRef: description: BIOSSettingsRef is a reference to a ServerBIOS object. properties: name: diff --git a/config/crd/kustomization.yaml b/config/crd/kustomization.yaml index 1a362d8..791fec1 100644 --- a/config/crd/kustomization.yaml +++ b/config/crd/kustomization.yaml @@ -6,6 +6,7 @@ resources: - bases/metal.ironcore.dev_bmcsecrets.yaml - bases/metal.ironcore.dev_bmcs.yaml - bases/metal.ironcore.dev_servers.yaml +- bases/metal.ironcore.dev_serverbioses.yaml - bases/metal.ironcore.dev_serverbootconfigurations.yaml - bases/metal.ironcore.dev_serverclaims.yaml #+kubebuilder:scaffold:crdkustomizeresource diff --git a/config/default/kustomization.yaml b/config/default/kustomization.yaml index c2a38f4..b898c86 100644 --- a/config/default/kustomization.yaml +++ b/config/default/kustomization.yaml @@ -25,6 +25,7 @@ resources: - ../certmanager # [PROMETHEUS] To enable prometheus monitor, uncomment all sections with 'PROMETHEUS'. #- ../prometheus +- ../fmi patches: # Protect the /metrics endpoint by putting it behind auth. diff --git a/config/dev/fmiserver_patch.yaml b/config/dev/fmiserver_patch.yaml new file mode 100644 index 0000000..c5e8426 --- /dev/null +++ b/config/dev/fmiserver_patch.yaml @@ -0,0 +1,22 @@ +apiVersion: apps/v1 +kind: Deployment +metadata: + name: fmi-server + namespace: system +spec: + template: + spec: + containers: + - name: fmi-server + args: + - --task-runner-type=fake + imagePullPolicy: IfNotPresent + ports: + - containerPort: 9080 + protocol: TCP + - name: redfish + image: dmtf/redfish-mockup-server:latest + imagePullPolicy: Always + ports: + - containerPort: 8000 + protocol: TCP diff --git a/config/dev/kustomization.yaml b/config/dev/kustomization.yaml index cbcb96d..d1537a3 100644 --- a/config/dev/kustomization.yaml +++ b/config/dev/kustomization.yaml @@ -6,6 +6,7 @@ resources: patches: - path: delete_manager_auth_proxy_patch.yaml - path: manager_patch.yaml +- path: fmiserver_patch.yaml secretGenerator: - name: macdb diff --git a/config/dev/manager_patch.yaml b/config/dev/manager_patch.yaml index 55aff1a..d117185 100644 --- a/config/dev/manager_patch.yaml +++ b/config/dev/manager_patch.yaml @@ -18,6 +18,7 @@ spec: - --registry-url=http://127.0.0.1:30000 - --registry-port=30000 - --enforce-first-boot + - --fmi-server-address=metal-operator-fmi-server-svc:80 ports: - containerPort: 30000 volumeMounts: diff --git a/config/fmi/fmiserver.yaml b/config/fmi/fmiserver.yaml new file mode 100644 index 0000000..5589de6 --- /dev/null +++ b/config/fmi/fmiserver.yaml @@ -0,0 +1,109 @@ +--- +apiVersion: v1 +kind: ServiceAccount +metadata: + labels: + app.kubernetes.io/name: serviceaccount + app.kubernetes.io/instance: fmi-server-sa + app.kubernetes.io/component: rbac + app.kubernetes.io/created-by: metal-operator + app.kubernetes.io/part-of: metal-operator + app.kubernetes.io/managed-by: kustomize + name: fmi-server-sa + namespace: system +--- +apiVersion: rbac.authorization.k8s.io/v1 +kind: ClusterRole +metadata: + name: fmi-server-role +rules: + - apiGroups: + - metal.ironcore.dev + resources: + - bmcs + - bmcsecrets + - endpoints + - serverbioses + - servers + verbs: + - get + - list + - watch +--- +apiVersion: rbac.authorization.k8s.io/v1 +kind: ClusterRoleBinding +metadata: + labels: + app.kubernetes.io/name: clusterrolebinding + app.kubernetes.io/instance: fmi-server-rolebinding + app.kubernetes.io/component: rbac + app.kubernetes.io/created-by: metal-operator + app.kubernetes.io/part-of: metal-operator + app.kubernetes.io/managed-by: kustomize + name: fmi-server-rolebinding +roleRef: + apiGroup: rbac.authorization.k8s.io + kind: ClusterRole + name: fmi-server-role +subjects: + - kind: ServiceAccount + name: fmi-server-sa + namespace: system +--- +apiVersion: v1 +kind: Service +metadata: + labels: + app.kubernetes.io/name: fmi-server + app.kubernetes.io/instance: fmi-service + app.kubernetes.io/component: fmi + app.kubernetes.io/created-by: metal-operator + app.kubernetes.io/part-of: metal-operator + app.kubernetes.io/managed-by: kustomize + name: fmi-server-svc + namespace: system +spec: + ports: + - port: 80 + protocol: TCP + targetPort: 9080 + selector: + app.kubernetes.io/name: fmi-server +--- +apiVersion: apps/v1 +kind: Deployment +metadata: + labels: + app.kubernetes.io/name: fmi-server + app.kubernetes.io/instance: fmi-server + app.kubernetes.io/component: fmi + app.kubernetes.io/created-by: metal-operator + app.kubernetes.io/part-of: metal-operator + app.kubernetes.io/managed-by: kustomize + name: fmi-server + namespace: system +spec: + selector: + matchLabels: + app.kubernetes.io/name: fmi-server + template: + metadata: + labels: + app.kubernetes.io/name: fmi-server + spec: + serviceAccountName: fmi-server-sa + containers: + - name: fmi-server + command: + - /fmi-server + image: fmi-server:latest + imagePullPolicy: IfNotPresent + ports: + - containerPort: 9080 + protocol: TCP + - name: redfish + image: dmtf/redfish-mockup-server:latest + imagePullPolicy: Always + ports: + - containerPort: 8000 + protocol: TCP diff --git a/config/fmi/kustomization.yaml b/config/fmi/kustomization.yaml new file mode 100644 index 0000000..9ce6c63 --- /dev/null +++ b/config/fmi/kustomization.yaml @@ -0,0 +1,2 @@ +resources: + - fmiserver.yaml diff --git a/config/samples/metal_v1alpha1_serverbios.yaml b/config/samples/metal_v1alpha1_serverbios.yaml new file mode 100644 index 0000000..e75d361 --- /dev/null +++ b/config/samples/metal_v1alpha1_serverbios.yaml @@ -0,0 +1,15 @@ +apiVersion: metal.ironcore.dev/v1alpha1 +kind: ServerBIOS +metadata: + labels: + app.kubernetes.io/name: serverbios + app.kubernetes.io/instance: serverbios-sample + app.kubernetes.io/part-of: metal-operator + app.kubernetes.io/managed-by: kustomize + app.kubernetes.io/created-by: metal-operator + name: serverbios-sample +spec: + serverRef: + name: endpoint-sample-system-0 + bios: + version: "1.0.0-fake" diff --git a/docs/api-reference/api.md b/docs/api-reference/api.md index 1c84105..0eaad79 100644 --- a/docs/api-reference/api.md +++ b/docs/api-reference/api.md @@ -13,10 +13,10 @@ Resource Types:

BIOSSettings

-(Appears on:ServerSpec, ServerStatus) +(Appears on:ServerBIOSSpec, ServerBIOSStatus)

-

BIOSSettings represents the BIOS settings for a server.

+

BIOSSettings contains a version, settings and a flag defining whether it is a current version

@@ -34,7 +34,7 @@ string @@ -45,7 +45,8 @@ map[string]string @@ -1316,15 +1317,15 @@ if no boot configuration is specified.

-

Version specifies the version of the server BIOS for which the settings are defined.

+

Version contains BIOS version

-

Settings is a map of key-value pairs representing the BIOS settings.

+(Optional) +

Settings contains BIOS settings as map

-BIOS
+biOSSettingsRef
- -[]BIOSSettings + +Kubernetes core/v1.LocalObjectReference
-

BIOS specifies the BIOS settings for the server.

+

BIOSSettingsRef is a reference to a ServerBIOS object.

@@ -1344,6 +1345,193 @@ ServerStatus +

ServerBIOS +

+
+

ServerBIOS is the Schema for the serverbios API

+
+ + + + + + + + + + + + + + + + + + + + + +
FieldDescription
+metadata
+ + +Kubernetes meta/v1.ObjectMeta + + +
+Refer to the Kubernetes API documentation for the fields of the +metadata field. +
+spec
+ + +ServerBIOSSpec + + +
+
+
+ + + + + + + + + + + + + +
+scanPeriodMinutes
+ +int32 + +
+(Optional) +

ScanPeriodMinutes defines the period in minutes after which scanned data is considered obsolete.

+
+serverRef
+ + +Kubernetes core/v1.LocalObjectReference + + +
+(Optional) +

ServerRef is a reference to Server object

+
+bios
+ + +BIOSSettings + + +
+(Optional) +

BIOS contains a bios version and settings.

+
+
+status
+ + +ServerBIOSStatus + + +
+
+

ServerBIOSSpec +

+

+(Appears on:ServerBIOS) +

+
+

ServerBIOSSpec defines the desired state of ServerBIOS

+
+ + + + + + + + + + + + + + + + + + + + + +
FieldDescription
+scanPeriodMinutes
+ +int32 + +
+(Optional) +

ScanPeriodMinutes defines the period in minutes after which scanned data is considered obsolete.

+
+serverRef
+ + +Kubernetes core/v1.LocalObjectReference + + +
+(Optional) +

ServerRef is a reference to Server object

+
+bios
+ + +BIOSSettings + + +
+(Optional) +

BIOS contains a bios version and settings.

+
+

ServerBIOSStatus +

+

+(Appears on:ServerBIOS) +

+
+

ServerBIOSStatus defines the observed state of ServerBIOS

+
+ + + + + + + + + + + + + +
FieldDescription
+bios
+ + +BIOSSettings + + +
+(Optional) +

BIOS contains a bios version and settings.

+

ServerBootConfiguration

@@ -1952,15 +2140,15 @@ if no boot configuration is specified.

-BIOS
+biOSSettingsRef
- -[]BIOSSettings + +Kubernetes core/v1.LocalObjectReference -

BIOS specifies the BIOS settings for the server.

+

BIOSSettingsRef is a reference to a ServerBIOS object.

@@ -2124,18 +2312,6 @@ ServerState -BIOS
- - -BIOSSettings - - - - - - - - conditions
diff --git a/fmi/client.go b/fmi/client.go deleted file mode 100644 index f332cd4..0000000 --- a/fmi/client.go +++ /dev/null @@ -1,81 +0,0 @@ -package fmi - -import ( - "bytes" - "context" - "encoding/json" - "fmt" - "net/http" -) - -type Client struct { - *http.Client - serverURL string - scanEndpoint string - settingsApplyEndpoint string - versionUpdateEndpoint string -} - -func (c *Client) Scan(_ context.Context, serverBIOSRef string) (ScanResult, error) { - jsonBody, err := json.Marshal(TaskPayload{ServerBIOSRef: serverBIOSRef}) - if err != nil { - return ScanResult{}, err - } - - resp, err := c.Post(fmt.Sprintf("%s/%s", c.serverURL, c.scanEndpoint), "application/json", bytes.NewBuffer(jsonBody)) - if err != nil { - return ScanResult{}, err - } - if resp.StatusCode != http.StatusOK { - return ScanResult{}, fmt.Errorf("unexpected status code: %d", resp.StatusCode) - } - defer func() { - _ = resp.Body.Close() - }() - - var result ScanResult - if err = json.NewDecoder(resp.Body).Decode(&result); err != nil { - return ScanResult{}, err - } - return result, nil -} - -func (c *Client) SettingsApply(_ context.Context, serverBIOSRef string) error { - jsonBody, err := json.Marshal(TaskPayload{ServerBIOSRef: serverBIOSRef}) - if err != nil { - return err - } - - resp, err := c.Post( - fmt.Sprintf("%s/%s", c.serverURL, c.settingsApplyEndpoint), "application/json", bytes.NewBuffer(jsonBody)) - if err != nil { - return err - } - if resp.StatusCode != http.StatusOK { - return fmt.Errorf("unexpected status code: %d", resp.StatusCode) - } - defer func() { - _ = resp.Body.Close() - }() - return nil -} - -func (c *Client) VersionUpdate(_ context.Context, serverBIOSRef string) error { - jsonBody, err := json.Marshal(TaskPayload{ServerBIOSRef: serverBIOSRef}) - if err != nil { - return err - } - - resp, err := c.Post( - fmt.Sprintf("%s/%s", c.serverURL, c.versionUpdateEndpoint), "application/json", bytes.NewBuffer(jsonBody)) - if err != nil { - return err - } - if resp.StatusCode != http.StatusOK { - return fmt.Errorf("unexpected status code: %d", resp.StatusCode) - } - defer func() { - _ = resp.Body.Close() - }() - return nil -} diff --git a/fmi/client_grpc.go b/fmi/client_grpc.go new file mode 100644 index 0000000..05035b1 --- /dev/null +++ b/fmi/client_grpc.go @@ -0,0 +1,138 @@ +package fmi + +import ( + "context" + "crypto/tls" + "crypto/x509" + "fmt" + "os" + "time" + + commonv1alpha1 "github.com/ironcore-dev/metal-operator/api/gen/common/v1alpha1" + "github.com/ironcore-dev/metal-operator/api/gen/serverbios/v1alpha1" + "google.golang.org/grpc" + "google.golang.org/grpc/credentials" + "google.golang.org/grpc/credentials/insecure" +) + +type ClientGRPC struct { + address string + requestTimeout time.Duration + tlsCredentials credentials.TransportCredentials +} + +func NewClientGRPC(config ClientConfig) (*ClientGRPC, error) { + tlsCredentials := insecure.NewCredentials() + + if config.CertFile != "" && config.KeyFile != "" && config.CAFile != "" { + pemServerCA, err := os.ReadFile(config.CAFile) + if err != nil { + return nil, err + } + + certPool := x509.NewCertPool() + if !certPool.AppendCertsFromPEM(pemServerCA) { + return nil, fmt.Errorf("failed to add server CA's certificate") + } + + clientCert, err := tls.LoadX509KeyPair(config.CertFile, config.KeyFile) + if err != nil { + return nil, err + } + + clientTLSConfig := &tls.Config{ + Certificates: []tls.Certificate{clientCert}, + RootCAs: certPool, + } + tlsCredentials = credentials.NewTLS(clientTLSConfig) + } + + return &ClientGRPC{ + address: config.ServerURL, + requestTimeout: config.RequestTimeout, + tlsCredentials: tlsCredentials, + }, nil +} + +func (c *ClientGRPC) Scan(ctx context.Context, serverBIOSRef string) (ScanResult, error) { + conn, err := grpc.NewClient(c.address, grpc.WithTransportCredentials(c.tlsCredentials)) + if err != nil { + return ScanResult{}, err + } + defer func() { + _ = conn.Close() + }() + + ctx, cancel := context.WithTimeout(ctx, c.requestTimeout) + defer cancel() + + client := v1alpha1.NewServerBIOSServiceClient(conn) + req := &v1alpha1.BIOSScanRequest{ + ServerBiosRef: serverBIOSRef, + } + resp, err := client.BIOSScan(ctx, req) + if err != nil { + return ScanResult{}, err + } + if resp.Result != commonv1alpha1.RequestResult_REQUEST_RESULT_SUCCESS { + return ScanResult{}, fmt.Errorf("unexpected result: %s", resp.Result) + } + return ScanResult{ + Version: resp.Version, + Settings: resp.Settings, + }, nil +} + +func (c *ClientGRPC) SettingsApply(ctx context.Context, serverBIOSRef string) (SettingsApplyResult, error) { + conn, err := grpc.NewClient(c.address, grpc.WithTransportCredentials(c.tlsCredentials)) + if err != nil { + return SettingsApplyResult{}, err + } + defer func() { + _ = conn.Close() + }() + + ctx, cancel := context.WithTimeout(ctx, c.requestTimeout) + defer cancel() + + client := v1alpha1.NewServerBIOSServiceClient(conn) + req := &v1alpha1.BIOSSettingsApplyRequest{ + ServerBiosRef: serverBIOSRef, + } + + resp, err := client.BIOSSettingsApply(ctx, req) + if err != nil { + return SettingsApplyResult{}, err + } + if resp.Result != commonv1alpha1.RequestResult_REQUEST_RESULT_SUCCESS { + return SettingsApplyResult{}, fmt.Errorf("unexpected result: %s", resp.Result) + } + return SettingsApplyResult{RebootRequired: resp.RebootRequired}, nil +} + +func (c *ClientGRPC) VersionUpdate(ctx context.Context, serverBIOSRef string) error { + conn, err := grpc.NewClient(c.address, grpc.WithTransportCredentials(c.tlsCredentials)) + if err != nil { + return err + } + defer func() { + _ = conn.Close() + }() + + ctx, cancel := context.WithTimeout(ctx, c.requestTimeout) + defer cancel() + + client := v1alpha1.NewServerBIOSServiceClient(conn) + req := &v1alpha1.BIOSVersionUpdateRequest{ + ServerBiosRef: serverBIOSRef, + } + + resp, err := client.BIOSVersionUpdate(ctx, req) + if err != nil { + return err + } + if resp.Result != commonv1alpha1.RequestResult_REQUEST_RESULT_SUCCESS { + return fmt.Errorf("unexpected result: %s", resp.Result) + } + return nil +} diff --git a/fmi/client_http.go b/fmi/client_http.go new file mode 100644 index 0000000..9a16fa9 --- /dev/null +++ b/fmi/client_http.go @@ -0,0 +1,111 @@ +package fmi + +import ( + "bytes" + "context" + "crypto/tls" + "crypto/x509" + "encoding/json" + "fmt" + "net/http" + "os" +) + +type ClientHTTP struct { + *http.Client + serverURL string +} + +func NewClientHTTP(config ClientConfig) (*ClientHTTP, error) { + tlsConfig := &tls.Config{} + if config.CertFile != "" && config.KeyFile != "" { + cert, err := tls.LoadX509KeyPair(config.CertFile, config.KeyFile) + if err != nil { + return nil, err + } + tlsConfig.Certificates = []tls.Certificate{cert} + } + + if config.CAFile != "" { + caCert, err := os.ReadFile(config.CAFile) + if err != nil { + return nil, err + } + caCertPool := x509.NewCertPool() + caCertPool.AppendCertsFromPEM(caCert) + tlsConfig.RootCAs = caCertPool + } + + tlsConfig.InsecureSkipVerify = config.InsecureSkipVerify + + transport := &http.Transport{TLSClientConfig: tlsConfig} + httpClient := &http.Client{Transport: transport} + return &ClientHTTP{ + Client: httpClient, + serverURL: config.ServerURL, + }, nil +} + +func (c *ClientHTTP) Scan(_ context.Context, serverBIOSRef string) (ScanResult, error) { + jsonBody, err := json.Marshal(TaskPayload{ServerBIOSRef: serverBIOSRef}) + if err != nil { + return ScanResult{}, err + } + + resp, err := c.Post(fmt.Sprintf("%s/%s", c.serverURL, "scan"), "application/json", bytes.NewBuffer(jsonBody)) + if err != nil { + return ScanResult{}, err + } + if resp.StatusCode != http.StatusOK { + return ScanResult{}, fmt.Errorf("unexpected status code: %d", resp.StatusCode) + } + defer func() { + _ = resp.Body.Close() + }() + + var result ScanResult + if err = json.NewDecoder(resp.Body).Decode(&result); err != nil { + return ScanResult{}, err + } + return result, nil +} + +func (c *ClientHTTP) SettingsApply(_ context.Context, serverBIOSRef string) (SettingsApplyResult, error) { + jsonBody, err := json.Marshal(TaskPayload{ServerBIOSRef: serverBIOSRef}) + if err != nil { + return SettingsApplyResult{}, err + } + + resp, err := c.Post( + fmt.Sprintf("%s/%s", c.serverURL, "settings-apply"), "application/json", bytes.NewBuffer(jsonBody)) + if err != nil { + return SettingsApplyResult{}, err + } + if resp.StatusCode != http.StatusOK { + return SettingsApplyResult{}, fmt.Errorf("unexpected status code: %d", resp.StatusCode) + } + defer func() { + _ = resp.Body.Close() + }() + return SettingsApplyResult{RebootRequired: true}, nil +} + +func (c *ClientHTTP) VersionUpdate(_ context.Context, serverBIOSRef string) error { + jsonBody, err := json.Marshal(TaskPayload{ServerBIOSRef: serverBIOSRef}) + if err != nil { + return err + } + + resp, err := c.Post( + fmt.Sprintf("%s/%s", c.serverURL, "version-update"), "application/json", bytes.NewBuffer(jsonBody)) + if err != nil { + return err + } + if resp.StatusCode != http.StatusOK { + return fmt.Errorf("unexpected status code: %d", resp.StatusCode) + } + defer func() { + _ = resp.Body.Close() + }() + return nil +} diff --git a/fmi/fmi.go b/fmi/fmi.go index 27e3d15..25933a9 100644 --- a/fmi/fmi.go +++ b/fmi/fmi.go @@ -2,26 +2,54 @@ package fmi import ( "context" - "crypto/tls" - "crypto/x509" - "net/http" - "os" + "fmt" + "time" + + "sigs.k8s.io/controller-runtime/pkg/client" +) + +const ( + ClientTypeHTTP = "http" + ClientTypeGRPC = "grpc" ) +const ( + TaskRunnerTypeDefault = "default" + TaskRunnerTypeFake = "fake" +) + +// ServerConfig contains the configuration for a task runner server. +type ServerConfig struct { + // Hostname is the hostname of the task runner server. + Hostname string + + // Port is the port of the task runner server. + Port int + + // ShutdownTimeout is the timeout to wait for the server to shut down. + ShutdownTimeout time.Duration + + // CAFile is the path to the CA file for TLS authentication. + CAFile string + + // CertFile is the path to the server certificate file for TLS authentication. + CertFile string + + // KeyFile is the path to the server key file for TLS authentication. + KeyFile string + + // KubeClient is the Kubernetes client. + KubeClient client.Client + + // TaskRunnerType is the type of task runner to use. + TaskRunnerType string +} + // ClientConfig contains the configuration for a task runner client. type ClientConfig struct { // ServerURL is the URL of the task runner server. ServerURL string - // ScanEndpoint is the endpoint for the scan task. - ScanEndpoint string - - // SettingsApplyEndpoint is the endpoint for the settings apply task. - SettingsApplyEndpoint string - - // VersionUpdateEndpoint is the endpoint for the version update task. - VersionUpdateEndpoint string - // CAFile is the path to the CA file for TLS authentication. CAFile string @@ -33,6 +61,9 @@ type ClientConfig struct { // InsecureSkipVerify skips TLS verification. InsecureSkipVerify bool + + // RequestTimeout is the timeout for requests to the task runner server. + RequestTimeout time.Duration } // TaskPayload represents the payload for a task. @@ -50,13 +81,19 @@ type ScanResult struct { Settings map[string]string `json:"settings"` } +// SettingsApplyResult represents the result of a settings apply. +type SettingsApplyResult struct { + // RebootRequired indicates whether a reboot is required. + RebootRequired bool `json:"success"` +} + // TaskRunnerClient is the interface for a task runner client. type TaskRunnerClient interface { // Scan requests a scan task. Scan(ctx context.Context, serverBIOSRef string) (ScanResult, error) // SettingsApply requests a settings apply task. - SettingsApply(ctx context.Context, serverBIOSRef string) error + SettingsApply(ctx context.Context, serverBIOSRef string) (SettingsApplyResult, error) // VersionUpdate requests a version update task. VersionUpdate(ctx context.Context, serverBIOSRef string) error @@ -68,43 +105,31 @@ type TaskRunner interface { ExecuteScan(ctx context.Context, serverBIOSRef string) (ScanResult, error) // ExecuteSettingsApply executes a settings apply task. - ExecuteSettingsApply(ctx context.Context, serverBIOSRef string) error + ExecuteSettingsApply(ctx context.Context, serverBIOSRef string) (SettingsApplyResult, error) // ExecuteVersionUpdate executes a version update task. ExecuteVersionUpdate(ctx context.Context, serverBIOSRef string) error } // NewClientForConfig returns the client for the server for given config. -func NewClientForConfig(config ClientConfig) (TaskRunnerClient, error) { - tlsConfig := &tls.Config{} - if config.CertFile != "" && config.KeyFile != "" { - cert, err := tls.LoadX509KeyPair(config.CertFile, config.KeyFile) - if err != nil { - return nil, err - } - tlsConfig.Certificates = []tls.Certificate{cert} +func NewClientForConfig(clientType string, config ClientConfig) (TaskRunnerClient, error) { + switch clientType { + case ClientTypeHTTP: + return NewClientHTTP(config) + case ClientTypeGRPC: + return NewClientGRPC(config) + default: + return nil, fmt.Errorf("unknown client type: %s", clientType) } +} - if config.CAFile != "" { - caCert, err := os.ReadFile(config.CAFile) - if err != nil { - return nil, err - } - caCertPool := x509.NewCertPool() - caCertPool.AppendCertsFromPEM(caCert) - tlsConfig.RootCAs = caCertPool +func NewTaskRunner(runnerType string, kubeClient client.Client, insecureBMC bool) (TaskRunner, error) { + switch runnerType { + case TaskRunnerTypeDefault: + return NewDefaultTaskRunner(kubeClient, insecureBMC), nil + case TaskRunnerTypeFake: + return NewFakeTaskRunner(kubeClient, insecureBMC), nil + default: + return nil, fmt.Errorf("unknown task runner type: %s", runnerType) } - - tlsConfig.InsecureSkipVerify = config.InsecureSkipVerify - - transport := &http.Transport{TLSClientConfig: tlsConfig} - httpClient := &http.Client{Transport: transport} - - return &Client{ - Client: httpClient, - serverURL: config.ServerURL, - scanEndpoint: config.ScanEndpoint, - settingsApplyEndpoint: config.SettingsApplyEndpoint, - versionUpdateEndpoint: config.VersionUpdateEndpoint, - }, nil } diff --git a/fmi/default_runner.go b/fmi/runner_default.go similarity index 81% rename from fmi/default_runner.go rename to fmi/runner_default.go index 118368c..03bfa6f 100644 --- a/fmi/default_runner.go +++ b/fmi/runner_default.go @@ -7,8 +7,6 @@ import ( metalv1alpha1 "github.com/ironcore-dev/metal-operator/api/v1alpha1" "github.com/ironcore-dev/metal-operator/internal/bmcutils" - "k8s.io/apimachinery/pkg/api/meta" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "sigs.k8s.io/controller-runtime/pkg/client" ) @@ -57,22 +55,25 @@ func (s *DefaultTaskRunner) ExecuteScan(ctx context.Context, serverBIOSRef strin } // ExecuteSettingsApply applies the settings to the server. -func (s *DefaultTaskRunner) ExecuteSettingsApply(ctx context.Context, serverBIOSRef string) error { +func (s *DefaultTaskRunner) ExecuteSettingsApply( + ctx context.Context, + serverBIOSRef string, +) (SettingsApplyResult, error) { inProgress, err := s.isTaskInProgress(ctx, serverBIOSRef) if err != nil { - return err + return SettingsApplyResult{}, err } if inProgress { - return nil + return SettingsApplyResult{}, nil } serverBIOS, server, err := s.getObjects(ctx, serverBIOSRef) if err != nil { - return err + return SettingsApplyResult{}, err } bmcClient, err := bmcutils.GetBMCClientForServer(ctx, s.Client, server, s.insecure) if err != nil { - return err + return SettingsApplyResult{}, err } defer bmcClient.Logout() @@ -85,14 +86,11 @@ func (s *DefaultTaskRunner) ExecuteSettingsApply(ctx context.Context, serverBIOS } reset, err := bmcClient.SetBiosAttributes(server.Spec.UUID, diff) if err != nil { - return err + return SettingsApplyResult{}, err } - if reset { - if err = s.patchServerCondition(ctx, server); err != nil { - return fmt.Errorf("failed to patch Server status: %w", err) - } - } - return nil + return SettingsApplyResult{ + RebootRequired: reset, + }, nil } // todo: remove nolint @@ -137,16 +135,3 @@ func (s *DefaultTaskRunner) getObjects( } return serverBIOS, server, nil } - -// patchServerCondition patches the Server status with the given condition. -func (s *DefaultTaskRunner) patchServerCondition(ctx context.Context, server *metalv1alpha1.Server) error { - serverBase := server.DeepCopy() - changed := meta.SetStatusCondition(&server.Status.Conditions, metav1.Condition{ - Type: "RebootRequired", - }) - if changed { - return s.Status().Patch(ctx, serverBase, client.MergeFrom(server)) - - } - return nil -} diff --git a/fmi/runner_fake.go b/fmi/runner_fake.go new file mode 100644 index 0000000..1161ee1 --- /dev/null +++ b/fmi/runner_fake.go @@ -0,0 +1,63 @@ +package fmi + +import ( + "context" + "fmt" + + metalv1alpha1 "github.com/ironcore-dev/metal-operator/api/v1alpha1" + "sigs.k8s.io/controller-runtime/pkg/client" +) + +// FakeTaskRunner is the fake implementation of the TaskRunner interface. +type FakeTaskRunner struct { + client.Client + insecure bool +} + +// NewFakeTaskRunner creates a new FakeTaskRunner. +func NewFakeTaskRunner(client client.Client, insecure bool) *FakeTaskRunner { + return &FakeTaskRunner{ + Client: client, + insecure: insecure, + } +} + +// ExecuteScan executes a scan task. +func (s *FakeTaskRunner) ExecuteScan(_ context.Context, _ string) (ScanResult, error) { + return ScanResult{ + Version: "1.0.0-fake", + Settings: map[string]string{}, + }, nil +} + +// ExecuteSettingsApply applies the settings to the server. +func (s *FakeTaskRunner) ExecuteSettingsApply(_ context.Context, _ string) (SettingsApplyResult, error) { + return SettingsApplyResult{ + RebootRequired: true, + }, nil +} + +// todo: remove nolint + +// ExecuteVersionUpdate updates the BIOS version of the server. +// nolint:unparam +func (s *FakeTaskRunner) ExecuteVersionUpdate(_ context.Context, _ string) error { + return fmt.Errorf("not implemented") +} + +// getObjects returns the ServerBIOS and Server objects for the given serverBIOSRef. +// nolint: unused +func (s *FakeTaskRunner) getObjects( + ctx context.Context, + serverBIOSRef string, +) (*metalv1alpha1.ServerBIOS, *metalv1alpha1.Server, error) { + serverBIOS := &metalv1alpha1.ServerBIOS{} + if err := s.Get(ctx, client.ObjectKey{Name: serverBIOSRef}, serverBIOS); err != nil { + return nil, nil, err + } + server := &metalv1alpha1.Server{} + if err := s.Get(ctx, client.ObjectKey{Name: serverBIOS.Spec.ServerRef.Name}, server); err != nil { + return nil, nil, err + } + return serverBIOS, server, nil +} diff --git a/fmi/server_grpc.go b/fmi/server_grpc.go new file mode 100644 index 0000000..5de4724 --- /dev/null +++ b/fmi/server_grpc.go @@ -0,0 +1,105 @@ +package fmi + +import ( + "context" + "fmt" + "net" + "time" + + commonv1alpha1 "github.com/ironcore-dev/metal-operator/api/gen/common/v1alpha1" + "github.com/ironcore-dev/metal-operator/api/gen/serverbios/v1alpha1" + "golang.org/x/sync/errgroup" + "google.golang.org/grpc" +) + +// ServerGRPC implements the ServerBIOS gRPC service. +type ServerGRPC struct { + port int + shutdownTimeout time.Duration + taskRunner TaskRunner +} + +// NewServerGRPC creates a new ServerGRPC. +func NewServerGRPC(config ServerConfig, insecureBMC bool) (*ServerGRPC, error) { + taskRunner, err := NewTaskRunner(config.TaskRunnerType, config.KubeClient, insecureBMC) + if err != nil { + return nil, err + } + return &ServerGRPC{ + port: config.Port, + shutdownTimeout: config.ShutdownTimeout, + taskRunner: taskRunner, + }, nil +} + +// Start starts the gRPC server. +func (s *ServerGRPC) Start(ctx context.Context) error { + g, ctx := errgroup.WithContext(ctx) + listener, err := net.Listen("tcp", fmt.Sprintf(":%d", s.port)) + if err != nil { + return err + } + server := grpc.NewServer() + v1alpha1.RegisterServerBIOSServiceServer(server, s) + + g.Go(func() error { + <-ctx.Done() + shutdownCtx, cancel := context.WithTimeout(context.Background(), s.shutdownTimeout) + defer cancel() + return s.Shutdown(shutdownCtx, server) + }) + + g.Go(func() error { + return server.Serve(listener) + }) + + return g.Wait() +} + +// Shutdown shuts down the gRPC server. +func (s *ServerGRPC) Shutdown(_ context.Context, server *grpc.Server) error { + server.GracefulStop() + // TODO add shutdown logic here: wait for task in progress and etc. + return nil +} + +// BIOSScan implements the BIOSScan gRPC service. +func (s *ServerGRPC) BIOSScan( + ctx context.Context, + request *v1alpha1.BIOSScanRequest, +) (*v1alpha1.BIOSScanResponse, error) { + result, err := s.taskRunner.ExecuteScan(ctx, request.ServerBiosRef) + if err != nil { + return nil, err + } + return &v1alpha1.BIOSScanResponse{ + Result: commonv1alpha1.RequestResult_REQUEST_RESULT_SUCCESS, + Version: result.Version, + Settings: result.Settings, + }, nil +} + +// BIOSSettingsApply implements the BIOSSettingsApply gRPC service. +func (s *ServerGRPC) BIOSSettingsApply( + ctx context.Context, + request *v1alpha1.BIOSSettingsApplyRequest, +) (*v1alpha1.BIOSSettingsApplyResponse, error) { + result, err := s.taskRunner.ExecuteSettingsApply(ctx, request.ServerBiosRef) + if err != nil { + return nil, err + } + return &v1alpha1.BIOSSettingsApplyResponse{ + Result: commonv1alpha1.RequestResult_REQUEST_RESULT_SUCCESS, + RebootRequired: result.RebootRequired, + }, nil +} + +// BIOSVersionUpdate implements the BIOSVersionUpdate gRPC service. +func (s *ServerGRPC) BIOSVersionUpdate( + _ context.Context, + _ *v1alpha1.BIOSVersionUpdateRequest, +) (*v1alpha1.BIOSVersionUpdateResponse, error) { + return &v1alpha1.BIOSVersionUpdateResponse{ + Result: commonv1alpha1.RequestResult_REQUEST_RESULT_UNSPECIFIED, + }, nil +} diff --git a/fmi/default_server.go b/fmi/server_http.go similarity index 70% rename from fmi/default_server.go rename to fmi/server_http.go index 56011a3..ca0c0ad 100644 --- a/fmi/default_server.go +++ b/fmi/server_http.go @@ -3,48 +3,68 @@ package fmi import ( "context" "encoding/json" + "fmt" "net/http" "time" "golang.org/x/sync/errgroup" - "sigs.k8s.io/controller-runtime/pkg/client" ) -type DefaultFMIServer struct { +type ServerHTTP struct { address string mux *http.ServeMux shutdownTimeout time.Duration taskRunner TaskRunner } -// NewDefaultFMIServer creates a new DefaultFMIServer. -func NewDefaultFMIServer( - address string, - kubeClient client.Client, - shutdownTimeout time.Duration, - insecure bool, -) *DefaultFMIServer { +// NewServerHTTP creates a new ServerHTTP. +func NewServerHTTP(config ServerConfig, insecureBMC bool) (*ServerHTTP, error) { mux := http.NewServeMux() - taskRunner := NewDefaultTaskRunner(kubeClient, insecure) - server := &DefaultFMIServer{ - address: address, + taskRunner, err := NewTaskRunner(config.TaskRunnerType, config.KubeClient, insecureBMC) + if err != nil { + return nil, err + } + server := &ServerHTTP{ + address: fmt.Sprintf("%s:%d", config.Hostname, config.Port), mux: mux, - shutdownTimeout: shutdownTimeout, + shutdownTimeout: config.ShutdownTimeout, taskRunner: taskRunner, } server.registerRoutes() - return server + return server, nil +} + +// Start starts the server. +func (s *ServerHTTP) Start(ctx context.Context) error { + g, ctx := errgroup.WithContext(ctx) + server := &http.Server{ + Addr: s.address, + Handler: s.mux, + } + + g.Go(func() error { + <-ctx.Done() + shutdownCtx, cancel := context.WithTimeout(context.Background(), s.shutdownTimeout) + defer cancel() + return server.Shutdown(shutdownCtx) + }) + + g.Go(func() error { + return server.ListenAndServe() + }) + + return g.Wait() } // registerRoutes registers the server's routes. -func (s *DefaultFMIServer) registerRoutes() { +func (s *ServerHTTP) registerRoutes() { s.mux.HandleFunc("/scan", s.scanHandler) s.mux.HandleFunc("/settings-apply", s.settingsApplyHandler) s.mux.HandleFunc("/version-update", s.versionUpdateHandler) } // scanHandler handles the /scan endpoint. -func (s *DefaultFMIServer) scanHandler(w http.ResponseWriter, r *http.Request) { +func (s *ServerHTTP) scanHandler(w http.ResponseWriter, r *http.Request) { if r.Method != http.MethodPost { w.WriteHeader(http.StatusMethodNotAllowed) return @@ -66,7 +86,7 @@ func (s *DefaultFMIServer) scanHandler(w http.ResponseWriter, r *http.Request) { } // settingsApplyHandler handles the /settings-apply endpoint. -func (s *DefaultFMIServer) settingsApplyHandler(w http.ResponseWriter, r *http.Request) { +func (s *ServerHTTP) settingsApplyHandler(w http.ResponseWriter, r *http.Request) { if r.Method != http.MethodPost { w.WriteHeader(http.StatusMethodNotAllowed) return @@ -78,16 +98,18 @@ func (s *DefaultFMIServer) settingsApplyHandler(w http.ResponseWriter, r *http.R return } - if err := s.taskRunner.ExecuteSettingsApply(r.Context(), payload.ServerBIOSRef); err != nil { + result, err := s.taskRunner.ExecuteSettingsApply(r.Context(), payload.ServerBIOSRef) + if err != nil { w.WriteHeader(http.StatusInternalServerError) return } w.WriteHeader(http.StatusOK) + _ = json.NewEncoder(w).Encode(result) } // versionUpdateHandler handles the /version-update endpoint. -func (s *DefaultFMIServer) versionUpdateHandler(w http.ResponseWriter, r *http.Request) { +func (s *ServerHTTP) versionUpdateHandler(w http.ResponseWriter, r *http.Request) { if r.Method != http.MethodPost { w.WriteHeader(http.StatusMethodNotAllowed) return @@ -106,25 +128,3 @@ func (s *DefaultFMIServer) versionUpdateHandler(w http.ResponseWriter, r *http.R w.WriteHeader(http.StatusOK) } - -// Start starts the FMI server. -func (s *DefaultFMIServer) Start(ctx context.Context) error { - g, ctx := errgroup.WithContext(ctx) - server := &http.Server{ - Addr: s.address, - Handler: s.mux, - } - - g.Go(func() error { - <-ctx.Done() - shutdownCtx, cancel := context.WithTimeout(context.Background(), s.shutdownTimeout) - defer cancel() - return server.Shutdown(shutdownCtx) - }) - - g.Go(func() error { - return server.ListenAndServe() - }) - - return g.Wait() -} diff --git a/go.mod b/go.mod index e1a573f..74afbe6 100644 --- a/go.mod +++ b/go.mod @@ -10,6 +10,8 @@ require ( github.com/onsi/gomega v1.34.2 github.com/stmcginnis/gofish v0.19.0 golang.org/x/sync v0.8.0 + google.golang.org/grpc v1.65.0 + google.golang.org/protobuf v1.34.2 k8s.io/api v0.31.1 k8s.io/apimachinery v0.31.1 k8s.io/client-go v0.31.1 @@ -63,7 +65,7 @@ require ( golang.org/x/time v0.3.0 // indirect golang.org/x/tools v0.24.0 // indirect gomodules.xyz/jsonpatch/v2 v2.4.0 // indirect - google.golang.org/protobuf v1.34.2 // indirect + google.golang.org/genproto/googleapis/rpc v0.0.0-20240701130421-f6361c86f094 // indirect gopkg.in/inf.v0 v0.9.1 // indirect gopkg.in/yaml.v2 v2.4.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect diff --git a/go.sum b/go.sum index 14594f2..870f111 100644 --- a/go.sum +++ b/go.sum @@ -165,6 +165,10 @@ golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8T golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= gomodules.xyz/jsonpatch/v2 v2.4.0 h1:Ci3iUJyx9UeRx7CeFN8ARgGbkESwJK+KB9lLcWxY/Zw= gomodules.xyz/jsonpatch/v2 v2.4.0/go.mod h1:AH3dM2RI6uoBZxn3LVrfvJ3E0/9dG4cSrbuBJT4moAY= +google.golang.org/genproto/googleapis/rpc v0.0.0-20240701130421-f6361c86f094 h1:BwIjyKYGsK9dMCBOorzRri8MQwmi7mT9rGHsCEinZkA= +google.golang.org/genproto/googleapis/rpc v0.0.0-20240701130421-f6361c86f094/go.mod h1:Ue6ibwXGpU+dqIcODieyLOcgj7z8+IcskoNIgZxtrFY= +google.golang.org/grpc v1.65.0 h1:bs/cUb4lp1G5iImFFd3u5ixQzweKizoZJAwBNLR42lc= +google.golang.org/grpc v1.65.0/go.mod h1:WgYC2ypjlB0EiQi6wdKixMqukr6lBc0Vo+oOgjrM5ZQ= google.golang.org/protobuf v1.34.2 h1:6xV6lTsCfpGD21XK49h7MhtcApnLqkfYgPcdHftf6hg= google.golang.org/protobuf v1.34.2/go.mod h1:qYOHts0dSfpeUzUFpOMr/WGzszTmLH+DiWniOlNbLDw= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= diff --git a/internal/controller/serverbios_controller.go b/internal/controller/serverbios_controller.go index 4c927a3..2a7f5b2 100644 --- a/internal/controller/serverbios_controller.go +++ b/internal/controller/serverbios_controller.go @@ -13,6 +13,7 @@ import ( metalv1alpha1 "github.com/ironcore-dev/metal-operator/api/v1alpha1" "github.com/ironcore-dev/metal-operator/fmi" corev1 "k8s.io/api/core/v1" + "k8s.io/apimachinery/pkg/api/meta" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime" ctrl "sigs.k8s.io/controller-runtime" @@ -27,8 +28,8 @@ type ServerBIOSReconciler struct { client.Client Scheme *runtime.Scheme - TaskExecutor fmi.TaskRunnerClient - RequeueInterval time.Duration + TaskRunnerClient fmi.TaskRunnerClient + RequeueInterval time.Duration } // +kubebuilder:rbac:groups=metal.ironcore.dev,resources=serverbioses,verbs=get;list;watch;create;update;patch;delete @@ -169,7 +170,7 @@ func (r *ServerBIOSReconciler) reconcileScan( serverBIOS *metalv1alpha1.ServerBIOS, ) (bool, error) { log.V(1).Info("invoking scan job") - result, err := r.TaskExecutor.Scan(ctx, serverBIOS.Name) + result, err := r.TaskRunnerClient.Scan(ctx, serverBIOS.Name) if err != nil { return false, err } @@ -216,7 +217,7 @@ func (r *ServerBIOSReconciler) reconcileVersionUpdate( serverBIOS *metalv1alpha1.ServerBIOS, ) (ctrl.Result, error) { log.V(1).Info("invoking version update job") - return ctrl.Result{}, r.TaskExecutor.VersionUpdate(ctx, serverBIOS.Name) + return ctrl.Result{}, r.TaskRunnerClient.VersionUpdate(ctx, serverBIOS.Name) } func (r *ServerBIOSReconciler) reconcileSettingsUpdate( @@ -225,7 +226,16 @@ func (r *ServerBIOSReconciler) reconcileSettingsUpdate( serverBIOS *metalv1alpha1.ServerBIOS, ) (ctrl.Result, error) { log.V(1).Info("invoking settings update job") - return ctrl.Result{}, r.TaskExecutor.SettingsApply(ctx, serverBIOS.Name) + result, err := r.TaskRunnerClient.SettingsApply(ctx, serverBIOS.Name) + if err != nil { + return ctrl.Result{}, err + } + + server, err := r.getReferredServer(ctx, log, serverBIOS.Spec.ServerRef.Name) + if err != nil { + return ctrl.Result{}, err + } + return ctrl.Result{}, r.patchServerCondition(ctx, &server, result.RebootRequired) } // SetupWithManager sets up the controller with the Manager. @@ -263,3 +273,24 @@ func (r *ServerBIOSReconciler) patchBIOSSettingsRef( } return err } + +// patchServerCondition patches the Server status with the given condition. +func (r *ServerBIOSReconciler) patchServerCondition(ctx context.Context, server *metalv1alpha1.Server, reboot bool) error { + status := metav1.ConditionFalse + reason := "" + if reboot { + status = metav1.ConditionTrue + reason = "BIOSSettingsChanged" + } + serverBase := server.DeepCopy() + changed := meta.SetStatusCondition(&server.Status.Conditions, metav1.Condition{ + Type: "RebootRequired", + Status: status, + Reason: reason, + }) + if changed { + return r.Status().Patch(ctx, serverBase, client.MergeFrom(server)) + + } + return nil +}