forked from openshift/installer
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request openshift#120 from staebler/asset_graph_engine
Create asset graph engine
- Loading branch information
Showing
106 changed files
with
22,719 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
Oops, something went wrong.