1
0
mirror of https://github.com/rancher/rke.git synced 2025-06-28 16:28:26 +00:00

Merge pull request #444 from galal-hussein/addrress_annotations

Set node-ip and addresses annotations
This commit is contained in:
Alena Prokharchyk 2018-03-27 09:43:49 -07:00 committed by GitHub
commit c20bbb9205
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 37 additions and 2 deletions

View File

@ -281,6 +281,9 @@ func (c *Cluster) SyncLabelsAndTaints(ctx context.Context) error {
return fmt.Errorf("Failed to initialize new kubernetes client: %v", err)
}
for _, host := range hosts.GetUniqueHostList(c.EtcdHosts, c.ControlPlaneHosts, c.WorkerHosts) {
if err := k8s.SetAddressesAnnotations(k8sClient, host.HostnameOverride, host.InternalAddress, host.Address); err != nil {
return err
}
if err := k8s.SyncLabels(k8sClient, host.HostnameOverride, host.ToAddLabels, host.ToDelLabels); err != nil {
return err
}

View File

@ -246,7 +246,9 @@ func (c *Cluster) BuildKubeletProcess(host *hosts.Host) v3.Process {
"require-kubeconfig": "True",
"fail-swap-on": strconv.FormatBool(c.Services.Kubelet.FailSwapOn),
}
if host.Address != host.InternalAddress {
CommandArgs["node-ip"] = host.InternalAddress
}
VolumesFrom := []string{
services.SidekickContainerName,
}

View File

@ -6,6 +6,7 @@ import (
"strings"
"time"
"github.com/pkg/errors"
"github.com/sirupsen/logrus"
"k8s.io/api/core/v1"
apierrors "k8s.io/apimachinery/pkg/api/errors"
@ -15,7 +16,9 @@ import (
)
const (
HostnameLabel = "kubernetes.io/hostname"
HostnameLabel = "kubernetes.io/hostname"
InternalAddressAnnotation = "rke.io/internal-ip"
ExternalAddressAnnotation = "rke.io/external-ip"
)
func DeleteNode(k8sClient *kubernetes.Clientset, nodeName string) error {
@ -244,3 +247,30 @@ func toTaint(taintStr string) v1.Taint {
Effect: effect,
}
}
func SetAddressesAnnotations(k8sClient *kubernetes.Clientset, nodeName, internalAddress, externalAddress string) error {
var listErr error
for retries := 0; retries <= 5; retries++ {
node, err := GetNode(k8sClient, nodeName)
if err != nil {
listErr = errors.Wrapf(err, "Failed to get kubernetes node [%s]", nodeName)
time.Sleep(time.Second * 5)
continue
}
currentExternalAnnotation := node.Annotations[ExternalAddressAnnotation]
currentInternalAnnotation := node.Annotations[ExternalAddressAnnotation]
if currentExternalAnnotation == externalAddress && currentInternalAnnotation == internalAddress {
return nil
}
node.Annotations[ExternalAddressAnnotation] = externalAddress
node.Annotations[InternalAddressAnnotation] = internalAddress
_, err = k8sClient.CoreV1().Nodes().Update(node)
if err != nil {
listErr = errors.Wrapf(err, "Error updating node [%s] with address annotations: %v", nodeName, err)
time.Sleep(time.Second * 5)
continue
}
return nil
}
return listErr
}