Merge pull request #318 from technosophos/feat/dm-install-generator

feat(dm install): use template to generate manifest
pull/333/head
Matt Butcher 9 years ago
commit d6ed7aeab0

@ -48,9 +48,28 @@ func dmCmd() cli.Command {
Name: "dry-run",
Usage: "Show what would be installed, but don't install anything.",
},
cli.StringFlag{
Name: "resourcifier-image",
Usage: "The full image name of the Docker image for resourcifier.",
EnvVar: "HELM_RESOURCIFIER_IMAGE",
},
cli.StringFlag{
Name: "expandybird-image",
Usage: "The full image name of the Docker image for expandybird.",
EnvVar: "HELM_EXPANDYBIRD_IMAGE",
},
cli.StringFlag{
Name: "manager-image",
Usage: "The full image name of the Docker image for manager.",
EnvVar: "HELM_MANAGER_IMAGE",
},
},
Action: func(c *cli.Context) {
if err := install(c.Bool("dry-run")); err != nil {
dry := c.Bool("dry-run")
ri := c.String("resourcifier-image")
ei := c.String("expandybird-image")
mi := c.String("manager-image")
if err := install(dry, ei, mi, ri); err != nil {
format.Err("%s (Run 'helm doctor' for more information)", err)
os.Exit(1)
}
@ -111,12 +130,17 @@ func dmCmd() cli.Command {
}
}
func install(dryRun bool) error {
func install(dryRun bool, ebImg, manImg, resImg string) error {
runner := getKubectlRunner(dryRun)
out, err := dm.Install(runner)
i := dm.NewInstaller()
i.Manager["Image"] = manImg
i.Resourcifier["Image"] = resImg
i.Expandybird["Image"] = ebImg
out, err := i.Install(runner)
if err != nil {
format.Err("Error installing: %s %s", out, err)
return err
}
format.Msg(out)
return nil

23
glide.lock generated

@ -1,5 +1,5 @@
hash: 2d8e32786782b7979a79850cfc489866a74c068e865f433a73ed4f50ef2644e9
updated: 2016-02-29T11:21:24.093936684-08:00
hash: d9beab9a799ac8dd0d76c4f7a3a32753d44833dd3527b3caa8e786865ea26816
updated: 2016-03-04T09:54:13.155442463-07:00
imports:
- name: github.com/aokoli/goutils
version: 9c37978a95bd5c709a15883b6242714ea6709e64
@ -11,10 +11,6 @@ imports:
- log
- name: github.com/ghodss/yaml
version: 73d445a93680fa1a78ae23a5839bad48f32ba1ee
- name: github.com/golang/protobuf
version: 6aaa8d47701fa6cf07e914ec01fde3d4a1fe79c3
subpackages:
- proto
- name: github.com/google/go-github
version: b8b4ac742977310ff6e75140a403a38dab109977
subpackages:
@ -31,6 +27,8 @@ imports:
version: 26a6070f849969ba72b72256e9f14cf519751690
- name: github.com/Masterminds/semver
version: c4f7ef0702f269161a60489ccbbc9f1241ad1265
- name: github.com/Masterminds/sprig
version: fd057ca403105755181f84645696d705a58852dd
- name: golang.org/x/net
version: 04b9de9b512f58addf28c9853d50ebef61c3953e
subpackages:
@ -50,18 +48,6 @@ imports:
- gensupport
- googleapi
- googleapi/internal/uritemplates
- name: google.golang.org/appengine
version: 6bde959377a90acb53366051d7d587bfd7171354
subpackages:
- urlfetch
- internal
- internal/urlfetch
- internal/app_identity
- internal/modules
- internal/base
- internal/datastore
- internal/log
- internal/remote_api
- name: google.golang.org/cloud
version: fb10e8da373d97f6ba5e648299a10b3b91f14cd5
subpackages:
@ -71,7 +57,6 @@ imports:
version: d90005c5262a3463800497ea5a89aed5fe22c886
subpackages:
- bson
- internal/sasl
- internal/scram
- name: gopkg.in/yaml.v2
version: f7716cbe52baa25d2e9b0d0da546fcf909fc16b4

@ -1,4 +1,6 @@
package: github.com/kubernetes/deployment-manager
ignore:
- google.golang.com/appengine
import:
- package: github.com/Masterminds/semver
- package: github.com/aokoli/goutils
@ -7,10 +9,8 @@ import:
- package: github.com/ghodss/yaml
- package: github.com/google/go-github
subpackages:
- /github
- github
- package: github.com/gorilla/handlers
- package: github.com/gorilla/mux
- package: gopkg.in/yaml.v2
- package: github.com/Masterminds/semver
ignore:
- google.golang.com/appengine
- package: github.com/Masterminds/sprig

@ -17,19 +17,58 @@ limitations under the License.
package dm
import (
"bytes"
"text/template"
"github.com/Masterminds/sprig"
"github.com/kubernetes/deployment-manager/pkg/format"
"github.com/kubernetes/deployment-manager/pkg/kubectl"
)
// Installer is capable of installing DM into Kubernetes.
//
// See InstallYAML.
type Installer struct {
// TODO: At some point we could transform these from maps to structs.
// Expandybird params are used to render the expandybird manifest.
Expandybird map[string]interface{}
// Resourcifier params are used to render the resourcifier manifest.
Resourcifier map[string]interface{}
// Manager params are used to render the manager manifest.
Manager map[string]interface{}
}
// NewInstaller creates a new Installer.
func NewInstaller() *Installer {
return &Installer{
Expandybird: map[string]interface{}{},
Resourcifier: map[string]interface{}{},
Manager: map[string]interface{}{},
}
}
// Install uses kubectl to install the base DM.
//
// Returns the string output received from the operation, and an error if the
// command failed.
func Install(runner kubectl.Runner) (string, error) {
o, err := runner.Create([]byte(InstallYAML))
func (i *Installer) Install(runner kubectl.Runner) (string, error) {
b, err := i.expand()
if err != nil {
return "", err
}
o, err := runner.Create(b)
return string(o), err
}
func (i *Installer) expand() ([]byte, error) {
var b bytes.Buffer
t := template.Must(template.New("manifest").Funcs(sprig.TxtFuncMap()).Parse(InstallYAML))
err := t.Execute(&b, i)
return b.Bytes(), err
}
// IsInstalled checks whether DM has been installed.
func IsInstalled(runner kubectl.Runner) bool {
// Basically, we test "all-or-nothing" here: if this returns without error
@ -104,7 +143,7 @@ spec:
spec:
containers:
- env: []
image: gcr.io/dm-k8s-testing/expandybird:latest
image: {{default "gcr.io/dm-k8s-testing/expandybird:latest" .Expandybird.Image}}
name: expandybird
ports:
- containerPort: 8080
@ -148,7 +187,7 @@ spec:
spec:
containers:
- env: []
image: gcr.io/dm-k8s-testing/resourcifier:latest
image: {{ default "gcr.io/dm-k8s-testing/resourcifier:latest" .Resourcifier.Image }}
name: resourcifier
ports:
- containerPort: 8080
@ -192,7 +231,7 @@ spec:
spec:
containers:
- env: []
image: gcr.io/dm-k8s-testing/manager:latest
image: {{ default "gcr.io/dm-k8s-testing/manager:latest" .Manager.Image }}
name: manager
ports:
- containerPort: 8080

Loading…
Cancel
Save