Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Assets: Always use source file for hash #4100

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 2 additions & 16 deletions pkg/assets/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -214,20 +214,9 @@ func (a *AssetBuilder) RemapFileAndSHAValue(fileURL *url.URL, shaValue string) (
// FindHash returns the hash value of a FileAsset.
func (a *AssetBuilder) findHash(file *FileAsset) (*hashing.Hash, error) {

// If the phase is "assets" we use the CanonicalFileURL,
// but during other phases we use the hash from the FileRepository or the base kops path.
// We do not want to just test for CanonicalFileURL as it is defined in
// other phases, but is not used to test for the SHA.
// This prevents a chicken and egg problem where the file is not yet in the FileRepository.
//
// assets phase -> get the sha file from the source / CanonicalFileURL
// any other phase -> get the sha file from the kops base location or the FileRepository
//
// TLDR; we use the file.CanonicalFileURL during assets phase, and use file.FileUrl the
// rest of the time. If not we get a chicken and the egg problem where we are reading the sha file
// before it exists.
// The source file is in CanonicalFileURL if it is set, otherwise it is in FileURL
u := file.FileURL
if a.Phase == "assets" && file.CanonicalFileURL != nil {
if file.CanonicalFileURL != nil {
u = file.CanonicalFileURL
}

Expand All @@ -248,9 +237,6 @@ func (a *AssetBuilder) findHash(file *FileAsset) (*hashing.Hash, error) {
return hashing.FromString(hashString)
}

if a.AssetsLocation != nil && a.AssetsLocation.FileRepository != nil {
return nil, fmt.Errorf("you may have not staged your files correctly, please execute kops update cluster using the assets phase")
}
return nil, fmt.Errorf("cannot determine hash for %q (have you specified a valid file location?)", u)
}

Expand Down