-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Create asset graph engine #120
Changes from all commits
989532b
cccbb37
1b92ef7
e3a94b1
2947139
805a790
34b0c74
403e5bf
e735e38
d730f91
1273983
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package asset | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Golint comments: should have a package comment, unless it's in another file for this package. More info. |
||
|
||
// 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) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package installconfig | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Golint comments: should have a package comment, unless it's in another file for this package. More info. |
||
|
||
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())}, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note that There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I think we should just switch to asking for a version 4 UUID. It looks like that's There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good point, I can address this when rebasing my pr #145 |
||
}, | ||
}, nil | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
package installconfig | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Golint comments: should have a package comment, unless it's in another file for this package. More info. |
||
|
||
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{ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why do we need objectmeta if it's just for ClusterName? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I don't know what the plans are for objectmeta. It was defined that way in https://github.com/openshift/installer/blob/master/Documentation/design/installconfig.md. I also don't have a strong opinion one way or the other whether the Cluster Name is placed in the objectmeta or in a separate field. |
||
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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is probably stale after #127. Can we move this out of |
||
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) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. From #145 (comment):
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sounds reasonable. |
||
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 | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Golint comments: should have a package comment, unless it's in another file for this package. More info.