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

Use internal "cache" module to cache libvirt and baremetal images #2595

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
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
13 changes: 9 additions & 4 deletions pkg/tfvars/baremetal/baremetal.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"fmt"
"github.com/metal3-io/baremetal-operator/pkg/bmc"
"github.com/metal3-io/baremetal-operator/pkg/hardware"
libvirttfvars "github.com/openshift/installer/pkg/tfvars/libvirt"
"github.com/openshift/installer/pkg/tfvars/internal/cache"
"github.com/openshift/installer/pkg/types/baremetal"
"github.com/pkg/errors"
"net/url"
Expand All @@ -31,9 +31,14 @@ type config struct {

// TFVars generates bare metal specific Terraform variables.
func TFVars(libvirtURI, bootstrapProvisioningIP, bootstrapOSImage, externalBridge, provisioningBridge string, platformHosts []*baremetal.Host, image string) ([]byte, error) {
bootstrapOSImage, err := libvirttfvars.CachedImage(bootstrapOSImage)
if err != nil {
return nil, errors.Wrap(err, "failed to use cached bootstrap libvirt image")
// Reuse bootstrapOSImage if it is already a local path URI
if !strings.HasPrefix(bootstrapOSImage, "file://") {
var err error
bootstrapOSImage, err = cache.DownloadImageFile(bootstrapOSImage)
if err != nil {
return nil, errors.Wrap(err, "failed to use cached bootstrap libvirt image")
}
bootstrapOSImage = cache.PathToURI(bootstrapOSImage)
}

var hosts, rootDevices, properties, driverInfos, instanceInfos []map[string]interface{}
Expand Down
5 changes: 5 additions & 0 deletions pkg/tfvars/internal/cache/cache.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,3 +199,8 @@ func DownloadImageFile(baseURL string) (string, error) {

return DownloadFile(baseURL, imageDataType)
}

// PathToURI converts a local file path into a URI
func PathToURI(filePath string) string {
return fmt.Sprintf("file://%s", filepath.ToSlash(filePath))
}
176 changes: 0 additions & 176 deletions pkg/tfvars/libvirt/cache.go

This file was deleted.

12 changes: 9 additions & 3 deletions pkg/tfvars/libvirt/libvirt.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@ import (
"fmt"
"net"
"strconv"
"strings"

"github.com/apparentlymart/go-cidr/cidr"
"github.com/openshift/cluster-api-provider-libvirt/pkg/apis/libvirtproviderconfig/v1beta1"
"github.com/openshift/installer/pkg/tfvars/internal/cache"
"github.com/pkg/errors"
)

Expand All @@ -34,9 +36,13 @@ func TFVars(masterConfig *v1beta1.LibvirtMachineProviderConfig, osImage string,
return nil, err
}

osImage, err = cachedImage(osImage)
if err != nil {
return nil, errors.Wrap(err, "failed to use cached libvirt image")
// Reuse osImage if it is already a local path URI
if !strings.HasPrefix(osImage, "file://") {
osImage, err = cache.DownloadImageFile(osImage)
if err != nil {
return nil, errors.Wrap(err, "failed to use cached libvirt image")
}
osImage = cache.PathToURI(osImage)
}

cfg := &config{
Expand Down