Skip to content

add controller to snippetsFilter status #2570

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
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
28 changes: 27 additions & 1 deletion apis/v1alpha1/snippetsfilter_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package v1alpha1

import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
v1 "sigs.k8s.io/gateway-api/apis/v1"
)

// +genclient
Expand Down Expand Up @@ -79,10 +80,35 @@ const (

// SnippetsFilterStatus defines the state of SnippetsFilter.
type SnippetsFilterStatus struct {
// Conditions describes the state of the SnippetsFilter.
// Controllers is a list of Gateway API controllers that processed the SnippetsFilter
// and the status of the SnippetsFilter with respect to each controller.
//
// +kubebuilder:validation:MaxItems=16
Controllers []ControllerStatus `json:"controllers,omitempty"`
}

type ControllerStatus struct {
// ControllerName is a domain/path string that indicates the name of the
// controller that wrote this status. This corresponds with the
// controllerName field on GatewayClass.
//
// Example: "example.net/gateway-controller".
//
// The format of this field is DOMAIN "/" PATH, where DOMAIN and PATH are
// valid Kubernetes names
// (https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names).
//
// Controllers MUST populate this field when writing status. Controllers should ensure that
// entries to status populated with their ControllerName are cleaned up when they are no
// longer necessary.
ControllerName v1.GatewayController `json:"controllerName"`

// Conditions describe the status of the SnippetsFilter.
//
// +optional
// +listType=map
// +listMapKey=type
// +kubebuilder:validation:MinItems=1
// +kubebuilder:validation:MaxItems=8
Conditions []metav1.Condition `json:"conditions,omitempty"`
}
Expand Down
28 changes: 25 additions & 3 deletions apis/v1alpha1/zz_generated.deepcopy.go

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

138 changes: 85 additions & 53 deletions config/crd/bases/gateway.nginx.org_snippetsfilters.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -86,67 +86,99 @@ spec:
status:
description: Status defines the state of the SnippetsFilter.
properties:
conditions:
description: Conditions describes the state of the SnippetsFilter.
controllers:
description: |-
Controllers is a list of Gateway API controllers that processed the SnippetsFilter
and the status of the SnippetsFilter with respect to each controller.
items:
description: Condition contains details for one aspect of the current
state of this API Resource.
properties:
lastTransitionTime:
description: |-
lastTransitionTime is the last time the condition transitioned from one status to another.
This should be when the underlying condition changed. If that is not known, then using the time when the API field changed is acceptable.
format: date-time
type: string
message:
description: |-
message is a human readable message indicating details about the transition.
This may be an empty string.
maxLength: 32768
type: string
observedGeneration:
conditions:
description: Conditions describe the status of the SnippetsFilter.
items:
description: Condition contains details for one aspect of
the current state of this API Resource.
properties:
lastTransitionTime:
description: |-
lastTransitionTime is the last time the condition transitioned from one status to another.
This should be when the underlying condition changed. If that is not known, then using the time when the API field changed is acceptable.
format: date-time
type: string
message:
description: |-
message is a human readable message indicating details about the transition.
This may be an empty string.
maxLength: 32768
type: string
observedGeneration:
description: |-
observedGeneration represents the .metadata.generation that the condition was set based upon.
For instance, if .metadata.generation is currently 12, but the .status.conditions[x].observedGeneration is 9, the condition is out of date
with respect to the current state of the instance.
format: int64
minimum: 0
type: integer
reason:
description: |-
reason contains a programmatic identifier indicating the reason for the condition's last transition.
Producers of specific condition types may define expected values and meanings for this field,
and whether the values are considered a guaranteed API.
The value should be a CamelCase string.
This field may not be empty.
maxLength: 1024
minLength: 1
pattern: ^[A-Za-z]([A-Za-z0-9_,:]*[A-Za-z0-9_])?$
type: string
status:
description: status of the condition, one of True, False,
Unknown.
enum:
- "True"
- "False"
- Unknown
type: string
type:
description: type of condition in CamelCase or in foo.example.com/CamelCase.
maxLength: 316
pattern: ^([a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*/)?(([A-Za-z0-9][-A-Za-z0-9_.]*)?[A-Za-z0-9])$
type: string
required:
- lastTransitionTime
- message
- reason
- status
- type
type: object
maxItems: 8
minItems: 1
type: array
x-kubernetes-list-map-keys:
- type
x-kubernetes-list-type: map
controllerName:
description: |-
observedGeneration represents the .metadata.generation that the condition was set based upon.
For instance, if .metadata.generation is currently 12, but the .status.conditions[x].observedGeneration is 9, the condition is out of date
with respect to the current state of the instance.
format: int64
minimum: 0
type: integer
reason:
description: |-
reason contains a programmatic identifier indicating the reason for the condition's last transition.
Producers of specific condition types may define expected values and meanings for this field,
and whether the values are considered a guaranteed API.
The value should be a CamelCase string.
This field may not be empty.
maxLength: 1024
ControllerName is a domain/path string that indicates the name of the
controller that wrote this status. This corresponds with the
controllerName field on GatewayClass.

Example: "example.net/gateway-controller".

The format of this field is DOMAIN "/" PATH, where DOMAIN and PATH are
valid Kubernetes names
(https://kubernetes.io/docs/concepts/overview/working-with-objects/names/#names).

Controllers MUST populate this field when writing status. Controllers should ensure that
entries to status populated with their ControllerName are cleaned up when they are no
longer necessary.
maxLength: 253
minLength: 1
pattern: ^[A-Za-z]([A-Za-z0-9_,:]*[A-Za-z0-9_])?$
type: string
status:
description: status of the condition, one of True, False, Unknown.
enum:
- "True"
- "False"
- Unknown
type: string
type:
description: type of condition in CamelCase or in foo.example.com/CamelCase.
maxLength: 316
pattern: ^([a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*/)?(([A-Za-z0-9][-A-Za-z0-9_.]*)?[A-Za-z0-9])$
pattern: ^[a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*\/[A-Za-z0-9\/\-._~%!$&'()*+,;=:]+$
type: string
required:
- lastTransitionTime
- message
- reason
- status
- type
- controllerName
type: object
maxItems: 8
maxItems: 16
type: array
x-kubernetes-list-map-keys:
- type
x-kubernetes-list-type: map
type: object
required:
- spec
Expand Down
6 changes: 5 additions & 1 deletion internal/mode/static/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,11 @@ func (h *eventHandlerImpl) updateStatuses(ctx context.Context, logger logr.Logge

polReqs := status.PrepareBackendTLSPolicyRequests(graph.BackendTLSPolicies, transitionTime, h.cfg.gatewayCtlrName)
ngfPolReqs := status.PrepareNGFPolicyRequests(graph.NGFPolicies, transitionTime, h.cfg.gatewayCtlrName)
snippetsFilterReqs := status.PrepareSnippetsFilterRequests(graph.SnippetsFilters, transitionTime)
snippetsFilterReqs := status.PrepareSnippetsFilterRequests(
graph.SnippetsFilters,
transitionTime,
h.cfg.gatewayCtlrName,
)

reqs := make(
[]frameworkStatus.UpdateRequest,
Expand Down
10 changes: 8 additions & 2 deletions internal/mode/static/status/prepare_requests.go
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,7 @@ func PrepareBackendTLSPolicyRequests(
func PrepareSnippetsFilterRequests(
snippetsFilters map[types.NamespacedName]*graph.SnippetsFilter,
transitionTime metav1.Time,
gatewayCtlrName string,
) []frameworkStatus.UpdateRequest {
reqs := make([]frameworkStatus.UpdateRequest, 0, len(snippetsFilters))

Expand All @@ -425,13 +426,18 @@ func PrepareSnippetsFilterRequests(
conds := conditions.DeduplicateConditions(allConds)
apiConds := conditions.ConvertConditions(conds, snippetsFilter.Source.GetGeneration(), transitionTime)
status := ngfAPI.SnippetsFilterStatus{
Conditions: apiConds,
Controllers: []ngfAPI.ControllerStatus{
{
Conditions: apiConds,
ControllerName: v1alpha2.GatewayController(gatewayCtlrName),
},
},
}

reqs = append(reqs, frameworkStatus.UpdateRequest{
NsName: nsname,
ResourceType: snippetsFilter.Source,
Setter: newSnippetsFilterStatusSetter(status),
Setter: newSnippetsFilterStatusSetter(status, gatewayCtlrName),
})
}

Expand Down
41 changes: 26 additions & 15 deletions internal/mode/static/status/prepare_requests_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1771,6 +1771,7 @@ func TestBuildNGFPolicyStatuses(t *testing.T) {

func TestBuildSnippetsFilterStatuses(t *testing.T) {
transitionTime := helpers.PrepareTimeForFakeClient(metav1.Now())
const gatewayCtlrName = "controller"

validSnippetsFilter := &graph.SnippetsFilter{
Source: &ngfAPI.SnippetsFilter{
Expand Down Expand Up @@ -1822,14 +1823,19 @@ func TestBuildSnippetsFilterStatuses(t *testing.T) {
expectedReqs: 1,
expected: map[types.NamespacedName]ngfAPI.SnippetsFilterStatus{
{Namespace: "test", Name: "valid-snippet"}: {
Conditions: []metav1.Condition{
Controllers: []ngfAPI.ControllerStatus{
{
Type: string(ngfAPI.SnippetsFilterConditionTypeAccepted),
Status: metav1.ConditionTrue,
ObservedGeneration: 1,
LastTransitionTime: transitionTime,
Reason: string(ngfAPI.SnippetsFilterConditionReasonAccepted),
Message: "SnippetsFilter is accepted",
Conditions: []metav1.Condition{
{
Type: string(ngfAPI.SnippetsFilterConditionTypeAccepted),
Status: metav1.ConditionTrue,
ObservedGeneration: 1,
LastTransitionTime: transitionTime,
Reason: string(ngfAPI.SnippetsFilterConditionReasonAccepted),
Message: "SnippetsFilter is accepted",
},
},
ControllerName: gatewayCtlrName,
},
},
},
Expand All @@ -1843,14 +1849,19 @@ func TestBuildSnippetsFilterStatuses(t *testing.T) {
expectedReqs: 1,
expected: map[types.NamespacedName]ngfAPI.SnippetsFilterStatus{
{Namespace: "test", Name: "invalid-snippet"}: {
Conditions: []metav1.Condition{
Controllers: []ngfAPI.ControllerStatus{
{
Type: string(ngfAPI.SnippetsFilterConditionTypeAccepted),
Status: metav1.ConditionFalse,
ObservedGeneration: 1,
LastTransitionTime: transitionTime,
Reason: string(ngfAPI.SnippetsFilterConditionReasonInvalid),
Message: "invalid snippetsFilter",
Conditions: []metav1.Condition{
{
Type: string(ngfAPI.SnippetsFilterConditionTypeAccepted),
Status: metav1.ConditionFalse,
ObservedGeneration: 1,
LastTransitionTime: transitionTime,
Reason: string(ngfAPI.SnippetsFilterConditionReasonInvalid),
Message: "invalid snippetsFilter",
},
},
ControllerName: gatewayCtlrName,
},
},
},
Expand All @@ -1871,7 +1882,7 @@ func TestBuildSnippetsFilterStatuses(t *testing.T) {

updater := statusFramework.NewUpdater(k8sClient, zap.New())

reqs := PrepareSnippetsFilterRequests(test.snippetsFilters, transitionTime)
reqs := PrepareSnippetsFilterRequests(test.snippetsFilters, transitionTime, gatewayCtlrName)

g.Expect(reqs).To(HaveLen(test.expectedReqs))

Expand Down
Loading
Loading