From 5c9609914a7418ea34d1ff15dfc21877fb197763 Mon Sep 17 00:00:00 2001 From: Yuhang Wei Date: Thu, 24 Aug 2023 11:00:26 +0800 Subject: [PATCH 4/5] KubeOS: delete raw and docker image upgrade delete the part of using raw and docker image to upgrade Signed-off-by: Yuhang Wei --- api/v1alpha1/os_types.go | 9 - cmd/agent/api/agent.pb.go | 337 ++++--------- cmd/agent/api/agent.proto | 15 +- cmd/agent/server/disk_image.go | 217 -------- cmd/agent/server/disk_image_test.go | 471 ------------------ cmd/agent/server/docker_image.go | 73 --- cmd/agent/server/docker_image_test.go | 118 ----- cmd/agent/server/server.go | 8 - cmd/agent/server/server_test.go | 23 +- .../controllers/os_controller_test.go | 8 - cmd/proxy/controllers/os_controller.go | 6 - cmd/proxy/controllers/os_controller_test.go | 16 - .../config/crd/upgrade.openeuler.org_os.yaml | 15 - pkg/agentclient/connection.go | 15 - 14 files changed, 115 insertions(+), 1216 deletions(-) delete mode 100644 cmd/agent/server/disk_image.go delete mode 100644 cmd/agent/server/disk_image_test.go delete mode 100644 cmd/agent/server/docker_image.go delete mode 100644 cmd/agent/server/docker_image_test.go diff --git a/api/v1alpha1/os_types.go b/api/v1alpha1/os_types.go index f9474b7..b4655e8 100644 --- a/api/v1alpha1/os_types.go +++ b/api/v1alpha1/os_types.go @@ -19,22 +19,13 @@ import ( // OSSpec defines the desired state of OS type OSSpec struct { OSVersion string `json:"osversion"` - ImageURL string `json:"imageurl"` MaxUnavailable int `json:"maxunavailable"` CheckSum string `json:"checksum"` - FlagSafe bool `json:"flagSafe"` - MTLS bool `json:"mtls"` ImageType string `json:"imagetype"` ContainerImage string `json:"containerimage"` OpsType string `json:"opstype"` EvictPodForce bool `json:"evictpodforce"` // +kubebuilder:validation:Optional - CaCert string `json:"cacert"` - // +kubebuilder:validation:Optional - ClientCert string `json:"clientcert"` - // +kubebuilder:validation:Optional - ClientKey string `json:"clientkey"` - // +kubebuilder:validation:Optional SysConfigs SysConfigs `json:"sysconfigs"` // +kubebuilder:validation:Optional UpgradeConfigs SysConfigs `json:"upgradeconfigs"` diff --git a/cmd/agent/api/agent.pb.go b/cmd/agent/api/agent.pb.go index 077a57e..034337d 100644 --- a/cmd/agent/api/agent.pb.go +++ b/cmd/agent/api/agent.pb.go @@ -36,14 +36,10 @@ type UpdateRequest struct { sizeCache protoimpl.SizeCache unknownFields protoimpl.UnknownFields - Version string `protobuf:"bytes,1,opt,name=version,proto3" json:"version,omitempty"` - ImageUrl string `protobuf:"bytes,2,opt,name=image_url,json=imageUrl,proto3" json:"image_url,omitempty"` - CheckSum string `protobuf:"bytes,3,opt,name=check_sum,json=checkSum,proto3" json:"check_sum,omitempty"` - FlagSafe bool `protobuf:"varint,4,opt,name=flagSafe,proto3" json:"flagSafe,omitempty"` - MTLS bool `protobuf:"varint,5,opt,name=mTLS,proto3" json:"mTLS,omitempty"` - ImageType string `protobuf:"bytes,6,opt,name=image_type,json=imageType,proto3" json:"image_type,omitempty"` - ContainerImage string `protobuf:"bytes,7,opt,name=container_image,json=containerImage,proto3" json:"container_image,omitempty"` - Certs *CertsInfo `protobuf:"bytes,8,opt,name=certs,proto3" json:"certs,omitempty"` + Version string `protobuf:"bytes,1,opt,name=version,proto3" json:"version,omitempty"` + CheckSum string `protobuf:"bytes,2,opt,name=check_sum,json=checkSum,proto3" json:"check_sum,omitempty"` + ImageType string `protobuf:"bytes,3,opt,name=image_type,json=imageType,proto3" json:"image_type,omitempty"` + ContainerImage string `protobuf:"bytes,4,opt,name=container_image,json=containerImage,proto3" json:"container_image,omitempty"` } func (x *UpdateRequest) Reset() { @@ -85,13 +81,6 @@ func (x *UpdateRequest) GetVersion() string { return "" } -func (x *UpdateRequest) GetImageUrl() string { - if x != nil { - return x.ImageUrl - } - return "" -} - func (x *UpdateRequest) GetCheckSum() string { if x != nil { return x.CheckSum @@ -99,20 +88,6 @@ func (x *UpdateRequest) GetCheckSum() string { return "" } -func (x *UpdateRequest) GetFlagSafe() bool { - if x != nil { - return x.FlagSafe - } - return false -} - -func (x *UpdateRequest) GetMTLS() bool { - if x != nil { - return x.MTLS - } - return false -} - func (x *UpdateRequest) GetImageType() string { if x != nil { return x.ImageType @@ -127,76 +102,6 @@ func (x *UpdateRequest) GetContainerImage() string { return "" } -func (x *UpdateRequest) GetCerts() *CertsInfo { - if x != nil { - return x.Certs - } - return nil -} - -type CertsInfo struct { - state protoimpl.MessageState - sizeCache protoimpl.SizeCache - unknownFields protoimpl.UnknownFields - - CaCaert string `protobuf:"bytes,1,opt,name=ca_caert,json=caCaert,proto3" json:"ca_caert,omitempty"` - ClientCert string `protobuf:"bytes,2,opt,name=client_cert,json=clientCert,proto3" json:"client_cert,omitempty"` - ClientKey string `protobuf:"bytes,3,opt,name=client_key,json=clientKey,proto3" json:"client_key,omitempty"` -} - -func (x *CertsInfo) Reset() { - *x = CertsInfo{} - if protoimpl.UnsafeEnabled { - mi := &file_api_agent_proto_msgTypes[1] - ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) - ms.StoreMessageInfo(mi) - } -} - -func (x *CertsInfo) String() string { - return protoimpl.X.MessageStringOf(x) -} - -func (*CertsInfo) ProtoMessage() {} - -func (x *CertsInfo) ProtoReflect() protoreflect.Message { - mi := &file_api_agent_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 CertsInfo.ProtoReflect.Descriptor instead. -func (*CertsInfo) Descriptor() ([]byte, []int) { - return file_api_agent_proto_rawDescGZIP(), []int{1} -} - -func (x *CertsInfo) GetCaCaert() string { - if x != nil { - return x.CaCaert - } - return "" -} - -func (x *CertsInfo) GetClientCert() string { - if x != nil { - return x.ClientCert - } - return "" -} - -func (x *CertsInfo) GetClientKey() string { - if x != nil { - return x.ClientKey - } - return "" -} - type UpdateResponse struct { state protoimpl.MessageState sizeCache protoimpl.SizeCache @@ -208,7 +113,7 @@ type UpdateResponse struct { func (x *UpdateResponse) Reset() { *x = UpdateResponse{} if protoimpl.UnsafeEnabled { - mi := &file_api_agent_proto_msgTypes[2] + mi := &file_api_agent_proto_msgTypes[1] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -221,7 +126,7 @@ func (x *UpdateResponse) String() string { func (*UpdateResponse) ProtoMessage() {} func (x *UpdateResponse) ProtoReflect() protoreflect.Message { - mi := &file_api_agent_proto_msgTypes[2] + mi := &file_api_agent_proto_msgTypes[1] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -234,7 +139,7 @@ func (x *UpdateResponse) ProtoReflect() protoreflect.Message { // Deprecated: Use UpdateResponse.ProtoReflect.Descriptor instead. func (*UpdateResponse) Descriptor() ([]byte, []int) { - return file_api_agent_proto_rawDescGZIP(), []int{2} + return file_api_agent_proto_rawDescGZIP(), []int{1} } func (x *UpdateResponse) GetErr() int32 { @@ -253,7 +158,7 @@ type RollbackRequest struct { func (x *RollbackRequest) Reset() { *x = RollbackRequest{} if protoimpl.UnsafeEnabled { - mi := &file_api_agent_proto_msgTypes[3] + mi := &file_api_agent_proto_msgTypes[2] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -266,7 +171,7 @@ func (x *RollbackRequest) String() string { func (*RollbackRequest) ProtoMessage() {} func (x *RollbackRequest) ProtoReflect() protoreflect.Message { - mi := &file_api_agent_proto_msgTypes[3] + mi := &file_api_agent_proto_msgTypes[2] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -279,7 +184,7 @@ func (x *RollbackRequest) ProtoReflect() protoreflect.Message { // Deprecated: Use RollbackRequest.ProtoReflect.Descriptor instead. func (*RollbackRequest) Descriptor() ([]byte, []int) { - return file_api_agent_proto_rawDescGZIP(), []int{3} + return file_api_agent_proto_rawDescGZIP(), []int{2} } type RollbackResponse struct { @@ -293,7 +198,7 @@ type RollbackResponse struct { func (x *RollbackResponse) Reset() { *x = RollbackResponse{} if protoimpl.UnsafeEnabled { - mi := &file_api_agent_proto_msgTypes[4] + mi := &file_api_agent_proto_msgTypes[3] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -306,7 +211,7 @@ func (x *RollbackResponse) String() string { func (*RollbackResponse) ProtoMessage() {} func (x *RollbackResponse) ProtoReflect() protoreflect.Message { - mi := &file_api_agent_proto_msgTypes[4] + mi := &file_api_agent_proto_msgTypes[3] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -319,7 +224,7 @@ func (x *RollbackResponse) ProtoReflect() protoreflect.Message { // Deprecated: Use RollbackResponse.ProtoReflect.Descriptor instead. func (*RollbackResponse) Descriptor() ([]byte, []int) { - return file_api_agent_proto_rawDescGZIP(), []int{4} + return file_api_agent_proto_rawDescGZIP(), []int{3} } func (x *RollbackResponse) GetErr() int32 { @@ -340,7 +245,7 @@ type ConfigureRequest struct { func (x *ConfigureRequest) Reset() { *x = ConfigureRequest{} if protoimpl.UnsafeEnabled { - mi := &file_api_agent_proto_msgTypes[5] + mi := &file_api_agent_proto_msgTypes[4] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -353,7 +258,7 @@ func (x *ConfigureRequest) String() string { func (*ConfigureRequest) ProtoMessage() {} func (x *ConfigureRequest) ProtoReflect() protoreflect.Message { - mi := &file_api_agent_proto_msgTypes[5] + mi := &file_api_agent_proto_msgTypes[4] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -366,7 +271,7 @@ func (x *ConfigureRequest) ProtoReflect() protoreflect.Message { // Deprecated: Use ConfigureRequest.ProtoReflect.Descriptor instead. func (*ConfigureRequest) Descriptor() ([]byte, []int) { - return file_api_agent_proto_rawDescGZIP(), []int{5} + return file_api_agent_proto_rawDescGZIP(), []int{4} } func (x *ConfigureRequest) GetConfigs() []*SysConfig { @@ -387,7 +292,7 @@ type ConfigureResponse struct { func (x *ConfigureResponse) Reset() { *x = ConfigureResponse{} if protoimpl.UnsafeEnabled { - mi := &file_api_agent_proto_msgTypes[6] + mi := &file_api_agent_proto_msgTypes[5] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -400,7 +305,7 @@ func (x *ConfigureResponse) String() string { func (*ConfigureResponse) ProtoMessage() {} func (x *ConfigureResponse) ProtoReflect() protoreflect.Message { - mi := &file_api_agent_proto_msgTypes[6] + mi := &file_api_agent_proto_msgTypes[5] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -413,7 +318,7 @@ func (x *ConfigureResponse) ProtoReflect() protoreflect.Message { // Deprecated: Use ConfigureResponse.ProtoReflect.Descriptor instead. func (*ConfigureResponse) Descriptor() ([]byte, []int) { - return file_api_agent_proto_rawDescGZIP(), []int{6} + return file_api_agent_proto_rawDescGZIP(), []int{5} } func (x *ConfigureResponse) GetErr() int32 { @@ -436,7 +341,7 @@ type SysConfig struct { func (x *SysConfig) Reset() { *x = SysConfig{} if protoimpl.UnsafeEnabled { - mi := &file_api_agent_proto_msgTypes[7] + mi := &file_api_agent_proto_msgTypes[6] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -449,7 +354,7 @@ func (x *SysConfig) String() string { func (*SysConfig) ProtoMessage() {} func (x *SysConfig) ProtoReflect() protoreflect.Message { - mi := &file_api_agent_proto_msgTypes[7] + mi := &file_api_agent_proto_msgTypes[6] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -462,7 +367,7 @@ func (x *SysConfig) ProtoReflect() protoreflect.Message { // Deprecated: Use SysConfig.ProtoReflect.Descriptor instead. func (*SysConfig) Descriptor() ([]byte, []int) { - return file_api_agent_proto_rawDescGZIP(), []int{7} + return file_api_agent_proto_rawDescGZIP(), []int{6} } func (x *SysConfig) GetModel() string { @@ -498,7 +403,7 @@ type KeyInfo struct { func (x *KeyInfo) Reset() { *x = KeyInfo{} if protoimpl.UnsafeEnabled { - mi := &file_api_agent_proto_msgTypes[8] + mi := &file_api_agent_proto_msgTypes[7] ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) ms.StoreMessageInfo(mi) } @@ -511,7 +416,7 @@ func (x *KeyInfo) String() string { func (*KeyInfo) ProtoMessage() {} func (x *KeyInfo) ProtoReflect() protoreflect.Message { - mi := &file_api_agent_proto_msgTypes[8] + mi := &file_api_agent_proto_msgTypes[7] if protoimpl.UnsafeEnabled && x != nil { ms := protoimpl.X.MessageStateOf(protoimpl.Pointer(x)) if ms.LoadMessageInfo() == nil { @@ -524,7 +429,7 @@ func (x *KeyInfo) ProtoReflect() protoreflect.Message { // Deprecated: Use KeyInfo.ProtoReflect.Descriptor instead. func (*KeyInfo) Descriptor() ([]byte, []int) { - return file_api_agent_proto_rawDescGZIP(), []int{8} + return file_api_agent_proto_rawDescGZIP(), []int{7} } func (x *KeyInfo) GetValue() string { @@ -545,74 +450,60 @@ var File_api_agent_proto protoreflect.FileDescriptor var file_api_agent_proto_rawDesc = []byte{ 0x0a, 0x0f, 0x61, 0x70, 0x69, 0x2f, 0x61, 0x67, 0x65, 0x6e, 0x74, 0x2e, 0x70, 0x72, 0x6f, 0x74, - 0x6f, 0x12, 0x05, 0x61, 0x67, 0x65, 0x6e, 0x74, 0x22, 0x83, 0x02, 0x0a, 0x0d, 0x55, 0x70, 0x64, + 0x6f, 0x12, 0x05, 0x61, 0x67, 0x65, 0x6e, 0x74, 0x22, 0x8e, 0x01, 0x0a, 0x0d, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x18, 0x0a, 0x07, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x76, 0x65, 0x72, - 0x73, 0x69, 0x6f, 0x6e, 0x12, 0x1b, 0x0a, 0x09, 0x69, 0x6d, 0x61, 0x67, 0x65, 0x5f, 0x75, 0x72, - 0x6c, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x69, 0x6d, 0x61, 0x67, 0x65, 0x55, 0x72, - 0x6c, 0x12, 0x1b, 0x0a, 0x09, 0x63, 0x68, 0x65, 0x63, 0x6b, 0x5f, 0x73, 0x75, 0x6d, 0x18, 0x03, - 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x63, 0x68, 0x65, 0x63, 0x6b, 0x53, 0x75, 0x6d, 0x12, 0x1a, - 0x0a, 0x08, 0x66, 0x6c, 0x61, 0x67, 0x53, 0x61, 0x66, 0x65, 0x18, 0x04, 0x20, 0x01, 0x28, 0x08, - 0x52, 0x08, 0x66, 0x6c, 0x61, 0x67, 0x53, 0x61, 0x66, 0x65, 0x12, 0x12, 0x0a, 0x04, 0x6d, 0x54, - 0x4c, 0x53, 0x18, 0x05, 0x20, 0x01, 0x28, 0x08, 0x52, 0x04, 0x6d, 0x54, 0x4c, 0x53, 0x12, 0x1d, - 0x0a, 0x0a, 0x69, 0x6d, 0x61, 0x67, 0x65, 0x5f, 0x74, 0x79, 0x70, 0x65, 0x18, 0x06, 0x20, 0x01, - 0x28, 0x09, 0x52, 0x09, 0x69, 0x6d, 0x61, 0x67, 0x65, 0x54, 0x79, 0x70, 0x65, 0x12, 0x27, 0x0a, - 0x0f, 0x63, 0x6f, 0x6e, 0x74, 0x61, 0x69, 0x6e, 0x65, 0x72, 0x5f, 0x69, 0x6d, 0x61, 0x67, 0x65, - 0x18, 0x07, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0e, 0x63, 0x6f, 0x6e, 0x74, 0x61, 0x69, 0x6e, 0x65, - 0x72, 0x49, 0x6d, 0x61, 0x67, 0x65, 0x12, 0x26, 0x0a, 0x05, 0x63, 0x65, 0x72, 0x74, 0x73, 0x18, - 0x08, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x10, 0x2e, 0x61, 0x67, 0x65, 0x6e, 0x74, 0x2e, 0x43, 0x65, - 0x72, 0x74, 0x73, 0x49, 0x6e, 0x66, 0x6f, 0x52, 0x05, 0x63, 0x65, 0x72, 0x74, 0x73, 0x22, 0x66, - 0x0a, 0x09, 0x43, 0x65, 0x72, 0x74, 0x73, 0x49, 0x6e, 0x66, 0x6f, 0x12, 0x19, 0x0a, 0x08, 0x63, - 0x61, 0x5f, 0x63, 0x61, 0x65, 0x72, 0x74, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x07, 0x63, - 0x61, 0x43, 0x61, 0x65, 0x72, 0x74, 0x12, 0x1f, 0x0a, 0x0b, 0x63, 0x6c, 0x69, 0x65, 0x6e, 0x74, - 0x5f, 0x63, 0x65, 0x72, 0x74, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0a, 0x63, 0x6c, 0x69, - 0x65, 0x6e, 0x74, 0x43, 0x65, 0x72, 0x74, 0x12, 0x1d, 0x0a, 0x0a, 0x63, 0x6c, 0x69, 0x65, 0x6e, - 0x74, 0x5f, 0x6b, 0x65, 0x79, 0x18, 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x63, 0x6c, 0x69, - 0x65, 0x6e, 0x74, 0x4b, 0x65, 0x79, 0x22, 0x22, 0x0a, 0x0e, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, - 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x10, 0x0a, 0x03, 0x65, 0x72, 0x72, 0x18, - 0x01, 0x20, 0x01, 0x28, 0x05, 0x52, 0x03, 0x65, 0x72, 0x72, 0x22, 0x11, 0x0a, 0x0f, 0x52, 0x6f, - 0x6c, 0x6c, 0x62, 0x61, 0x63, 0x6b, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x22, 0x24, 0x0a, - 0x10, 0x52, 0x6f, 0x6c, 0x6c, 0x62, 0x61, 0x63, 0x6b, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, - 0x65, 0x12, 0x10, 0x0a, 0x03, 0x65, 0x72, 0x72, 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, 0x52, 0x03, - 0x65, 0x72, 0x72, 0x22, 0x3e, 0x0a, 0x10, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x75, 0x72, 0x65, - 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x2a, 0x0a, 0x07, 0x63, 0x6f, 0x6e, 0x66, 0x69, - 0x67, 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x10, 0x2e, 0x61, 0x67, 0x65, 0x6e, 0x74, - 0x2e, 0x53, 0x79, 0x73, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x52, 0x07, 0x63, 0x6f, 0x6e, 0x66, - 0x69, 0x67, 0x73, 0x22, 0x25, 0x0a, 0x11, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x75, 0x72, 0x65, - 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x10, 0x0a, 0x03, 0x65, 0x72, 0x72, 0x18, - 0x01, 0x20, 0x01, 0x28, 0x05, 0x52, 0x03, 0x65, 0x72, 0x72, 0x22, 0xca, 0x01, 0x0a, 0x09, 0x53, - 0x79, 0x73, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x12, 0x14, 0x0a, 0x05, 0x6d, 0x6f, 0x64, 0x65, - 0x6c, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x6d, 0x6f, 0x64, 0x65, 0x6c, 0x12, 0x1e, - 0x0a, 0x0a, 0x63, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x50, 0x61, 0x74, 0x68, 0x18, 0x02, 0x20, 0x01, - 0x28, 0x09, 0x52, 0x0a, 0x63, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x50, 0x61, 0x74, 0x68, 0x12, 0x3a, - 0x0a, 0x08, 0x63, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x74, 0x73, 0x18, 0x03, 0x20, 0x03, 0x28, 0x0b, - 0x32, 0x1e, 0x2e, 0x61, 0x67, 0x65, 0x6e, 0x74, 0x2e, 0x53, 0x79, 0x73, 0x43, 0x6f, 0x6e, 0x66, - 0x69, 0x67, 0x2e, 0x43, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x74, 0x73, 0x45, 0x6e, 0x74, 0x72, 0x79, - 0x52, 0x08, 0x63, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x74, 0x73, 0x1a, 0x4b, 0x0a, 0x0d, 0x43, 0x6f, - 0x6e, 0x74, 0x65, 0x6e, 0x74, 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, 0x24, 0x0a, - 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, 0x0e, 0x2e, 0x61, - 0x67, 0x65, 0x6e, 0x74, 0x2e, 0x4b, 0x65, 0x79, 0x49, 0x6e, 0x66, 0x6f, 0x52, 0x05, 0x76, 0x61, - 0x6c, 0x75, 0x65, 0x3a, 0x02, 0x38, 0x01, 0x22, 0x3d, 0x0a, 0x07, 0x4b, 0x65, 0x79, 0x49, 0x6e, - 0x66, 0x6f, 0x12, 0x14, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x01, 0x20, 0x01, 0x28, - 0x09, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x12, 0x1c, 0x0a, 0x09, 0x6f, 0x70, 0x65, 0x72, - 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x6f, 0x70, 0x65, - 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x32, 0xbe, 0x01, 0x0a, 0x02, 0x4f, 0x53, 0x12, 0x37, 0x0a, - 0x06, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x12, 0x14, 0x2e, 0x61, 0x67, 0x65, 0x6e, 0x74, 0x2e, - 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x15, 0x2e, - 0x61, 0x67, 0x65, 0x6e, 0x74, 0x2e, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x52, 0x65, 0x73, 0x70, - 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x12, 0x3d, 0x0a, 0x08, 0x52, 0x6f, 0x6c, 0x6c, 0x62, 0x61, - 0x63, 0x6b, 0x12, 0x16, 0x2e, 0x61, 0x67, 0x65, 0x6e, 0x74, 0x2e, 0x52, 0x6f, 0x6c, 0x6c, 0x62, - 0x61, 0x63, 0x6b, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x17, 0x2e, 0x61, 0x67, 0x65, - 0x6e, 0x74, 0x2e, 0x52, 0x6f, 0x6c, 0x6c, 0x62, 0x61, 0x63, 0x6b, 0x52, 0x65, 0x73, 0x70, 0x6f, - 0x6e, 0x73, 0x65, 0x22, 0x00, 0x12, 0x40, 0x0a, 0x09, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x75, - 0x72, 0x65, 0x12, 0x17, 0x2e, 0x61, 0x67, 0x65, 0x6e, 0x74, 0x2e, 0x43, 0x6f, 0x6e, 0x66, 0x69, - 0x67, 0x75, 0x72, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x18, 0x2e, 0x61, 0x67, - 0x65, 0x6e, 0x74, 0x2e, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x75, 0x72, 0x65, 0x52, 0x65, 0x73, - 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x42, 0x20, 0x5a, 0x1e, 0x6f, 0x70, 0x65, 0x6e, 0x65, - 0x75, 0x6c, 0x65, 0x72, 0x2e, 0x6f, 0x72, 0x67, 0x2f, 0x6b, 0x75, 0x62, 0x65, 0x6f, 0x73, 0x2f, - 0x61, 0x70, 0x69, 0x2f, 0x61, 0x67, 0x65, 0x6e, 0x74, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, - 0x33, + 0x73, 0x69, 0x6f, 0x6e, 0x12, 0x1b, 0x0a, 0x09, 0x63, 0x68, 0x65, 0x63, 0x6b, 0x5f, 0x73, 0x75, + 0x6d, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x08, 0x63, 0x68, 0x65, 0x63, 0x6b, 0x53, 0x75, + 0x6d, 0x12, 0x1d, 0x0a, 0x0a, 0x69, 0x6d, 0x61, 0x67, 0x65, 0x5f, 0x74, 0x79, 0x70, 0x65, 0x18, + 0x03, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, 0x69, 0x6d, 0x61, 0x67, 0x65, 0x54, 0x79, 0x70, 0x65, + 0x12, 0x27, 0x0a, 0x0f, 0x63, 0x6f, 0x6e, 0x74, 0x61, 0x69, 0x6e, 0x65, 0x72, 0x5f, 0x69, 0x6d, + 0x61, 0x67, 0x65, 0x18, 0x04, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0e, 0x63, 0x6f, 0x6e, 0x74, 0x61, + 0x69, 0x6e, 0x65, 0x72, 0x49, 0x6d, 0x61, 0x67, 0x65, 0x22, 0x22, 0x0a, 0x0e, 0x55, 0x70, 0x64, + 0x61, 0x74, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x10, 0x0a, 0x03, 0x65, + 0x72, 0x72, 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, 0x52, 0x03, 0x65, 0x72, 0x72, 0x22, 0x11, 0x0a, + 0x0f, 0x52, 0x6f, 0x6c, 0x6c, 0x62, 0x61, 0x63, 0x6b, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, + 0x22, 0x24, 0x0a, 0x10, 0x52, 0x6f, 0x6c, 0x6c, 0x62, 0x61, 0x63, 0x6b, 0x52, 0x65, 0x73, 0x70, + 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x10, 0x0a, 0x03, 0x65, 0x72, 0x72, 0x18, 0x01, 0x20, 0x01, 0x28, + 0x05, 0x52, 0x03, 0x65, 0x72, 0x72, 0x22, 0x3e, 0x0a, 0x10, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, + 0x75, 0x72, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x2a, 0x0a, 0x07, 0x63, 0x6f, + 0x6e, 0x66, 0x69, 0x67, 0x73, 0x18, 0x01, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x10, 0x2e, 0x61, 0x67, + 0x65, 0x6e, 0x74, 0x2e, 0x53, 0x79, 0x73, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x52, 0x07, 0x63, + 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x73, 0x22, 0x25, 0x0a, 0x11, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, + 0x75, 0x72, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x12, 0x10, 0x0a, 0x03, 0x65, + 0x72, 0x72, 0x18, 0x01, 0x20, 0x01, 0x28, 0x05, 0x52, 0x03, 0x65, 0x72, 0x72, 0x22, 0xca, 0x01, + 0x0a, 0x09, 0x53, 0x79, 0x73, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x12, 0x14, 0x0a, 0x05, 0x6d, + 0x6f, 0x64, 0x65, 0x6c, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x6d, 0x6f, 0x64, 0x65, + 0x6c, 0x12, 0x1e, 0x0a, 0x0a, 0x63, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x50, 0x61, 0x74, 0x68, 0x18, + 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x0a, 0x63, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x50, 0x61, 0x74, + 0x68, 0x12, 0x3a, 0x0a, 0x08, 0x63, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x74, 0x73, 0x18, 0x03, 0x20, + 0x03, 0x28, 0x0b, 0x32, 0x1e, 0x2e, 0x61, 0x67, 0x65, 0x6e, 0x74, 0x2e, 0x53, 0x79, 0x73, 0x43, + 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x2e, 0x43, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x74, 0x73, 0x45, 0x6e, + 0x74, 0x72, 0x79, 0x52, 0x08, 0x63, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x74, 0x73, 0x1a, 0x4b, 0x0a, + 0x0d, 0x43, 0x6f, 0x6e, 0x74, 0x65, 0x6e, 0x74, 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, 0x24, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x02, 0x20, 0x01, 0x28, 0x0b, 0x32, + 0x0e, 0x2e, 0x61, 0x67, 0x65, 0x6e, 0x74, 0x2e, 0x4b, 0x65, 0x79, 0x49, 0x6e, 0x66, 0x6f, 0x52, + 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x3a, 0x02, 0x38, 0x01, 0x22, 0x3d, 0x0a, 0x07, 0x4b, 0x65, + 0x79, 0x49, 0x6e, 0x66, 0x6f, 0x12, 0x14, 0x0a, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x18, 0x01, + 0x20, 0x01, 0x28, 0x09, 0x52, 0x05, 0x76, 0x61, 0x6c, 0x75, 0x65, 0x12, 0x1c, 0x0a, 0x09, 0x6f, + 0x70, 0x65, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x18, 0x02, 0x20, 0x01, 0x28, 0x09, 0x52, 0x09, + 0x6f, 0x70, 0x65, 0x72, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x32, 0xbe, 0x01, 0x0a, 0x02, 0x4f, 0x53, + 0x12, 0x37, 0x0a, 0x06, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x12, 0x14, 0x2e, 0x61, 0x67, 0x65, + 0x6e, 0x74, 0x2e, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, + 0x1a, 0x15, 0x2e, 0x61, 0x67, 0x65, 0x6e, 0x74, 0x2e, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x52, + 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x12, 0x3d, 0x0a, 0x08, 0x52, 0x6f, 0x6c, + 0x6c, 0x62, 0x61, 0x63, 0x6b, 0x12, 0x16, 0x2e, 0x61, 0x67, 0x65, 0x6e, 0x74, 0x2e, 0x52, 0x6f, + 0x6c, 0x6c, 0x62, 0x61, 0x63, 0x6b, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x17, 0x2e, + 0x61, 0x67, 0x65, 0x6e, 0x74, 0x2e, 0x52, 0x6f, 0x6c, 0x6c, 0x62, 0x61, 0x63, 0x6b, 0x52, 0x65, + 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x12, 0x40, 0x0a, 0x09, 0x43, 0x6f, 0x6e, 0x66, + 0x69, 0x67, 0x75, 0x72, 0x65, 0x12, 0x17, 0x2e, 0x61, 0x67, 0x65, 0x6e, 0x74, 0x2e, 0x43, 0x6f, + 0x6e, 0x66, 0x69, 0x67, 0x75, 0x72, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x18, + 0x2e, 0x61, 0x67, 0x65, 0x6e, 0x74, 0x2e, 0x43, 0x6f, 0x6e, 0x66, 0x69, 0x67, 0x75, 0x72, 0x65, + 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x22, 0x00, 0x42, 0x20, 0x5a, 0x1e, 0x6f, 0x70, + 0x65, 0x6e, 0x65, 0x75, 0x6c, 0x65, 0x72, 0x2e, 0x6f, 0x72, 0x67, 0x2f, 0x6b, 0x75, 0x62, 0x65, + 0x6f, 0x73, 0x2f, 0x61, 0x70, 0x69, 0x2f, 0x61, 0x67, 0x65, 0x6e, 0x74, 0x62, 0x06, 0x70, 0x72, + 0x6f, 0x74, 0x6f, 0x33, } var ( @@ -627,35 +518,33 @@ func file_api_agent_proto_rawDescGZIP() []byte { return file_api_agent_proto_rawDescData } -var file_api_agent_proto_msgTypes = make([]protoimpl.MessageInfo, 10) +var file_api_agent_proto_msgTypes = make([]protoimpl.MessageInfo, 9) var file_api_agent_proto_goTypes = []interface{}{ (*UpdateRequest)(nil), // 0: agent.UpdateRequest - (*CertsInfo)(nil), // 1: agent.CertsInfo - (*UpdateResponse)(nil), // 2: agent.UpdateResponse - (*RollbackRequest)(nil), // 3: agent.RollbackRequest - (*RollbackResponse)(nil), // 4: agent.RollbackResponse - (*ConfigureRequest)(nil), // 5: agent.ConfigureRequest - (*ConfigureResponse)(nil), // 6: agent.ConfigureResponse - (*SysConfig)(nil), // 7: agent.SysConfig - (*KeyInfo)(nil), // 8: agent.KeyInfo - nil, // 9: agent.SysConfig.ContentsEntry + (*UpdateResponse)(nil), // 1: agent.UpdateResponse + (*RollbackRequest)(nil), // 2: agent.RollbackRequest + (*RollbackResponse)(nil), // 3: agent.RollbackResponse + (*ConfigureRequest)(nil), // 4: agent.ConfigureRequest + (*ConfigureResponse)(nil), // 5: agent.ConfigureResponse + (*SysConfig)(nil), // 6: agent.SysConfig + (*KeyInfo)(nil), // 7: agent.KeyInfo + nil, // 8: agent.SysConfig.ContentsEntry } var file_api_agent_proto_depIdxs = []int32{ - 1, // 0: agent.UpdateRequest.certs:type_name -> agent.CertsInfo - 7, // 1: agent.ConfigureRequest.configs:type_name -> agent.SysConfig - 9, // 2: agent.SysConfig.contents:type_name -> agent.SysConfig.ContentsEntry - 8, // 3: agent.SysConfig.ContentsEntry.value:type_name -> agent.KeyInfo - 0, // 4: agent.OS.Update:input_type -> agent.UpdateRequest - 3, // 5: agent.OS.Rollback:input_type -> agent.RollbackRequest - 5, // 6: agent.OS.Configure:input_type -> agent.ConfigureRequest - 2, // 7: agent.OS.Update:output_type -> agent.UpdateResponse - 4, // 8: agent.OS.Rollback:output_type -> agent.RollbackResponse - 6, // 9: agent.OS.Configure:output_type -> agent.ConfigureResponse - 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 + 6, // 0: agent.ConfigureRequest.configs:type_name -> agent.SysConfig + 8, // 1: agent.SysConfig.contents:type_name -> agent.SysConfig.ContentsEntry + 7, // 2: agent.SysConfig.ContentsEntry.value:type_name -> agent.KeyInfo + 0, // 3: agent.OS.Update:input_type -> agent.UpdateRequest + 2, // 4: agent.OS.Rollback:input_type -> agent.RollbackRequest + 4, // 5: agent.OS.Configure:input_type -> agent.ConfigureRequest + 1, // 6: agent.OS.Update:output_type -> agent.UpdateResponse + 3, // 7: agent.OS.Rollback:output_type -> agent.RollbackResponse + 5, // 8: agent.OS.Configure:output_type -> agent.ConfigureResponse + 6, // [6:9] is the sub-list for method output_type + 3, // [3:6] is the sub-list for method input_type + 3, // [3:3] is the sub-list for extension type_name + 3, // [3:3] is the sub-list for extension extendee + 0, // [0:3] is the sub-list for field type_name } func init() { file_api_agent_proto_init() } @@ -677,18 +566,6 @@ func file_api_agent_proto_init() { } } file_api_agent_proto_msgTypes[1].Exporter = func(v interface{}, i int) interface{} { - switch v := v.(*CertsInfo); i { - case 0: - return &v.state - case 1: - return &v.sizeCache - case 2: - return &v.unknownFields - default: - return nil - } - } - file_api_agent_proto_msgTypes[2].Exporter = func(v interface{}, i int) interface{} { switch v := v.(*UpdateResponse); i { case 0: return &v.state @@ -700,7 +577,7 @@ func file_api_agent_proto_init() { return nil } } - file_api_agent_proto_msgTypes[3].Exporter = func(v interface{}, i int) interface{} { + file_api_agent_proto_msgTypes[2].Exporter = func(v interface{}, i int) interface{} { switch v := v.(*RollbackRequest); i { case 0: return &v.state @@ -712,7 +589,7 @@ func file_api_agent_proto_init() { return nil } } - file_api_agent_proto_msgTypes[4].Exporter = func(v interface{}, i int) interface{} { + file_api_agent_proto_msgTypes[3].Exporter = func(v interface{}, i int) interface{} { switch v := v.(*RollbackResponse); i { case 0: return &v.state @@ -724,7 +601,7 @@ func file_api_agent_proto_init() { return nil } } - file_api_agent_proto_msgTypes[5].Exporter = func(v interface{}, i int) interface{} { + file_api_agent_proto_msgTypes[4].Exporter = func(v interface{}, i int) interface{} { switch v := v.(*ConfigureRequest); i { case 0: return &v.state @@ -736,7 +613,7 @@ func file_api_agent_proto_init() { return nil } } - file_api_agent_proto_msgTypes[6].Exporter = func(v interface{}, i int) interface{} { + file_api_agent_proto_msgTypes[5].Exporter = func(v interface{}, i int) interface{} { switch v := v.(*ConfigureResponse); i { case 0: return &v.state @@ -748,7 +625,7 @@ func file_api_agent_proto_init() { return nil } } - file_api_agent_proto_msgTypes[7].Exporter = func(v interface{}, i int) interface{} { + file_api_agent_proto_msgTypes[6].Exporter = func(v interface{}, i int) interface{} { switch v := v.(*SysConfig); i { case 0: return &v.state @@ -760,7 +637,7 @@ func file_api_agent_proto_init() { return nil } } - file_api_agent_proto_msgTypes[8].Exporter = func(v interface{}, i int) interface{} { + file_api_agent_proto_msgTypes[7].Exporter = func(v interface{}, i int) interface{} { switch v := v.(*KeyInfo); i { case 0: return &v.state @@ -779,7 +656,7 @@ func file_api_agent_proto_init() { GoPackagePath: reflect.TypeOf(x{}).PkgPath(), RawDescriptor: file_api_agent_proto_rawDesc, NumEnums: 0, - NumMessages: 10, + NumMessages: 9, NumExtensions: 0, NumServices: 1, }, diff --git a/cmd/agent/api/agent.proto b/cmd/agent/api/agent.proto index fd15b9f..e81ad54 100644 --- a/cmd/agent/api/agent.proto +++ b/cmd/agent/api/agent.proto @@ -24,20 +24,11 @@ service OS { message UpdateRequest { string version = 1; - string image_url = 2; - string check_sum = 3; - bool flagSafe = 4; - bool mTLS = 5; - string image_type = 6; - string container_image = 7; - CertsInfo certs = 8; + string check_sum = 2; + string image_type = 3; + string container_image = 4; } -message CertsInfo { - string ca_caert = 1; - string client_cert = 2; - string client_key = 3; -} message UpdateResponse { int32 err = 1; diff --git a/cmd/agent/server/disk_image.go b/cmd/agent/server/disk_image.go deleted file mode 100644 index 8bd6bf6..0000000 --- a/cmd/agent/server/disk_image.go +++ /dev/null @@ -1,217 +0,0 @@ -/* - * Copyright (c) Huawei Technologies Co., Ltd. 2022. All rights reserved. - * KubeOS is licensed under the Mulan PSL v2. - * You can use this software according to the terms and conditions of the Mulan PSL v2. - * You may obtain a copy of Mulan PSL v2 at: - * http://license.coscl.org.cn/MulanPSL2 - * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR - * PURPOSE. - * See the Mulan PSL v2 for more details. - */ - -// Package server implements server of os-agent and listener of os-agent server. The server uses gRPC interface. -package server - -import ( - "crypto/sha256" - "crypto/tls" - "crypto/x509" - "encoding/hex" - "fmt" - "io" - "io/ioutil" - "net/http" - "os" - "path/filepath" - "strings" - "syscall" - - "github.com/sirupsen/logrus" - - pb "openeuler.org/KubeOS/cmd/agent/api" -) - -type diskHandler struct{} - -func (d diskHandler) downloadImage(req *pb.UpdateRequest) (string, error) { - imagePath, err := d.getRootfsArchive(req, preparePath{}) - if err != nil { - return "", err - } - return imagePath, nil -} - -func (d diskHandler) getRootfsArchive(req *pb.UpdateRequest, neededPath preparePath) (string, error) { - imagePath, err := download(req) - if err != nil { - return "", err - } - if err = checkSumMatch(imagePath, req.CheckSum); err != nil { - return "", err - } - return imagePath, nil -} - -func download(req *pb.UpdateRequest) (string, error) { - resp, err := getImageURL(req) - if err != nil { - return "", err - } - defer resp.Body.Close() - if resp.StatusCode != http.StatusOK { - return "", fmt.Errorf("URL %s returns error %s", req.ImageUrl, resp.Status) - } - fs := syscall.Statfs_t{} - if err = syscall.Statfs(PersistDir, &fs); err != nil { - return "", err - } - if int64(fs.Bfree)*fs.Bsize < resp.ContentLength+buffer { // these data come from disk size, will not overflow - return "", fmt.Errorf("space is not enough for downloaing") - } - - out, err := os.Create(filepath.Join(PersistDir, "update.img")) - if err != nil { - return "", err - } - defer out.Close() - err = os.Chmod(out.Name(), imgPermission) - if err != nil { - return "", err - } - logrus.Infoln("downloading to file " + out.Name()) - if _, err = io.Copy(out, resp.Body); err != nil { - if errRemove := os.Remove(out.Name()); errRemove != nil { - logrus.Errorln("remove " + out.Name() + " error " + errRemove.Error()) - } - return "", err - } - return out.Name(), nil -} - -func checkSumMatch(filePath, checkSum string) error { - file, err := os.Open(filePath) - if err != nil { - return err - } - defer file.Close() - hash := sha256.New() - if _, err := io.Copy(hash, file); err != nil { - return err - } - if calSum := hex.EncodeToString(hash.Sum(nil)); calSum != checkSum { - defer os.Remove(filePath) - return fmt.Errorf("checkSum %s mismatch to %s", calSum, checkSum) - } - return nil -} - -func getImageURL(req *pb.UpdateRequest) (*http.Response, error) { - imageURL := req.ImageUrl - flagSafe := req.FlagSafe - mTLS := req.MTLS - caCert := req.Certs.CaCaert - clientCert := req.Certs.ClientCert - clientKey := req.Certs.ClientKey - - if !strings.HasPrefix(imageURL, "https://") { - if !flagSafe { - logrus.Errorln("this imageUrl is not safe") - return &http.Response{}, fmt.Errorf("this imageUrl is not safe") - } - resp, err := http.Get(imageURL) - if err != nil { - return &http.Response{}, err - } - return resp, nil - } else if mTLS { - client, err := loadClientCerts(caCert, clientCert, clientKey) - if err != nil { - return &http.Response{}, err - } - resp, err := client.Get(imageURL) - if err != nil { - return &http.Response{}, err - } - return resp, nil - } else { - client, err := loadCaCerts(caCert) - if err != nil { - return &http.Response{}, err - } - resp, err := client.Get(imageURL) - if err != nil { - return &http.Response{}, err - } - return resp, nil - } -} - -func loadCaCerts(caCert string) (*http.Client, error) { - pool := x509.NewCertPool() - err := certExist(caCert) - if err != nil { - return &http.Client{}, err - } - ca, err := ioutil.ReadFile(getCertPath() + caCert) - if err != nil { - return &http.Client{}, fmt.Errorf("read the ca certificate error %s", err) - } - pool.AppendCertsFromPEM(ca) - tr := &http.Transport{ - TLSClientConfig: &tls.Config{ - RootCAs: pool, - }, - } - client := &http.Client{Transport: tr} - return client, nil -} - -func loadClientCerts(caCert, clientCert, clientKey string) (*http.Client, error) { - pool := x509.NewCertPool() - err := certExist(caCert) - if err != nil { - return &http.Client{}, err - } - ca, err := ioutil.ReadFile(getCertPath() + caCert) - if err != nil { - return &http.Client{}, err - } - pool.AppendCertsFromPEM(ca) - err = certExist(clientCert) - if err != nil { - return &http.Client{}, err - } - err = certExist(clientKey) - if err != nil { - return &http.Client{}, err - } - cliCrt, err := tls.LoadX509KeyPair(getCertPath()+clientCert, getCertPath()+clientKey) - if err != nil { - return &http.Client{}, err - } - - tr := &http.Transport{ - TLSClientConfig: &tls.Config{ - RootCAs: pool, - Certificates: []tls.Certificate{cliCrt}, - }, - } - - client := &http.Client{Transport: tr} - return client, nil -} - -func certExist(certFile string) error { - if certFile == "" { - return fmt.Errorf("please provide the certificate") - } - _, err := os.Stat(getCertPath() + certFile) - if err != nil { - if os.IsNotExist(err) { - return fmt.Errorf("certificate is not exist %s ", err) - } - return fmt.Errorf("certificate has an error %s", err) - } - return nil -} diff --git a/cmd/agent/server/disk_image_test.go b/cmd/agent/server/disk_image_test.go deleted file mode 100644 index f970bd7..0000000 --- a/cmd/agent/server/disk_image_test.go +++ /dev/null @@ -1,471 +0,0 @@ -/* - * Copyright (c) Huawei Technologies Co., Ltd. 2022. All rights reserved. - * KubeOS is licensed under the Mulan PSL v2. - * You can use this software according to the terms and conditions of the Mulan PSL v2. - * You may obtain a copy of Mulan PSL v2 at: - * http://license.coscl.org.cn/MulanPSL2 - * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR - * PURPOSE. - * See the Mulan PSL v2 for more details. - */ - -// Package server implements server of os-agent and listener of os-agent server. The server uses gRPC interface. -package server - -import ( - "crypto/rand" - "crypto/rsa" - "crypto/sha256" - "crypto/x509" - "crypto/x509/pkix" - "encoding/hex" - "encoding/pem" - "fmt" - "io" - "io/fs" - "math/big" - "net/http" - "os" - "reflect" - "strings" - "syscall" - "testing" - "time" - - "github.com/agiledragon/gomonkey/v2" - pb "openeuler.org/KubeOS/cmd/agent/api" -) - -func Test_download(t *testing.T) { - tmpDir := t.TempDir() - tmpFileForDownload := tmpDir + "/tmpFileForDownload" - tmpFile, err := os.Create(tmpFileForDownload) - if err != nil { - t.Errorf("open file error: %v", err) - } - defer tmpFile.Close() - type args struct { - req *pb.UpdateRequest - } - tests := []struct { - name string - args args - want string - wantErr bool - }{ - {name: "errornil", args: args{&pb.UpdateRequest{Certs: &pb.CertsInfo{}}}, want: "", wantErr: true}, - {name: "error response", args: args{&pb.UpdateRequest{ImageUrl: "http://www.openeuler.abc", FlagSafe: true, Certs: &pb.CertsInfo{}}}, want: "", wantErr: true}, - { - name: "normal", - args: args{ - req: &pb.UpdateRequest{ - ImageUrl: "http://www.openeuler.org/zh/", - FlagSafe: true, - Certs: &pb.CertsInfo{}, - }, - }, - want: tmpFileForDownload, - wantErr: false, - }, - { - name: "disk space not enough", - args: args{ - req: &pb.UpdateRequest{ - ImageUrl: "http://www.openeuler.org/zh/", - FlagSafe: true, - Certs: &pb.CertsInfo{}, - }, - }, - want: "", - wantErr: true, - }, - } - var patchStatfs *gomonkey.Patches - patchStatfs = gomonkey.ApplyFunc(syscall.Statfs, func(path string, stat *syscall.Statfs_t) error { - stat.Bfree = 3000 - stat.Bsize = 4096 - return nil - }) - defer patchStatfs.Reset() - patchGetImageUrl := gomonkey.ApplyFuncSeq(getImageURL, - []gomonkey.OutputCell{ - {Values: gomonkey.Params{&http.Response{}, fmt.Errorf("error")}}, - {Values: gomonkey.Params{&http.Response{StatusCode: http.StatusBadRequest, Body: io.NopCloser(strings.NewReader(""))}, nil}}, - { - Values: gomonkey.Params{ - &http.Response{ - StatusCode: http.StatusOK, - ContentLength: 5, - Body: io.NopCloser(strings.NewReader("hello")), - }, - nil, - }, - }, - { - Values: gomonkey.Params{ - &http.Response{ - StatusCode: http.StatusOK, - ContentLength: 5, - Body: io.NopCloser(strings.NewReader("hello")), - }, - nil, - }, - }, - }, - ) - defer patchGetImageUrl.Reset() - patchOSCreate := gomonkey.ApplyFuncReturn(os.Create, tmpFile, nil) - defer patchOSCreate.Reset() - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - if tt.name == "disk space not enough" { - patchStatfs = gomonkey.ApplyFunc(syscall.Statfs, func(path string, stat *syscall.Statfs_t) error { - stat.Bfree = 1 - stat.Bsize = 4096 - return nil - }) - } - got, err := download(tt.args.req) - if (err != nil) != tt.wantErr { - t.Errorf("download() error = %v, wantErr %v", err, tt.wantErr) - return - } - if got != tt.want { - t.Errorf("download() got = %v, want %v", got, tt.want) - } - }) - } -} - -func Test_checkSumMatch(t *testing.T) { - tmpDir := t.TempDir() - tmpFileForCheckSum := tmpDir + "/tmpFileForCheckSum" - err := os.WriteFile(tmpFileForCheckSum, []byte("hello"), 0644) - if err != nil { - t.Errorf("open file error: %v", err) - } - type args struct { - filePath string - checkSum string - } - tests := []struct { - name string - args args - wantErr bool - }{ - { - name: "normal", - args: args{filePath: tmpFileForCheckSum, checkSum: calculateChecksum("hello")}, - wantErr: false, - }, - {name: "error", args: args{filePath: tmpFileForCheckSum, checkSum: "aaa"}, wantErr: true}, - {name: "unfound error", args: args{filePath: "", checkSum: "aaa"}, wantErr: true}, - } - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - if err := checkSumMatch(tt.args.filePath, tt.args.checkSum); (err != nil) != tt.wantErr { - t.Errorf("checkSumMatch() error = %v, wantErr %v", err, tt.wantErr) - } - }) - } -} - -func Test_getImageURL(t *testing.T) { - type args struct { - req *pb.UpdateRequest - } - tests := []struct { - name string - args args - want *http.Response - wantErr bool - }{ - {name: "httpNotSafe", args: args{req: &pb.UpdateRequest{ - ImageUrl: "http://www.openeuler.abc/zh/", - FlagSafe: false, - MTLS: false, - Certs: &pb.CertsInfo{}, - }}, want: &http.Response{}, wantErr: true}, - {name: "httpSuccess", args: args{req: &pb.UpdateRequest{ - ImageUrl: "http://www.openeuler.abc/zh/", - FlagSafe: true, - MTLS: false, - Certs: &pb.CertsInfo{}, - }}, want: &http.Response{StatusCode: http.StatusOK}, wantErr: false}, - {name: "mTLSGetSuccess", args: args{req: &pb.UpdateRequest{ - ImageUrl: "https://www.openeuler.abc/zh/", - FlagSafe: true, - MTLS: true, - Certs: &pb.CertsInfo{}, - }}, want: &http.Response{StatusCode: http.StatusOK}, wantErr: false}, - {name: "httpsGetSuccess", args: args{req: &pb.UpdateRequest{ - ImageUrl: "https://www.openeuler.abc/zh/", - FlagSafe: true, - MTLS: false, - Certs: &pb.CertsInfo{}, - }}, want: &http.Response{StatusCode: http.StatusOK}, wantErr: false}, - {name: "httpsLoadCertsError", args: args{req: &pb.UpdateRequest{ - ImageUrl: "https://www.openeuler.abc/zh/", - FlagSafe: true, - MTLS: false, - Certs: &pb.CertsInfo{}, - }}, want: &http.Response{}, wantErr: true}, - {name: "httpsMLTSLoadCertsError", args: args{req: &pb.UpdateRequest{ - ImageUrl: "https://www.openeuler.abc/zh/", - FlagSafe: true, - MTLS: true, - Certs: &pb.CertsInfo{}, - }}, want: &http.Response{}, wantErr: true}, - } - patchLoadClientCerts := gomonkey.ApplyFuncSeq(loadClientCerts, []gomonkey.OutputCell{ - {Values: gomonkey.Params{&http.Client{}, nil}}, - {Values: gomonkey.Params{&http.Client{}, fmt.Errorf("error")}}, - }) - defer patchLoadClientCerts.Reset() - patchLoadCaCerts := gomonkey.ApplyFuncSeq(loadCaCerts, []gomonkey.OutputCell{ - {Values: gomonkey.Params{&http.Client{}, nil}}, - {Values: gomonkey.Params{&http.Client{}, fmt.Errorf("error")}}, - }) - defer patchLoadCaCerts.Reset() - patchGet := gomonkey.ApplyFunc(http.Get, func(url string) (resp *http.Response, err error) { - return &http.Response{StatusCode: http.StatusOK}, nil - }) - defer patchGet.Reset() - patchClientGet := gomonkey.ApplyMethod(reflect.TypeOf(&http.Client{}), "Get", func(_ *http.Client, url string) (resp *http.Response, err error) { - return &http.Response{StatusCode: http.StatusOK}, nil - }) - defer patchClientGet.Reset() - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - if tt.name == "httpSuccess" { - patchGet := gomonkey.ApplyFuncReturn(http.Get, &http.Response{StatusCode: http.StatusOK}, nil) - defer patchGet.Reset() - } - got, err := getImageURL(tt.args.req) - if (err != nil) != tt.wantErr { - t.Errorf("getImageURL() error = %v, wantErr %v", err, tt.wantErr) - return - } - if !reflect.DeepEqual(got, tt.want) { - t.Errorf("getImageURL() got = %v, want %v", got, tt.want) - } - }) - } -} - -func Test_loadCaCerts(t *testing.T) { - tmpDir := t.TempDir() - caPath := tmpDir + "/fake.crt" - createFakeCertKey(caPath, "") - type args struct { - caCert string - } - tests := []struct { - name string - args args - wantErr bool - }{ - { - name: "normal", - args: args{ - caCert: caPath, - }, - wantErr: false, - }, - {name: "no cert", args: args{caCert: ""}, wantErr: true}, - } - patchGetCertPath := gomonkey.ApplyFuncReturn(getCertPath, "") - defer patchGetCertPath.Reset() - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - got, err := loadCaCerts(tt.args.caCert) - if (err != nil) != tt.wantErr { - t.Errorf("loadCaCerts() error = %v, wantErr %v", err, tt.wantErr) - return - } - if got == nil { - t.Errorf("loadCaCerts() = %v", got) - } - }) - } - -} - -func Test_loadClientCerts(t *testing.T) { - tmpDir := t.TempDir() - clientCertPath := tmpDir + "/fakeClientCert.crt" - clientKeyPath := tmpDir + "/fakeClientKey.crt" - createFakeCertKey(clientCertPath, clientKeyPath) - type args struct { - caCert string - clientCert string - clientKey string - } - tests := []struct { - name string - args args - wantErr bool - }{ - { - name: "normal", - args: args{ - caCert: clientCertPath, clientCert: clientCertPath, clientKey: clientKeyPath, - }, - wantErr: false, - }, - } - patchGetCertPath := gomonkey.ApplyFuncReturn(getCertPath, "") - defer patchGetCertPath.Reset() - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - got, err := loadClientCerts(tt.args.caCert, tt.args.clientCert, tt.args.clientKey) - if (err != nil) != tt.wantErr { - t.Errorf("loadClientCerts() error = %v, wantErr %v", err, tt.wantErr) - return - } - if got == nil { - t.Errorf("loadClientCerts() got = %v", got) - } - }) - } -} - -func Test_certExist(t *testing.T) { - type args struct { - certFile string - } - tests := []struct { - name string - args args - wantErr bool - }{ - {name: "fileEmpty", args: args{certFile: ""}, wantErr: true}, - {name: "fileNotExist", args: args{certFile: "bb.txt"}, wantErr: true}, - {name: "unknow error", args: args{certFile: "cc.txt"}, wantErr: true}, - } - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - var patchStat *gomonkey.Patches - if tt.name == "unknow error" { - patchStat = gomonkey.ApplyFunc(os.Stat, func(name string) (fs.FileInfo, error) { - return fs.FileInfo(nil), fmt.Errorf("error") - }) - } - if err := certExist(tt.args.certFile); (err != nil) != tt.wantErr { - t.Errorf("certExist() error = %v, wantErr %v", err, tt.wantErr) - } - if tt.name == "unknow error" { - patchStat.Reset() - } - }) - } - defer os.RemoveAll("/etc/KubeOS/") -} - -func createFakeCertKey(certPath, keyPath string) { - privateKey, _ := rsa.GenerateKey(rand.Reader, 2048) - template := x509.Certificate{ - SerialNumber: big.NewInt(1), - Subject: pkix.Name{ - CommonName: "Fake Client Certificate", - }, - NotBefore: time.Now(), - NotAfter: time.Now().AddDate(1, 0, 0), - KeyUsage: x509.KeyUsageKeyEncipherment | x509.KeyUsageDigitalSignature, - ExtKeyUsage: []x509.ExtKeyUsage{x509.ExtKeyUsageClientAuth}, - BasicConstraintsValid: true, - } - certBytes, _ := x509.CreateCertificate(rand.Reader, &template, &template, &privateKey.PublicKey, privateKey) - certPEM := pem.EncodeToMemory(&pem.Block{Type: "CERTIFICATE", Bytes: certBytes}) - keyPEM := pem.EncodeToMemory(&pem.Block{Type: "RSA PRIVATE KEY", Bytes: x509.MarshalPKCS1PrivateKey(privateKey)}) - os.WriteFile(certPath, certPEM, 0644) - if keyPath != "" { - os.WriteFile(keyPath, keyPEM, 0644) - } -} - -func calculateChecksum(data string) string { - hash := sha256.New() - hash.Write([]byte(data)) - return hex.EncodeToString(hash.Sum(nil)) -} - -func Test_diskHandler_getRootfsArchive(t *testing.T) { - type args struct { - req *pb.UpdateRequest - neededPath preparePath - } - tests := []struct { - name string - d diskHandler - args args - want string - wantErr bool - }{ - { - name: "normal", d: diskHandler{}, - args: args{req: &pb.UpdateRequest{ImageUrl: "http://www.openeuler.org/zh/"}, neededPath: preparePath{}}, - want: "/persist/update.img", - wantErr: false, - }, - { - name: "error", d: diskHandler{}, - args: args{req: &pb.UpdateRequest{ImageUrl: "http://www.openeuler.org/zh/"}, neededPath: preparePath{}}, - want: "", - wantErr: true, - }, - } - patchDownload := gomonkey.ApplyFuncSeq(download, []gomonkey.OutputCell{ - {Values: gomonkey.Params{"/persist/update.img", nil}}, - {Values: gomonkey.Params{"", fmt.Errorf("error")}}, - }) - defer patchDownload.Reset() - patchCheckSumMatch := gomonkey.ApplyFuncReturn(checkSumMatch, nil) - defer patchCheckSumMatch.Reset() - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - d := diskHandler{} - got, err := d.getRootfsArchive(tt.args.req, tt.args.neededPath) - if (err != nil) != tt.wantErr { - t.Errorf("diskHandler.getRootfsArchive() error = %v, wantErr %v", err, tt.wantErr) - return - } - if got != tt.want { - t.Errorf("diskHandler.getRootfsArchive() = %v, want %v", got, tt.want) - } - }) - } -} - -func Test_diskHandler_downloadImage(t *testing.T) { - type args struct { - req *pb.UpdateRequest - } - tests := []struct { - name string - d diskHandler - args args - want string - wantErr bool - }{ - {name: "normal", d: diskHandler{}, args: args{req: &pb.UpdateRequest{ImageUrl: "http://www.openeuler.org/zh/"}}, want: "/persist/update.img", wantErr: false}, - } - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - d := diskHandler{} - patchGetRootfsArchive := gomonkey.ApplyPrivateMethod(reflect.TypeOf(d), "getRootfsArchive", func(_ *diskHandler, _ *pb.UpdateRequest, _ preparePath) (string, error) { - return "/persist/update.img", nil - }) - got, err := d.downloadImage(tt.args.req) - if (err != nil) != tt.wantErr { - t.Errorf("diskHandler.downloadImage() error = %v, wantErr %v", err, tt.wantErr) - return - } - if got != tt.want { - t.Errorf("diskHandler.downloadImage() = %v, want %v", got, tt.want) - } - patchGetRootfsArchive.Reset() - }) - } -} diff --git a/cmd/agent/server/docker_image.go b/cmd/agent/server/docker_image.go deleted file mode 100644 index 16bcea5..0000000 --- a/cmd/agent/server/docker_image.go +++ /dev/null @@ -1,73 +0,0 @@ -/* - * Copyright (c) Huawei Technologies Co., Ltd. 2022. All rights reserved. - * KubeOS is licensed under the Mulan PSL v2. - * You can use this software according to the terms and conditions of the Mulan PSL v2. - * You may obtain a copy of Mulan PSL v2 at: - * http://license.coscl.org.cn/MulanPSL2 - * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR - * PURPOSE. - * See the Mulan PSL v2 for more details. - */ - -// Package server implements server of os-agent and listener of os-agent server. The server uses gRPC interface. -package server - -import ( - "github.com/sirupsen/logrus" - - pb "openeuler.org/KubeOS/cmd/agent/api" -) - -type dockerImageHandler struct{} - -func (d dockerImageHandler) downloadImage(req *pb.UpdateRequest) (string, error) { - neededPath, err := prepareEnv() - if err != nil { - return "", err - } - if _, err = d.getRootfsArchive(req, neededPath); err != nil { - return "", err - } - return createOSImage(neededPath) -} - -func (d dockerImageHandler) getRootfsArchive(req *pb.UpdateRequest, neededPath preparePath) (string, error) { - imageName := req.ContainerImage - if err := isValidImageName(imageName); err != nil { - return "", err - } - logrus.Infof("start pull %s", imageName) - if err := runCommand("docker", "pull", imageName); err != nil { - return "", err - } - if err := checkOCIImageDigestMatch("docker", imageName, req.CheckSum); err != nil { - return "", err - } - containerName := "kubeos-temp" - dockerPsCmd := "docker ps -a -f=name=" + containerName + "| awk 'NR==2' | awk '{print $1}'" - existId, err := runCommandWithOut("bash", "-c", dockerPsCmd) - if err != nil { - return "", err - } - if existId != "" { - logrus.Infoln("kubeos-temp container exist,start clean environment first") - if err := runCommand("docker", "rm", existId); err != nil { - return "", err - } - } - logrus.Infof("start get rootfs") - containerId, err := runCommandWithOut("docker", "create", "--name", containerName, imageName) - if err != nil { - return "", err - } - defer func() { - if err := runCommand("docker", "rm", containerId); err != nil { - logrus.Errorln("remove kubeos-temp container error", err) - } - }() - if err := runCommand("docker", "cp", containerId+":/"+neededPath.rootfsFile, neededPath.updatePath); err != nil { - return "", err - } - return neededPath.tarPath, nil -} diff --git a/cmd/agent/server/docker_image_test.go b/cmd/agent/server/docker_image_test.go deleted file mode 100644 index 2dbf337..0000000 --- a/cmd/agent/server/docker_image_test.go +++ /dev/null @@ -1,118 +0,0 @@ -/* - * Copyright (c) Huawei Technologies Co., Ltd. 2022. All rights reserved. - * KubeOS is licensed under the Mulan PSL v2. - * You can use this software according to the terms and conditions of the Mulan PSL v2. - * You may obtain a copy of Mulan PSL v2 at: - * http://license.coscl.org.cn/MulanPSL2 - * THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND, EITHER EXPRESS OR - * IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT, MERCHANTABILITY OR FIT FOR A PARTICULAR - * PURPOSE. - * See the Mulan PSL v2 for more details. - */ - -// Package server implements server of os-agent and listener of os-agent server. The server uses gRPC interface. -package server - -import ( - "os" - "testing" - - "github.com/agiledragon/gomonkey/v2" - pb "openeuler.org/KubeOS/cmd/agent/api" -) - -func Test_dockerImageHandler_downloadImage(t *testing.T) { - type args struct { - req *pb.UpdateRequest - } - tests := []struct { - name string - d dockerImageHandler - args args - want string - wantErr bool - }{ - { - name: "pullImageError", - d: dockerImageHandler{}, - args: args{ - req: &pb.UpdateRequest{ContainerImage: "testError"}, - }, - want: "", - wantErr: true, - }, - - { - name: "checkSumError", - d: dockerImageHandler{}, - args: args{ - req: &pb.UpdateRequest{ContainerImage: "hello-world", CheckSum: "aaaaaa"}, - }, - want: "", - wantErr: true, - }, - - { - name: "normal", - d: dockerImageHandler{}, - args: args{ - req: &pb.UpdateRequest{ContainerImage: "hello-world"}, - }, - want: "update-test/upadte.img", - wantErr: false, - }, - } - patchPrepareEnv := gomonkey.ApplyFunc(prepareEnv, func() (preparePath, error) { - return preparePath{updatePath: "update-test/", - mountPath: "update-test/mountPath", - tarPath: "update-test/mountPath/hello", - imagePath: "update-test/upadte.img", - rootfsFile: "hello"}, nil - }) - defer patchPrepareEnv.Reset() - - patchCreateOSImage := gomonkey.ApplyFunc(createOSImage, func(neededPath preparePath) (string, error) { - return "update-test/upadte.img", nil - }) - defer patchCreateOSImage.Reset() - - if err := os.MkdirAll("update-test/mountPath", os.ModePerm); err != nil { - t.Errorf("create test dir error = %v", err) - return - } - - for _, tt := range tests { - t.Run(tt.name, func(t *testing.T) { - if tt.name == "normal" { - _, err := runCommandWithOut("docker", "create", "--name", "kubeos-temp", "hello-world") - if err != nil { - t.Errorf("Test_dockerImageHandler_getRootfsArchive create container error = %v", err) - return - } - imageDigests, err := getOCIImageDigest("docker", "hello-world") - - if err != nil { - t.Errorf("Test_dockerImageHandler_getRootfsArchive get oci image digests error = %v", err) - } - tt.args.req.CheckSum = imageDigests - } - d := dockerImageHandler{} - got, err := d.downloadImage(tt.args.req) - if (err != nil) != tt.wantErr { - t.Errorf("dockerImageHandler.downloadImage() error = %v, wantErr %v", err, tt.wantErr) - return - } - if got != tt.want { - t.Errorf("dockerImageHandler.downloadImage() = %v, want %v", got, tt.want) - } - }) - } - defer func() { - if err := runCommand("docker", "rmi", "hello-world"); err != nil { - t.Errorf("remove kubeos-temp container error = %v", err) - } - if err := os.RemoveAll("update-test"); err != nil { - t.Errorf("remove update-test error = %v", err) - } - }() -} diff --git a/cmd/agent/server/server.go b/cmd/agent/server/server.go index f8cbb41..23ab1c6 100644 --- a/cmd/agent/server/server.go +++ b/cmd/agent/server/server.go @@ -102,12 +102,8 @@ func (s *Server) update(req *pb.UpdateRequest) error { action := req.ImageType var handler imageDownload switch action { - case "docker": - handler = dockerImageHandler{} case "containerd": handler = conImageHandler{} - case "disk": - handler = diskHandler{} default: return fmt.Errorf("image type %s cannot be recognized", action) } @@ -180,7 +176,3 @@ func (s *Server) reboot() error { } return syscall.Reboot(syscall.LINUX_REBOOT_CMD_RESTART) } - -func getCertPath() string { - return certPath -} diff --git a/cmd/agent/server/server_test.go b/cmd/agent/server/server_test.go index 15b6f5e..22ed38c 100644 --- a/cmd/agent/server/server_test.go +++ b/cmd/agent/server/server_test.go @@ -87,10 +87,10 @@ func TestServerUpdate(t *testing.T) { wantErr bool }{ {name: "error", fields: fields{UnimplementedOSServer: pb.UnimplementedOSServer{}, disableReboot: true}, - args: args{in0: context.Background(), req: &pb.UpdateRequest{Version: "test", Certs: &pb.CertsInfo{}}}, + args: args{in0: context.Background(), req: &pb.UpdateRequest{Version: "test"}}, want: &pb.UpdateResponse{}, wantErr: true}, {name: "success", fields: fields{UnimplementedOSServer: pb.UnimplementedOSServer{}, disableReboot: true}, - args: args{in0: context.Background(), req: &pb.UpdateRequest{Version: "test", Certs: &pb.CertsInfo{}, ImageType: "containerd"}}, + args: args{in0: context.Background(), req: &pb.UpdateRequest{Version: "test", ImageType: "containerd"}}, want: &pb.UpdateResponse{}, wantErr: false}, } patchRootfsDisks := gomonkey.ApplyFuncReturn(getRootfsDisks, "/dev/sda2", "/dev/sda3", nil) @@ -197,22 +197,9 @@ func TestServerupdate(t *testing.T) { args args wantErr bool }{ - {name: "errortype", args: args{&pb.UpdateRequest{Certs: &pb.CertsInfo{}}}, wantErr: true}, - - {name: "errordisk", args: args{&pb.UpdateRequest{ - ImageUrl: "http://w3.huawei.com/", - FlagSafe: true, - CheckSum: "", - ImageType: "disk", - Certs: &pb.CertsInfo{}, - }}, - wantErr: true}, - {name: "errordocker", args: args{&pb.UpdateRequest{ - ContainerImage: "", - ImageType: "docker", - Certs: &pb.CertsInfo{}, - }}, - wantErr: true}, + {name: "errortype", args: args{&pb.UpdateRequest{}}, wantErr: true}, + {name: "errordisk", args: args{&pb.UpdateRequest{CheckSum: "", ImageType: "disk"}}, wantErr: true}, + {name: "errordocker", args: args{&pb.UpdateRequest{ContainerImage: "", ImageType: "docker"}}, wantErr: true}, } for _, tt := range tests { if tt.name == "errordisk" { diff --git a/cmd/operator/controllers/os_controller_test.go b/cmd/operator/controllers/os_controller_test.go index 6cc2760..66aa1a4 100644 --- a/cmd/operator/controllers/os_controller_test.go +++ b/cmd/operator/controllers/os_controller_test.go @@ -242,8 +242,6 @@ var _ = Describe("OsController", func() { OpsType: "rollback", MaxUnavailable: 3, OSVersion: "KubeOS v1", - FlagSafe: true, - MTLS: false, EvictPodForce: true, SysConfigs: upgradev1.SysConfigs{ Version: "v1", @@ -420,8 +418,6 @@ var _ = Describe("OsController", func() { OpsType: "config", MaxUnavailable: 3, OSVersion: "KubeOS v1", - FlagSafe: true, - MTLS: false, EvictPodForce: true, SysConfigs: upgradev1.SysConfigs{ Version: "v2", @@ -512,8 +508,6 @@ var _ = Describe("OsController", func() { OpsType: "upgrade", MaxUnavailable: 3, OSVersion: "KubeOS v2", - FlagSafe: true, - MTLS: false, EvictPodForce: true, SysConfigs: upgradev1.SysConfigs{ Configs: []upgradev1.SysConfig{}, @@ -686,8 +680,6 @@ var _ = Describe("OsController", func() { OpsType: "upgrade", MaxUnavailable: 3, OSVersion: "KubeOS v2", - FlagSafe: true, - MTLS: false, EvictPodForce: true, SysConfigs: upgradev1.SysConfigs{ Version: "v2", diff --git a/cmd/proxy/controllers/os_controller.go b/cmd/proxy/controllers/os_controller.go index b8d0f80..d7da343 100644 --- a/cmd/proxy/controllers/os_controller.go +++ b/cmd/proxy/controllers/os_controller.go @@ -211,13 +211,7 @@ func (r *OSReconciler) upgradeNode(ctx context.Context, osCr *upgradev1.OS, node case "upgrade": version := osVersionSpec downloadInfo := &agentclient.DownloadInfo{ - ImageURL: osCr.Spec.ImageURL, - FlagSafe: osCr.Spec.FlagSafe, CheckSum: osCr.Spec.CheckSum, - CaCert: osCr.Spec.CaCert, - ClientCert: osCr.Spec.ClientCert, - ClientKey: osCr.Spec.ClientKey, - MTLS: osCr.Spec.MTLS, ImageType: osCr.Spec.ImageType, ContainerImage: osCr.Spec.ContainerImage, } diff --git a/cmd/proxy/controllers/os_controller_test.go b/cmd/proxy/controllers/os_controller_test.go index 14b6b66..847f22e 100644 --- a/cmd/proxy/controllers/os_controller_test.go +++ b/cmd/proxy/controllers/os_controller_test.go @@ -173,8 +173,6 @@ var _ = Describe("OsController", func() { OpsType: "rollback", MaxUnavailable: 3, OSVersion: "KubeOS v1", - FlagSafe: true, - MTLS: false, EvictPodForce: true, SysConfigs: upgradev1.SysConfigs{Configs: []upgradev1.SysConfig{}}, UpgradeConfigs: upgradev1.SysConfigs{Configs: []upgradev1.SysConfig{}}, @@ -333,8 +331,6 @@ var _ = Describe("OsController", func() { OpsType: "config", MaxUnavailable: 3, OSVersion: "KubeOS v1", - FlagSafe: true, - MTLS: false, EvictPodForce: true, SysConfigs: upgradev1.SysConfigs{ Version: "v2", @@ -476,8 +472,6 @@ var _ = Describe("OsController", func() { OpsType: "upgrade", MaxUnavailable: 3, OSVersion: "KubeOS v2", - FlagSafe: true, - MTLS: false, EvictPodForce: false, SysConfigs: upgradev1.SysConfigs{Configs: []upgradev1.SysConfig{}}, UpgradeConfigs: upgradev1.SysConfigs{ @@ -564,8 +558,6 @@ var _ = Describe("OsController", func() { OpsType: "config", MaxUnavailable: 3, OSVersion: "KubeOS v1", - FlagSafe: true, - MTLS: false, EvictPodForce: true, SysConfigs: upgradev1.SysConfigs{ Version: "v1", @@ -709,8 +701,6 @@ var _ = Describe("OsController", func() { OpsType: "config", MaxUnavailable: 3, OSVersion: "KubeOS v1", - FlagSafe: true, - MTLS: false, EvictPodForce: true, SysConfigs: upgradev1.SysConfigs{ Version: "v2", @@ -875,8 +865,6 @@ var _ = Describe("OsController", func() { OpsType: "upgrade", MaxUnavailable: 3, OSVersion: "KubeOS v2", - FlagSafe: true, - MTLS: false, EvictPodForce: true, SysConfigs: upgradev1.SysConfigs{Configs: []upgradev1.SysConfig{}}, UpgradeConfigs: upgradev1.SysConfigs{ @@ -1071,8 +1059,6 @@ var _ = Describe("OsController", func() { OpsType: "upgrade", MaxUnavailable: 3, OSVersion: "KubeOS v2", - FlagSafe: true, - MTLS: false, EvictPodForce: true, SysConfigs: upgradev1.SysConfigs{ Version: "v2", @@ -1232,8 +1218,6 @@ var _ = Describe("OsController", func() { OpsType: "upgrade", MaxUnavailable: 3, OSVersion: "KubeOS v2", - FlagSafe: true, - MTLS: false, EvictPodForce: true, SysConfigs: upgradev1.SysConfigs{ Version: "v2", diff --git a/docs/example/config/crd/upgrade.openeuler.org_os.yaml b/docs/example/config/crd/upgrade.openeuler.org_os.yaml index 3bb1333..8fadb2c 100644 --- a/docs/example/config/crd/upgrade.openeuler.org_os.yaml +++ b/docs/example/config/crd/upgrade.openeuler.org_os.yaml @@ -32,28 +32,16 @@ spec: spec: description: OSSpec defines the desired state of OS properties: - cacert: - type: string checksum: type: string - clientcert: - type: string - clientkey: - type: string containerimage: type: string evictpodforce: type: boolean - flagSafe: - type: boolean imagetype: type: string - imageurl: - type: string maxunavailable: type: integer - mtls: - type: boolean opstype: type: string osversion: @@ -118,11 +106,8 @@ spec: - checksum - containerimage - evictpodforce - - flagSafe - imagetype - - imageurl - maxunavailable - - mtls - opstype - osversion type: object diff --git a/pkg/agentclient/connection.go b/pkg/agentclient/connection.go index 7b53a14..ad31da4 100644 --- a/pkg/agentclient/connection.go +++ b/pkg/agentclient/connection.go @@ -32,13 +32,7 @@ type Client struct { // DownloadInfo contains the information required for image download type DownloadInfo struct { - ImageURL string - FlagSafe bool CheckSum string - CaCert string - ClientCert string - ClientKey string - MTLS bool ImageType string ContainerImage string } @@ -83,19 +77,10 @@ func New(sockAddr string) (*Client, error) { // UpdateSpec send update requests to the server in os-agent func (c *Client) UpdateSpec(version string, downloadInfo *DownloadInfo) error { - certs := &pb.CertsInfo{ - CaCaert: downloadInfo.CaCert, - ClientCert: downloadInfo.ClientCert, - ClientKey: downloadInfo.ClientKey, - } _, err := c.client.Update(context.Background(), &pb.UpdateRequest{ Version: version, - ImageUrl: downloadInfo.ImageURL, - FlagSafe: downloadInfo.FlagSafe, CheckSum: downloadInfo.CheckSum, - MTLS: downloadInfo.MTLS, - Certs: certs, ImageType: downloadInfo.ImageType, ContainerImage: downloadInfo.ContainerImage, }) -- 2.39.0