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,13 +132,24 @@ func prepareUpdate(ctx context.Context, installer osInstaller, updateRequest *up
return err
}
// download & install the kubeadm binary
return installer.Install(ctx, &components.Component{
Url: updateRequest.KubeadmUrl,
Hash: updateRequest.KubeadmHash,
InstallPath: constants.KubeadmPath,
Extract: false,
})
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.

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,
},
}