Skip to content

Commit

Permalink
Add bundleName field to CrcBundleInfo
Browse files Browse the repository at this point in the history
This allows to simplify slightly machine.getBundleMetadataFromDriver()
  • Loading branch information
cfergeau authored and guillaumerose committed Mar 9, 2021
1 parent 2a60ffa commit c4c56b1
Show file tree
Hide file tree
Showing 6 changed files with 15 additions and 8 deletions.
5 changes: 5 additions & 0 deletions pkg/crc/machine/bundle/metadata.go
Expand Up @@ -23,6 +23,7 @@ type CrcBundleInfo struct {
Storage Storage `json:"storage"`
DriverInfo DriverInfo `json:"driverInfo"`
cachedPath string
bundleName string
}

type BuildInfo struct {
Expand Down Expand Up @@ -71,6 +72,10 @@ func (bundle *CrcBundleInfo) resolvePath(filename string) string {
return filepath.Join(bundle.cachedPath, filename)
}

func (bundle *CrcBundleInfo) GetBundleName() string {
return bundle.bundleName
}

func (bundle *CrcBundleInfo) GetAPIHostname() string {
return fmt.Sprintf("api.%s.%s", bundle.ClusterInfo.ClusterName, bundle.ClusterInfo.BaseDomain)
}
Expand Down
2 changes: 2 additions & 0 deletions pkg/crc/machine/bundle/repository.go
Expand Up @@ -45,6 +45,8 @@ func (repo *Repository) Get(bundleName string) (*CrcBundleInfo, error) {
return nil, err
}
bundleInfo.cachedPath = path
bundleInfo.bundleName = bundleName

if err := bundleInfo.verify(); err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/crc/machine/console.go
Expand Up @@ -19,7 +19,7 @@ func (client *client) GetConsoleURL() (*ConsoleResult, error) {
return nil, errors.Wrap(err, "Error getting the state for host")
}

_, crcBundleMetadata, err := getBundleMetadataFromDriver(host.Driver)
crcBundleMetadata, err := getBundleMetadataFromDriver(host.Driver)
if err != nil {
return nil, errors.Wrap(err, "Error loading bundle metadata")
}
Expand Down
8 changes: 4 additions & 4 deletions pkg/crc/machine/machine.go
Expand Up @@ -35,18 +35,18 @@ func getClusterConfig(bundleInfo *bundle.CrcBundleInfo) (*ClusterConfig, error)
}, nil
}

func getBundleMetadataFromDriver(driver drivers.Driver) (string, *bundle.CrcBundleInfo, error) {
func getBundleMetadataFromDriver(driver drivers.Driver) (*bundle.CrcBundleInfo, error) {
bundleName, err := driver.GetBundleName()
if err != nil {
err := fmt.Errorf("Error getting bundle name from CodeReady Containers instance, make sure you ran 'crc setup' and are using the latest bundle")
return "", nil, err
return nil, err
}
metadata, err := bundle.Get(bundleName)
if err != nil {
return "", nil, err
return nil, err
}

return bundleName, metadata, err
return metadata, err
}

func createLibMachineClient() (*libmachine.Client, func()) {
Expand Down
4 changes: 2 additions & 2 deletions pkg/crc/machine/start.go
Expand Up @@ -162,11 +162,11 @@ func (client *client) Start(ctx context.Context, startConfig StartConfig) (*Star
return nil, errors.Wrap(err, "Error loading machine")
}

var bundleName string
bundleName, crcBundleMetadata, err = getBundleMetadataFromDriver(host.Driver)
crcBundleMetadata, err = getBundleMetadataFromDriver(host.Driver)
if err != nil {
return nil, errors.Wrap(err, "Error loading bundle metadata")
}
bundleName := crcBundleMetadata.GetBundleName()
if bundleName != filepath.Base(startConfig.BundlePath) {
logging.Debugf("Bundle '%s' was requested, but the existing VM is using '%s'",
filepath.Base(startConfig.BundlePath), bundleName)
Expand Down
2 changes: 1 addition & 1 deletion pkg/crc/machine/status.go
Expand Up @@ -28,7 +28,7 @@ func (client *client) Status() (*ClusterStatusResult, error) {
return nil, errors.Wrap(err, "Cannot get machine state")
}

_, crcBundleMetadata, err := getBundleMetadataFromDriver(host.Driver)
crcBundleMetadata, err := getBundleMetadataFromDriver(host.Driver)
if err != nil {
return nil, errors.Wrap(err, "Error loading bundle metadata")
}
Expand Down

0 comments on commit c4c56b1

Please sign in to comment.