Skip to content

Commit

Permalink
Merge pull request #120 from staebler/asset_graph_engine
Browse files Browse the repository at this point in the history
Create asset graph engine
  • Loading branch information
openshift-merge-robot authored Aug 25, 2018
2 parents c07d8ac + 1273983 commit 4e92db8
Show file tree
Hide file tree
Showing 106 changed files with 22,719 additions and 3 deletions.
19 changes: 18 additions & 1 deletion Documentation/design/installconfig.md
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,13 @@ type InstallConfig struct {
metav1.ObjectMeta `json:"metadata"`

// ClusterID is the ID of the cluster.
ClusterID uuid.UUID `json:"clusterID"`
ClusterID string `json:"clusterID"`

// Admin is the configuration for the admin user.
Admin Admin `json:"admin"`

// BaseDomain is the base domain to which the cluster should belong.
BaseDomain string `json:"baseDomain"`

// Networking defines the pod network provider in the cluster.
Networking `json:"networking"`
Expand All @@ -253,6 +259,17 @@ type InstallConfig struct {

// only one of the platform configuration should be set
Platform `json:"platform"`

// License is an OpenShift license needed to install a cluster.
License string `json:"license"`

// PullSecret is the secret to use when pulling images.
PullSecret string `json:"pullSecret"`
}

type Admin struct {
Email string `json:"email"`
Password string `json:"password"`
}

type Platform struct {
Expand Down
44 changes: 44 additions & 0 deletions cmd/openshift-install/main.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package main

import (
"os"

log "github.com/Sirupsen/logrus"
"gopkg.in/alecthomas/kingpin.v2"

"github.com/openshift/installer/pkg/asset"
"github.com/openshift/installer/pkg/asset/stock"
)

var (
installConfigCommand = kingpin.Command("install-config", "Generate the Install Config asset")

dirFlag = kingpin.Flag("dir", "assets directory").Default(".").String()
logLevel = kingpin.Flag("log-level", "log level (e.g. \"debug\")").Default("info").Enum("debug", "info", "warn", "error", "fatal", "panic")
)

func main() {
command := kingpin.Parse()

assetStock := stock.EstablishStock(*dirFlag)

var targetAsset asset.Asset

switch command {
case installConfigCommand.FullCommand():
targetAsset = assetStock.InstallConfig()
}

l, err := log.ParseLevel(*logLevel)
if err != nil {
// By definition we should never enter this condition since kingpin should be guarding against incorrect values.
log.Fatalf("invalid log-level: %v", err)
}
log.SetLevel(l)

assetStore := &asset.StoreImpl{}
if _, err := assetStore.Fetch(targetAsset); err != nil {
log.Fatalf("failed to generate asset: %v", err)
os.Exit(1)
}
}
18 changes: 16 additions & 2 deletions glide.lock

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

10 changes: 10 additions & 0 deletions pkg/asset/asset.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package asset

// Asset used to install OpenShift.
type Asset interface {
// Dependencies returns the assets upon which this asset directly depends.
Dependencies() []Asset

// Generate generates this asset given the states of its dependent assets.
Generate(map[Asset]*State) (*State, error)
}
25 changes: 25 additions & 0 deletions pkg/asset/installconfig/clusterid.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package installconfig

import (
"github.com/pborman/uuid"

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

type clusterID struct{}

var _ asset.Asset = (*clusterID)(nil)

// Dependencies returns no dependencies.
func (a *clusterID) Dependencies() []asset.Asset {
return []asset.Asset{}
}

// Generate generates a new UUID
func (a *clusterID) Generate(map[asset.Asset]*asset.State) (*asset.State, error) {
return &asset.State{
Contents: []asset.Content{
{Data: []byte(uuid.NewUUID().String())},
},
}, nil
}
100 changes: 100 additions & 0 deletions pkg/asset/installconfig/installconfig.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
package installconfig

import (
"fmt"
"path/filepath"

"github.com/ghodss/yaml"

metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

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

// installConfig generates the install-config.yml file.
type installConfig struct {
assetStock Stock
directory string
}

var _ asset.Asset = (*installConfig)(nil)

// Dependencies returns all of the dependencies directly needed by an
// installConfig asset.
func (a *installConfig) Dependencies() []asset.Asset {
return []asset.Asset{
a.assetStock.ClusterID(),
a.assetStock.EmailAddress(),
a.assetStock.Password(),
a.assetStock.BaseDomain(),
a.assetStock.ClusterName(),
a.assetStock.License(),
a.assetStock.PullSecret(),
a.assetStock.Platform(),
}
}

// Generate generates the install-config.yml file.
func (a *installConfig) Generate(dependencies map[asset.Asset]*asset.State) (*asset.State, error) {
clusterID := string(dependencies[a.assetStock.ClusterID()].Contents[0].Data)
emailAddress := string(dependencies[a.assetStock.EmailAddress()].Contents[0].Data)
password := string(dependencies[a.assetStock.Password()].Contents[0].Data)
baseDomain := string(dependencies[a.assetStock.BaseDomain()].Contents[0].Data)
clusterName := string(dependencies[a.assetStock.ClusterName()].Contents[0].Data)
license := string(dependencies[a.assetStock.License()].Contents[0].Data)
pullSecret := string(dependencies[a.assetStock.PullSecret()].Contents[0].Data)

installConfig := types.InstallConfig{
ObjectMeta: metav1.ObjectMeta{
Name: clusterName,
},
ClusterID: clusterID,
Admin: types.Admin{
Email: emailAddress,
Password: password,
},
BaseDomain: baseDomain,
License: license,
PullSecret: pullSecret,
}

platformState := dependencies[a.assetStock.Platform()]
platform := string(platformState.Contents[0].Data)
switch platform {
case AWSPlatformType:
region := string(platformState.Contents[1].Data)
keyPairName := string(platformState.Contents[2].Data)
installConfig.AWS = &types.AWSPlatform{
Region: region,
KeyPairName: keyPairName,
}
case LibvirtPlatformType:
uri := string(platformState.Contents[1].Data)
sshKey := string(platformState.Contents[2].Data)
installConfig.Libvirt = &types.LibvirtPlatform{
URI: uri,
SSHKey: sshKey,
}
default:
return nil, fmt.Errorf("unknown platform type %q", platform)
}

data, err := yaml.Marshal(installConfig)
if err != nil {
return nil, err
}

state := &asset.State{
Contents: []asset.Content{
{
Name: filepath.Join(a.directory, "install-config.yml"),
Data: data,
},
},
}

state.PersistToFile()

return state, nil
}
Loading

0 comments on commit 4e92db8

Please sign in to comment.