mirror of
https://github.com/tailscale/tailscale.git
synced 2026-05-05 20:26:47 +02:00
This file was never truly necessary and has never actually been used in the history of Tailscale's open source releases. A Brief History of AUTHORS files --- The AUTHORS file was a pattern developed at Google, originally for Chromium, then adopted by Go and a bunch of other projects. The problem was that Chromium originally had a copyright line only recognizing Google as the copyright holder. Because Google (and most open source projects) do not require copyright assignemnt for contributions, each contributor maintains their copyright. Some large corporate contributors then tried to add their own name to the copyright line in the LICENSE file or in file headers. This quickly becomes unwieldy, and puts a tremendous burden on anyone building on top of Chromium, since the license requires that they keep all copyright lines intact. The compromise was to create an AUTHORS file that would list all of the copyright holders. The LICENSE file and source file headers would then include that list by reference, listing the copyright holder as "The Chromium Authors". This also become cumbersome to simply keep the file up to date with a high rate of new contributors. Plus it's not always obvious who the copyright holder is. Sometimes it is the individual making the contribution, but many times it may be their employer. There is no way for the proejct maintainer to know. Eventually, Google changed their policy to no longer recommend trying to keep the AUTHORS file up to date proactively, and instead to only add to it when requested: https://opensource.google/docs/releasing/authors. They are also clear that: > Adding contributors to the AUTHORS file is entirely within the > project's discretion and has no implications for copyright ownership. It was primarily added to appease a small number of large contributors that insisted that they be recognized as copyright holders (which was entirely their right to do). But it's not truly necessary, and not even the most accurate way of identifying contributors and/or copyright holders. In practice, we've never added anyone to our AUTHORS file. It only lists Tailscale, so it's not really serving any purpose. It also causes confusion because Tailscalars put the "Tailscale Inc & AUTHORS" header in other open source repos which don't actually have an AUTHORS file, so it's ambiguous what that means. Instead, we just acknowledge that the contributors to Tailscale (whoever they are) are copyright holders for their individual contributions. We also have the benefit of using the DCO (developercertificate.org) which provides some additional certification of their right to make the contribution. The source file changes were purely mechanical with: git ls-files | xargs sed -i -e 's/\(Tailscale Inc &\) AUTHORS/\1 contributors/g' Updates #cleanup Change-Id: Ia101a4a3005adb9118051b3416f5a64a4a45987d Signed-off-by: Will Norris <will@tailscale.com>
181 lines
5.8 KiB
Go
181 lines
5.8 KiB
Go
// Copyright (c) Tailscale Inc & contributors
|
|
// SPDX-License-Identifier: BSD-3-Clause
|
|
|
|
//go:build !plan9
|
|
|
|
package main
|
|
|
|
import (
|
|
"context"
|
|
"errors"
|
|
"fmt"
|
|
"strings"
|
|
|
|
"go.uber.org/zap"
|
|
appsv1 "k8s.io/api/apps/v1"
|
|
corev1 "k8s.io/api/core/v1"
|
|
discoveryv1 "k8s.io/api/discovery/v1"
|
|
apiequality "k8s.io/apimachinery/pkg/api/equality"
|
|
apierrors "k8s.io/apimachinery/pkg/api/errors"
|
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
|
"sigs.k8s.io/controller-runtime/pkg/client"
|
|
"sigs.k8s.io/controller-runtime/pkg/reconcile"
|
|
tsoperator "tailscale.com/k8s-operator"
|
|
tsapi "tailscale.com/k8s-operator/apis/v1alpha1"
|
|
"tailscale.com/tstime"
|
|
)
|
|
|
|
const (
|
|
reasonReadinessCheckFailed = "ReadinessCheckFailed"
|
|
reasonClusterResourcesNotReady = "ClusterResourcesNotReady"
|
|
reasonNoProxies = "NoProxiesConfigured"
|
|
reasonNotReady = "NotReadyToRouteTraffic"
|
|
reasonReady = "ReadyToRouteTraffic"
|
|
reasonPartiallyReady = "PartiallyReadyToRouteTraffic"
|
|
msgReadyToRouteTemplate = "%d out of %d replicas are ready to route traffic"
|
|
)
|
|
|
|
type egressSvcsReadinessReconciler struct {
|
|
client.Client
|
|
logger *zap.SugaredLogger
|
|
clock tstime.Clock
|
|
tsNamespace string
|
|
}
|
|
|
|
// Reconcile reconciles an ExternalName Service that defines a tailnet target to be exposed on a ProxyGroup and sets the
|
|
// EgressSvcReady condition on it. The condition gets set to true if at least one of the proxies is currently ready to
|
|
// route traffic to the target. It compares proxy Pod IPs with the endpoints set on the EndpointSlice for the egress
|
|
// service to determine how many replicas are currently able to route traffic.
|
|
func (esrr *egressSvcsReadinessReconciler) Reconcile(ctx context.Context, req reconcile.Request) (res reconcile.Result, err error) {
|
|
lg := esrr.logger.With("Service", req.NamespacedName)
|
|
lg.Debugf("starting reconcile")
|
|
defer lg.Debugf("reconcile finished")
|
|
|
|
svc := new(corev1.Service)
|
|
if err = esrr.Get(ctx, req.NamespacedName, svc); apierrors.IsNotFound(err) {
|
|
lg.Debugf("Service not found")
|
|
return res, nil
|
|
} else if err != nil {
|
|
return res, fmt.Errorf("failed to get Service: %w", err)
|
|
}
|
|
var (
|
|
reason, msg string
|
|
st metav1.ConditionStatus = metav1.ConditionUnknown
|
|
)
|
|
oldStatus := svc.Status.DeepCopy()
|
|
defer func() {
|
|
tsoperator.SetServiceCondition(svc, tsapi.EgressSvcReady, st, reason, msg, esrr.clock, lg)
|
|
if !apiequality.Semantic.DeepEqual(oldStatus, &svc.Status) {
|
|
err = errors.Join(err, esrr.Status().Update(ctx, svc))
|
|
}
|
|
}()
|
|
|
|
crl := egressSvcChildResourceLabels(svc)
|
|
eps, err := getSingleObject[discoveryv1.EndpointSlice](ctx, esrr.Client, esrr.tsNamespace, crl)
|
|
if err != nil {
|
|
err = fmt.Errorf("error getting EndpointSlice: %w", err)
|
|
reason = reasonReadinessCheckFailed
|
|
msg = err.Error()
|
|
return res, err
|
|
}
|
|
if eps == nil {
|
|
lg.Infof("EndpointSlice for Service does not yet exist, waiting...")
|
|
reason, msg = reasonClusterResourcesNotReady, reasonClusterResourcesNotReady
|
|
st = metav1.ConditionFalse
|
|
return res, nil
|
|
}
|
|
pg := &tsapi.ProxyGroup{
|
|
ObjectMeta: metav1.ObjectMeta{
|
|
Name: svc.Annotations[AnnotationProxyGroup],
|
|
},
|
|
}
|
|
err = esrr.Get(ctx, client.ObjectKeyFromObject(pg), pg)
|
|
if apierrors.IsNotFound(err) {
|
|
lg.Infof("ProxyGroup for Service does not exist, waiting...")
|
|
reason, msg = reasonClusterResourcesNotReady, reasonClusterResourcesNotReady
|
|
st = metav1.ConditionFalse
|
|
return res, nil
|
|
}
|
|
if err != nil {
|
|
err = fmt.Errorf("error retrieving ProxyGroup: %w", err)
|
|
reason = reasonReadinessCheckFailed
|
|
msg = err.Error()
|
|
return res, err
|
|
}
|
|
if !tsoperator.ProxyGroupAvailable(pg) {
|
|
lg.Infof("ProxyGroup for Service is not ready, waiting...")
|
|
reason, msg = reasonClusterResourcesNotReady, reasonClusterResourcesNotReady
|
|
st = metav1.ConditionFalse
|
|
return res, nil
|
|
}
|
|
|
|
replicas := pgReplicas(pg)
|
|
if replicas == 0 {
|
|
lg.Infof("ProxyGroup replicas set to 0")
|
|
reason, msg = reasonNoProxies, reasonNoProxies
|
|
st = metav1.ConditionFalse
|
|
return res, nil
|
|
}
|
|
podLabels := pgLabels(pg.Name, nil)
|
|
var readyReplicas int32
|
|
for i := range replicas {
|
|
podLabels[appsv1.PodIndexLabel] = fmt.Sprintf("%d", i)
|
|
pod, err := getSingleObject[corev1.Pod](ctx, esrr.Client, esrr.tsNamespace, podLabels)
|
|
if err != nil {
|
|
err = fmt.Errorf("error retrieving ProxyGroup Pod: %w", err)
|
|
reason = reasonReadinessCheckFailed
|
|
msg = err.Error()
|
|
return res, err
|
|
}
|
|
if pod == nil {
|
|
lg.Warnf("[unexpected] ProxyGroup is ready, but replica %d was not found", i)
|
|
reason, msg = reasonClusterResourcesNotReady, reasonClusterResourcesNotReady
|
|
return res, nil
|
|
}
|
|
lg.Debugf("looking at Pod with IPs %v", pod.Status.PodIPs)
|
|
ready := false
|
|
for _, ep := range eps.Endpoints {
|
|
lg.Debugf("looking at endpoint with addresses %v", ep.Addresses)
|
|
if endpointReadyForPod(&ep, pod, lg) {
|
|
lg.Debugf("endpoint is ready for Pod")
|
|
ready = true
|
|
break
|
|
}
|
|
}
|
|
if ready {
|
|
readyReplicas++
|
|
}
|
|
}
|
|
msg = fmt.Sprintf(msgReadyToRouteTemplate, readyReplicas, replicas)
|
|
if readyReplicas == 0 {
|
|
reason = reasonNotReady
|
|
st = metav1.ConditionFalse
|
|
return res, nil
|
|
}
|
|
st = metav1.ConditionTrue
|
|
if readyReplicas < replicas {
|
|
reason = reasonPartiallyReady
|
|
} else {
|
|
reason = reasonReady
|
|
}
|
|
return res, nil
|
|
}
|
|
|
|
// endpointReadyForPod returns true if the endpoint is for the Pod's IPv4 address and is ready to serve traffic.
|
|
// Endpoint must not be nil.
|
|
func endpointReadyForPod(ep *discoveryv1.Endpoint, pod *corev1.Pod, lg *zap.SugaredLogger) bool {
|
|
podIP, err := podIPv4(pod)
|
|
if err != nil {
|
|
lg.Warnf("[unexpected] error retrieving Pod's IPv4 address: %v", err)
|
|
return false
|
|
}
|
|
// Currently we only ever set a single address on and Endpoint and nothing else is meant to modify this.
|
|
if len(ep.Addresses) != 1 {
|
|
return false
|
|
}
|
|
return strings.EqualFold(ep.Addresses[0], podIP) &&
|
|
*ep.Conditions.Ready &&
|
|
*ep.Conditions.Serving &&
|
|
!*ep.Conditions.Terminating
|
|
}
|