mirror of https://github.com/kubernetes/kops.git
Merge pull request #31 from justinsb/aws_set_hostname_override
AWS: set hostname-override from metadata service
This commit is contained in:
commit
d37e896fd9
|
|
@ -1,3 +1,5 @@
|
|||
Kubelet:
|
||||
CloudProvider: aws
|
||||
CgroupRoot: docker
|
||||
# Use the hostname from the AWS metadata service
|
||||
HostnameOverride: "@aws"
|
||||
|
|
|
|||
|
|
@ -48,9 +48,11 @@ type KubeletConfig struct {
|
|||
//// default /var/run/kubernetes). If tlsCertFile and tlsPrivateKeyFile
|
||||
//// are provided, this flag will be ignored.
|
||||
//CertDirectory string `json:"certDirectory"`
|
||||
//// hostnameOverride is the hostname used to identify the kubelet instead
|
||||
//// of the actual hostname.
|
||||
//HostnameOverride string `json:"hostnameOverride"`
|
||||
// hostnameOverride is the hostname used to identify the kubelet instead
|
||||
// of the actual hostname.
|
||||
// Note: We recognize some additional values:
|
||||
// @aws uses the hostname from the AWS metadata service
|
||||
HostnameOverride string `json:"hostnameOverride" flag:"hostname-override"`
|
||||
//// podInfraContainerImage is the image whose network/ipc namespaces
|
||||
//// containers in each pod will use.
|
||||
//PodInfraContainerImage string `json:"podInfraContainerImage"`
|
||||
|
|
|
|||
|
|
@ -10,6 +10,7 @@ import (
|
|||
"k8s.io/kops/upup/pkg/fi/nodeup/local"
|
||||
"k8s.io/kops/upup/pkg/fi/utils"
|
||||
"k8s.io/kops/upup/pkg/fi/vfs"
|
||||
"strings"
|
||||
)
|
||||
|
||||
type NodeUpCommand struct {
|
||||
|
|
@ -83,6 +84,11 @@ func (c *NodeUpCommand) Run(out io.Writer) error {
|
|||
return fmt.Errorf("ClusterLocation is required")
|
||||
}
|
||||
|
||||
err := evaluateSpec(c.cluster)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
//if c.Config.ConfigurationStore != "" {
|
||||
// // TODO: If we ever delete local files, we need to filter so we only copy
|
||||
// // certain directories (i.e. not secrets / keys), because dest is a parent dir!
|
||||
|
|
@ -165,3 +171,41 @@ func (c *NodeUpCommand) Run(out io.Writer) error {
|
|||
|
||||
return nil
|
||||
}
|
||||
|
||||
func evaluateSpec(c *api.Cluster) error {
|
||||
var err error
|
||||
|
||||
c.Spec.Kubelet.HostnameOverride, err = evaluateHostnameOverride(c.Spec.Kubelet.HostnameOverride)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
c.Spec.MasterKubelet.HostnameOverride, err = evaluateHostnameOverride(c.Spec.MasterKubelet.HostnameOverride)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func evaluateHostnameOverride(hostnameOverride string) (string, error) {
|
||||
k := strings.TrimSpace(hostnameOverride)
|
||||
k = strings.ToLower(k)
|
||||
|
||||
if hostnameOverride != "@aws" {
|
||||
return hostnameOverride, nil
|
||||
}
|
||||
|
||||
// We recognize @aws as meaning "the local-hostname from the aws metadata service"
|
||||
vBytes, err := vfs.Context.ReadFile("metadata://aws/meta-data/local-hostname")
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("error reading local hostname from AWS metadata: %v", err)
|
||||
}
|
||||
v := strings.TrimSpace(string(vBytes))
|
||||
if v == "" {
|
||||
glog.Warningf("Local hostname from AWS metadata service was empty")
|
||||
} else {
|
||||
glog.Infof("Using hostname from AWS metadata service: %s", v)
|
||||
}
|
||||
return v, nil
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue