Skip to content
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
6 changes: 6 additions & 0 deletions pkg/asset/cluster/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (

"github.com/openshift/installer/pkg/asset"
"github.com/openshift/installer/pkg/asset/cluster/aws"
"github.com/openshift/installer/pkg/asset/cluster/vsphere"
"github.com/openshift/installer/pkg/asset/installconfig"
"github.com/openshift/installer/pkg/asset/password"
"github.com/openshift/installer/pkg/terraform"
Expand Down Expand Up @@ -77,6 +78,11 @@ func (c *Cluster) Generate(parents asset.Parents) (err error) {
return err
}
}
if installConfig.Config.Platform.VSphere != nil {
if err := vsphere.PreTerraform(context.TODO(), clusterID.InfraID, installConfig); err != nil {
return err
}
}

stateFile, err := terraform.Apply(tmpDir, installConfig.Config.Platform.Name(), extraArgs...)
if err != nil {
Expand Down
5 changes: 4 additions & 1 deletion pkg/asset/cluster/tfvars.go
Original file line number Diff line number Diff line change
Expand Up @@ -425,17 +425,20 @@ func (t *TerraformVariables) Generate(parents asset.Parents) error {
for i, c := range controlPlanes {
controlPlaneConfigs[i] = c.Spec.ProviderSpec.Value.Object.(*vsphereprovider.VSphereMachineProviderSpec)
}
data, err = vspheretfvars.TFVars(
data, cachedImage, err := vspheretfvars.TFVars(
vspheretfvars.TFVarsSources{
ControlPlaneConfigs: controlPlaneConfigs,
Username: installConfig.Config.VSphere.Username,
Password: installConfig.Config.VSphere.Password,
Cluster: installConfig.Config.VSphere.Cluster,
ImageURI: string(*rhcosImage),
},
)
if err != nil {
return errors.Wrapf(err, "failed to get %s Terraform variables", platform)
}
installConfig.Config.VSphere.ClusterOSImage = cachedImage
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the effect of doing this? Is this value saved or used later?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The goal here is to stuff the cached location back into the installConfig so we can pass it to the preterraform func. https://github.com/openshift/installer/pull/2922/files#diff-661643e1b9745123649391076bfa5a01R22. I don't believe it's ever written out to disk, though.

Copy link
Contributor

@abhinavdahiya abhinavdahiya Feb 20, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think you can assume writeback to your dependency assets, the asset store could easily be providing you the ready only copies.

dependency loops are not great.


t.FileList = append(t.FileList, &asset.File{
Filename: fmt.Sprintf(TfPlatformVarsFileName, platform),
Data: data,
Expand Down
10 changes: 10 additions & 0 deletions pkg/asset/cluster/vsphere/vsphere.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package vsphere

import (
"context"

"github.com/openshift/installer/pkg/asset/installconfig"
"github.com/openshift/installer/pkg/types"
"github.com/openshift/installer/pkg/types/vsphere"
)
Expand All @@ -13,3 +16,10 @@ func Metadata(config *types.InstallConfig) *vsphere.Metadata {
Password: config.VSphere.Password,
}
}

// PreTerraform performs any infrastructure initialization which must
// happen before Terraform creates the remaining infrastructure.
func PreTerraform(ctx context.Context, infraID string, installConfig *installconfig.InstallConfig) error {
// TODO: create VM Template using cachedImage
return nil
}
Comment on lines +20 to +25
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the goal for pre terraform was to put in code that was not easily done by terraform itself, like tagging subnets for AWS.

my preference would be keep any cloud creation into terraform, we can easily keep local terraform providers for the custom objects/operations like the uploading ova.

9 changes: 8 additions & 1 deletion pkg/asset/rhcos/image.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,15 @@ func osImage(config *types.InstallConfig) (string, error) {
// because this contains the necessary ironic config drive
// ignition support, which isn't enabled in the UPI BM images
osimage, err = rhcos.OpenStack(ctx, arch)
case none.Name, vsphere.Name:
case vsphere.Name:
// Check for RHCOS image URL override
if config.Platform.VSphere.ClusterOSImage != "" {
osimage = config.Platform.VSphere.ClusterOSImage
break
}

osimage, err = rhcos.VMware(ctx, arch)
case none.Name:
default:
return "", errors.New("invalid Platform")
}
Expand Down
4 changes: 4 additions & 0 deletions pkg/rhcos/builds.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,10 @@ type metadata struct {
SHA256 string `json:"sha256"`
UncompressedSHA256 string `json:"uncompressed-sha256"`
} `json:"openstack"`
VMware struct {
Path string `json:"path"`
SHA256 string `json:"sha256"`
} `json:"vmware"`
} `json:"images"`
OSTreeVersion string `json:"ostree-version"`
}
Expand Down
44 changes: 44 additions & 0 deletions pkg/rhcos/vmware.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package rhcos

import (
"context"
"net/url"

"github.com/pkg/errors"

"github.com/openshift/installer/pkg/types"
)

// VMware fetches the URL of the Red Hat Enterprise Linux CoreOS release.
func VMware(ctx context.Context, arch types.Architecture) (string, error) {
meta, err := fetchRHCOSBuild(ctx, arch)
if err != nil {
return "", errors.Wrap(err, "failed to fetch RHCOS metadata")
}

base, err := url.Parse(meta.BaseURI)
if err != nil {
return "", err
}

image, err := url.Parse(meta.Images.VMware.Path)
if err != nil {
return "", err
}

baseURL := base.ResolveReference(image).String()

// TODO: Get Uncompressed SHA256 into rhcos.json
// Attach sha256 checksum to the URL. Always provide the
// uncompressed SHA256; the cache will take care of
// uncompressing before checksumming.
//baseURL += "?sha256=" + meta.Images.VMware.UncompressedSHA256

// Check that we have generated a valid URL
_, err = url.ParseRequestURI(baseURL)
if err != nil {
return "", err
}

return baseURL, nil
}
18 changes: 16 additions & 2 deletions pkg/tfvars/vsphere/vsphere.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ package vsphere
import (
"encoding/json"

"github.com/pkg/errors"

"github.com/openshift/installer/pkg/tfvars/internal/cache"
vsphereapis "github.com/openshift/machine-api-operator/pkg/apis/vsphereprovider/v1alpha1"
)

Expand All @@ -28,12 +31,18 @@ type TFVarsSources struct {
Username string
Password string
Cluster string
ImageURI string
}

//TFVars generate vSphere-specific Terraform variables
func TFVars(sources TFVarsSources) ([]byte, error) {
func TFVars(sources TFVarsSources) ([]byte, string, error) {
controlPlaneConfig := sources.ControlPlaneConfigs[0]

cachedImage, err := cache.DownloadImageFile(sources.ImageURI)
if err != nil {
return nil, "", errors.Wrap(err, "failed to use cached vsphere image")
}

cfg := &config{
VSphereURL: controlPlaneConfig.Workspace.Server,
VSphereUsername: sources.Username,
Expand All @@ -50,5 +59,10 @@ func TFVars(sources TFVarsSources) ([]byte, error) {
Template: controlPlaneConfig.Template,
}

return json.MarshalIndent(cfg, "", " ")
cfgFormatted, err := json.MarshalIndent(cfg, "", " ")
if err != nil {
return nil, "", err
}

return cfgFormatted, cachedImage, nil
}