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", Name: "dry-run",
Usage: "Show what would be installed, but don't install anything.", 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) { 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) format.Err("%s (Run 'helm doctor' for more information)", err)
os.Exit(1) 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) 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 { if err != nil {
format.Err("Error installing: %s %s", out, err) return err
} }
format.Msg(out) format.Msg(out)
return nil return nil

23
glide.lock generated

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

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

@ -17,19 +17,58 @@ limitations under the License.
package dm package dm
import ( import (
"bytes"
"text/template"
"github.com/Masterminds/sprig"
"github.com/kubernetes/deployment-manager/pkg/format" "github.com/kubernetes/deployment-manager/pkg/format"
"github.com/kubernetes/deployment-manager/pkg/kubectl" "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. // Install uses kubectl to install the base DM.
// //
// Returns the string output received from the operation, and an error if the // Returns the string output received from the operation, and an error if the
// command failed. // command failed.
func Install(runner kubectl.Runner) (string, error) { func (i *Installer) Install(runner kubectl.Runner) (string, error) {
o, err := runner.Create([]byte(InstallYAML)) b, err := i.expand()
if err != nil {
return "", err
}
o, err := runner.Create(b)
return string(o), err 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. // IsInstalled checks whether DM has been installed.
func IsInstalled(runner kubectl.Runner) bool { func IsInstalled(runner kubectl.Runner) bool {
// Basically, we test "all-or-nothing" here: if this returns without error // Basically, we test "all-or-nothing" here: if this returns without error
@ -104,7 +143,7 @@ spec:
spec: spec:
containers: containers:
- env: [] - env: []
image: gcr.io/dm-k8s-testing/expandybird:latest image: {{default "gcr.io/dm-k8s-testing/expandybird:latest" .Expandybird.Image}}
name: expandybird name: expandybird
ports: ports:
- containerPort: 8080 - containerPort: 8080
@ -148,7 +187,7 @@ spec:
spec: spec:
containers: containers:
- env: [] - env: []
image: gcr.io/dm-k8s-testing/resourcifier:latest image: {{ default "gcr.io/dm-k8s-testing/resourcifier:latest" .Resourcifier.Image }}
name: resourcifier name: resourcifier
ports: ports:
- containerPort: 8080 - containerPort: 8080
@ -192,7 +231,7 @@ spec:
spec: spec:
containers: containers:
- env: [] - env: []
image: gcr.io/dm-k8s-testing/manager:latest image: {{ default "gcr.io/dm-k8s-testing/manager:latest" .Manager.Image }}
name: manager name: manager
ports: ports:
- containerPort: 8080 - containerPort: 8080

Loading…
Cancel
Save