mirror of
https://github.com/tailscale/tailscale.git
synced 2025-06-10 01:38:35 +00:00
cmd/k8s-operator: fix Tailscale Service API errors check (#16020)
Updates tailscale/tailscale#15895 Signed-off-by: Irbe Krumina <irbe@tailscale.com>
This commit is contained in:
parent
3cc80cce6a
commit
c4fb380f3c
@ -1105,13 +1105,11 @@ func isErrorFeatureFlagNotEnabled(err error) bool {
|
|||||||
// Tailscale control plane when a Tailscale Service API call is made for a
|
// Tailscale control plane when a Tailscale Service API call is made for a
|
||||||
// tailnet that does not have the Tailscale Services feature flag enabled.
|
// tailnet that does not have the Tailscale Services feature flag enabled.
|
||||||
const messageFFNotEnabled = "feature unavailable for tailnet"
|
const messageFFNotEnabled = "feature unavailable for tailnet"
|
||||||
var errResp *tailscale.ErrResponse
|
return err != nil && strings.Contains(err.Error(), messageFFNotEnabled)
|
||||||
ok := errors.As(err, &errResp)
|
|
||||||
return ok && strings.Contains(errResp.Message, messageFFNotEnabled)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func isErrorTailscaleServiceNotFound(err error) bool {
|
func isErrorTailscaleServiceNotFound(err error) bool {
|
||||||
var errResp *tailscale.ErrResponse
|
var errResp tailscale.ErrResponse
|
||||||
ok := errors.As(err, &errResp)
|
ok := errors.As(err, &errResp)
|
||||||
return ok && errResp.Status == http.StatusNotFound
|
return ok && errResp.Status == http.StatusNotFound
|
||||||
}
|
}
|
||||||
|
@ -8,10 +8,8 @@ package main
|
|||||||
import (
|
import (
|
||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
|
||||||
"fmt"
|
"fmt"
|
||||||
"math/rand/v2"
|
"math/rand/v2"
|
||||||
"net/http"
|
|
||||||
"net/netip"
|
"net/netip"
|
||||||
"testing"
|
"testing"
|
||||||
|
|
||||||
@ -23,7 +21,6 @@ import (
|
|||||||
"k8s.io/client-go/tools/record"
|
"k8s.io/client-go/tools/record"
|
||||||
"sigs.k8s.io/controller-runtime/pkg/client"
|
"sigs.k8s.io/controller-runtime/pkg/client"
|
||||||
"sigs.k8s.io/controller-runtime/pkg/client/fake"
|
"sigs.k8s.io/controller-runtime/pkg/client/fake"
|
||||||
"tailscale.com/internal/client/tailscale"
|
|
||||||
"tailscale.com/ipn/ipnstate"
|
"tailscale.com/ipn/ipnstate"
|
||||||
tsoperator "tailscale.com/k8s-operator"
|
tsoperator "tailscale.com/k8s-operator"
|
||||||
tsapi "tailscale.com/k8s-operator/apis/v1alpha1"
|
tsapi "tailscale.com/k8s-operator/apis/v1alpha1"
|
||||||
@ -108,8 +105,7 @@ func TestServicePGReconciler_UpdateHostname(t *testing.T) {
|
|||||||
if err == nil {
|
if err == nil {
|
||||||
t.Fatalf("svc:default-%s not cleaned up", svc.Name)
|
t.Fatalf("svc:default-%s not cleaned up", svc.Name)
|
||||||
}
|
}
|
||||||
var errResp *tailscale.ErrResponse
|
if !isErrorTailscaleServiceNotFound(err) {
|
||||||
if !errors.As(err, &errResp) || errResp.Status != http.StatusNotFound {
|
|
||||||
t.Fatalf("unexpected error: %v", err)
|
t.Fatalf("unexpected error: %v", err)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -901,11 +901,11 @@ func (c *fakeTSClient) GetVIPService(ctx context.Context, name tailcfg.ServiceNa
|
|||||||
c.Lock()
|
c.Lock()
|
||||||
defer c.Unlock()
|
defer c.Unlock()
|
||||||
if c.vipServices == nil {
|
if c.vipServices == nil {
|
||||||
return nil, &tailscale.ErrResponse{Status: http.StatusNotFound}
|
return nil, tailscale.ErrResponse{Status: http.StatusNotFound}
|
||||||
}
|
}
|
||||||
svc, ok := c.vipServices[name]
|
svc, ok := c.vipServices[name]
|
||||||
if !ok {
|
if !ok {
|
||||||
return nil, &tailscale.ErrResponse{Status: http.StatusNotFound}
|
return nil, tailscale.ErrResponse{Status: http.StatusNotFound}
|
||||||
}
|
}
|
||||||
return svc, nil
|
return svc, nil
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user