Skip to content

Commit

Permalink
work
Browse files Browse the repository at this point in the history
  • Loading branch information
chrislovecnm committed Oct 16, 2017
1 parent 8624015 commit 64f5ca6
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 11 deletions.
23 changes: 15 additions & 8 deletions pkg/assets/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,16 +178,20 @@ func (a *AssetBuilder) RemapFileAndSHA(file string, sha string) (string, *hashin
}

a.FileAssets = append(a.FileAssets, fileAsset)

h, err := a.FindHash(fileAsset)
if err != nil {
return "", nil, err
}

glog.V(8).Infof("returning remapped file asset: %q and SHA %q", fileAsset.File, h.String())

return fileAsset.File, h, nil
}

func (a *AssetBuilder) RemapFileAndSHAValue(file string, shaValue string) (string, *hashing.Hash, error) {
func (a *AssetBuilder) RemapFileAndSHAValue(file string, shaValue string) (string, error) {
if file == "" {
return "", nil, fmt.Errorf("unable to remap an empty string")
return "", fmt.Errorf("unable to remap an empty string")
}

fileAsset := &FileAsset{
Expand All @@ -200,31 +204,34 @@ func (a *AssetBuilder) RemapFileAndSHAValue(file string, shaValue string) (strin

file, err := a.normalizeURL(file)
if err != nil {
return "", nil, fmt.Errorf("unable to parse file url %q: %v", file, err)
return "", fmt.Errorf("unable to parse file url %q: %v", file, err)
}

fileAsset.File = file
glog.V(4).Infof("adding remapped file: %q", fileAsset.File)
}

a.FileAssets = append(a.FileAssets, fileAsset)
h, err := a.FindHash(fileAsset)
if err != nil {
return "", nil, err
}
return fileAsset.File, h, nil

return fileAsset.File, nil
}

// TODO we should probably make this a task....
// TODO we need to make this an interface so that we can mock out our unit tests

func (a *AssetBuilder) FindHash(file *FileAsset) (*hashing.Hash, error) {
u := file.File

// FIXME ugly hack because dep loop with lifecycle
// FIXME move lifecycle out of fi??
if a.Lifecycle == string("Sync") {
u = file.CanonicalLocation
}

if u == "" {
return nil, fmt.Errorf("file url is not defined")
}

for _, ext := range []string{".sha1"} {
hashURL := u + ext
b, err := vfs.Context.ReadFile(hashURL)
Expand Down
2 changes: 1 addition & 1 deletion pkg/assets/builder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ func TestRemap_File(t *testing.T) {
// TODO FIXME
builder := NewAssetBuilder(g.kopsAssets, "")

actual, _, err := builder.RemapFileAndSHAValue(g.testFile, g.sha)
actual,_, err := builder.RemapFileAndSHA(g.testFile, g.sha)
if err != nil {
t.Errorf("err occurred: %v", err)
}
Expand Down
2 changes: 1 addition & 1 deletion upup/pkg/fi/cloudup/networking.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ func findCNIAssets(c *api.Cluster, assetBuilder *assets.AssetBuilder) (string, s
glog.V(2).Infof("Adding default CNI asset for k8s 1.5: %s", defaultCNIAssetK8s1_5)
}

defaultCNIAssetK8s, _, err = assetBuilder.RemapFileAndSHAValue(defaultCNIAssetK8s, defaultCNIAssetHashStringK8s)
defaultCNIAssetK8s, err = assetBuilder.RemapFileAndSHAValue(defaultCNIAssetK8s, defaultCNIAssetHashStringK8s)
if err != nil {
return "", "", err
}
Expand Down
2 changes: 1 addition & 1 deletion upup/pkg/fi/cloudup/urls.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ func FileUrl(file string, assetBuilder *assets.AssetBuilder) (string, *hashing.H
b = kopsUrl
}

fileUrl, hash, err := assetBuilder.RemapFileAndSHAValue(b+file, b+file+".sha1")
fileUrl, hash, err := assetBuilder.RemapFileAndSHA(b+file, b+file+".sha1")
if err != nil {
return "", nil, err
}
Expand Down

0 comments on commit 64f5ca6

Please sign in to comment.