Merge pull request #343 from justinsb/custom_build

Make it easy to run a custom build
This commit is contained in:
Justin Santa Barbara 2016-08-19 00:35:11 -04:00 committed by GitHub
commit 14aa1dc18f
5 changed files with 54 additions and 5 deletions

View File

@ -5,8 +5,8 @@ After=docker.service
[Service]
EnvironmentFile=/etc/sysconfig/protokube
ExecStartPre=/usr/bin/docker pull kope/protokube:1.3
ExecStart=/usr/bin/docker run -v /:/rootfs/ --privileged kope/protokube:1.3 /usr/bin/protokube "$DAEMON_ARGS"
ExecStartPre=/usr/bin/docker pull {{ ProtokubeImage }}
ExecStart=/usr/bin/docker run -v /:/rootfs/ --privileged {{ ProtokubeImage }} /usr/bin/protokube "$DAEMON_ARGS"
Restart=always
RestartSec=2s
StartLimitInterval=0

View File

@ -129,8 +129,13 @@ func (c *ApplyClusterCmd) Run() error {
}
if c.NodeUpSource == "" {
location := "https://kubeupv2.s3.amazonaws.com/nodeup/nodeup-1.3.tar.gz"
glog.Infof("Using default nodeup location: %q", location)
location := os.Getenv("NODEUP_URL")
if location == "" {
location = "https://kubeupv2.s3.amazonaws.com/nodeup/nodeup-1.3.tar.gz"
glog.Infof("Using default nodeup location: %q", location)
} else {
glog.Warningf("Using nodeup location from NODEUP_URL env var: %q", location)
}
c.NodeUpSource = location
}
@ -350,6 +355,19 @@ func (c *ApplyClusterCmd) Run() error {
}
config.Images = images
{
protokubeImage := os.Getenv("PROTOKUBE_IMAGE")
if protokubeImage != "" {
glog.Warningf("Using protokube image specified in PROTOKUBE_IMAGE env var: %q", protokubeImage)
} else {
protokubeImage = nodeup.DefaultProtokubeImage
}
config.ProtokubeImage = &nodeup.Image{
Source: protokubeImage,
}
}
yaml, err := api.ToYaml(config)
if err != nil {
return "", err

View File

@ -21,6 +21,9 @@ type NodeUpConfig struct {
// Technically this is redundant - it is in ClusterLocation, but this can serve as a cross-check,
// and it allows us to more easily identify the cluster, for example when we are deleting resources.
ClusterName string `json:",omitempty"`
// ProtokubeImage is the docker image to load for protokube (bootstrapping)
ProtokubeImage *Image `json:"protokubeImage"`
}
// Image is a docker image we should pre-load

View File

@ -124,7 +124,18 @@ func (r *Loader) newTaskHandler(prefix string, builder TaskBuilder) loader.Handl
if err != nil {
return err
}
task, err := builder(i.Name, contents, i.Meta)
name := i.Name
if strings.HasSuffix(name, ".template") {
name = strings.TrimSuffix(name, ".template")
expanded, err := r.executeTemplate(name, contents)
if err != nil {
return fmt.Errorf("error executing template %q: %v", i.RelativePath, err)
}
contents = expanded
}
task, err := builder(name, contents, i.Meta)
if err != nil {
return fmt.Errorf("error building %s for %q: %v", i.Name, i.Path, err)
}

View File

@ -12,6 +12,8 @@ import (
const TagMaster = "_kubernetes_master"
const DefaultProtokubeImage = "kope/protokube:1.3"
// templateFunctions is a simple helper-class for the functions accessible to templates
type templateFunctions struct {
nodeupConfig *NodeUpConfig
@ -98,6 +100,8 @@ func (t *templateFunctions) populate(dest template.FuncMap) {
}
}
dest["ClusterName"] = func() string { return t.cluster.Name }
dest["ProtokubeImage"] = t.ProtokubeImage
}
// IsMaster returns true if we are tagged as a master
@ -174,3 +178,16 @@ func (t *templateFunctions) GetToken(key string) (string, error) {
}
return string(token.Data), nil
}
// ProtokubeImage returns the docker image for protokube
func (t *templateFunctions) ProtokubeImage() string {
image := ""
if t.nodeupConfig.ProtokubeImage != nil {
image = t.nodeupConfig.ProtokubeImage.Source
}
if image == "" {
// use current default corresponding to this version of nodeup
image = DefaultProtokubeImage
}
return image
}