Skip to content

Commit 4e92db8

Browse files
Merge pull request #120 from staebler/asset_graph_engine
Create asset graph engine
2 parents c07d8ac + 1273983 commit 4e92db8

File tree

106 files changed

+22719
-3
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

106 files changed

+22719
-3
lines changed

Documentation/design/installconfig.md

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,13 @@ type InstallConfig struct {
243243
metav1.ObjectMeta `json:"metadata"`
244244

245245
// ClusterID is the ID of the cluster.
246-
ClusterID uuid.UUID `json:"clusterID"`
246+
ClusterID string `json:"clusterID"`
247+
248+
// Admin is the configuration for the admin user.
249+
Admin Admin `json:"admin"`
250+
251+
// BaseDomain is the base domain to which the cluster should belong.
252+
BaseDomain string `json:"baseDomain"`
247253

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

254260
// only one of the platform configuration should be set
255261
Platform `json:"platform"`
262+
263+
// License is an OpenShift license needed to install a cluster.
264+
License string `json:"license"`
265+
266+
// PullSecret is the secret to use when pulling images.
267+
PullSecret string `json:"pullSecret"`
268+
}
269+
270+
type Admin struct {
271+
Email string `json:"email"`
272+
Password string `json:"password"`
256273
}
257274

258275
type Platform struct {

cmd/openshift-install/main.go

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
package main
2+
3+
import (
4+
"os"
5+
6+
log "github.com/Sirupsen/logrus"
7+
"gopkg.in/alecthomas/kingpin.v2"
8+
9+
"github.com/openshift/installer/pkg/asset"
10+
"github.com/openshift/installer/pkg/asset/stock"
11+
)
12+
13+
var (
14+
installConfigCommand = kingpin.Command("install-config", "Generate the Install Config asset")
15+
16+
dirFlag = kingpin.Flag("dir", "assets directory").Default(".").String()
17+
logLevel = kingpin.Flag("log-level", "log level (e.g. \"debug\")").Default("info").Enum("debug", "info", "warn", "error", "fatal", "panic")
18+
)
19+
20+
func main() {
21+
command := kingpin.Parse()
22+
23+
assetStock := stock.EstablishStock(*dirFlag)
24+
25+
var targetAsset asset.Asset
26+
27+
switch command {
28+
case installConfigCommand.FullCommand():
29+
targetAsset = assetStock.InstallConfig()
30+
}
31+
32+
l, err := log.ParseLevel(*logLevel)
33+
if err != nil {
34+
// By definition we should never enter this condition since kingpin should be guarding against incorrect values.
35+
log.Fatalf("invalid log-level: %v", err)
36+
}
37+
log.SetLevel(l)
38+
39+
assetStore := &asset.StoreImpl{}
40+
if _, err := assetStore.Fetch(targetAsset); err != nil {
41+
log.Fatalf("failed to generate asset: %v", err)
42+
os.Exit(1)
43+
}
44+
}

glide.lock

Lines changed: 16 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/asset/asset.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package asset
2+
3+
// Asset used to install OpenShift.
4+
type Asset interface {
5+
// Dependencies returns the assets upon which this asset directly depends.
6+
Dependencies() []Asset
7+
8+
// Generate generates this asset given the states of its dependent assets.
9+
Generate(map[Asset]*State) (*State, error)
10+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package installconfig
2+
3+
import (
4+
"github.com/pborman/uuid"
5+
6+
"github.com/openshift/installer/pkg/asset"
7+
)
8+
9+
type clusterID struct{}
10+
11+
var _ asset.Asset = (*clusterID)(nil)
12+
13+
// Dependencies returns no dependencies.
14+
func (a *clusterID) Dependencies() []asset.Asset {
15+
return []asset.Asset{}
16+
}
17+
18+
// Generate generates a new UUID
19+
func (a *clusterID) Generate(map[asset.Asset]*asset.State) (*asset.State, error) {
20+
return &asset.State{
21+
Contents: []asset.Content{
22+
{Data: []byte(uuid.NewUUID().String())},
23+
},
24+
}, nil
25+
}
Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
package installconfig
2+
3+
import (
4+
"fmt"
5+
"path/filepath"
6+
7+
"github.com/ghodss/yaml"
8+
9+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
10+
11+
"github.com/openshift/installer/pkg/asset"
12+
"github.com/openshift/installer/pkg/types"
13+
)
14+
15+
// installConfig generates the install-config.yml file.
16+
type installConfig struct {
17+
assetStock Stock
18+
directory string
19+
}
20+
21+
var _ asset.Asset = (*installConfig)(nil)
22+
23+
// Dependencies returns all of the dependencies directly needed by an
24+
// installConfig asset.
25+
func (a *installConfig) Dependencies() []asset.Asset {
26+
return []asset.Asset{
27+
a.assetStock.ClusterID(),
28+
a.assetStock.EmailAddress(),
29+
a.assetStock.Password(),
30+
a.assetStock.BaseDomain(),
31+
a.assetStock.ClusterName(),
32+
a.assetStock.License(),
33+
a.assetStock.PullSecret(),
34+
a.assetStock.Platform(),
35+
}
36+
}
37+
38+
// Generate generates the install-config.yml file.
39+
func (a *installConfig) Generate(dependencies map[asset.Asset]*asset.State) (*asset.State, error) {
40+
clusterID := string(dependencies[a.assetStock.ClusterID()].Contents[0].Data)
41+
emailAddress := string(dependencies[a.assetStock.EmailAddress()].Contents[0].Data)
42+
password := string(dependencies[a.assetStock.Password()].Contents[0].Data)
43+
baseDomain := string(dependencies[a.assetStock.BaseDomain()].Contents[0].Data)
44+
clusterName := string(dependencies[a.assetStock.ClusterName()].Contents[0].Data)
45+
license := string(dependencies[a.assetStock.License()].Contents[0].Data)
46+
pullSecret := string(dependencies[a.assetStock.PullSecret()].Contents[0].Data)
47+
48+
installConfig := types.InstallConfig{
49+
ObjectMeta: metav1.ObjectMeta{
50+
Name: clusterName,
51+
},
52+
ClusterID: clusterID,
53+
Admin: types.Admin{
54+
Email: emailAddress,
55+
Password: password,
56+
},
57+
BaseDomain: baseDomain,
58+
License: license,
59+
PullSecret: pullSecret,
60+
}
61+
62+
platformState := dependencies[a.assetStock.Platform()]
63+
platform := string(platformState.Contents[0].Data)
64+
switch platform {
65+
case AWSPlatformType:
66+
region := string(platformState.Contents[1].Data)
67+
keyPairName := string(platformState.Contents[2].Data)
68+
installConfig.AWS = &types.AWSPlatform{
69+
Region: region,
70+
KeyPairName: keyPairName,
71+
}
72+
case LibvirtPlatformType:
73+
uri := string(platformState.Contents[1].Data)
74+
sshKey := string(platformState.Contents[2].Data)
75+
installConfig.Libvirt = &types.LibvirtPlatform{
76+
URI: uri,
77+
SSHKey: sshKey,
78+
}
79+
default:
80+
return nil, fmt.Errorf("unknown platform type %q", platform)
81+
}
82+
83+
data, err := yaml.Marshal(installConfig)
84+
if err != nil {
85+
return nil, err
86+
}
87+
88+
state := &asset.State{
89+
Contents: []asset.Content{
90+
{
91+
Name: filepath.Join(a.directory, "install-config.yml"),
92+
Data: data,
93+
},
94+
},
95+
}
96+
97+
state.PersistToFile()
98+
99+
return state, nil
100+
}

0 commit comments

Comments
 (0)