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
8 changes: 7 additions & 1 deletion Gopkg.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

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
7 changes: 6 additions & 1 deletion pkg/asset/cluster/tfvars.go
Original file line number Diff line number Diff line change
Expand Up @@ -425,17 +425,22 @@ 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)
}

// TODO: is this wise to overwrite the install-config?
installConfig.Config.VSphere.ClusterOSImage = cachedImage

t.FileList = append(t.FileList, &asset.File{
Filename: fmt.Sprintf(TfPlatformVarsFileName, platform),
Data: data,
Expand Down
203 changes: 203 additions & 0 deletions pkg/asset/cluster/vsphere/archive.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,203 @@
/*
Copyright (c) 2014-2015 VMware, Inc. All Rights Reserved.

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package vsphere

import (
"archive/tar"
"bytes"
"context"
"errors"
"flag"
"fmt"
"io"
"io/ioutil"
"net/url"
"os"
"path"
"path/filepath"
"strings"

"github.com/vmware/govmomi/ovf"
"github.com/vmware/govmomi/vim25"
"github.com/vmware/govmomi/vim25/soap"
)

// ArchiveFlag doesn't register any flags;
// only encapsulates some common archive related functionality.
type ArchiveFlag struct {
Archive
}

func newArchiveFlag(ctx context.Context) (*ArchiveFlag, context.Context) {
return &ArchiveFlag{}, ctx
}

// Register ArchiveFlag
Copy link
Contributor

Choose a reason for hiding this comment

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

It seems like the only thing being changed from the govmomi repo is adding some comments. These are exported types so I would think we should be able to use these just from the vendored code and not copy here...

Copy link
Contributor

Choose a reason for hiding this comment

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

It's a technical reason... the things we need from the vendored code is not exportable. Therefore, we copied file(s) here with a modified package vsphere thereby making them accessible.

func (f *ArchiveFlag) Register(ctx context.Context, fs *flag.FlagSet) {
}

// Process ArchiveFlag
func (f *ArchiveFlag) Process(ctx context.Context) error {
return nil
}

// ReadOvf - open and read OVF file
func (f *ArchiveFlag) ReadOvf(fpath string) ([]byte, error) {
r, _, err := f.Open(fpath)
if err != nil {
return nil, err
}
defer r.Close()

return ioutil.ReadAll(r)
}

// ReadEnvelope - open and read OVF envelope
func (f *ArchiveFlag) ReadEnvelope(data []byte) (*ovf.Envelope, error) {
e, err := ovf.Unmarshal(bytes.NewReader(data))
if err != nil {
return nil, fmt.Errorf("failed to parse ovf: %s", err)
}

return e, nil
}

// Archive interface
type Archive interface {
Open(string) (io.ReadCloser, int64, error)
}

// TapeArchive struct
type TapeArchive struct {
Path string
Opener
}

//TapeArchiveEntry struct
type TapeArchiveEntry struct {
io.Reader
f io.Closer

Name string
}

// Close the TapeArchiveEntry
func (t *TapeArchiveEntry) Close() error {
return t.f.Close()
}

// Open the TapeArchive locally
func (t *TapeArchive) Open(name string) (io.ReadCloser, int64, error) {
f, _, err := t.OpenFile(t.Path)
if err != nil {
return nil, 0, err
}

r := tar.NewReader(f)

for {
h, err := r.Next()
if err == io.EOF {
break
}
if err != nil {
return nil, 0, err
}

matched, err := path.Match(name, path.Base(h.Name))
if err != nil {
return nil, 0, err
}

if matched {
return &TapeArchiveEntry{r, f, h.Name}, h.Size, nil
}
}

_ = f.Close()

return nil, 0, os.ErrNotExist
}

// FileArchive contains the path and the opener, which can be either remotely vCenter
// or locally
type FileArchive struct {
Path string
Opener
}

// Open the FileArchive
func (t *FileArchive) Open(name string) (io.ReadCloser, int64, error) {
fpath := name
if name != t.Path {
index := strings.LastIndex(t.Path, "/")
if index != -1 {
fpath = t.Path[:index] + "/" + name
}
}

return t.OpenFile(fpath)
}

// Opener - contains the soap client to vCenter
type Opener struct {
*vim25.Client
}

func isRemotePath(path string) bool {
if strings.HasPrefix(path, "http://") || strings.HasPrefix(path, "https://") {
return true
}
return false
}

// OpenLocal - open the OVF/OVA locally
func (o Opener) OpenLocal(path string) (io.ReadCloser, int64, error) {
f, err := os.Open(filepath.Clean(path))
if err != nil {
return nil, 0, err
}

s, err := f.Stat()
if err != nil {
return nil, 0, err
}

return f, s.Size(), nil
}

// OpenFile - determine which method to open the OVA/OVF
func (o Opener) OpenFile(path string) (io.ReadCloser, int64, error) {
if isRemotePath(path) {
return o.OpenRemote(path)
}
return o.OpenLocal(path)
}

// OpenRemote - open in vSphere
func (o Opener) OpenRemote(link string) (io.ReadCloser, int64, error) {
if o.Client == nil {
return nil, 0, errors.New("remote path not supported")
}

u, err := url.Parse(link)
if err != nil {
return nil, 0, err
}

return o.Download(context.Background(), u, &soap.DefaultDownload)
}
Loading