installer: make hash checking optional

This commit is contained in:
Markus Rudy 2023-12-08 18:19:24 +01:00 committed by Markus Rudy
parent dac4bb04f2
commit 138057a2ee
2 changed files with 10 additions and 1 deletions

View File

@ -70,7 +70,7 @@ func (i *OsInstaller) Install(ctx context.Context, kubernetesComponent *componen
return fmt.Errorf("reading file %q: %w", tempPath, err)
}
calculatedHash := fmt.Sprintf("sha256:%x", sha.Sum(nil))
if calculatedHash != kubernetesComponent.Hash {
if len(kubernetesComponent.Hash) > 0 && calculatedHash != kubernetesComponent.Hash {
return fmt.Errorf("hash of file %q %s does not match expected hash %s", tempPath, calculatedHash, kubernetesComponent.Hash)
}

View File

@ -70,6 +70,15 @@ func TestInstall(t *testing.T) {
},
wantErr: true,
},
"hash is not mandatory": {
server: newHTTPBufconnServerWithBody([]byte("file-contents")),
component: components.Component{
URL: serverURL,
Hash: "",
InstallPath: "/destination",
},
wantFiles: map[string][]byte{"/destination": []byte("file-contents")},
},
"download fails": {
server: newHTTPBufconnServer(func(w http.ResponseWriter, r *http.Request) { w.WriteHeader(500) }),
component: &components.Component{