Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
)

const (
exactlyOneBackendSourceMsg = "exactly one of backendSelector and edgeListenerRef is required"
exactlyOneBackendSourceMsg = "choose attachment backends or an edgeListenerRef"
emptySelectorMsg = "backendSelector must not be empty"
)

Expand All @@ -38,6 +38,11 @@ func TestNetworkServiceBackendSource(t *testing.T) {
s.Spec.BackendSelector = metav1.LabelSelector{}
s.Spec.EdgeListenerRef = listener
}, ""},
{"AddressesAndListener", func(s *networkv1alpha1.NetworkService) {
s.Spec.BackendSelector = metav1.LabelSelector{}
s.Spec.BackendAddresses = &[]string{"2001:db8::1"}
s.Spec.EdgeListenerRef = listener
}, exactlyOneBackendSourceMsg},
{"Both", func(s *networkv1alpha1.NetworkService) { s.Spec.EdgeListenerRef = listener }, exactlyOneBackendSourceMsg},
{"Neither", func(s *networkv1alpha1.NetworkService) {
s.Spec.BackendSelector = metav1.LabelSelector{}
Expand Down
27 changes: 27 additions & 0 deletions api/network/v1alpha1/networkservice_protocol_envtest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,33 @@ func protocolService(name string, protocol networkv1alpha1.NetworkServiceProtoco
}
}

func TestNetworkServiceBackendAddressAdmission(t *testing.T) {
c, _ := startProtocolAPI(t)
ctx := context.Background()
svc := protocolService("address-only", networkv1alpha1.NetworkServiceProtocolTCP, 443, 8443)
svc.Spec.BackendSelector = metav1.LabelSelector{}
addresses := []string{"fd00:10::1"}
svc.Spec.BackendAddresses = &addresses
if err := c.Create(ctx, svc); err != nil {
t.Fatalf("address-only service must be admitted: %v", err)
}
addresses = []string{}
if err := c.Update(ctx, svc); err != nil {
t.Fatalf("explicit empty address list must permit withdrawal: %v", err)
}
svc.Spec.BackendAddresses = nil
if err := c.Update(ctx, svc); err == nil {
t.Fatal("service with no selector or address list must be refused")
}
bad := protocolService("ipv4-backend-address", networkv1alpha1.NetworkServiceProtocolTCP, 443, 8443)
bad.Spec.BackendSelector = metav1.LabelSelector{}
v4 := []string{"192.0.2.1"}
bad.Spec.BackendAddresses = &v4
if err := c.Create(ctx, bad); err == nil {
t.Fatal("IPv4 backend address must be refused")
}
}

// requireRefusal fails unless err is a schema rejection containing every one
// of want and none of unwanted.
func requireRefusal(t *testing.T, err error, want, unwanted []string) {
Expand Down
32 changes: 20 additions & 12 deletions api/network/v1alpha1/networkservice_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,13 +114,11 @@ const (
// backend selection never needs a single "owning" node the way Full-NAT's
// SNAT-source model did.
//
// Backends are not listed. BackendSelector picks the VPCAttachments that
// serve the service, so the backend set follows attachments as they are
// created, deleted or moved to another node, and galactic-router on each
// node generates the ServiceVIPBinding its backends need from the same
// selection. A service in the gateway namespace can instead name an
// EdgeListener with EdgeListenerRef, whose listener attachments are then its
// backends.
// BackendSelector and optional BackendAddresses select VPCAttachments in the
// service's observed VPC. Address-only selection does not require a label.
// galactic-router generates ServiceVIPBindings from the same selection.
// A service in the gateway namespace can instead name an EdgeListener with
// EdgeListenerRef to use its listener attachments.
//
// +kubebuilder:object:root=true
// +kubebuilder:subresource:status
Expand Down Expand Up @@ -148,7 +146,8 @@ type NetworkService struct {
// +kubebuilder:validation:XValidation:rule="!(self.protocol in ['esp', 'gre', 'icmp']) || !has(self.port)",message="port must not be set for esp, gre and icmp, which have no ports"
// +kubebuilder:validation:XValidation:rule="!(self.protocol in ['esp', 'gre', 'icmp']) || !has(self.backendPort)",message="backendPort must not be set for esp, gre and icmp, which have no ports"
// +kubebuilder:validation:XValidation:rule="self.protocol != 'udp' || !has(self.healthCheck) || has(self.healthCheck.port)",message="healthCheck.port is required for udp: a health check probes a TCP port"
// +kubebuilder:validation:XValidation:rule="has(self.backendSelector) != has(self.edgeListenerRef)",message="exactly one of backendSelector and edgeListenerRef is required"
// +kubebuilder:validation:XValidation:rule="(has(self.backendSelector) || has(self.backendAddresses)) != has(self.edgeListenerRef)",message="choose attachment backends or an edgeListenerRef"
// +kubebuilder:validation:XValidation:rule="!has(self.backendSelector) || has(self.backendAddresses) || (has(self.backendSelector) && ((has(self.backendSelector.matchLabels) && size(self.backendSelector.matchLabels) > 0) || (has(self.backendSelector.matchExpressions) && size(self.backendSelector.matchExpressions) > 0)))",message="backendSelector must not be empty without backendAddresses"
type NetworkServiceSpec struct {
// VPCRef is the opaque identifier of the target VPC this service applies
// to, a VPC's status.vpc. In a gateway namespace, the platform API that
Expand Down Expand Up @@ -238,13 +237,22 @@ type NetworkServiceSpec struct {
// BackendPort, for both VIPs: its node translates the IPv4 VIP's flows to
// and from IPv6, and its IPv4 addresses are never backends. An attachment
// with no status.node, or no IPv6 address, is not a backend until it has
// both. An empty selector is rejected rather than read as "every
// attachment in the VPC". Exactly one of BackendSelector and
// EdgeListenerRef is required.
// both. An empty selector is accepted only with BackendAddresses and then
// matches all attachments in this service's observed VPC.
// +optional
// +kubebuilder:validation:XValidation:rule="(has(self.matchLabels) && size(self.matchLabels) > 0) || (has(self.matchExpressions) && size(self.matchExpressions) > 0)",message="backendSelector must not be empty"
BackendSelector metav1.LabelSelector `json:"backendSelector,omitzero"`

// BackendAddresses restricts selected attachments to these IPv6 backend
// addresses. When set without a selector, it matches attachments by address
// only, still requiring status.vpc to equal VPCRef. An explicit empty list
// withdraws all backends and their bindings without broadening selection.
// +optional
// +kubebuilder:validation:MaxItems=64
// +kubebuilder:validation:items:MaxLength=45
// +kubebuilder:validation:XValidation:rule="self.all(a, isIP(a) && ip(a).family() == 6)",message="backendAddresses must contain IPv6 addresses"
// +listType=set
BackendAddresses *[]string `json:"backendAddresses,omitempty"`

// EdgeListenerRef names the EdgeListener, in the service's namespace,
// whose listener attachments are the service's backends, in place of
// BackendSelector. Core sets it on the services it writes for a
Expand Down
24 changes: 24 additions & 0 deletions api/network/v1alpha1/networkservice_types_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,23 @@ func newTestService() *NetworkService {
// copy: mutations to slices in the copy must not affect the original.
func TestNetworkServiceDeepCopy(t *testing.T) {
orig := newTestService()
addresses := []string{"fd00:10::1"}
orig.Spec.BackendAddresses = &addresses
dup := orig.DeepCopy()

dup.Spec.VIPAddresses[0] = "2001:db8:1::20"
dup.Spec.BackendSelector.MatchLabels["app"] = "api"
(*dup.Spec.BackendAddresses)[0] = "fd00:10::2"

if orig.Spec.VIPAddresses[0] != "2001:db8:1::10" {
t.Errorf("VIPAddresses[0] mutated: got %q", orig.Spec.VIPAddresses[0])
}
if orig.Spec.BackendSelector.MatchLabels["app"] != "web" {
t.Errorf("BackendSelector.MatchLabels mutated: got %v", orig.Spec.BackendSelector.MatchLabels)
}
if (*orig.Spec.BackendAddresses)[0] != "fd00:10::1" {
t.Errorf("BackendAddresses mutated: got %v", *orig.Spec.BackendAddresses)
}
}

// TestNetworkServiceDeepCopyNil verifies DeepCopy on a nil pointer returns nil.
Expand Down Expand Up @@ -148,6 +154,24 @@ func TestNetworkServiceBackendFieldNames(t *testing.T) {
}
}

func TestNetworkServiceExplicitEmptyBackendAddresses(t *testing.T) {
svc := newTestService()
svc.Spec.BackendSelector = metav1.LabelSelector{}
addresses := []string{}
svc.Spec.BackendAddresses = &addresses
data, err := json.Marshal(svc.Spec)
if err != nil {
t.Fatal(err)
}
if !strings.Contains(string(data), `"backendAddresses":[]`) {
t.Fatalf("explicit empty list lost during encoding: %s", data)
}
var got NetworkServiceSpec
if err := json.Unmarshal(data, &got); err != nil || got.BackendAddresses == nil || len(*got.BackendAddresses) != 0 {
t.Fatalf("explicit empty list lost during decoding: %+v, %v", got.BackendAddresses, err)
}
}

// TestNetworkServiceProtocolValues pins the NetworkServiceProtocol values,
// which are part of the published API.
func TestNetworkServiceProtocolValues(t *testing.T) {
Expand Down
9 changes: 9 additions & 0 deletions api/network/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

45 changes: 29 additions & 16 deletions config/crd/galactic.datumapis.com_networkservices.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -64,13 +64,11 @@ spec:
backend selection never needs a single "owning" node the way Full-NAT's
SNAT-source model did.

Backends are not listed. BackendSelector picks the VPCAttachments that
serve the service, so the backend set follows attachments as they are
created, deleted or moved to another node, and galactic-router on each
node generates the ServiceVIPBinding its backends need from the same
selection. A service in the gateway namespace can instead name an
EdgeListener with EdgeListenerRef, whose listener attachments are then its
backends.
BackendSelector and optional BackendAddresses select VPCAttachments in the
service's observed VPC. Address-only selection does not require a label.
galactic-router generates ServiceVIPBindings from the same selection.
A service in the gateway namespace can instead name an EdgeListener with
EdgeListenerRef to use its listener attachments.
properties:
apiVersion:
description: |-
Expand Down Expand Up @@ -184,6 +182,21 @@ spec:
- message: listenerName must identify a declared listener
rule: '!has(self.listenerName) || (has(self.listeners) && self.listeners.exists(l,
l.name == self.listenerName))'
backendAddresses:
description: |-
BackendAddresses restricts selected attachments to these IPv6 backend
addresses. When set without a selector, it matches attachments by address
only, still requiring status.vpc to equal VPCRef. An explicit empty list
withdraws all backends and their bindings without broadening selection.
items:
maxLength: 45
type: string
maxItems: 64
type: array
x-kubernetes-list-type: set
x-kubernetes-validations:
- message: backendAddresses must contain IPv6 addresses
rule: self.all(a, isIP(a) && ip(a).family() == 6)
backendPort:
description: |-
BackendPort is the destination port on every selected backend, 1-65535.
Expand All @@ -206,9 +219,8 @@ spec:
BackendPort, for both VIPs: its node translates the IPv4 VIP's flows to
and from IPv6, and its IPv4 addresses are never backends. An attachment
with no status.node, or no IPv6 address, is not a backend until it has
both. An empty selector is rejected rather than read as "every
attachment in the VPC". Exactly one of BackendSelector and
EdgeListenerRef is required.
both. An empty selector is accepted only with BackendAddresses and then
matches all attachments in this service's observed VPC.
properties:
matchExpressions:
description: matchExpressions is a list of label selector requirements.
Expand Down Expand Up @@ -253,10 +265,6 @@ spec:
type: object
type: object
x-kubernetes-map-type: atomic
x-kubernetes-validations:
- message: backendSelector must not be empty
rule: (has(self.matchLabels) && size(self.matchLabels) > 0) || (has(self.matchExpressions)
&& size(self.matchExpressions) > 0)
edgeListenerRef:
description: |-
EdgeListenerRef names the EdgeListener, in the service's namespace,
Expand Down Expand Up @@ -508,8 +516,13 @@ spec:
- message: 'healthCheck.port is required for udp: a health check probes
a TCP port'
rule: self.protocol != 'udp' || !has(self.healthCheck) || has(self.healthCheck.port)
- message: exactly one of backendSelector and edgeListenerRef is required
rule: has(self.backendSelector) != has(self.edgeListenerRef)
- message: choose attachment backends or an edgeListenerRef
rule: (has(self.backendSelector) || has(self.backendAddresses)) != has(self.edgeListenerRef)
- message: backendSelector must not be empty without backendAddresses
rule: '!has(self.backendSelector) || has(self.backendAddresses) || (has(self.backendSelector)
&& ((has(self.backendSelector.matchLabels) && size(self.backendSelector.matchLabels)
> 0) || (has(self.backendSelector.matchExpressions) && size(self.backendSelector.matchExpressions)
> 0)))'
status:
description: NetworkServiceStatus defines the observed state of a NetworkService.
properties:
Expand Down
15 changes: 7 additions & 8 deletions docs/api/network-gateway.md
Original file line number Diff line number Diff line change
Expand Up @@ -426,13 +426,11 @@ flow (internal/maglev), and forwards without rewriting anything —
backend selection never needs a single "owning" node the way Full-NAT's
SNAT-source model did.

Backends are not listed. BackendSelector picks the VPCAttachments that
serve the service, so the backend set follows attachments as they are
created, deleted or moved to another node, and galactic-router on each
node generates the ServiceVIPBinding its backends need from the same
selection. A service in the gateway namespace can instead name an
EdgeListener with EdgeListenerRef, whose listener attachments are then its
backends.
BackendSelector and optional BackendAddresses select VPCAttachments in the
service's observed VPC. Address-only selection does not require a label.
galactic-router generates ServiceVIPBindings from the same selection.
A service in the gateway namespace can instead name an EdgeListener with
EdgeListenerRef to use its listener attachments.



Expand Down Expand Up @@ -663,7 +661,8 @@ _Appears in:_
| `port` _integer_ | Port is the ingress port on VIPAddresses that this service load-balances,<br />1-65535. It is required when PortRange is absent for tcp, udp and sctp<br />and must be unset for one without (esp, gre and icmp). Zero means unset<br />and is omitted when encoding, and an explicit 0 is refused. | | Maximum: 65535 <br />Minimum: 1 <br /> |
| `portRange` _[PortRange](#portrange)_ | PortRange replaces Port for an inclusive IPv6 UDP interval. Backend ports<br />are preserved; BackendPort must be omitted. | | |
| `addressGroup` _[NetworkServiceAddressGroup](#networkserviceaddressgroup)_ | AddressGroup binds this listener to a complete, authoritative address inventory. | | |
| `backendSelector` _[LabelSelector](https://kubernetes.io/docs/reference/generated/kubernetes-api/v/#labelselector-v1-meta)_ | BackendSelector selects the VPCAttachments (galactic.datumapis.com/v1alpha1)<br />that serve this service, matched against each VPCAttachment object's own<br />labels: in any namespace for a service in a gateway namespace, and only<br />in its own namespace for a service in a project namespace. Only<br />attachments whose status.vpc equals VPCRef are candidates, whatever their<br />labels, so a selector cannot reach into another tenant's VPC. Each selected attachment contributes the<br />IPv6 addresses in its spec.interface.addresses as backends, on<br />BackendPort, for both VIPs: its node translates the IPv4 VIP's flows to<br />and from IPv6, and its IPv4 addresses are never backends. An attachment<br />with no status.node, or no IPv6 address, is not a backend until it has<br />both. An empty selector is rejected rather than read as "every<br />attachment in the VPC". Exactly one of BackendSelector and<br />EdgeListenerRef is required. | | |
| `backendSelector` _[LabelSelector](https://kubernetes.io/docs/reference/generated/kubernetes-api/v/#labelselector-v1-meta)_ | BackendSelector selects the VPCAttachments (galactic.datumapis.com/v1alpha1)<br />that serve this service, matched against each VPCAttachment object's own<br />labels: in any namespace for a service in a gateway namespace, and only<br />in its own namespace for a service in a project namespace. Only<br />attachments whose status.vpc equals VPCRef are candidates, whatever their<br />labels, so a selector cannot reach into another tenant's VPC. Each selected attachment contributes the<br />IPv6 addresses in its spec.interface.addresses as backends, on<br />BackendPort, for both VIPs: its node translates the IPv4 VIP's flows to<br />and from IPv6, and its IPv4 addresses are never backends. An attachment<br />with no status.node, or no IPv6 address, is not a backend until it has<br />both. An empty selector is accepted only with BackendAddresses and then<br />matches all attachments in this service's observed VPC. | | |
| `backendAddresses` _string_ | BackendAddresses restricts selected attachments to these IPv6 backend<br />addresses. When set without a selector, it matches attachments by address<br />only, still requiring status.vpc to equal VPCRef. An explicit empty list<br />withdraws all backends and their bindings without broadening selection. | | MaxItems: 64 <br />items:MaxLength: 45 <br /> |
| `edgeListenerRef` _[NetworkServiceEdgeListenerReference](#networkserviceedgelistenerreference)_ | EdgeListenerRef names the EdgeListener, in the service's namespace,<br />whose listener attachments are the service's backends, in place of<br />BackendSelector. Core sets it on the services it writes for a<br />listener, one per listener port. It is allowed only in the gateway<br />namespace. Its backends are the listener's status.backends that core<br />reports serving; gateways and backend nodes never select them from<br />VPCAttachments. | | |
| `backendPort` _integer_ | BackendPort is the destination port on every selected backend, 1-65535.<br />Like Port, it is required for tcp, udp and sctp and must be unset for<br />esp, gre and icmp. Zero means unset and is omitted when encoding, and an<br />explicit 0 is refused. | | Maximum: 65535 <br />Minimum: 1 <br /> |
| `sessionAffinity` _[NetworkServiceSessionAffinity](#networkservicesessionaffinity)_ | SessionAffinity selects which connections from one client share a<br />backend: None, the default, balances each connection on its own;<br />ClientIP pins a client address to one backend; ClientIPAndProtocol pins<br />a client address and protocol to one. Two services pin a client to the<br />same backend only if both set the same affinity and select the same<br />backend addresses. A change takes effect on every gateway node without a<br />restart, and rehashes every connection of the service, so most open<br />connections reach a different backend afterwards. | None | Enum: [None ClientIP ClientIPAndProtocol] <br /> |
Expand Down
Loading
Loading