upgrade-agent: allow more than one KubernetesComponent

This commit is contained in:
Markus Rudy 2023-12-08 18:38:00 +01:00 committed by Markus Rudy
parent 4ba483ec0e
commit 6f1b6b532f
5 changed files with 126 additions and 43 deletions

View File

@ -132,14 +132,25 @@ func prepareUpdate(ctx context.Context, installer osInstaller, updateRequest *up
return err
}
// download & install the kubeadm binary
return installer.Install(ctx, &components.Component{
var cs components.Components
if len(updateRequest.KubeadmUrl) > 0 {
cs = append(cs, &components.Component{
Url: updateRequest.KubeadmUrl,
Hash: updateRequest.KubeadmHash,
InstallPath: constants.KubeadmPath,
Extract: false,
})
}
cs = append(cs, updateRequest.KubernetesComponents...)
// Download & install the Kubernetes components.
for _, c := range cs {
if err := installer.Install(ctx, c); err != nil {
return fmt.Errorf("installing Kubernetes component %q: %w", c.Url, err)
}
}
return nil
}
// verifyVersion verifies the provided Kubernetes version.
func verifyVersion(version string) error {

View File

@ -56,9 +56,38 @@ func TestVersionVerifier(t *testing.T) {
}
func TestPrepareUpdate(t *testing.T) {
validUpdateRequest := &upgradeproto.ExecuteUpdateRequest{
invalidUpgradeRequest := &upgradeproto.ExecuteUpdateRequest{
WantedKubernetesVersion: "1337",
}
slimUpdateRequest := &upgradeproto.ExecuteUpdateRequest{
WantedKubernetesVersion: "v1.1.1",
}
oldStyleUpdateRequest := &upgradeproto.ExecuteUpdateRequest{
WantedKubernetesVersion: "v1.1.1",
KubeadmUrl: "http://example.com/kubeadm",
KubeadmHash: "sha256:foo",
}
newStyleUpdateRequest := &upgradeproto.ExecuteUpdateRequest{
WantedKubernetesVersion: "v1.1.1",
KubernetesComponents: []*components.Component{
{
Url: "http://example.com/kubeadm",
Hash: "sha256:foo",
InstallPath: "/tmp/kubeadm",
},
},
}
combinedStyleUpdateRequest := &upgradeproto.ExecuteUpdateRequest{
WantedKubernetesVersion: "v1.1.1",
KubeadmUrl: "http://example.com/kubeadm",
KubeadmHash: "sha256:foo",
KubernetesComponents: []*components.Component{
{
Url: "data:application/octet-stream,foo",
InstallPath: "/tmp/foo",
},
},
}
testCases := map[string]struct {
installer osInstaller
updateRequest *upgradeproto.ExecuteUpdateRequest
@ -66,16 +95,34 @@ func TestPrepareUpdate(t *testing.T) {
}{
"works": {
installer: stubOsInstaller{},
updateRequest: validUpdateRequest,
updateRequest: slimUpdateRequest,
},
"invalid version string": {
installer: stubOsInstaller{},
updateRequest: &upgradeproto.ExecuteUpdateRequest{WantedKubernetesVersion: "1337"},
updateRequest: invalidUpgradeRequest,
wantErr: true,
},
"install error": {
installer: stubOsInstaller{InstallErr: fmt.Errorf("install error")},
updateRequest: validUpdateRequest,
updateRequest: oldStyleUpdateRequest,
wantErr: true,
},
"new style works": {
installer: stubOsInstaller{},
updateRequest: newStyleUpdateRequest,
},
"new style install error": {
installer: stubOsInstaller{InstallErr: fmt.Errorf("install error")},
updateRequest: newStyleUpdateRequest,
wantErr: true,
},
"combined style works": {
installer: stubOsInstaller{},
updateRequest: combinedStyleUpdateRequest,
},
"combined style install error": {
installer: stubOsInstaller{InstallErr: fmt.Errorf("install error")},
updateRequest: combinedStyleUpdateRequest,
wantErr: true,
},
}

View File

@ -7,6 +7,7 @@ proto_library(
name = "upgradeproto_proto",
srcs = ["upgrade.proto"],
visibility = ["//visibility:public"],
deps = ["//internal/versions/components:components_proto"],
)
go_proto_library(
@ -16,6 +17,7 @@ go_proto_library(
importpath = "github.com/edgelesssys/constellation/v2/upgrade-agent/upgradeproto",
proto = ":upgradeproto_proto",
visibility = ["//visibility:public"],
deps = ["//internal/versions/components"],
)
go_library(

View File

@ -8,6 +8,7 @@ package upgradeproto
import (
context "context"
components "github.com/edgelesssys/constellation/v2/internal/versions/components"
grpc "google.golang.org/grpc"
codes "google.golang.org/grpc/codes"
status "google.golang.org/grpc/status"
@ -32,6 +33,7 @@ type ExecuteUpdateRequest struct {
KubeadmUrl string `protobuf:"bytes,1,opt,name=kubeadm_url,json=kubeadmUrl,proto3" json:"kubeadm_url,omitempty"`
KubeadmHash string `protobuf:"bytes,2,opt,name=kubeadm_hash,json=kubeadmHash,proto3" json:"kubeadm_hash,omitempty"`
WantedKubernetesVersion string `protobuf:"bytes,3,opt,name=wanted_kubernetes_version,json=wantedKubernetesVersion,proto3" json:"wanted_kubernetes_version,omitempty"`
KubernetesComponents []*components.Component `protobuf:"bytes,4,rep,name=kubernetes_components,json=kubernetesComponents,proto3" json:"kubernetes_components,omitempty"`
}
func (x *ExecuteUpdateRequest) Reset() {
@ -87,6 +89,13 @@ func (x *ExecuteUpdateRequest) GetWantedKubernetesVersion() string {
return ""
}
func (x *ExecuteUpdateRequest) GetKubernetesComponents() []*components.Component {
if x != nil {
return x.KubernetesComponents
}
return nil
}
type ExecuteUpdateResponse struct {
state protoimpl.MessageState
sizeCache protoimpl.SizeCache
@ -131,28 +140,36 @@ var file_upgrade_agent_upgradeproto_upgrade_proto_rawDesc = []byte{
0x0a, 0x28, 0x75, 0x70, 0x67, 0x72, 0x61, 0x64, 0x65, 0x2d, 0x61, 0x67, 0x65, 0x6e, 0x74, 0x2f,
0x75, 0x70, 0x67, 0x72, 0x61, 0x64, 0x65, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x2f, 0x75, 0x70, 0x67,
0x72, 0x61, 0x64, 0x65, 0x2e, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x12, 0x07, 0x75, 0x70, 0x67, 0x72,
0x61, 0x64, 0x65, 0x22, 0x96, 0x01, 0x0a, 0x14, 0x45, 0x78, 0x65, 0x63, 0x75, 0x74, 0x65, 0x55,
0x70, 0x64, 0x61, 0x74, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x1f, 0x0a, 0x0b,
0x6b, 0x75, 0x62, 0x65, 0x61, 0x64, 0x6d, 0x5f, 0x75, 0x72, 0x6c, 0x18, 0x01, 0x20, 0x01, 0x28,
0x09, 0x52, 0x0a, 0x6b, 0x75, 0x62, 0x65, 0x61, 0x64, 0x6d, 0x55, 0x72, 0x6c, 0x12, 0x21, 0x0a,
0x0c, 0x6b, 0x75, 0x62, 0x65, 0x61, 0x64, 0x6d, 0x5f, 0x68, 0x61, 0x73, 0x68, 0x18, 0x02, 0x20,
0x01, 0x28, 0x09, 0x52, 0x0b, 0x6b, 0x75, 0x62, 0x65, 0x61, 0x64, 0x6d, 0x48, 0x61, 0x73, 0x68,
0x12, 0x3a, 0x0a, 0x19, 0x77, 0x61, 0x6e, 0x74, 0x65, 0x64, 0x5f, 0x6b, 0x75, 0x62, 0x65, 0x72,
0x6e, 0x65, 0x74, 0x65, 0x73, 0x5f, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x18, 0x03, 0x20,
0x01, 0x28, 0x09, 0x52, 0x17, 0x77, 0x61, 0x6e, 0x74, 0x65, 0x64, 0x4b, 0x75, 0x62, 0x65, 0x72,
0x6e, 0x65, 0x74, 0x65, 0x73, 0x56, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x22, 0x17, 0x0a, 0x15,
0x45, 0x78, 0x65, 0x63, 0x75, 0x74, 0x65, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x52, 0x65, 0x73,
0x70, 0x6f, 0x6e, 0x73, 0x65, 0x32, 0x58, 0x0a, 0x06, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x12,
0x4e, 0x0a, 0x0d, 0x45, 0x78, 0x65, 0x63, 0x75, 0x74, 0x65, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65,
0x12, 0x1d, 0x2e, 0x75, 0x70, 0x67, 0x72, 0x61, 0x64, 0x65, 0x2e, 0x45, 0x78, 0x65, 0x63, 0x75,
0x74, 0x65, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a,
0x1e, 0x2e, 0x75, 0x70, 0x67, 0x72, 0x61, 0x64, 0x65, 0x2e, 0x45, 0x78, 0x65, 0x63, 0x75, 0x74,
0x65, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x42,
0x44, 0x5a, 0x42, 0x67, 0x69, 0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x65, 0x64,
0x67, 0x65, 0x6c, 0x65, 0x73, 0x73, 0x73, 0x79, 0x73, 0x2f, 0x63, 0x6f, 0x6e, 0x73, 0x74, 0x65,
0x6c, 0x6c, 0x61, 0x74, 0x69, 0x6f, 0x6e, 0x2f, 0x76, 0x32, 0x2f, 0x75, 0x70, 0x67, 0x72, 0x61,
0x64, 0x65, 0x2d, 0x61, 0x67, 0x65, 0x6e, 0x74, 0x2f, 0x75, 0x70, 0x67, 0x72, 0x61, 0x64, 0x65,
0x70, 0x72, 0x6f, 0x74, 0x6f, 0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
0x61, 0x64, 0x65, 0x1a, 0x2d, 0x69, 0x6e, 0x74, 0x65, 0x72, 0x6e, 0x61, 0x6c, 0x2f, 0x76, 0x65,
0x72, 0x73, 0x69, 0x6f, 0x6e, 0x73, 0x2f, 0x63, 0x6f, 0x6d, 0x70, 0x6f, 0x6e, 0x65, 0x6e, 0x74,
0x73, 0x2f, 0x63, 0x6f, 0x6d, 0x70, 0x6f, 0x6e, 0x65, 0x6e, 0x74, 0x73, 0x2e, 0x70, 0x72, 0x6f,
0x74, 0x6f, 0x22, 0xe2, 0x01, 0x0a, 0x14, 0x45, 0x78, 0x65, 0x63, 0x75, 0x74, 0x65, 0x55, 0x70,
0x64, 0x61, 0x74, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x12, 0x1f, 0x0a, 0x0b, 0x6b,
0x75, 0x62, 0x65, 0x61, 0x64, 0x6d, 0x5f, 0x75, 0x72, 0x6c, 0x18, 0x01, 0x20, 0x01, 0x28, 0x09,
0x52, 0x0a, 0x6b, 0x75, 0x62, 0x65, 0x61, 0x64, 0x6d, 0x55, 0x72, 0x6c, 0x12, 0x21, 0x0a, 0x0c,
0x6b, 0x75, 0x62, 0x65, 0x61, 0x64, 0x6d, 0x5f, 0x68, 0x61, 0x73, 0x68, 0x18, 0x02, 0x20, 0x01,
0x28, 0x09, 0x52, 0x0b, 0x6b, 0x75, 0x62, 0x65, 0x61, 0x64, 0x6d, 0x48, 0x61, 0x73, 0x68, 0x12,
0x3a, 0x0a, 0x19, 0x77, 0x61, 0x6e, 0x74, 0x65, 0x64, 0x5f, 0x6b, 0x75, 0x62, 0x65, 0x72, 0x6e,
0x65, 0x74, 0x65, 0x73, 0x5f, 0x76, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x18, 0x03, 0x20, 0x01,
0x28, 0x09, 0x52, 0x17, 0x77, 0x61, 0x6e, 0x74, 0x65, 0x64, 0x4b, 0x75, 0x62, 0x65, 0x72, 0x6e,
0x65, 0x74, 0x65, 0x73, 0x56, 0x65, 0x72, 0x73, 0x69, 0x6f, 0x6e, 0x12, 0x4a, 0x0a, 0x15, 0x6b,
0x75, 0x62, 0x65, 0x72, 0x6e, 0x65, 0x74, 0x65, 0x73, 0x5f, 0x63, 0x6f, 0x6d, 0x70, 0x6f, 0x6e,
0x65, 0x6e, 0x74, 0x73, 0x18, 0x04, 0x20, 0x03, 0x28, 0x0b, 0x32, 0x15, 0x2e, 0x63, 0x6f, 0x6d,
0x70, 0x6f, 0x6e, 0x65, 0x6e, 0x74, 0x73, 0x2e, 0x43, 0x6f, 0x6d, 0x70, 0x6f, 0x6e, 0x65, 0x6e,
0x74, 0x52, 0x14, 0x6b, 0x75, 0x62, 0x65, 0x72, 0x6e, 0x65, 0x74, 0x65, 0x73, 0x43, 0x6f, 0x6d,
0x70, 0x6f, 0x6e, 0x65, 0x6e, 0x74, 0x73, 0x22, 0x17, 0x0a, 0x15, 0x45, 0x78, 0x65, 0x63, 0x75,
0x74, 0x65, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65,
0x32, 0x58, 0x0a, 0x06, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x12, 0x4e, 0x0a, 0x0d, 0x45, 0x78,
0x65, 0x63, 0x75, 0x74, 0x65, 0x55, 0x70, 0x64, 0x61, 0x74, 0x65, 0x12, 0x1d, 0x2e, 0x75, 0x70,
0x67, 0x72, 0x61, 0x64, 0x65, 0x2e, 0x45, 0x78, 0x65, 0x63, 0x75, 0x74, 0x65, 0x55, 0x70, 0x64,
0x61, 0x74, 0x65, 0x52, 0x65, 0x71, 0x75, 0x65, 0x73, 0x74, 0x1a, 0x1e, 0x2e, 0x75, 0x70, 0x67,
0x72, 0x61, 0x64, 0x65, 0x2e, 0x45, 0x78, 0x65, 0x63, 0x75, 0x74, 0x65, 0x55, 0x70, 0x64, 0x61,
0x74, 0x65, 0x52, 0x65, 0x73, 0x70, 0x6f, 0x6e, 0x73, 0x65, 0x42, 0x44, 0x5a, 0x42, 0x67, 0x69,
0x74, 0x68, 0x75, 0x62, 0x2e, 0x63, 0x6f, 0x6d, 0x2f, 0x65, 0x64, 0x67, 0x65, 0x6c, 0x65, 0x73,
0x73, 0x73, 0x79, 0x73, 0x2f, 0x63, 0x6f, 0x6e, 0x73, 0x74, 0x65, 0x6c, 0x6c, 0x61, 0x74, 0x69,
0x6f, 0x6e, 0x2f, 0x76, 0x32, 0x2f, 0x75, 0x70, 0x67, 0x72, 0x61, 0x64, 0x65, 0x2d, 0x61, 0x67,
0x65, 0x6e, 0x74, 0x2f, 0x75, 0x70, 0x67, 0x72, 0x61, 0x64, 0x65, 0x70, 0x72, 0x6f, 0x74, 0x6f,
0x62, 0x06, 0x70, 0x72, 0x6f, 0x74, 0x6f, 0x33,
}
var (
@ -171,15 +188,17 @@ var file_upgrade_agent_upgradeproto_upgrade_proto_msgTypes = make([]protoimpl.Me
var file_upgrade_agent_upgradeproto_upgrade_proto_goTypes = []interface{}{
(*ExecuteUpdateRequest)(nil), // 0: upgrade.ExecuteUpdateRequest
(*ExecuteUpdateResponse)(nil), // 1: upgrade.ExecuteUpdateResponse
(*components.Component)(nil), // 2: components.Component
}
var file_upgrade_agent_upgradeproto_upgrade_proto_depIdxs = []int32{
0, // 0: upgrade.Update.ExecuteUpdate:input_type -> upgrade.ExecuteUpdateRequest
1, // 1: upgrade.Update.ExecuteUpdate:output_type -> upgrade.ExecuteUpdateResponse
1, // [1:2] is the sub-list for method output_type
0, // [0:1] 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
2, // 0: upgrade.ExecuteUpdateRequest.kubernetes_components:type_name -> components.Component
0, // 1: upgrade.Update.ExecuteUpdate:input_type -> upgrade.ExecuteUpdateRequest
1, // 2: upgrade.Update.ExecuteUpdate:output_type -> upgrade.ExecuteUpdateResponse
2, // [2:3] is the sub-list for method output_type
1, // [1:2] is the sub-list for method input_type
1, // [1:1] is the sub-list for extension type_name
1, // [1:1] is the sub-list for extension extendee
0, // [0:1] is the sub-list for field type_name
}
func init() { file_upgrade_agent_upgradeproto_upgrade_proto_init() }

View File

@ -2,6 +2,8 @@ syntax = "proto3";
package upgrade;
import "internal/versions/components/components.proto";
option go_package = "github.com/edgelesssys/constellation/v2/upgrade-agent/upgradeproto";
service Update {
@ -12,6 +14,8 @@ message ExecuteUpdateRequest {
string kubeadm_url = 1;
string kubeadm_hash = 2;
string wanted_kubernetes_version = 3;
repeated components.Component kubernetes_components = 4;
}
message ExecuteUpdateResponse {}