Skip to content

Commit

Permalink
Include partial IG Spec in nodeup bootstrap script.
Browse files Browse the repository at this point in the history
  • Loading branch information
KashifSaadat committed Aug 9, 2017
1 parent 56d0748 commit 6d9b1fd
Show file tree
Hide file tree
Showing 7 changed files with 55 additions and 8 deletions.
1 change: 0 additions & 1 deletion pkg/apis/kops/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,6 @@ type ClusterSpec struct {
UpdatePolicy *string `json:"updatePolicy,omitempty"`
// Additional policies to add for roles
AdditionalPolicies *map[string]string `json:"additionalPolicies,omitempty"`

// EtcdClusters stores the configuration for each cluster
EtcdClusters []*EtcdClusterSpec `json:"etcdClusters,omitempty"`
// Component configurations
Expand Down
26 changes: 21 additions & 5 deletions pkg/model/bootstrapscript.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,22 @@ func (b *BootstrapScript) ResourceNodeUp(ig *kops.InstanceGroup, cs *kops.Cluste
}
return string(content), nil
},

"IGSpec": func() (string, error) {
spec := make(map[string]interface{})
spec["nodeLabels"] = ig.Spec.NodeLabels
spec["taints"] = ig.Spec.Taints

j, err := json.Marshal(spec)
if err != nil {
return "", err
}
content, err := yaml.JSONToYAML(j)
if err != nil {
return "", err
}
return string(content), nil
},
}

templateResource, err := NewTemplateResource("nodeup", resources.AWSNodeUpTemplate, functions, nil)
Expand All @@ -129,22 +145,22 @@ func (b *BootstrapScript) createProxyEnv(ps *kops.EgressProxySpec) string {
var buffer bytes.Buffer

if ps != nil && ps.HTTPProxy.Host != "" {
var httpProxyUrl string
var httpProxyURL string

// TODO double check that all the code does this
// TODO move this into a validate so we can enforce the string syntax
if !strings.HasPrefix(ps.HTTPProxy.Host, "http://") {
httpProxyUrl = "http://"
httpProxyURL = "http://"
}

if ps.HTTPProxy.Port != 0 {
httpProxyUrl += ps.HTTPProxy.Host + ":" + strconv.Itoa(ps.HTTPProxy.Port)
httpProxyURL += ps.HTTPProxy.Host + ":" + strconv.Itoa(ps.HTTPProxy.Port)
} else {
httpProxyUrl += ps.HTTPProxy.Host
httpProxyURL += ps.HTTPProxy.Host
}

// Set base env variables
buffer.WriteString("export http_proxy=" + httpProxyUrl + "\n")
buffer.WriteString("export http_proxy=" + httpProxyURL + "\n")
buffer.WriteString("export https_proxy=${http_proxy}\n")
buffer.WriteString("export no_proxy=" + ps.ProxyExcludes + "\n")
buffer.WriteString("export NO_PROXY=${no_proxy}\n")
Expand Down
8 changes: 8 additions & 0 deletions pkg/model/bootstrapscript_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,14 @@ func makeTestInstanceGroup(role kops.InstanceGroupRole) *kops.InstanceGroup {
return &kops.InstanceGroup{
Spec: kops.InstanceGroupSpec{
Role: role,
NodeLabels: map[string]string{
"labelname": "labelvalue",
"label2": "value2",
},
Taints: []string{
"key1=value1:NoSchedule",
"key2=value2:NoExecute",
},
},
}
}
4 changes: 4 additions & 0 deletions pkg/model/resources/nodeup.go
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,10 @@ cat > cluster_spec.yaml << __EOF_CLUSTER_SPEC
{{ ClusterSpec }}
__EOF_CLUSTER_SPEC
cat > ig_spec.yaml << __EOF_IG_SPEC
{{ IGSpec }}
__EOF_IG_SPEC
cat > kube_env.yaml << __EOF_KUBE_ENV
{{ KubeEnv }}
__EOF_KUBE_ENV
Expand Down
10 changes: 10 additions & 0 deletions pkg/model/tests/data/bootstrapscript_0.txt
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,16 @@ masterKubelet:
__EOF_CLUSTER_SPEC

cat > ig_spec.yaml << __EOF_IG_SPEC
nodeLabels:
label2: value2
labelname: labelvalue
taints:
- key1=value1:NoSchedule
- key2=value2:NoExecute
__EOF_IG_SPEC

cat > kube_env.yaml << __EOF_KUBE_ENV
{}
Expand Down
10 changes: 10 additions & 0 deletions pkg/model/tests/data/bootstrapscript_1.txt
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,16 @@ kubelet:
__EOF_CLUSTER_SPEC

cat > ig_spec.yaml << __EOF_IG_SPEC
nodeLabels:
label2: value2
labelname: labelvalue
taints:
- key1=value1:NoSchedule
- key2=value2:NoExecute
__EOF_IG_SPEC

cat > kube_env.yaml << __EOF_KUBE_ENV
{}
Expand Down
4 changes: 2 additions & 2 deletions tests/integration/minimal/cloudformation.json

Large diffs are not rendered by default.

0 comments on commit 6d9b1fd

Please sign in to comment.