mirror of
https://github.com/tailscale/tailscale.git
synced 2024-11-29 13:05:46 +00:00
cmd/k8s-operator: rename egress annotation
It was tailscale.com/ts-tailnet-target-ip, which was pretty redundant. Change it to tailscale.com/tailnet-ip. Updates #502 Signed-off-by: Maisem Ali <maisem@tailscale.com>
This commit is contained in:
parent
ea9dd8fabc
commit
5f4d76c18c
@ -39,10 +39,11 @@
|
|||||||
FinalizerName = "tailscale.com/finalizer"
|
FinalizerName = "tailscale.com/finalizer"
|
||||||
|
|
||||||
// Annotations settable by users on services.
|
// Annotations settable by users on services.
|
||||||
AnnotationExpose = "tailscale.com/expose"
|
AnnotationExpose = "tailscale.com/expose"
|
||||||
AnnotationTags = "tailscale.com/tags"
|
AnnotationTags = "tailscale.com/tags"
|
||||||
AnnotationHostname = "tailscale.com/hostname"
|
AnnotationHostname = "tailscale.com/hostname"
|
||||||
AnnotationTailnetTargetIP = "tailscale.com/ts-tailnet-target-ip"
|
annotationTailnetTargetIPOld = "tailscale.com/ts-tailnet-target-ip"
|
||||||
|
AnnotationTailnetTargetIP = "tailscale.com/tailnet-ip"
|
||||||
|
|
||||||
// Annotations settable by users on ingresses.
|
// Annotations settable by users on ingresses.
|
||||||
AnnotationFunnel = "tailscale.com/funnel"
|
AnnotationFunnel = "tailscale.com/funnel"
|
||||||
|
@ -77,7 +77,8 @@ func (a *ServiceReconciler) Reconcile(ctx context.Context, req reconcile.Request
|
|||||||
} else if err != nil {
|
} else if err != nil {
|
||||||
return reconcile.Result{}, fmt.Errorf("failed to get svc: %w", err)
|
return reconcile.Result{}, fmt.Errorf("failed to get svc: %w", err)
|
||||||
}
|
}
|
||||||
if !svc.DeletionTimestamp.IsZero() || !a.shouldExpose(svc) && !a.hasTailnetTargetAnnotation(svc) {
|
targetIP := a.tailnetTargetAnnotation(svc)
|
||||||
|
if !svc.DeletionTimestamp.IsZero() || !a.shouldExpose(svc) && targetIP == "" {
|
||||||
logger.Debugf("service is being deleted or is (no longer) referring to Tailscale ingress/egress, ensuring any created resources are cleaned up")
|
logger.Debugf("service is being deleted or is (no longer) referring to Tailscale ingress/egress, ensuring any created resources are cleaned up")
|
||||||
return reconcile.Result{}, a.maybeCleanup(ctx, logger, svc)
|
return reconcile.Result{}, a.maybeCleanup(ctx, logger, svc)
|
||||||
}
|
}
|
||||||
@ -170,8 +171,8 @@ func (a *ServiceReconciler) maybeProvision(ctx context.Context, logger *zap.Suga
|
|||||||
sts.ClusterTargetIP = svc.Spec.ClusterIP
|
sts.ClusterTargetIP = svc.Spec.ClusterIP
|
||||||
a.managedIngressProxies.Add(svc.UID)
|
a.managedIngressProxies.Add(svc.UID)
|
||||||
gaugeIngressProxies.Set(int64(a.managedIngressProxies.Len()))
|
gaugeIngressProxies.Set(int64(a.managedIngressProxies.Len()))
|
||||||
} else if a.hasTailnetTargetAnnotation(svc) {
|
} else if ip := a.tailnetTargetAnnotation(svc); ip != "" {
|
||||||
sts.TailnetTargetIP = svc.Annotations[AnnotationTailnetTargetIP]
|
sts.TailnetTargetIP = ip
|
||||||
a.managedEgressProxies.Add(svc.UID)
|
a.managedEgressProxies.Add(svc.UID)
|
||||||
gaugeEgressProxies.Set(int64(a.managedEgressProxies.Len()))
|
gaugeEgressProxies.Set(int64(a.managedEgressProxies.Len()))
|
||||||
}
|
}
|
||||||
@ -182,7 +183,7 @@ func (a *ServiceReconciler) maybeProvision(ctx context.Context, logger *zap.Suga
|
|||||||
return fmt.Errorf("failed to provision: %w", err)
|
return fmt.Errorf("failed to provision: %w", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if a.hasTailnetTargetAnnotation(svc) {
|
if sts.TailnetTargetIP != "" {
|
||||||
headlessSvcName := hsvc.Name + "." + hsvc.Namespace + ".svc"
|
headlessSvcName := hsvc.Name + "." + hsvc.Namespace + ".svc"
|
||||||
if svc.Spec.ExternalName != headlessSvcName || svc.Spec.Type != corev1.ServiceTypeExternalName {
|
if svc.Spec.ExternalName != headlessSvcName || svc.Spec.Type != corev1.ServiceTypeExternalName {
|
||||||
svc.Spec.ExternalName = headlessSvcName
|
svc.Spec.ExternalName = headlessSvcName
|
||||||
@ -261,8 +262,16 @@ func (a *ServiceReconciler) hasExposeAnnotation(svc *corev1.Service) bool {
|
|||||||
return svc != nil && svc.Annotations[AnnotationExpose] == "true"
|
return svc != nil && svc.Annotations[AnnotationExpose] == "true"
|
||||||
}
|
}
|
||||||
|
|
||||||
// hasTailnetTargetAnnotation reports whether Service has a
|
// hasTailnetTargetAnnotation returns the value of tailscale.com/tailnet-ip
|
||||||
// tailscale.com/ts-tailnet-target-ip annotation set
|
// annotation or of the deprecated tailscale.com/ts-tailnet-target-ip
|
||||||
func (a *ServiceReconciler) hasTailnetTargetAnnotation(svc *corev1.Service) bool {
|
// annotation. If neither is set, it returns an empty string. If both are set,
|
||||||
return svc != nil && svc.Annotations[AnnotationTailnetTargetIP] != ""
|
// it returns the value of the new annotation.
|
||||||
|
func (a *ServiceReconciler) tailnetTargetAnnotation(svc *corev1.Service) string {
|
||||||
|
if svc == nil {
|
||||||
|
return ""
|
||||||
|
}
|
||||||
|
if ip := svc.Annotations[AnnotationTailnetTargetIP]; ip != "" {
|
||||||
|
return ip
|
||||||
|
}
|
||||||
|
return svc.Annotations[annotationTailnetTargetIPOld]
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user