Always set canonical location of assets

This commit is contained in:
John Gardiner Myers 2021-05-28 20:45:06 -07:00
parent 5e7c6da57e
commit 1c33270f91
3 changed files with 13 additions and 18 deletions

View File

@ -120,9 +120,10 @@ func (a *AssetBuilder) RemapManifest(data []byte) ([]byte, error) {
// RemapImage normalizes a containers location if a user sets the AssetsLocation ContainerRegistry location.
func (a *AssetBuilder) RemapImage(image string) (string, error) {
asset := &ContainerAsset{}
asset.DockerImage = image
asset := &ContainerAsset{
DockerImage: image,
CanonicalLocation: image,
}
if strings.HasPrefix(image, "k8s.gcr.io/kops/dns-controller:") {
// To use user-defined DNS Controller:
@ -167,7 +168,6 @@ func (a *AssetBuilder) RemapImage(image string) (string, error) {
}
asset.DockerImage = normalized
asset.CanonicalLocation = image
// Run the new image
image = asset.DockerImage
@ -192,8 +192,6 @@ func (a *AssetBuilder) RemapImage(image string) (string, error) {
asset.DockerImage = registryMirror + "/" + normalized
}
asset.CanonicalLocation = image
// Run the new image
image = asset.DockerImage
}
@ -210,11 +208,11 @@ func (a *AssetBuilder) RemapFileAndSHA(fileURL *url.URL) (*url.URL, *hashing.Has
}
fileAsset := &FileAsset{
DownloadURL: fileURL,
DownloadURL: fileURL,
CanonicalURL: fileURL,
}
if a.AssetsLocation != nil && a.AssetsLocation.FileRepository != nil {
fileAsset.CanonicalURL = fileURL
normalizedFileURL, err := a.remapURL(fileURL)
if err != nil {
@ -245,13 +243,12 @@ func (a *AssetBuilder) RemapFileAndSHAValue(fileURL *url.URL, shaValue string) (
}
fileAsset := &FileAsset{
DownloadURL: fileURL,
SHAValue: shaValue,
DownloadURL: fileURL,
CanonicalURL: fileURL,
SHAValue: shaValue,
}
if a.AssetsLocation != nil && a.AssetsLocation.FileRepository != nil {
fileAsset.CanonicalURL = fileURL
normalizedFile, err := a.remapURL(fileURL)
if err != nil {
return nil, err
@ -283,7 +280,7 @@ func (a *AssetBuilder) findHash(file *FileAsset) (*hashing.Hash, error) {
// rest of the time. If not we get a chicken and the egg problem where we are reading the sha file
// before it exists.
u := file.DownloadURL
if a.Phase == "assets" && file.CanonicalURL != nil {
if a.Phase == "assets" {
u = file.CanonicalURL
}

View File

@ -67,7 +67,7 @@ func (l *Loader) BuildTasks(assetBuilder *assets.AssetBuilder, lifecycle *fi.Lif
func (l *Loader) addAssetCopyTasks(assets []*assets.ContainerAsset, lifecycle *fi.Lifecycle) error {
for _, asset := range assets {
if asset.CanonicalLocation != "" && asset.DockerImage != asset.CanonicalLocation {
if asset.DockerImage != asset.CanonicalLocation {
context := &fi.ModelBuilderContext{
Tasks: l.tasks,
}
@ -100,7 +100,7 @@ func (l *Loader) addAssetFileCopyTasks(assets []*assets.FileAsset, lifecycle *fi
}
// test if the asset needs to be copied
if asset.CanonicalURL != nil && asset.DownloadURL.String() != asset.CanonicalURL.String() {
if asset.DownloadURL.String() != asset.CanonicalURL.String() {
klog.V(10).Infof("processing asset: %q, %q", asset.DownloadURL.String(), asset.CanonicalURL.String())
context := &fi.ModelBuilderContext{
Tasks: l.tasks,

View File

@ -262,10 +262,8 @@ func (t *DryRunTarget) PrintReport(taskMap map[string]Task, out io.Writer) error
if len(t.assetBuilder.FileAssets) != 0 {
klog.V(4).Infof("FileAssets:")
for _, a := range t.assetBuilder.FileAssets {
if a.DownloadURL != nil && a.CanonicalURL != nil {
if a.DownloadURL != nil {
klog.V(4).Infof(" %s %s", a.DownloadURL.String(), a.CanonicalURL.String())
} else if a.DownloadURL != nil {
klog.V(4).Infof(" %s", a.DownloadURL.String())
}
}
}