Skip to content
Merged
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
2 changes: 1 addition & 1 deletion cmd/openshift-install/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ var (
ignitionConfigsCommand = kingpin.Command("ignition-configs", "Generate the Ignition Config assets")

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")
logLevel = kingpin.Flag("log-level", "log level (e.g. \"debug\")").Default("warn").Enum("debug", "info", "warn", "error", "fatal", "panic")
)

func main() {
Expand Down
1 change: 1 addition & 0 deletions pkg/asset/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ go_library(
],
importpath = "github.com/openshift/installer/pkg/asset",
visibility = ["//visibility:public"],
deps = ["//vendor/github.com/Sirupsen/logrus:go_default_library"],
)

go_test(
Expand Down
3 changes: 3 additions & 0 deletions pkg/asset/asset.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ type Asset interface {

// Generate generates this asset given the states of its dependent assets.
Generate(map[Asset]*State) (*State, error)

// Name returns the human-friendly name of the asset.
Name() string
}

// GetDataByFilename searches the file in the asset.State.Contents, and returns its data.
Expand Down
5 changes: 5 additions & 0 deletions pkg/asset/ignition/bootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,11 @@ func (a *bootstrap) Generate(dependencies map[asset.Asset]*asset.State) (*asset.
}, nil
}

// Name returns the human-friendly name of the asset.
func (a *bootstrap) Name() string {
return "Bootstrap Ignition Config"
}

// getTemplateData returns the data to use to execute bootstrap templates.
func (a *bootstrap) getTemplateData(installConfig *types.InstallConfig) (*bootstrapTemplateData, error) {
clusterDNSIP, err := installconfig.ClusterDNSIP(installConfig)
Expand Down
5 changes: 5 additions & 0 deletions pkg/asset/ignition/master.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,3 +56,8 @@ func (a *master) Generate(dependencies map[asset.Asset]*asset.State) (*asset.Sta

return state, nil
}

// Name returns the human-friendly name of the asset.
func (a *master) Name() string {
return "Master Ignition Config(s)"
}
4 changes: 4 additions & 0 deletions pkg/asset/ignition/testasset_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ func (a *testAsset) Generate(map[asset.Asset]*asset.State) (*asset.State, error)
return nil, nil
}

func (a *testAsset) Name() string {
return "Test Asset"
}

func stateWithContentsData(contentsData ...string) *asset.State {
state := &asset.State{
Contents: make([]asset.Content, len(contentsData)),
Expand Down
5 changes: 5 additions & 0 deletions pkg/asset/ignition/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,8 @@ func (a *worker) Generate(dependencies map[asset.Asset]*asset.State) (*asset.Sta
}},
}, nil
}

// Name returns the human-friendly name of the asset.
func (a *worker) Name() string {
return "Worker Ignition Config"
}
5 changes: 5 additions & 0 deletions pkg/asset/installconfig/clusterid.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,8 @@ func (a *clusterID) Generate(map[asset.Asset]*asset.State) (*asset.State, error)
},
}, nil
}

// Name returns the human-friendly name of the asset.
func (a *clusterID) Name() string {
return "Cluster ID"
}
5 changes: 5 additions & 0 deletions pkg/asset/installconfig/installconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,11 @@ func (a *installConfig) Generate(dependencies map[asset.Asset]*asset.State) (*as
}, nil
}

// Name returns the human-friendly name of the asset.
func (a installConfig) Name() string {
return "Install Config"
}

// GetInstallConfig returns the *types.InstallConfig from the parent asset map.
func GetInstallConfig(installConfig asset.Asset, parents map[asset.Asset]*asset.State) (*types.InstallConfig, error) {
var cfg types.InstallConfig
Expand Down
4 changes: 4 additions & 0 deletions pkg/asset/installconfig/installconfig_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@ func (a *testAsset) Generate(map[asset.Asset]*asset.State) (*asset.State, error)
return nil, nil
}

func (a *testAsset) Name() string {
return "Test Asset"
}

func TestInstallConfigDependencies(t *testing.T) {
stock := &StockImpl{
clusterID: &testAsset{name: "test-cluster-id"},
Expand Down
11 changes: 8 additions & 3 deletions pkg/asset/installconfig/platform.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const (

var (
validPlatforms = []string{AWSPlatformType, LibvirtPlatformType}
platformPrompt = fmt.Sprintf("Platform (%s):", strings.Join(validPlatforms, ", "))
platformPrompt = fmt.Sprintf("Platform (%s)", strings.Join(validPlatforms, ", "))
)

// Platform is an asset that queries the user for the platform on which to install
Expand Down Expand Up @@ -54,6 +54,11 @@ func (a *Platform) Generate(map[asset.Asset]*asset.State) (*asset.State, error)
}
}

// Name returns the human-friendly name of the asset.
func (a *Platform) Name() string {
return "Platform"
}

func (a *Platform) queryUserForPlatform() string {
for {
input := asset.QueryUser(a.InputReader, platformPrompt)
Expand All @@ -70,15 +75,15 @@ func (a *Platform) queryUserForPlatform() string {
func (a *Platform) awsPlatform() (*asset.State, error) {
return assetStateForStringContents(
AWSPlatformType,
asset.QueryUser(a.InputReader, "Region:"),
asset.QueryUser(a.InputReader, "Region"),
), nil
}

func (a *Platform) libvirtPlatform() (*asset.State, error) {
return assetStateForStringContents(
LibvirtPlatformType,
// TODO(yifan): Set the default URI.
asset.QueryUser(a.InputReader, "URI:"),
asset.QueryUser(a.InputReader, "URI"),
), nil
}

Expand Down
5 changes: 5 additions & 0 deletions pkg/asset/installconfig/ssh.go
Original file line number Diff line number Diff line change
Expand Up @@ -112,3 +112,8 @@ func (a *sshPublicKey) Generate(map[asset.Asset]*asset.State) (state *asset.Stat
},
}, nil
}

// Name returns the human-friendly name of the asset.
func (a *sshPublicKey) Name() string {
return "SSH Key"
}
10 changes: 5 additions & 5 deletions pkg/asset/installconfig/stock.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,26 +51,26 @@ func (s *StockImpl) EstablishStock(directory string, inputReader *bufio.Reader)
}
s.clusterID = &clusterID{}
s.emailAddress = &asset.UserProvided{
Prompt: "Email Address:",
Prompt: "Email Address",
InputReader: inputReader,
}
s.password = &asset.UserProvided{
Prompt: "Password:",
Prompt: "Password",
InputReader: inputReader,
}
s.sshKey = &sshPublicKey{
inputReader: inputReader,
}
s.baseDomain = &asset.UserProvided{
Prompt: "Base Domain:",
Prompt: "Base Domain",
InputReader: inputReader,
}
s.clusterName = &asset.UserProvided{
Prompt: "Cluster Name:",
Prompt: "Cluster Name",
InputReader: inputReader,
}
s.pullSecret = &asset.UserProvided{
Prompt: "Pull Secret:",
Prompt: "Pull Secret",
InputReader: inputReader,
}
s.platform = &Platform{InputReader: inputReader}
Expand Down
5 changes: 5 additions & 0 deletions pkg/asset/kubeconfig/kubeconfig.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,3 +114,8 @@ func (k *Kubeconfig) Generate(parents map[asset.Asset]*asset.State) (*asset.Stat
},
}, nil
}

// Name returns the human-friendly name of the asset.
func (k *Kubeconfig) Name() string {
return "Kubeconfig"
}
4 changes: 4 additions & 0 deletions pkg/asset/kubeconfig/kubeconfig_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@ func (f fakeAsset) Generate(map[asset.Asset]*asset.State) (*asset.State, error)
return nil, nil
}

func (f fakeAsset) Name() string {
return "Fake Asset"
}

func TestKubeconfigGenerate(t *testing.T) {
testDir, err := ioutil.TempDir(os.TempDir(), "kubeconfig_test")
if err != nil {
Expand Down
24 changes: 20 additions & 4 deletions pkg/asset/store.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
package asset

import (
"github.com/Sirupsen/logrus"
)

// Store is a store for the states of assets.
type Store interface {
// Fetch retrieves the state of the given asset, generating it and its
Expand All @@ -15,19 +19,31 @@ type StoreImpl struct {
// Fetch retrieves the state of the given asset, generating it and its
// dependencies if necessary.
func (s *StoreImpl) Fetch(asset Asset) (*State, error) {
return s.fetch(asset, "")
}

func (s *StoreImpl) fetch(asset Asset, indent string) (*State, error) {
logrus.Infof("%sFetching %s...", indent, asset.Name())
state, ok := s.assets[asset]
if ok {
logrus.Debugf("%sFound %s...", indent, asset.Name())
return state, nil
}
dependies := asset.Dependencies()
dependenciesStates := make(map[Asset]*State, len(dependies))
for _, d := range dependies {
ds, err := s.Fetch(d)

dependencies := asset.Dependencies()
dependenciesStates := make(map[Asset]*State, len(dependencies))
if len(dependencies) > 0 {
logrus.Debugf("%sGenerating dependencies of %s...", indent, asset.Name())
}
for _, d := range dependencies {
ds, err := s.fetch(d, indent+" ")
if err != nil {
return nil, err
}
dependenciesStates[d] = ds
}

logrus.Debugf("%sGenerating %s...", indent, asset.Name())
state, err := asset.Generate(dependenciesStates)
if err != nil {
return nil, err
Expand Down
4 changes: 4 additions & 0 deletions pkg/asset/store_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ func (a *testAsset) Generate(map[Asset]*State) (*State, error) {
return nil, nil
}

func (a *testAsset) Name() string {
return "Test Asset"
}

func newTestAsset(gl *generationLog, name string) *testAsset {
return &testAsset{
name: name,
Expand Down
5 changes: 5 additions & 0 deletions pkg/asset/tls/certkey.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,11 @@ func (c *CertKey) Generate(parents map[asset.Asset]*asset.State) (*asset.State,
}, nil
}

// Name returns the human-friendly name of the asset.
func (c *CertKey) Name() string {
return fmt.Sprintf("Certificate (%s)", c.Subject.CommonName)
}

func parseCAFromAssetState(ca *asset.State) (*rsa.PrivateKey, *x509.Certificate, error) {
var key *rsa.PrivateKey
var cert *x509.Certificate
Expand Down
4 changes: 4 additions & 0 deletions pkg/asset/tls/certkey_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ func (f fakeInstallConfig) Generate(map[asset.Asset]*asset.State) (*asset.State,
}, nil
}

func (f fakeInstallConfig) Name() string {
return "Fake Install Config"
}

func TestCertKeyGenerate(t *testing.T) {
testDir, err := ioutil.TempDir(os.TempDir(), "certkey_test")
if err != nil {
Expand Down
5 changes: 5 additions & 0 deletions pkg/asset/tls/keypair.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,8 @@ func (k *KeyPair) Generate(map[asset.Asset]*asset.State) (*asset.State, error) {
},
}, nil
}

// Name returns the human-friendly name of the asset.
func (k *KeyPair) Name() string {
return fmt.Sprintf("Key Pair (%s)", k.PubKeyFileName)
}
5 changes: 5 additions & 0 deletions pkg/asset/tls/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,8 @@ func (c *RootCA) Generate(parents map[asset.Asset]*asset.State) (*asset.State, e
},
}, nil
}

// Name returns the human-friendly name of the asset.
func (c *RootCA) Name() string {
return "Root CA"
}
7 changes: 6 additions & 1 deletion pkg/asset/userprovided.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,15 @@ func (a *UserProvided) Generate(map[Asset]*State) (*State, error) {
}, nil
}

// Name returns the human-friendly name of the asset.
func (a UserProvided) Name() string {
return a.Prompt
}

// QueryUser queries the user for input.
func QueryUser(inputReader *bufio.Reader, prompt string) string {
for {
fmt.Println(prompt)
fmt.Printf("%s: ", prompt)
input, err := inputReader.ReadString('\n')
if err != nil && err != io.EOF {
fmt.Println("Could not understand response. Please retry.")
Expand Down