Skip to content

Commit

Permalink
Standardize common route status fields.
Browse files Browse the repository at this point in the history
All the route types share a common need to expose when they are
successfully bound to a Gateway. To address this, we can hoist the
`HTTPRouteStatus` fields into a generic struct and inline it into
all the route types.

Signed-off-by: James Peach <jpeach@vmware.com>
  • Loading branch information
jpeach committed Sep 10, 2020
1 parent 335c3ae commit 8c25d9e
Show file tree
Hide file tree
Showing 10 changed files with 279 additions and 150 deletions.
62 changes: 1 addition & 61 deletions apis/v1alpha1/httproute_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ limitations under the License.
package v1alpha1

import (
core "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

Expand Down Expand Up @@ -453,66 +452,7 @@ type RouteHostExtensionObjectReference = ConfigMapsDefaultLocalObjectReference

// HTTPRouteStatus defines the observed state of HTTPRoute.
type HTTPRouteStatus struct {
// Gateways is a list of the Gateways that are associated with the
// HTTPRoute, and the status of the route with respect to each of these
// Gateways. When a Gateway selects this route, the controller that
// manages the Gateway should add an entry to this list when the
// controller first sees the route and should update the entry as
// appropriate when the route is modified.
Gateways []RouteGatewayStatus `json:"gateways"`
}

// GatewayObjectReference identifies a Gateway object.
type GatewayObjectReference struct {
// Namespace is the namespace of the referent.
// +optional
Namespace string `json:"namespace,omitempty"`
// Name is the name of the referent.
//
// +kubebuilder:validation:Required
// +required
Name string `json:"name"`
}

// RouteGatewayStatus describes the status of a route with respect to an
// associated Gateway.
type RouteGatewayStatus struct {
// GatewayRef is a reference to a Gateway object that is associated with
// the route.
GatewayRef GatewayObjectReference `json:"gatewayRef"`
// Conditions describes the status of the route with respect to the
// Gateway. For example, the "Admitted" condition indicates whether the
// route has been admitted or rejected by the Gateway, and why. Note
// that the route's availability is also subject to the Gateway's own
// status conditions and listener status.
Conditions []RouteCondition `json:"conditions,omitempty"`
}

// RouteConditionType is a type of condition for a route.
type RouteConditionType string

const (
// ConditionRouteAdmitted indicates whether the route has been admitted
// or rejected by a Gateway, and why.
ConditionRouteAdmitted RouteConditionType = "Admitted"
)

// RouteCondition is a status condition for a given route.
type RouteCondition struct {
// Type indicates the type of condition.
Type RouteConditionType `json:"type"`
// Status describes the current state of this condition. Can be "True",
// "False", or "Unknown".
Status core.ConditionStatus `json:"status"`
// Message is a human-understandable message describing the condition.
// +optional
Message string `json:"message,omitempty"`
// Reason indicates why the condition is in this state.
// +optional
Reason string `json:"reason,omitempty"`
// LastTransitionTime indicates the last time this condition changed.
// +optional
LastTransitionTime metav1.Time `json:"lastTransitionTime,omitempty"`
RouteStatus `json:",inline"`
}

// +genclient
Expand Down
86 changes: 86 additions & 0 deletions apis/v1alpha1/route_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
/*
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package v1alpha1

import (
core "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

// GatewayObjectReference identifies a Gateway object.
type GatewayObjectReference struct {
// Namespace is the namespace of the referent.
// +optional
Namespace string `json:"namespace,omitempty"`
// Name is the name of the referent.
//
// +kubebuilder:validation:Required
// +required
Name string `json:"name"`
}

// RouteConditionType is a type of condition for a route.
type RouteConditionType string

const (
// ConditionRouteAdmitted indicates whether the route has been admitted
// or rejected by a Gateway, and why.
ConditionRouteAdmitted RouteConditionType = "Admitted"
)

// RouteCondition is a status condition for a given route.
type RouteCondition struct {
// Type indicates the type of condition.
Type RouteConditionType `json:"type"`
// Status describes the current state of this condition. Can be "True",
// "False", or "Unknown".
Status core.ConditionStatus `json:"status"`
// Message is a human-understandable message describing the condition.
// +optional
Message string `json:"message,omitempty"`
// Reason indicates why the condition is in this state.
// +optional
Reason string `json:"reason,omitempty"`
// LastTransitionTime indicates the last time this condition changed.
// +optional
LastTransitionTime metav1.Time `json:"lastTransitionTime,omitempty"`
}

// RouteGatewayStatus describes the status of a route with respect to an
// associated Gateway.
type RouteGatewayStatus struct {
// GatewayRef is a reference to a Gateway object that is associated with
// the route.
GatewayRef GatewayObjectReference `json:"gatewayRef"`
// Conditions describes the status of the route with respect to the
// Gateway. For example, the "Admitted" condition indicates whether the
// route has been admitted or rejected by the Gateway, and why. Note
// that the route's availability is also subject to the Gateway's own
// status conditions and listener status.
Conditions []RouteCondition `json:"conditions,omitempty"`
}

// RouteStatus defines the observed state that is required across
// all route types.
type RouteStatus struct {
// Gateways is a list of the Gateways that are associated with the
// route, and the status of the route with respect to each of these
// Gateways. When a Gateway selects this route, the controller that
// manages the Gateway should add an entry to this list when the
// controller first sees the route and should update the entry as
// appropriate when the route is modified.
Gateways []RouteGatewayStatus `json:"gateways"`
}
8 changes: 1 addition & 7 deletions apis/v1alpha1/tcproute_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,7 @@ type TCPRouteSpec struct {

// TCPRouteStatus defines the observed state of TCPRoute
type TCPRouteStatus struct {
// Gateways is a list of the Gateways that are associated with the
// TCPRoute, and the status of the route with respect to each of these
// Gateways. When a Gateway selects this route, the controller that
// manages the Gateway should add an entry to this list when the
// controller first sees the route and should update the entry as
// appropriate when the route is modified.
Gateways []RouteGatewayStatus `json:"gateways"`
RouteStatus `json:",inline"`
}

// +genclient
Expand Down
2 changes: 1 addition & 1 deletion apis/v1alpha1/udproute_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ type UDPRouteSpec struct {

// UDPRouteStatus defines the observed state of UDPRoute.
type UDPRouteStatus struct {
GatewayRefs []GatewayObjectReference `json:"gatewayRefs" protobuf:"bytes,1,rep,name=gatewayRefs"`
RouteStatus `json:",inline"`
}

// +genclient
Expand Down
44 changes: 25 additions & 19 deletions apis/v1alpha1/zz_generated.deepcopy.go

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

2 changes: 1 addition & 1 deletion config/crd/bases/networking.x-k8s.io_httproutes.yaml

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

2 changes: 1 addition & 1 deletion config/crd/bases/networking.x-k8s.io_tcproutes.yaml

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

53 changes: 43 additions & 10 deletions config/crd/bases/networking.x-k8s.io_udproutes.yaml

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

Loading

0 comments on commit 8c25d9e

Please sign in to comment.