Skip to content

Commit

Permalink
Refactors gateway api type to use label selectors
Browse files Browse the repository at this point in the history
  • Loading branch information
danehans committed Feb 7, 2020
1 parent 12ca3b8 commit 940f2f6
Show file tree
Hide file tree
Showing 3 changed files with 231 additions and 35 deletions.
48 changes: 44 additions & 4 deletions api/v1alpha1/gateway_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,9 +56,15 @@ type GatewaySpec struct {
// Listeners associated with this Gateway. Listeners define what addresses,
// ports, protocols are bound on this Gateway.
Listeners []Listener `json:"listeners"`
// Routes associated with this Gateway. Routes define
// protocol-specific routing to backends (e.g. Services).
Routes []core.TypedLocalObjectReference `json:"routes"`
// RouteSelector specifies routes to associate with the Gateway. Routes define
// protocol-specific routing to back-ends (e.g. Services).
//
// If undefined, the Gateway will be associated to all routes.
//
// Support: Core
//
// +optional
RouteSelector *RouteSelector `json:"routeSelector,omitempty"`
}

const (
Expand Down Expand Up @@ -180,7 +186,41 @@ type ListenerTLS struct {
Options map[string]string `json:"options"`
}

// GatewayStatus defines the observed state of Gateway.
// RouteSelector provides a mechanism to associate routes with the Gateway.
type RouteSelector struct {
// RouteRefs specifies what routes to associate with the Gateway. If defined,
// NamespaceSelector and LabelSelector are ignored and only the specified
// routes are associated with the Gateway.
//
// If undefined, all routes or routes matching NamespaceSelector and/or
// LabelSelector are associated with the Gateway.
//
// +optional
RouteRefs []core.ObjectReference `json:"routeRefs,omitempty"`
// NamespaceSelector specifies a set of namespace labels used for selecting
// routes to associate with the Gateway.
//
// If undefined, routes from all namespaces will be associated to the Gateway.
// If undefined and LabelSelector is defined, routes containing LabelSelector
// labels across all namespaces are associated to the Gateway. If NamespaceSelector
// and LabelSelector are defined, only routes matching the LabelSelector labels
// from NamespaceSelector namespaces are associated to the Gateway.
//
// +optional
NamespaceSelector *metav1.LabelSelector `json:"namespaceSelector,omitempty"`
// LabelSelector specifies route labels for associating routes to the Gateway.
//
// If undefined, the default is all routes are associated to the Gateway. If undefined
// and NamespaceSelector is defined, all routes within the NamespaceSelector namespaces
// are associated to the Gateway. If LabelSelector and NamespaceSelector are defined,
// only routes matching the LabelSelector labels from NamespaceSelector namespaces are
// associated to the Gateway.
//
// +optional
LabelSelector *metav1.LabelSelector `json:"labelSelector,omitempty"`
}

// GatewayStatus defines the observed state of Gateway
type GatewayStatus struct {
// Conditions describe the current conditions of the Gateway.
Conditions []GatewayCondition `json:"conditions"`
Expand Down
41 changes: 35 additions & 6 deletions api/v1alpha1/zz_generated.deepcopy.go

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

177 changes: 152 additions & 25 deletions config/crd/bases/networking.x.k8s.io_gateways.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -153,34 +153,161 @@ spec:
type: object
type: object
type: array
routes:
description: Routes associated with this Gateway. Routes define protocol-specific
routing to backends (e.g. Services).
items:
description: TypedLocalObjectReference contains enough information
to let you locate the typed referenced object inside the same namespace.
properties:
apiGroup:
description: APIGroup is the group for the resource being referenced.
If APIGroup is not specified, the specified Kind must be in
the core API group. For any other third-party types, APIGroup
is required.
type: string
kind:
description: Kind is the type of resource being referenced
type: string
name:
description: Name is the name of resource being referenced
type: string
required:
- kind
- name
type: object
type: array
routeSelector:
description: "RouteSelector specifies routes to associate with this
Gateway. Routes define protocol-specific routing to back-ends (e.g.
Services). \n If undefined, this Gateway will be associated to all
routes."
properties:
labelSelector:
description: "LabelSelector specifies route labels for associating
routes to this Gateway. \n If undefined, the default is all routes
are associated to this Gateway. If undefined and NamespaceSelector
is defined, all routes within the NamespaceSelector namespaces
are associated to this Gateway. If LabelSelector and NamespaceSelector
are defined, only routes matching the LabelSelector labels from
NamespaceSelector namespaces are associated to this Gateway."
properties:
matchExpressions:
description: matchExpressions is a list of label selector requirements.
The requirements are ANDed.
items:
description: A label selector requirement is a selector that
contains values, a key, and an operator that relates the
key and values.
properties:
key:
description: key is the label key that the selector applies
to.
type: string
operator:
description: operator represents a key's relationship
to a set of values. Valid operators are In, NotIn, Exists
and DoesNotExist.
type: string
values:
description: values is an array of string values. If the
operator is In or NotIn, the values array must be non-empty.
If the operator is Exists or DoesNotExist, the values
array must be empty. This array is replaced during a
strategic merge patch.
items:
type: string
type: array
required:
- key
- operator
type: object
type: array
matchLabels:
additionalProperties:
type: string
description: matchLabels is a map of {key,value} pairs. A single
{key,value} in the matchLabels map is equivalent to an element
of matchExpressions, whose key field is "key", the operator
is "In", and the values array contains only "value". The requirements
are ANDed.
type: object
type: object
namespaceSelector:
description: "NamespaceSelector specifies a set of namespace labels
used for selecting routes to associate with this Gateway. \n If
undefined, routes from all namespaces will be associated to this
Gateway. If undefined and LabelSelector is defined, routes containing
LabelSelector labels across all namespaces are associated to this
Gateway. If NamespaceSelector and LabelSelector are defined, only
routes matching the LabelSelector labels from NamespaceSelector
namespaces are associated to this Gateway."
properties:
matchExpressions:
description: matchExpressions is a list of label selector requirements.
The requirements are ANDed.
items:
description: A label selector requirement is a selector that
contains values, a key, and an operator that relates the
key and values.
properties:
key:
description: key is the label key that the selector applies
to.
type: string
operator:
description: operator represents a key's relationship
to a set of values. Valid operators are In, NotIn, Exists
and DoesNotExist.
type: string
values:
description: values is an array of string values. If the
operator is In or NotIn, the values array must be non-empty.
If the operator is Exists or DoesNotExist, the values
array must be empty. This array is replaced during a
strategic merge patch.
items:
type: string
type: array
required:
- key
- operator
type: object
type: array
matchLabels:
additionalProperties:
type: string
description: matchLabels is a map of {key,value} pairs. A single
{key,value} in the matchLabels map is equivalent to an element
of matchExpressions, whose key field is "key", the operator
is "In", and the values array contains only "value". The requirements
are ANDed.
type: object
type: object
routes:
description: "Routes specifies what routes to associate with this
Gateway. If defined, NamespaceSelector and LabelSelector are ignored
and only the specified routes are associated with this Gateway.
\n If undefined, all routes or routes matching NamespaceSelector
and/or LabelSelector are associated with this Gateway."
items:
description: ObjectReference contains enough information to let
you inspect or modify the referred object.
properties:
apiVersion:
description: API version of the referent.
type: string
fieldPath:
description: 'If referring to a piece of an object instead
of an entire object, this string should contain a valid
JSON/Go field access statement, such as desiredState.manifest.containers[2].
For example, if the object reference is to a container within
a pod, this would take on a value like: "spec.containers{name}"
(where "name" refers to the name of the container that triggered
the event) or if no container name is specified "spec.containers[2]"
(container with index 2 in this pod). This syntax is chosen
only to have some well-defined way of referencing a part
of an object. TODO: this design is not final and this field
is subject to change in the future.'
type: string
kind:
description: 'Kind of the referent. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds'
type: string
name:
description: 'Name of the referent. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names'
type: string
namespace:
description: 'Namespace of the referent. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/namespaces/'
type: string
resourceVersion:
description: 'Specific resourceVersion to which this reference
is made, if any. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#concurrency-control-and-consistency'
type: string
uid:
description: 'UID of the referent. More info: https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#uids'
type: string
type: object
type: array
type: object
required:
- class
- listeners
- routes
type: object
status:
description: GatewayStatus defines the observed state of Gateway
Expand Down

0 comments on commit 940f2f6

Please sign in to comment.