mirror of
https://github.com/rancher/rke.git
synced 2025-06-28 08:18:58 +00:00
Merge pull request #444 from galal-hussein/addrress_annotations
Set node-ip and addresses annotations
This commit is contained in:
commit
c20bbb9205
@ -281,6 +281,9 @@ func (c *Cluster) SyncLabelsAndTaints(ctx context.Context) error {
|
|||||||
return fmt.Errorf("Failed to initialize new kubernetes client: %v", err)
|
return fmt.Errorf("Failed to initialize new kubernetes client: %v", err)
|
||||||
}
|
}
|
||||||
for _, host := range hosts.GetUniqueHostList(c.EtcdHosts, c.ControlPlaneHosts, c.WorkerHosts) {
|
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 {
|
if err := k8s.SyncLabels(k8sClient, host.HostnameOverride, host.ToAddLabels, host.ToDelLabels); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
@ -246,7 +246,9 @@ func (c *Cluster) BuildKubeletProcess(host *hosts.Host) v3.Process {
|
|||||||
"require-kubeconfig": "True",
|
"require-kubeconfig": "True",
|
||||||
"fail-swap-on": strconv.FormatBool(c.Services.Kubelet.FailSwapOn),
|
"fail-swap-on": strconv.FormatBool(c.Services.Kubelet.FailSwapOn),
|
||||||
}
|
}
|
||||||
|
if host.Address != host.InternalAddress {
|
||||||
|
CommandArgs["node-ip"] = host.InternalAddress
|
||||||
|
}
|
||||||
VolumesFrom := []string{
|
VolumesFrom := []string{
|
||||||
services.SidekickContainerName,
|
services.SidekickContainerName,
|
||||||
}
|
}
|
||||||
|
30
k8s/node.go
30
k8s/node.go
@ -6,6 +6,7 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"github.com/pkg/errors"
|
||||||
"github.com/sirupsen/logrus"
|
"github.com/sirupsen/logrus"
|
||||||
"k8s.io/api/core/v1"
|
"k8s.io/api/core/v1"
|
||||||
apierrors "k8s.io/apimachinery/pkg/api/errors"
|
apierrors "k8s.io/apimachinery/pkg/api/errors"
|
||||||
@ -16,6 +17,8 @@ import (
|
|||||||
|
|
||||||
const (
|
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 {
|
func DeleteNode(k8sClient *kubernetes.Clientset, nodeName string) error {
|
||||||
@ -244,3 +247,30 @@ func toTaint(taintStr string) v1.Taint {
|
|||||||
Effect: effect,
|
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
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user