diff --git a/apis/applyconfiguration/apis/v1/cookieconfig.go b/apis/applyconfiguration/apis/v1/cookieconfig.go new file mode 100644 index 0000000000..7702c69a56 --- /dev/null +++ b/apis/applyconfiguration/apis/v1/cookieconfig.go @@ -0,0 +1,43 @@ +/* +Copyright The Kubernetes Authors. + +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. +*/ + +// Code generated by applyconfiguration-gen. DO NOT EDIT. + +package v1 + +import ( + v1 "sigs.k8s.io/gateway-api/apis/v1" +) + +// CookieConfigApplyConfiguration represents an declarative configuration of the CookieConfig type for use +// with apply. +type CookieConfigApplyConfiguration struct { + LifetimeType *v1.CookieLifetimeType `json:"lifetimeType,omitempty"` +} + +// CookieConfigApplyConfiguration constructs an declarative configuration of the CookieConfig type for use with +// apply. +func CookieConfig() *CookieConfigApplyConfiguration { + return &CookieConfigApplyConfiguration{} +} + +// WithLifetimeType sets the LifetimeType field in the declarative configuration to the given value +// and returns the receiver, so that objects can be built by chaining "With" function invocations. +// If called multiple times, the LifetimeType field is set to the value of the last call. +func (b *CookieConfigApplyConfiguration) WithLifetimeType(value v1.CookieLifetimeType) *CookieConfigApplyConfiguration { + b.LifetimeType = &value + return b +} diff --git a/apis/applyconfiguration/apis/v1/grpcrouterule.go b/apis/applyconfiguration/apis/v1/grpcrouterule.go index fa87715054..367fe37260 100644 --- a/apis/applyconfiguration/apis/v1/grpcrouterule.go +++ b/apis/applyconfiguration/apis/v1/grpcrouterule.go @@ -21,9 +21,10 @@ package v1 // GRPCRouteRuleApplyConfiguration represents an declarative configuration of the GRPCRouteRule type for use // with apply. type GRPCRouteRuleApplyConfiguration struct { - Matches []GRPCRouteMatchApplyConfiguration `json:"matches,omitempty"` - Filters []GRPCRouteFilterApplyConfiguration `json:"filters,omitempty"` - BackendRefs []GRPCBackendRefApplyConfiguration `json:"backendRefs,omitempty"` + Matches []GRPCRouteMatchApplyConfiguration `json:"matches,omitempty"` + Filters []GRPCRouteFilterApplyConfiguration `json:"filters,omitempty"` + BackendRefs []GRPCBackendRefApplyConfiguration `json:"backendRefs,omitempty"` + SessionPersistence *SessionPersistenceApplyConfiguration `json:"sessionPersistence,omitempty"` } // GRPCRouteRuleApplyConfiguration constructs an declarative configuration of the GRPCRouteRule type for use with @@ -70,3 +71,11 @@ func (b *GRPCRouteRuleApplyConfiguration) WithBackendRefs(values ...*GRPCBackend } return b } + +// WithSessionPersistence sets the SessionPersistence field in the declarative configuration to the given value +// and returns the receiver, so that objects can be built by chaining "With" function invocations. +// If called multiple times, the SessionPersistence field is set to the value of the last call. +func (b *GRPCRouteRuleApplyConfiguration) WithSessionPersistence(value *SessionPersistenceApplyConfiguration) *GRPCRouteRuleApplyConfiguration { + b.SessionPersistence = value + return b +} diff --git a/apis/applyconfiguration/apis/v1/httprouterule.go b/apis/applyconfiguration/apis/v1/httprouterule.go index 2142fb7a62..dcef6b12e2 100644 --- a/apis/applyconfiguration/apis/v1/httprouterule.go +++ b/apis/applyconfiguration/apis/v1/httprouterule.go @@ -21,10 +21,11 @@ package v1 // HTTPRouteRuleApplyConfiguration represents an declarative configuration of the HTTPRouteRule type for use // with apply. type HTTPRouteRuleApplyConfiguration struct { - Matches []HTTPRouteMatchApplyConfiguration `json:"matches,omitempty"` - Filters []HTTPRouteFilterApplyConfiguration `json:"filters,omitempty"` - BackendRefs []HTTPBackendRefApplyConfiguration `json:"backendRefs,omitempty"` - Timeouts *HTTPRouteTimeoutsApplyConfiguration `json:"timeouts,omitempty"` + Matches []HTTPRouteMatchApplyConfiguration `json:"matches,omitempty"` + Filters []HTTPRouteFilterApplyConfiguration `json:"filters,omitempty"` + BackendRefs []HTTPBackendRefApplyConfiguration `json:"backendRefs,omitempty"` + Timeouts *HTTPRouteTimeoutsApplyConfiguration `json:"timeouts,omitempty"` + SessionPersistence *SessionPersistenceApplyConfiguration `json:"sessionPersistence,omitempty"` } // HTTPRouteRuleApplyConfiguration constructs an declarative configuration of the HTTPRouteRule type for use with @@ -79,3 +80,11 @@ func (b *HTTPRouteRuleApplyConfiguration) WithTimeouts(value *HTTPRouteTimeoutsA b.Timeouts = value return b } + +// WithSessionPersistence sets the SessionPersistence field in the declarative configuration to the given value +// and returns the receiver, so that objects can be built by chaining "With" function invocations. +// If called multiple times, the SessionPersistence field is set to the value of the last call. +func (b *HTTPRouteRuleApplyConfiguration) WithSessionPersistence(value *SessionPersistenceApplyConfiguration) *HTTPRouteRuleApplyConfiguration { + b.SessionPersistence = value + return b +} diff --git a/apis/applyconfiguration/apis/v1/sessionpersistence.go b/apis/applyconfiguration/apis/v1/sessionpersistence.go new file mode 100644 index 0000000000..7b9de44e3b --- /dev/null +++ b/apis/applyconfiguration/apis/v1/sessionpersistence.go @@ -0,0 +1,79 @@ +/* +Copyright The Kubernetes Authors. + +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. +*/ + +// Code generated by applyconfiguration-gen. DO NOT EDIT. + +package v1 + +import ( + v1 "sigs.k8s.io/gateway-api/apis/v1" +) + +// SessionPersistenceApplyConfiguration represents an declarative configuration of the SessionPersistence type for use +// with apply. +type SessionPersistenceApplyConfiguration struct { + SessionName *string `json:"sessionName,omitempty"` + AbsoluteTimeout *v1.Duration `json:"absoluteTimeout,omitempty"` + IdleTimeout *v1.Duration `json:"idleTimeout,omitempty"` + Type *v1.SessionPersistenceType `json:"type,omitempty"` + CookieConfig *CookieConfigApplyConfiguration `json:"cookieConfig,omitempty"` +} + +// SessionPersistenceApplyConfiguration constructs an declarative configuration of the SessionPersistence type for use with +// apply. +func SessionPersistence() *SessionPersistenceApplyConfiguration { + return &SessionPersistenceApplyConfiguration{} +} + +// WithSessionName sets the SessionName field in the declarative configuration to the given value +// and returns the receiver, so that objects can be built by chaining "With" function invocations. +// If called multiple times, the SessionName field is set to the value of the last call. +func (b *SessionPersistenceApplyConfiguration) WithSessionName(value string) *SessionPersistenceApplyConfiguration { + b.SessionName = &value + return b +} + +// WithAbsoluteTimeout sets the AbsoluteTimeout field in the declarative configuration to the given value +// and returns the receiver, so that objects can be built by chaining "With" function invocations. +// If called multiple times, the AbsoluteTimeout field is set to the value of the last call. +func (b *SessionPersistenceApplyConfiguration) WithAbsoluteTimeout(value v1.Duration) *SessionPersistenceApplyConfiguration { + b.AbsoluteTimeout = &value + return b +} + +// WithIdleTimeout sets the IdleTimeout field in the declarative configuration to the given value +// and returns the receiver, so that objects can be built by chaining "With" function invocations. +// If called multiple times, the IdleTimeout field is set to the value of the last call. +func (b *SessionPersistenceApplyConfiguration) WithIdleTimeout(value v1.Duration) *SessionPersistenceApplyConfiguration { + b.IdleTimeout = &value + return b +} + +// WithType sets the Type field in the declarative configuration to the given value +// and returns the receiver, so that objects can be built by chaining "With" function invocations. +// If called multiple times, the Type field is set to the value of the last call. +func (b *SessionPersistenceApplyConfiguration) WithType(value v1.SessionPersistenceType) *SessionPersistenceApplyConfiguration { + b.Type = &value + return b +} + +// WithCookieConfig sets the CookieConfig field in the declarative configuration to the given value +// and returns the receiver, so that objects can be built by chaining "With" function invocations. +// If called multiple times, the CookieConfig field is set to the value of the last call. +func (b *SessionPersistenceApplyConfiguration) WithCookieConfig(value *CookieConfigApplyConfiguration) *SessionPersistenceApplyConfiguration { + b.CookieConfig = value + return b +} diff --git a/apis/applyconfiguration/apis/v1alpha2/backendlbpolicy.go b/apis/applyconfiguration/apis/v1alpha2/backendlbpolicy.go new file mode 100644 index 0000000000..fd340bd014 --- /dev/null +++ b/apis/applyconfiguration/apis/v1alpha2/backendlbpolicy.go @@ -0,0 +1,258 @@ +/* +Copyright The Kubernetes Authors. + +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. +*/ + +// Code generated by applyconfiguration-gen. DO NOT EDIT. + +package v1alpha2 + +import ( + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + types "k8s.io/apimachinery/pkg/types" + managedfields "k8s.io/apimachinery/pkg/util/managedfields" + v1 "k8s.io/client-go/applyconfigurations/meta/v1" + internal "sigs.k8s.io/gateway-api/apis/applyconfiguration/internal" + apisv1alpha2 "sigs.k8s.io/gateway-api/apis/v1alpha2" +) + +// BackendLBPolicyApplyConfiguration represents an declarative configuration of the BackendLBPolicy type for use +// with apply. +type BackendLBPolicyApplyConfiguration struct { + v1.TypeMetaApplyConfiguration `json:",inline"` + *v1.ObjectMetaApplyConfiguration `json:"metadata,omitempty"` + Spec *BackendLBPolicySpecApplyConfiguration `json:"spec,omitempty"` + Status *PolicyStatusApplyConfiguration `json:"status,omitempty"` +} + +// BackendLBPolicy constructs an declarative configuration of the BackendLBPolicy type for use with +// apply. +func BackendLBPolicy(name, namespace string) *BackendLBPolicyApplyConfiguration { + b := &BackendLBPolicyApplyConfiguration{} + b.WithName(name) + b.WithNamespace(namespace) + b.WithKind("BackendLBPolicy") + b.WithAPIVersion("gateway.networking.k8s.io/v1alpha2") + return b +} + +// ExtractBackendLBPolicy extracts the applied configuration owned by fieldManager from +// backendLBPolicy. If no managedFields are found in backendLBPolicy for fieldManager, a +// BackendLBPolicyApplyConfiguration is returned with only the Name, Namespace (if applicable), +// APIVersion and Kind populated. It is possible that no managed fields were found for because other +// field managers have taken ownership of all the fields previously owned by fieldManager, or because +// the fieldManager never owned fields any fields. +// backendLBPolicy must be a unmodified BackendLBPolicy API object that was retrieved from the Kubernetes API. +// ExtractBackendLBPolicy provides a way to perform a extract/modify-in-place/apply workflow. +// Note that an extracted apply configuration will contain fewer fields than what the fieldManager previously +// applied if another fieldManager has updated or force applied any of the previously applied fields. +// Experimental! +func ExtractBackendLBPolicy(backendLBPolicy *apisv1alpha2.BackendLBPolicy, fieldManager string) (*BackendLBPolicyApplyConfiguration, error) { + return extractBackendLBPolicy(backendLBPolicy, fieldManager, "") +} + +// ExtractBackendLBPolicyStatus is the same as ExtractBackendLBPolicy except +// that it extracts the status subresource applied configuration. +// Experimental! +func ExtractBackendLBPolicyStatus(backendLBPolicy *apisv1alpha2.BackendLBPolicy, fieldManager string) (*BackendLBPolicyApplyConfiguration, error) { + return extractBackendLBPolicy(backendLBPolicy, fieldManager, "status") +} + +func extractBackendLBPolicy(backendLBPolicy *apisv1alpha2.BackendLBPolicy, fieldManager string, subresource string) (*BackendLBPolicyApplyConfiguration, error) { + b := &BackendLBPolicyApplyConfiguration{} + err := managedfields.ExtractInto(backendLBPolicy, internal.Parser().Type("io.k8s.sigs.gateway-api.apis.v1alpha2.BackendLBPolicy"), fieldManager, b, subresource) + if err != nil { + return nil, err + } + b.WithName(backendLBPolicy.Name) + b.WithNamespace(backendLBPolicy.Namespace) + + b.WithKind("BackendLBPolicy") + b.WithAPIVersion("gateway.networking.k8s.io/v1alpha2") + return b, nil +} + +// WithKind sets the Kind field in the declarative configuration to the given value +// and returns the receiver, so that objects can be built by chaining "With" function invocations. +// If called multiple times, the Kind field is set to the value of the last call. +func (b *BackendLBPolicyApplyConfiguration) WithKind(value string) *BackendLBPolicyApplyConfiguration { + b.Kind = &value + return b +} + +// WithAPIVersion sets the APIVersion field in the declarative configuration to the given value +// and returns the receiver, so that objects can be built by chaining "With" function invocations. +// If called multiple times, the APIVersion field is set to the value of the last call. +func (b *BackendLBPolicyApplyConfiguration) WithAPIVersion(value string) *BackendLBPolicyApplyConfiguration { + b.APIVersion = &value + return b +} + +// WithName sets the Name field in the declarative configuration to the given value +// and returns the receiver, so that objects can be built by chaining "With" function invocations. +// If called multiple times, the Name field is set to the value of the last call. +func (b *BackendLBPolicyApplyConfiguration) WithName(value string) *BackendLBPolicyApplyConfiguration { + b.ensureObjectMetaApplyConfigurationExists() + b.Name = &value + return b +} + +// WithGenerateName sets the GenerateName field in the declarative configuration to the given value +// and returns the receiver, so that objects can be built by chaining "With" function invocations. +// If called multiple times, the GenerateName field is set to the value of the last call. +func (b *BackendLBPolicyApplyConfiguration) WithGenerateName(value string) *BackendLBPolicyApplyConfiguration { + b.ensureObjectMetaApplyConfigurationExists() + b.GenerateName = &value + return b +} + +// WithNamespace sets the Namespace field in the declarative configuration to the given value +// and returns the receiver, so that objects can be built by chaining "With" function invocations. +// If called multiple times, the Namespace field is set to the value of the last call. +func (b *BackendLBPolicyApplyConfiguration) WithNamespace(value string) *BackendLBPolicyApplyConfiguration { + b.ensureObjectMetaApplyConfigurationExists() + b.Namespace = &value + return b +} + +// WithUID sets the UID field in the declarative configuration to the given value +// and returns the receiver, so that objects can be built by chaining "With" function invocations. +// If called multiple times, the UID field is set to the value of the last call. +func (b *BackendLBPolicyApplyConfiguration) WithUID(value types.UID) *BackendLBPolicyApplyConfiguration { + b.ensureObjectMetaApplyConfigurationExists() + b.UID = &value + return b +} + +// WithResourceVersion sets the ResourceVersion field in the declarative configuration to the given value +// and returns the receiver, so that objects can be built by chaining "With" function invocations. +// If called multiple times, the ResourceVersion field is set to the value of the last call. +func (b *BackendLBPolicyApplyConfiguration) WithResourceVersion(value string) *BackendLBPolicyApplyConfiguration { + b.ensureObjectMetaApplyConfigurationExists() + b.ResourceVersion = &value + return b +} + +// WithGeneration sets the Generation field in the declarative configuration to the given value +// and returns the receiver, so that objects can be built by chaining "With" function invocations. +// If called multiple times, the Generation field is set to the value of the last call. +func (b *BackendLBPolicyApplyConfiguration) WithGeneration(value int64) *BackendLBPolicyApplyConfiguration { + b.ensureObjectMetaApplyConfigurationExists() + b.Generation = &value + return b +} + +// WithCreationTimestamp sets the CreationTimestamp field in the declarative configuration to the given value +// and returns the receiver, so that objects can be built by chaining "With" function invocations. +// If called multiple times, the CreationTimestamp field is set to the value of the last call. +func (b *BackendLBPolicyApplyConfiguration) WithCreationTimestamp(value metav1.Time) *BackendLBPolicyApplyConfiguration { + b.ensureObjectMetaApplyConfigurationExists() + b.CreationTimestamp = &value + return b +} + +// WithDeletionTimestamp sets the DeletionTimestamp field in the declarative configuration to the given value +// and returns the receiver, so that objects can be built by chaining "With" function invocations. +// If called multiple times, the DeletionTimestamp field is set to the value of the last call. +func (b *BackendLBPolicyApplyConfiguration) WithDeletionTimestamp(value metav1.Time) *BackendLBPolicyApplyConfiguration { + b.ensureObjectMetaApplyConfigurationExists() + b.DeletionTimestamp = &value + return b +} + +// WithDeletionGracePeriodSeconds sets the DeletionGracePeriodSeconds field in the declarative configuration to the given value +// and returns the receiver, so that objects can be built by chaining "With" function invocations. +// If called multiple times, the DeletionGracePeriodSeconds field is set to the value of the last call. +func (b *BackendLBPolicyApplyConfiguration) WithDeletionGracePeriodSeconds(value int64) *BackendLBPolicyApplyConfiguration { + b.ensureObjectMetaApplyConfigurationExists() + b.DeletionGracePeriodSeconds = &value + return b +} + +// WithLabels puts the entries into the Labels field in the declarative configuration +// and returns the receiver, so that objects can be build by chaining "With" function invocations. +// If called multiple times, the entries provided by each call will be put on the Labels field, +// overwriting an existing map entries in Labels field with the same key. +func (b *BackendLBPolicyApplyConfiguration) WithLabels(entries map[string]string) *BackendLBPolicyApplyConfiguration { + b.ensureObjectMetaApplyConfigurationExists() + if b.Labels == nil && len(entries) > 0 { + b.Labels = make(map[string]string, len(entries)) + } + for k, v := range entries { + b.Labels[k] = v + } + return b +} + +// WithAnnotations puts the entries into the Annotations field in the declarative configuration +// and returns the receiver, so that objects can be build by chaining "With" function invocations. +// If called multiple times, the entries provided by each call will be put on the Annotations field, +// overwriting an existing map entries in Annotations field with the same key. +func (b *BackendLBPolicyApplyConfiguration) WithAnnotations(entries map[string]string) *BackendLBPolicyApplyConfiguration { + b.ensureObjectMetaApplyConfigurationExists() + if b.Annotations == nil && len(entries) > 0 { + b.Annotations = make(map[string]string, len(entries)) + } + for k, v := range entries { + b.Annotations[k] = v + } + return b +} + +// WithOwnerReferences adds the given value to the OwnerReferences field in the declarative configuration +// and returns the receiver, so that objects can be build by chaining "With" function invocations. +// If called multiple times, values provided by each call will be appended to the OwnerReferences field. +func (b *BackendLBPolicyApplyConfiguration) WithOwnerReferences(values ...*v1.OwnerReferenceApplyConfiguration) *BackendLBPolicyApplyConfiguration { + b.ensureObjectMetaApplyConfigurationExists() + for i := range values { + if values[i] == nil { + panic("nil value passed to WithOwnerReferences") + } + b.OwnerReferences = append(b.OwnerReferences, *values[i]) + } + return b +} + +// WithFinalizers adds the given value to the Finalizers field in the declarative configuration +// and returns the receiver, so that objects can be build by chaining "With" function invocations. +// If called multiple times, values provided by each call will be appended to the Finalizers field. +func (b *BackendLBPolicyApplyConfiguration) WithFinalizers(values ...string) *BackendLBPolicyApplyConfiguration { + b.ensureObjectMetaApplyConfigurationExists() + for i := range values { + b.Finalizers = append(b.Finalizers, values[i]) + } + return b +} + +func (b *BackendLBPolicyApplyConfiguration) ensureObjectMetaApplyConfigurationExists() { + if b.ObjectMetaApplyConfiguration == nil { + b.ObjectMetaApplyConfiguration = &v1.ObjectMetaApplyConfiguration{} + } +} + +// WithSpec sets the Spec field in the declarative configuration to the given value +// and returns the receiver, so that objects can be built by chaining "With" function invocations. +// If called multiple times, the Spec field is set to the value of the last call. +func (b *BackendLBPolicyApplyConfiguration) WithSpec(value *BackendLBPolicySpecApplyConfiguration) *BackendLBPolicyApplyConfiguration { + b.Spec = value + return b +} + +// WithStatus sets the Status field in the declarative configuration to the given value +// and returns the receiver, so that objects can be built by chaining "With" function invocations. +// If called multiple times, the Status field is set to the value of the last call. +func (b *BackendLBPolicyApplyConfiguration) WithStatus(value *PolicyStatusApplyConfiguration) *BackendLBPolicyApplyConfiguration { + b.Status = value + return b +} diff --git a/apis/applyconfiguration/apis/v1alpha2/backendlbpolicyspec.go b/apis/applyconfiguration/apis/v1alpha2/backendlbpolicyspec.go new file mode 100644 index 0000000000..c233994c63 --- /dev/null +++ b/apis/applyconfiguration/apis/v1alpha2/backendlbpolicyspec.go @@ -0,0 +1,57 @@ +/* +Copyright The Kubernetes Authors. + +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. +*/ + +// Code generated by applyconfiguration-gen. DO NOT EDIT. + +package v1alpha2 + +import ( + v1 "sigs.k8s.io/gateway-api/apis/applyconfiguration/apis/v1" +) + +// BackendLBPolicySpecApplyConfiguration represents an declarative configuration of the BackendLBPolicySpec type for use +// with apply. +type BackendLBPolicySpecApplyConfiguration struct { + TargetRefs []LocalPolicyTargetReferenceApplyConfiguration `json:"targetRefs,omitempty"` + SessionPersistence *v1.SessionPersistenceApplyConfiguration `json:"sessionPersistence,omitempty"` +} + +// BackendLBPolicySpecApplyConfiguration constructs an declarative configuration of the BackendLBPolicySpec type for use with +// apply. +func BackendLBPolicySpec() *BackendLBPolicySpecApplyConfiguration { + return &BackendLBPolicySpecApplyConfiguration{} +} + +// WithTargetRefs adds the given value to the TargetRefs field in the declarative configuration +// and returns the receiver, so that objects can be build by chaining "With" function invocations. +// If called multiple times, values provided by each call will be appended to the TargetRefs field. +func (b *BackendLBPolicySpecApplyConfiguration) WithTargetRefs(values ...*LocalPolicyTargetReferenceApplyConfiguration) *BackendLBPolicySpecApplyConfiguration { + for i := range values { + if values[i] == nil { + panic("nil value passed to WithTargetRefs") + } + b.TargetRefs = append(b.TargetRefs, *values[i]) + } + return b +} + +// WithSessionPersistence sets the SessionPersistence field in the declarative configuration to the given value +// and returns the receiver, so that objects can be built by chaining "With" function invocations. +// If called multiple times, the SessionPersistence field is set to the value of the last call. +func (b *BackendLBPolicySpecApplyConfiguration) WithSessionPersistence(value *v1.SessionPersistenceApplyConfiguration) *BackendLBPolicySpecApplyConfiguration { + b.SessionPersistence = value + return b +} diff --git a/apis/applyconfiguration/internal/internal.go b/apis/applyconfiguration/internal/internal.go index b89ab0d41f..21866f5425 100644 --- a/apis/applyconfiguration/internal/internal.go +++ b/apis/applyconfiguration/internal/internal.go @@ -276,6 +276,12 @@ var schemaYAML = typed.YAMLObject(`types: - name: weight type: scalar: numeric +- name: io.k8s.sigs.gateway-api.apis.v1.CookieConfig + map: + fields: + - name: lifetimeType + type: + scalar: string - name: io.k8s.sigs.gateway-api.apis.v1.FrontendTLSValidation map: fields: @@ -414,6 +420,9 @@ var schemaYAML = typed.YAMLObject(`types: elementType: namedType: io.k8s.sigs.gateway-api.apis.v1.GRPCRouteMatch elementRelationship: atomic + - name: sessionPersistence + type: + namedType: io.k8s.sigs.gateway-api.apis.v1.SessionPersistence - name: io.k8s.sigs.gateway-api.apis.v1.GRPCRouteSpec map: fields: @@ -852,6 +861,9 @@ var schemaYAML = typed.YAMLObject(`types: elementType: namedType: io.k8s.sigs.gateway-api.apis.v1.HTTPRouteMatch elementRelationship: atomic + - name: sessionPersistence + type: + namedType: io.k8s.sigs.gateway-api.apis.v1.SessionPersistence - name: timeouts type: namedType: io.k8s.sigs.gateway-api.apis.v1.HTTPRouteTimeouts @@ -1094,6 +1106,61 @@ var schemaYAML = typed.YAMLObject(`types: - name: namespace type: scalar: string +- name: io.k8s.sigs.gateway-api.apis.v1.SessionPersistence + map: + fields: + - name: absoluteTimeout + type: + scalar: string + - name: cookieConfig + type: + namedType: io.k8s.sigs.gateway-api.apis.v1.CookieConfig + - name: idleTimeout + type: + scalar: string + - name: sessionName + type: + scalar: string + - name: type + type: + scalar: string +- name: io.k8s.sigs.gateway-api.apis.v1alpha2.BackendLBPolicy + map: + fields: + - name: apiVersion + type: + scalar: string + - name: kind + type: + scalar: string + - name: metadata + type: + namedType: io.k8s.apimachinery.pkg.apis.meta.v1.ObjectMeta + default: {} + - name: spec + type: + namedType: io.k8s.sigs.gateway-api.apis.v1alpha2.BackendLBPolicySpec + default: {} + - name: status + type: + namedType: io.k8s.sigs.gateway-api.apis.v1alpha2.PolicyStatus + default: {} +- name: io.k8s.sigs.gateway-api.apis.v1alpha2.BackendLBPolicySpec + map: + fields: + - name: sessionPersistence + type: + namedType: io.k8s.sigs.gateway-api.apis.v1.SessionPersistence + - name: targetRefs + type: + list: + elementType: + namedType: io.k8s.sigs.gateway-api.apis.v1alpha2.LocalPolicyTargetReference + elementRelationship: associative + keys: + - group + - kind + - name - name: io.k8s.sigs.gateway-api.apis.v1alpha2.GRPCRoute map: fields: @@ -1115,6 +1182,21 @@ var schemaYAML = typed.YAMLObject(`types: type: namedType: io.k8s.sigs.gateway-api.apis.v1.GRPCRouteStatus default: {} +- name: io.k8s.sigs.gateway-api.apis.v1alpha2.LocalPolicyTargetReference + map: + fields: + - name: group + type: + scalar: string + default: "" + - name: kind + type: + scalar: string + default: "" + - name: name + type: + scalar: string + default: "" - name: io.k8s.sigs.gateway-api.apis.v1alpha2.LocalPolicyTargetReferenceWithSectionName map: fields: diff --git a/apis/applyconfiguration/utils.go b/apis/applyconfiguration/utils.go index 7b94fe8168..9ee9075212 100644 --- a/apis/applyconfiguration/utils.go +++ b/apis/applyconfiguration/utils.go @@ -43,6 +43,8 @@ func ForKind(kind schema.GroupVersionKind) interface{} { return &apisv1.BackendRefApplyConfiguration{} case v1.SchemeGroupVersion.WithKind("CommonRouteSpec"): return &apisv1.CommonRouteSpecApplyConfiguration{} + case v1.SchemeGroupVersion.WithKind("CookieConfig"): + return &apisv1.CookieConfigApplyConfiguration{} case v1.SchemeGroupVersion.WithKind("FrontendTLSValidation"): return &apisv1.FrontendTLSValidationApplyConfiguration{} case v1.SchemeGroupVersion.WithKind("Gateway"): @@ -141,8 +143,14 @@ func ForKind(kind schema.GroupVersionKind) interface{} { return &apisv1.RouteStatusApplyConfiguration{} case v1.SchemeGroupVersion.WithKind("SecretObjectReference"): return &apisv1.SecretObjectReferenceApplyConfiguration{} + case v1.SchemeGroupVersion.WithKind("SessionPersistence"): + return &apisv1.SessionPersistenceApplyConfiguration{} // Group=gateway.networking.k8s.io, Version=v1alpha2 + case v1alpha2.SchemeGroupVersion.WithKind("BackendLBPolicy"): + return &apisv1alpha2.BackendLBPolicyApplyConfiguration{} + case v1alpha2.SchemeGroupVersion.WithKind("BackendLBPolicySpec"): + return &apisv1alpha2.BackendLBPolicySpecApplyConfiguration{} case v1alpha2.SchemeGroupVersion.WithKind("GRPCRoute"): return &apisv1alpha2.GRPCRouteApplyConfiguration{} case v1alpha2.SchemeGroupVersion.WithKind("LocalPolicyTargetReference"): diff --git a/apis/v1/grpcroute_types.go b/apis/v1/grpcroute_types.go index 691f8e6219..f67bc4cd7b 100644 --- a/apis/v1/grpcroute_types.go +++ b/apis/v1/grpcroute_types.go @@ -267,6 +267,15 @@ type GRPCRouteRule struct { // +optional // +kubebuilder:validation:MaxItems=16 BackendRefs []GRPCBackendRef `json:"backendRefs,omitempty"` + + // SessionPersistence defines and configures session persistence + // for the route rule. + // + // Support: Extended + // + // +optional + // + SessionPersistence *SessionPersistence `json:"sessionPersistence"` } // GRPCRouteMatch defines the predicate used to match requests to a given diff --git a/apis/v1/httproute_types.go b/apis/v1/httproute_types.go index 252a635074..0f2092c040 100644 --- a/apis/v1/httproute_types.go +++ b/apis/v1/httproute_types.go @@ -282,6 +282,15 @@ type HTTPRouteRule struct { // +optional // Timeouts *HTTPRouteTimeouts `json:"timeouts,omitempty"` + + // SessionPersistence defines and configures session persistence + // for the route rule. + // + // Support: Extended + // + // +optional + // + SessionPersistence *SessionPersistence `json:"sessionPersistence"` } // HTTPRouteTimeouts defines timeouts that can be configured for an HTTPRoute. diff --git a/apis/v1/shared_types.go b/apis/v1/shared_types.go index bb40b8880f..bed2cc8b8e 100644 --- a/apis/v1/shared_types.go +++ b/apis/v1/shared_types.go @@ -743,3 +743,115 @@ const ( // Support: Implementation-specific NamedAddressType AddressType = "NamedAddress" ) + +// SessionPersistence defines the desired state of SessionPersistence. +// +kubebuilder:validation:XValidation:message="AbsoluteTimeout must be specified when cookie lifetimeType is Permanent",rule="!has(self.cookieConfig.lifetimeType) || self.cookieConfig.lifetimeType != 'Permanent' || has(self.absoluteTimeout)" +type SessionPersistence struct { + // SessionName defines the name of the persistent session token + // which may be reflected in the cookie or the header. Users + // should avoid reusing session names to prevent unintended + // consequences, such as rejection or unpredictable behavior. + // + // Support: Implementation-specific + // + // +optional + // +kubebuilder:validation:MaxLength=128 + SessionName *string `json:"sessionName,omitempty"` + + // AbsoluteTimeout defines the absolute timeout of the persistent + // session. Once the AbsoluteTimeout duration has elapsed, the + // session becomes invalid. + // + // Support: Extended + // + // +optional + AbsoluteTimeout *Duration `json:"absoluteTimeout,omitempty"` + + // IdleTimeout defines the idle timeout of the persistent session. + // Once the session has been idle for more than the specified + // IdleTimeout duration, the session becomes invalid. + // + // Support: Extended + // + // +optional + IdleTimeout *Duration `json:"idleTimeout,omitempty"` + + // Type defines the type of session persistence such as through + // the use a header or cookie. Defaults to cookie based session + // persistence. + // + // Support: Core for "Cookie" type + // + // Support: Extended for "Header" type + // + // +optional + // +kubebuilder:default=Cookie + Type *SessionPersistenceType `json:"type,omitempty"` + + // CookieConfig provides configuration settings that are specific + // to cookie-based session persistence. + // + // Support: Core + // + // +optional + CookieConfig *CookieConfig `json:"cookieConfig,omitempty"` +} + +// +kubebuilder:validation:Enum=Cookie;Header +type SessionPersistenceType string + +const ( + // CookieBasedSessionPersistence specifies cookie-based session + // persistence. + // + // Support: Core + CookieBasedSessionPersistence SessionPersistenceType = "Cookie" + + // HeaderBasedSessionPersistence specifies header-based session + // persistence. + // + // Support: Extended + HeaderBasedSessionPersistence SessionPersistenceType = "Header" +) + +// CookieConfig defines the configuration for cookie-based session persistence. +type CookieConfig struct { + // LifetimeType specifies whether the cookie has a permanent or + // session-based lifetime. A permanent cookie persists until its + // specified expiry time, defined by the Expires or Max-Age cookie + // attributes, while a session cookie is deleted when the current + // session ends. + // + // When set to "Permanent", AbsoluteTimeout indicates the + // cookie's lifetime via the Expires or Max-Age cookie attributes + // and is required. + // + // When set to "Session", AbsoluteTimeout indicates the + // absolute lifetime of the cookie tracked by the gateway and + // is optional. + // + // Support: Core for "Session" type + // + // Support: Extended for "Permanent" type + // + // +optional + // +kubebuilder:default=Session + LifetimeType *CookieLifetimeType `json:"lifetimeType,omitempty"` +} + +// +kubebuilder:validation:Enum=Permanent;Session +type CookieLifetimeType string + +const ( + // SessionCookieLifetimeType specifies the type for a session + // cookie. + // + // Support: Core + SessionCookieLifetimeType CookieLifetimeType = "Session" + + // PermanentCookieLifetimeType specifies the type for a permanent + // cookie. + // + // Support: Extended + PermanentCookieLifetimeType CookieLifetimeType = "Permanent" +) diff --git a/apis/v1/zz_generated.deepcopy.go b/apis/v1/zz_generated.deepcopy.go index 3cde481a77..1d919fa380 100644 --- a/apis/v1/zz_generated.deepcopy.go +++ b/apis/v1/zz_generated.deepcopy.go @@ -130,6 +130,26 @@ func (in *CommonRouteSpec) DeepCopy() *CommonRouteSpec { return out } +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *CookieConfig) DeepCopyInto(out *CookieConfig) { + *out = *in + if in.LifetimeType != nil { + in, out := &in.LifetimeType, &out.LifetimeType + *out = new(CookieLifetimeType) + **out = **in + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new CookieConfig. +func (in *CookieConfig) DeepCopy() *CookieConfig { + if in == nil { + return nil + } + out := new(CookieConfig) + in.DeepCopyInto(out) + return out +} + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *FrontendTLSValidation) DeepCopyInto(out *FrontendTLSValidation) { *out = *in @@ -370,6 +390,11 @@ func (in *GRPCRouteRule) DeepCopyInto(out *GRPCRouteRule) { (*in)[i].DeepCopyInto(&(*out)[i]) } } + if in.SessionPersistence != nil { + in, out := &in.SessionPersistence, &out.SessionPersistence + *out = new(SessionPersistence) + (*in).DeepCopyInto(*out) + } } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new GRPCRouteRule. @@ -1165,6 +1190,11 @@ func (in *HTTPRouteRule) DeepCopyInto(out *HTTPRouteRule) { *out = new(HTTPRouteTimeouts) (*in).DeepCopyInto(*out) } + if in.SessionPersistence != nil { + in, out := &in.SessionPersistence, &out.SessionPersistence + *out = new(SessionPersistence) + (*in).DeepCopyInto(*out) + } } // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new HTTPRouteRule. @@ -1559,3 +1589,43 @@ func (in *SecretObjectReference) DeepCopy() *SecretObjectReference { in.DeepCopyInto(out) return out } + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *SessionPersistence) DeepCopyInto(out *SessionPersistence) { + *out = *in + if in.SessionName != nil { + in, out := &in.SessionName, &out.SessionName + *out = new(string) + **out = **in + } + if in.AbsoluteTimeout != nil { + in, out := &in.AbsoluteTimeout, &out.AbsoluteTimeout + *out = new(Duration) + **out = **in + } + if in.IdleTimeout != nil { + in, out := &in.IdleTimeout, &out.IdleTimeout + *out = new(Duration) + **out = **in + } + if in.Type != nil { + in, out := &in.Type, &out.Type + *out = new(SessionPersistenceType) + **out = **in + } + if in.CookieConfig != nil { + in, out := &in.CookieConfig, &out.CookieConfig + *out = new(CookieConfig) + (*in).DeepCopyInto(*out) + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new SessionPersistence. +func (in *SessionPersistence) DeepCopy() *SessionPersistence { + if in == nil { + return nil + } + out := new(SessionPersistence) + in.DeepCopyInto(out) + return out +} diff --git a/apis/v1alpha2/backendlbpolicy_types.go b/apis/v1alpha2/backendlbpolicy_types.go new file mode 100644 index 0000000000..5063f0f4e6 --- /dev/null +++ b/apis/v1alpha2/backendlbpolicy_types.go @@ -0,0 +1,74 @@ +/* +Copyright 2024 The Kubernetes Authors. + +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 v1alpha2 + +import ( + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" +) + +// +genclient +// +kubebuilder:object:root=true +// +kubebuilder:subresource:status +// +kubebuilder:storageversion +// +kubebuilder:resource:categories=gateway-api,shortName=blbpolicy +// +kubebuilder:printcolumn:name="Age",type=date,JSONPath=`.metadata.creationTimestamp` + +// BackendLBPolicy provides a way to define load balancing rules +// for a backend. +type BackendLBPolicy struct { + metav1.TypeMeta `json:",inline"` + metav1.ObjectMeta `json:"metadata,omitempty"` + + // Spec defines the desired state of BackendLBPolicy. + Spec BackendLBPolicySpec `json:"spec"` + + // Status defines the current state of BackendLBPolicy. + Status PolicyStatus `json:"status,omitempty"` +} + +// +kubebuilder:object:root=true +// BackendLBPolicyList contains a list of BackendLBPolicies +type BackendLBPolicyList struct { + metav1.TypeMeta `json:",inline"` + metav1.ListMeta `json:"metadata,omitempty"` + Items []BackendLBPolicy `json:"items"` +} + +// BackendLBPolicySpec defines the desired state of +// BackendLBPolicy. +// Note: there is no Override or Default policy configuration. +type BackendLBPolicySpec struct { + // TargetRef identifies an API object to apply policy to. + // Currently, Backends (i.e. Service, ServiceImport, or any + // implementation-specific backendRef) are the only valid API + // target references. + // +listType=map + // +listMapKey=group + // +listMapKey=kind + // +listMapKey=name + // +kubebuilder:validation:MinItems=1 + // +kubebuilder:validation:MaxItems=16 + TargetRefs []LocalPolicyTargetReference `json:"targetRefs"` + + // SessionPersistence defines and configures session persistence + // for the backend. + // + // Support: Extended + // + // +optional + SessionPersistence *SessionPersistence `json:"sessionPersistence"` +} diff --git a/apis/v1alpha2/shared_types.go b/apis/v1alpha2/shared_types.go index a2e484ae4f..af04601e41 100644 --- a/apis/v1alpha2/shared_types.go +++ b/apis/v1alpha2/shared_types.go @@ -384,3 +384,8 @@ const ( // Support: Implementation-specific NamedAddressType AddressType = "NamedAddress" ) + +// SessionPersistence defines the desired state of +// SessionPersistence. +// +k8s:deepcopy-gen=false +type SessionPersistence = v1.SessionPersistence diff --git a/apis/v1alpha2/zz_generated.deepcopy.go b/apis/v1alpha2/zz_generated.deepcopy.go index 7bc87e9568..805d34c608 100644 --- a/apis/v1alpha2/zz_generated.deepcopy.go +++ b/apis/v1alpha2/zz_generated.deepcopy.go @@ -26,6 +26,90 @@ import ( "sigs.k8s.io/gateway-api/apis/v1" ) +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *BackendLBPolicy) DeepCopyInto(out *BackendLBPolicy) { + *out = *in + out.TypeMeta = in.TypeMeta + in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) + in.Spec.DeepCopyInto(&out.Spec) + in.Status.DeepCopyInto(&out.Status) +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new BackendLBPolicy. +func (in *BackendLBPolicy) DeepCopy() *BackendLBPolicy { + if in == nil { + return nil + } + out := new(BackendLBPolicy) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *BackendLBPolicy) DeepCopyObject() runtime.Object { + if c := in.DeepCopy(); c != nil { + return c + } + return nil +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *BackendLBPolicyList) DeepCopyInto(out *BackendLBPolicyList) { + *out = *in + out.TypeMeta = in.TypeMeta + in.ListMeta.DeepCopyInto(&out.ListMeta) + if in.Items != nil { + in, out := &in.Items, &out.Items + *out = make([]BackendLBPolicy, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new BackendLBPolicyList. +func (in *BackendLBPolicyList) DeepCopy() *BackendLBPolicyList { + if in == nil { + return nil + } + out := new(BackendLBPolicyList) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *BackendLBPolicyList) DeepCopyObject() runtime.Object { + if c := in.DeepCopy(); c != nil { + return c + } + return nil +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *BackendLBPolicySpec) DeepCopyInto(out *BackendLBPolicySpec) { + *out = *in + if in.TargetRefs != nil { + in, out := &in.TargetRefs, &out.TargetRefs + *out = make([]LocalPolicyTargetReference, len(*in)) + copy(*out, *in) + } + if in.SessionPersistence != nil { + in, out := &in.SessionPersistence, &out.SessionPersistence + *out = new(v1.SessionPersistence) + (*in).DeepCopyInto(*out) + } +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new BackendLBPolicySpec. +func (in *BackendLBPolicySpec) DeepCopy() *BackendLBPolicySpec { + if in == nil { + return nil + } + out := new(BackendLBPolicySpec) + in.DeepCopyInto(out) + return out +} + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *GRPCRoute) DeepCopyInto(out *GRPCRoute) { *out = *in diff --git a/apis/v1alpha2/zz_generated.register.go b/apis/v1alpha2/zz_generated.register.go index 0cc50c40cb..2fff9ce2ca 100644 --- a/apis/v1alpha2/zz_generated.register.go +++ b/apis/v1alpha2/zz_generated.register.go @@ -58,6 +58,8 @@ func init() { // Adds the list of known types to Scheme. func addKnownTypes(scheme *runtime.Scheme) error { scheme.AddKnownTypes(SchemeGroupVersion, + &BackendLBPolicy{}, + &BackendLBPolicyList{}, &GRPCRoute{}, &GRPCRouteList{}, &ReferenceGrant{}, diff --git a/config/crd/experimental/gateway.networking.k8s.io_backendlbpolicies.yaml b/config/crd/experimental/gateway.networking.k8s.io_backendlbpolicies.yaml new file mode 100644 index 0000000000..73d0ce0ab5 --- /dev/null +++ b/config/crd/experimental/gateway.networking.k8s.io_backendlbpolicies.yaml @@ -0,0 +1,553 @@ +apiVersion: apiextensions.k8s.io/v1 +kind: CustomResourceDefinition +metadata: + annotations: + api-approved.kubernetes.io: https://github.com/kubernetes-sigs/gateway-api/pull/2466 + gateway.networking.k8s.io/bundle-version: v1.0.0 + gateway.networking.k8s.io/channel: experimental + creationTimestamp: null + name: backendlbpolicies.gateway.networking.k8s.io +spec: + group: gateway.networking.k8s.io + names: + categories: + - gateway-api + kind: BackendLBPolicy + listKind: BackendLBPolicyList + plural: backendlbpolicies + shortNames: + - blbpolicy + singular: backendlbpolicy + scope: Namespaced + versions: + - additionalPrinterColumns: + - jsonPath: .metadata.creationTimestamp + name: Age + type: date + name: v1alpha2 + schema: + openAPIV3Schema: + description: |- + BackendLBPolicy provides a way to define load balancing rules + for a backend. + properties: + apiVersion: + description: |- + APIVersion defines the versioned schema of this representation of an object. + Servers should convert recognized schemas to the latest internal value, and + may reject unrecognized values. + More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources + type: string + kind: + description: |- + Kind is a string value representing the REST resource this object represents. + Servers may infer this from the endpoint the client submits requests to. + Cannot be updated. + In CamelCase. + More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds + type: string + metadata: + type: object + spec: + description: Spec defines the desired state of BackendLBPolicy. + properties: + sessionPersistence: + description: |- + SessionPersistence defines and configures session persistence + for the backend. + + + Support: Extended + properties: + absoluteTimeout: + description: |- + AbsoluteTimeout defines the absolute timeout of the persistent + session. Once the AbsoluteTimeout duration has elapsed, the + session becomes invalid. + + + Support: Extended + pattern: ^([0-9]{1,5}(h|m|s|ms)){1,4}$ + type: string + cookieConfig: + description: |- + CookieConfig provides configuration settings that are specific + to cookie-based session persistence. + + + Support: Core + properties: + lifetimeType: + default: Session + description: |- + LifetimeType specifies whether the cookie has a permanent or + session-based lifetime. A permanent cookie persists until its + specified expiry time, defined by the Expires or Max-Age cookie + attributes, while a session cookie is deleted when the current + session ends. + + + When set to "Permanent", AbsoluteTimeout indicates the + cookie's lifetime via the Expires or Max-Age cookie attributes + and is required. + + + When set to "Session", AbsoluteTimeout indicates the + absolute lifetime of the cookie tracked by the gateway and + is optional. + + + Support: Core for "Session" type + + + Support: Extended for "Permanent" type + enum: + - Permanent + - Session + type: string + type: object + idleTimeout: + description: |- + IdleTimeout defines the idle timeout of the persistent session. + Once the session has been idle for more than the specified + IdleTimeout duration, the session becomes invalid. + + + Support: Extended + pattern: ^([0-9]{1,5}(h|m|s|ms)){1,4}$ + type: string + sessionName: + description: |- + SessionName defines the name of the persistent session token + which may be reflected in the cookie or the header. Users + should avoid reusing session names to prevent unintended + consequences, such as rejection or unpredictable behavior. + + + Support: Implementation-specific + maxLength: 128 + type: string + type: + default: Cookie + description: |- + Type defines the type of session persistence such as through + the use a header or cookie. Defaults to cookie based session + persistence. + + + Support: Core for "Cookie" type + + + Support: Extended for "Header" type + enum: + - Cookie + - Header + type: string + type: object + x-kubernetes-validations: + - message: AbsoluteTimeout must be specified when cookie lifetimeType + is Permanent + rule: '!has(self.cookieConfig.lifetimeType) || self.cookieConfig.lifetimeType + != ''Permanent'' || has(self.absoluteTimeout)' + targetRefs: + description: |- + TargetRef identifies an API object to apply policy to. + Currently, Backends (i.e. Service, ServiceImport, or any + implementation-specific backendRef) are the only valid API + target references. + items: + description: |- + LocalPolicyTargetReference identifies an API object to apply a direct or + inherited policy to. This should be used as part of Policy resources + that can target Gateway API resources. For more information on how this + policy attachment model works, and a sample Policy resource, refer to + the policy attachment documentation for Gateway API. + properties: + group: + description: Group is the group of the target resource. + maxLength: 253 + pattern: ^$|^[a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*$ + type: string + kind: + description: Kind is kind of the target resource. + maxLength: 63 + minLength: 1 + pattern: ^[a-zA-Z]([-a-zA-Z0-9]*[a-zA-Z0-9])?$ + type: string + name: + description: Name is the name of the target resource. + maxLength: 253 + minLength: 1 + type: string + required: + - group + - kind + - name + type: object + maxItems: 16 + minItems: 1 + type: array + x-kubernetes-list-map-keys: + - group + - kind + - name + x-kubernetes-list-type: map + required: + - targetRefs + type: object + status: + description: Status defines the current state of BackendLBPolicy. + properties: + ancestors: + description: |- + Ancestors is a list of ancestor resources (usually Gateways) that are + associated with the policy, and the status of the policy with respect to + each ancestor. When this policy attaches to a parent, the controller that + manages the parent and the ancestors MUST add an entry to this list when + the controller first sees the policy and SHOULD update the entry as + appropriate when the relevant ancestor is modified. + + + Note that choosing the relevant ancestor is left to the Policy designers; + an important part of Policy design is designing the right object level at + which to namespace this status. + + + Note also that implementations MUST ONLY populate ancestor status for + the Ancestor resources they are responsible for. Implementations MUST + use the ControllerName field to uniquely identify the entries in this list + that they are responsible for. + + + Note that to achieve this, the list of PolicyAncestorStatus structs + MUST be treated as a map with a composite key, made up of the AncestorRef + and ControllerName fields combined. + + + A maximum of 16 ancestors will be represented in this list. An empty list + means the Policy is not relevant for any ancestors. + + + If this slice is full, implementations MUST NOT add further entries. + Instead they MUST consider the policy unimplementable and signal that + on any related resources such as the ancestor that would be referenced + here. For example, if this list was full on BackendTLSPolicy, no + additional Gateways would be able to reference the Service targeted by + the BackendTLSPolicy. + items: + description: |- + PolicyAncestorStatus describes the status of a route with respect to an + associated Ancestor. + + + Ancestors refer to objects that are either the Target of a policy or above it + in terms of object hierarchy. For example, if a policy targets a Service, the + Policy's Ancestors are, in order, the Service, the HTTPRoute, the Gateway, and + the GatewayClass. Almost always, in this hierarchy, the Gateway will be the most + useful object to place Policy status on, so we recommend that implementations + SHOULD use Gateway as the PolicyAncestorStatus object unless the designers + have a _very_ good reason otherwise. + + + In the context of policy attachment, the Ancestor is used to distinguish which + resource results in a distinct application of this policy. For example, if a policy + targets a Service, it may have a distinct result per attached Gateway. + + + Policies targeting the same resource may have different effects depending on the + ancestors of those resources. For example, different Gateways targeting the same + Service may have different capabilities, especially if they have different underlying + implementations. + + + For example, in BackendTLSPolicy, the Policy attaches to a Service that is + used as a backend in a HTTPRoute that is itself attached to a Gateway. + In this case, the relevant object for status is the Gateway, and that is the + ancestor object referred to in this status. + + + Note that a parent is also an ancestor, so for objects where the parent is the + relevant object for status, this struct SHOULD still be used. + + + This struct is intended to be used in a slice that's effectively a map, + with a composite key made up of the AncestorRef and the ControllerName. + properties: + ancestorRef: + description: |- + AncestorRef corresponds with a ParentRef in the spec that this + PolicyAncestorStatus struct describes the status of. + properties: + group: + default: gateway.networking.k8s.io + description: |- + Group is the group of the referent. + When unspecified, "gateway.networking.k8s.io" is inferred. + To set the core API group (such as for a "Service" kind referent), + Group must be explicitly set to "" (empty string). + + + Support: Core + maxLength: 253 + pattern: ^$|^[a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*$ + type: string + kind: + default: Gateway + description: |- + Kind is kind of the referent. + + + There are two kinds of parent resources with "Core" support: + + + * Gateway (Gateway conformance profile) + * Service (Mesh conformance profile, ClusterIP Services only) + + + Support for other resources is Implementation-Specific. + maxLength: 63 + minLength: 1 + pattern: ^[a-zA-Z]([-a-zA-Z0-9]*[a-zA-Z0-9])?$ + type: string + name: + description: |- + Name is the name of the referent. + + + Support: Core + maxLength: 253 + minLength: 1 + type: string + namespace: + description: |- + Namespace is the namespace of the referent. When unspecified, this refers + to the local namespace of the Route. + + + Note that there are specific rules for ParentRefs which cross namespace + boundaries. Cross-namespace references are only valid if they are explicitly + allowed by something in the namespace they are referring to. For example: + Gateway has the AllowedRoutes field, and ReferenceGrant provides a + generic way to enable any other kind of cross-namespace reference. + + + + ParentRefs from a Route to a Service in the same namespace are "producer" + routes, which apply default routing rules to inbound connections from + any namespace to the Service. + + + ParentRefs from a Route to a Service in a different namespace are + "consumer" routes, and these routing rules are only applied to outbound + connections originating from the same namespace as the Route, for which + the intended destination of the connections are a Service targeted as a + ParentRef of the Route. + + + + Support: Core + maxLength: 63 + minLength: 1 + pattern: ^[a-z0-9]([-a-z0-9]*[a-z0-9])?$ + type: string + port: + description: |- + Port is the network port this Route targets. It can be interpreted + differently based on the type of parent resource. + + + When the parent resource is a Gateway, this targets all listeners + listening on the specified port that also support this kind of Route(and + select this Route). It's not recommended to set `Port` unless the + networking behaviors specified in a Route must apply to a specific port + as opposed to a listener(s) whose port(s) may be changed. When both Port + and SectionName are specified, the name and port of the selected listener + must match both specified values. + + + + When the parent resource is a Service, this targets a specific port in the + Service spec. When both Port (experimental) and SectionName are specified, + the name and port of the selected port must match both specified values. + + + + Implementations MAY choose to support other parent resources. + Implementations supporting other types of parent resources MUST clearly + document how/if Port is interpreted. + + + For the purpose of status, an attachment is considered successful as + long as the parent resource accepts it partially. For example, Gateway + listeners can restrict which Routes can attach to them by Route kind, + namespace, or hostname. If 1 of 2 Gateway listeners accept attachment + from the referencing Route, the Route MUST be considered successfully + attached. If no Gateway listeners accept attachment from this Route, + the Route MUST be considered detached from the Gateway. + + + Support: Extended + format: int32 + maximum: 65535 + minimum: 1 + type: integer + sectionName: + description: |- + SectionName is the name of a section within the target resource. In the + following resources, SectionName is interpreted as the following: + + + * Gateway: Listener name. When both Port (experimental) and SectionName + are specified, the name and port of the selected listener must match + both specified values. + * Service: Port name. When both Port (experimental) and SectionName + are specified, the name and port of the selected listener must match + both specified values. + + + Implementations MAY choose to support attaching Routes to other resources. + If that is the case, they MUST clearly document how SectionName is + interpreted. + + + When unspecified (empty string), this will reference the entire resource. + For the purpose of status, an attachment is considered successful if at + least one section in the parent resource accepts it. For example, Gateway + listeners can restrict which Routes can attach to them by Route kind, + namespace, or hostname. If 1 of 2 Gateway listeners accept attachment from + the referencing Route, the Route MUST be considered successfully + attached. If no Gateway listeners accept attachment from this Route, the + Route MUST be considered detached from the Gateway. + + + Support: Core + maxLength: 253 + minLength: 1 + pattern: ^[a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*$ + type: string + required: + - name + type: object + conditions: + description: Conditions describes the status of the Policy with + respect to the given Ancestor. + items: + description: "Condition contains details for one aspect of + the current state of this API Resource.\n---\nThis struct + is intended for direct use as an array at the field path + .status.conditions. For example,\n\n\n\ttype FooStatus + struct{\n\t // Represents the observations of a foo's + current state.\n\t // Known .status.conditions.type are: + \"Available\", \"Progressing\", and \"Degraded\"\n\t // + +patchMergeKey=type\n\t // +patchStrategy=merge\n\t // + +listType=map\n\t // +listMapKey=type\n\t Conditions + []metav1.Condition `json:\"conditions,omitempty\" patchStrategy:\"merge\" + patchMergeKey:\"type\" protobuf:\"bytes,1,rep,name=conditions\"`\n\n\n\t + \ // other fields\n\t}" + 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. + --- + Many .condition.type values are consistent across resources like Available, but because arbitrary conditions can be + useful (see .node.status.conditions), the ability to deconflict is important. + The regex it matches is (dns1123SubdomainFmt/)?(qualifiedNameFmt) + 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: |- + 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-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*\/[A-Za-z0-9\/\-._~%!$&'()*+,;=:]+$ + type: string + required: + - ancestorRef + - controllerName + type: object + maxItems: 16 + type: array + required: + - ancestors + type: object + required: + - spec + type: object + served: true + storage: true + subresources: + status: {} +status: + acceptedNames: + kind: "" + plural: "" + conditions: null + storedVersions: null diff --git a/config/crd/experimental/gateway.networking.k8s.io_grpcroutes.yaml b/config/crd/experimental/gateway.networking.k8s.io_grpcroutes.yaml index cd4256cff7..42f33343eb 100644 --- a/config/crd/experimental/gateway.networking.k8s.io_grpcroutes.yaml +++ b/config/crd/experimental/gateway.networking.k8s.io_grpcroutes.yaml @@ -1927,6 +1927,106 @@ spec: type: object maxItems: 8 type: array + sessionPersistence: + description: |+ + SessionPersistence defines and configures session persistence + for the route rule. + + + Support: Extended + + + properties: + absoluteTimeout: + description: |- + AbsoluteTimeout defines the absolute timeout of the persistent + session. Once the AbsoluteTimeout duration has elapsed, the + session becomes invalid. + + + Support: Extended + pattern: ^([0-9]{1,5}(h|m|s|ms)){1,4}$ + type: string + cookieConfig: + description: |- + CookieConfig provides configuration settings that are specific + to cookie-based session persistence. + + + Support: Core + properties: + lifetimeType: + default: Session + description: |- + LifetimeType specifies whether the cookie has a permanent or + session-based lifetime. A permanent cookie persists until its + specified expiry time, defined by the Expires or Max-Age cookie + attributes, while a session cookie is deleted when the current + session ends. + + + When set to "Permanent", AbsoluteTimeout indicates the + cookie's lifetime via the Expires or Max-Age cookie attributes + and is required. + + + When set to "Session", AbsoluteTimeout indicates the + absolute lifetime of the cookie tracked by the gateway and + is optional. + + + Support: Core for "Session" type + + + Support: Extended for "Permanent" type + enum: + - Permanent + - Session + type: string + type: object + idleTimeout: + description: |- + IdleTimeout defines the idle timeout of the persistent session. + Once the session has been idle for more than the specified + IdleTimeout duration, the session becomes invalid. + + + Support: Extended + pattern: ^([0-9]{1,5}(h|m|s|ms)){1,4}$ + type: string + sessionName: + description: |- + SessionName defines the name of the persistent session token + which may be reflected in the cookie or the header. Users + should avoid reusing session names to prevent unintended + consequences, such as rejection or unpredictable behavior. + + + Support: Implementation-specific + maxLength: 128 + type: string + type: + default: Cookie + description: |- + Type defines the type of session persistence such as through + the use a header or cookie. Defaults to cookie based session + persistence. + + + Support: Core for "Cookie" type + + + Support: Extended for "Header" type + enum: + - Cookie + - Header + type: string + type: object + x-kubernetes-validations: + - message: AbsoluteTimeout must be specified when cookie lifetimeType + is Permanent + rule: '!has(self.cookieConfig.lifetimeType) || self.cookieConfig.lifetimeType + != ''Permanent'' || has(self.absoluteTimeout)' type: object maxItems: 16 type: array @@ -4154,6 +4254,106 @@ spec: type: object maxItems: 8 type: array + sessionPersistence: + description: |+ + SessionPersistence defines and configures session persistence + for the route rule. + + + Support: Extended + + + properties: + absoluteTimeout: + description: |- + AbsoluteTimeout defines the absolute timeout of the persistent + session. Once the AbsoluteTimeout duration has elapsed, the + session becomes invalid. + + + Support: Extended + pattern: ^([0-9]{1,5}(h|m|s|ms)){1,4}$ + type: string + cookieConfig: + description: |- + CookieConfig provides configuration settings that are specific + to cookie-based session persistence. + + + Support: Core + properties: + lifetimeType: + default: Session + description: |- + LifetimeType specifies whether the cookie has a permanent or + session-based lifetime. A permanent cookie persists until its + specified expiry time, defined by the Expires or Max-Age cookie + attributes, while a session cookie is deleted when the current + session ends. + + + When set to "Permanent", AbsoluteTimeout indicates the + cookie's lifetime via the Expires or Max-Age cookie attributes + and is required. + + + When set to "Session", AbsoluteTimeout indicates the + absolute lifetime of the cookie tracked by the gateway and + is optional. + + + Support: Core for "Session" type + + + Support: Extended for "Permanent" type + enum: + - Permanent + - Session + type: string + type: object + idleTimeout: + description: |- + IdleTimeout defines the idle timeout of the persistent session. + Once the session has been idle for more than the specified + IdleTimeout duration, the session becomes invalid. + + + Support: Extended + pattern: ^([0-9]{1,5}(h|m|s|ms)){1,4}$ + type: string + sessionName: + description: |- + SessionName defines the name of the persistent session token + which may be reflected in the cookie or the header. Users + should avoid reusing session names to prevent unintended + consequences, such as rejection or unpredictable behavior. + + + Support: Implementation-specific + maxLength: 128 + type: string + type: + default: Cookie + description: |- + Type defines the type of session persistence such as through + the use a header or cookie. Defaults to cookie based session + persistence. + + + Support: Core for "Cookie" type + + + Support: Extended for "Header" type + enum: + - Cookie + - Header + type: string + type: object + x-kubernetes-validations: + - message: AbsoluteTimeout must be specified when cookie lifetimeType + is Permanent + rule: '!has(self.cookieConfig.lifetimeType) || self.cookieConfig.lifetimeType + != ''Permanent'' || has(self.absoluteTimeout)' type: object maxItems: 16 type: array diff --git a/config/crd/experimental/gateway.networking.k8s.io_httproutes.yaml b/config/crd/experimental/gateway.networking.k8s.io_httproutes.yaml index 08e1be80b8..6eae875e84 100644 --- a/config/crd/experimental/gateway.networking.k8s.io_httproutes.yaml +++ b/config/crd/experimental/gateway.networking.k8s.io_httproutes.yaml @@ -2708,6 +2708,106 @@ spec: type: object maxItems: 8 type: array + sessionPersistence: + description: |+ + SessionPersistence defines and configures session persistence + for the route rule. + + + Support: Extended + + + properties: + absoluteTimeout: + description: |- + AbsoluteTimeout defines the absolute timeout of the persistent + session. Once the AbsoluteTimeout duration has elapsed, the + session becomes invalid. + + + Support: Extended + pattern: ^([0-9]{1,5}(h|m|s|ms)){1,4}$ + type: string + cookieConfig: + description: |- + CookieConfig provides configuration settings that are specific + to cookie-based session persistence. + + + Support: Core + properties: + lifetimeType: + default: Session + description: |- + LifetimeType specifies whether the cookie has a permanent or + session-based lifetime. A permanent cookie persists until its + specified expiry time, defined by the Expires or Max-Age cookie + attributes, while a session cookie is deleted when the current + session ends. + + + When set to "Permanent", AbsoluteTimeout indicates the + cookie's lifetime via the Expires or Max-Age cookie attributes + and is required. + + + When set to "Session", AbsoluteTimeout indicates the + absolute lifetime of the cookie tracked by the gateway and + is optional. + + + Support: Core for "Session" type + + + Support: Extended for "Permanent" type + enum: + - Permanent + - Session + type: string + type: object + idleTimeout: + description: |- + IdleTimeout defines the idle timeout of the persistent session. + Once the session has been idle for more than the specified + IdleTimeout duration, the session becomes invalid. + + + Support: Extended + pattern: ^([0-9]{1,5}(h|m|s|ms)){1,4}$ + type: string + sessionName: + description: |- + SessionName defines the name of the persistent session token + which may be reflected in the cookie or the header. Users + should avoid reusing session names to prevent unintended + consequences, such as rejection or unpredictable behavior. + + + Support: Implementation-specific + maxLength: 128 + type: string + type: + default: Cookie + description: |- + Type defines the type of session persistence such as through + the use a header or cookie. Defaults to cookie based session + persistence. + + + Support: Core for "Cookie" type + + + Support: Extended for "Header" type + enum: + - Cookie + - Header + type: string + type: object + x-kubernetes-validations: + - message: AbsoluteTimeout must be specified when cookie lifetimeType + is Permanent + rule: '!has(self.cookieConfig.lifetimeType) || self.cookieConfig.lifetimeType + != ''Permanent'' || has(self.absoluteTimeout)' timeouts: description: |+ Timeouts defines the timeouts that can be configured for an HTTP request. @@ -5821,6 +5921,106 @@ spec: type: object maxItems: 8 type: array + sessionPersistence: + description: |+ + SessionPersistence defines and configures session persistence + for the route rule. + + + Support: Extended + + + properties: + absoluteTimeout: + description: |- + AbsoluteTimeout defines the absolute timeout of the persistent + session. Once the AbsoluteTimeout duration has elapsed, the + session becomes invalid. + + + Support: Extended + pattern: ^([0-9]{1,5}(h|m|s|ms)){1,4}$ + type: string + cookieConfig: + description: |- + CookieConfig provides configuration settings that are specific + to cookie-based session persistence. + + + Support: Core + properties: + lifetimeType: + default: Session + description: |- + LifetimeType specifies whether the cookie has a permanent or + session-based lifetime. A permanent cookie persists until its + specified expiry time, defined by the Expires or Max-Age cookie + attributes, while a session cookie is deleted when the current + session ends. + + + When set to "Permanent", AbsoluteTimeout indicates the + cookie's lifetime via the Expires or Max-Age cookie attributes + and is required. + + + When set to "Session", AbsoluteTimeout indicates the + absolute lifetime of the cookie tracked by the gateway and + is optional. + + + Support: Core for "Session" type + + + Support: Extended for "Permanent" type + enum: + - Permanent + - Session + type: string + type: object + idleTimeout: + description: |- + IdleTimeout defines the idle timeout of the persistent session. + Once the session has been idle for more than the specified + IdleTimeout duration, the session becomes invalid. + + + Support: Extended + pattern: ^([0-9]{1,5}(h|m|s|ms)){1,4}$ + type: string + sessionName: + description: |- + SessionName defines the name of the persistent session token + which may be reflected in the cookie or the header. Users + should avoid reusing session names to prevent unintended + consequences, such as rejection or unpredictable behavior. + + + Support: Implementation-specific + maxLength: 128 + type: string + type: + default: Cookie + description: |- + Type defines the type of session persistence such as through + the use a header or cookie. Defaults to cookie based session + persistence. + + + Support: Core for "Cookie" type + + + Support: Extended for "Header" type + enum: + - Cookie + - Header + type: string + type: object + x-kubernetes-validations: + - message: AbsoluteTimeout must be specified when cookie lifetimeType + is Permanent + rule: '!has(self.cookieConfig.lifetimeType) || self.cookieConfig.lifetimeType + != ''Permanent'' || has(self.absoluteTimeout)' timeouts: description: |+ Timeouts defines the timeouts that can be configured for an HTTP request. diff --git a/geps/gep-1619/index.md b/geps/gep-1619/index.md index 6e5139fde5..52096b7752 100644 --- a/geps/gep-1619/index.md +++ b/geps/gep-1619/index.md @@ -1,7 +1,7 @@ # GEP-1619: Session Persistence via BackendLBPolicy * Issue: [#1619](https://github.com/kubernetes-sigs/gateway-api/issues/1619) -* Status: Provisional +* Status: Experimental (See status definitions [here](/geps/overview/#gep-states).) @@ -468,7 +468,13 @@ type BackendLBPolicySpec struct { // Currently, Backends (i.e. Service, ServiceImport, or any // implementation-specific backendRef) are the only valid API // target references. - TargetRef gatewayv1a2.PolicyTargetReference `json:"targetRef"` + // +listType=map + // +listMapKey=group + // +listMapKey=kind + // +listMapKey=name + // +kubebuilder:validation:MinItems=1 + // +kubebuilder:validation:MaxItems=16 + TargetRefs []LocalPolicyTargetReference `json:"targetRefs"` // SessionPersistence defines and configures session persistence // for the backend. @@ -481,6 +487,7 @@ type BackendLBPolicySpec struct { // SessionPersistence defines the desired state of // SessionPersistence. +// +kubebuilder:validation:XValidation:rule="!has(self.cookieConfig.lifetimeType) || self.cookieConfig.lifetimeType != 'Permanent' || has(self.absoluteTimeout)",message="AbsoluteTimeout must be specified when cookie lifetimeType is Permanent" type SessionPersistence struct { // SessionName defines the name of the persistent session token // which may be reflected in the cookie or the header. Users @@ -490,7 +497,7 @@ type SessionPersistence struct { // Support: Implementation-specific // // +optional - // +kubebuilder:validation:MaxLength=4096 + // +kubebuilder:validation:MaxLength=128 SessionName *string `json:"sessionName,omitempty"` // AbsoluteTimeout defines the absolute timeout of the persistent diff --git a/mkdocs.yml b/mkdocs.yml index ea7bada33b..8dfd21bd5c 100644 --- a/mkdocs.yml +++ b/mkdocs.yml @@ -112,7 +112,6 @@ nav: - Provisional: - geps/gep-91/index.md - geps/gep-995/index.md - - geps/gep-1619/index.md - geps/gep-1651/index.md - geps/gep-1867/index.md - geps/gep-2648/index.md @@ -121,6 +120,7 @@ nav: # - - Experimental: - geps/gep-1016/index.md + - geps/gep-1619/index.md - geps/gep-1742/index.md - geps/gep-1748/index.md - geps/gep-1762/index.md diff --git a/pkg/client/clientset/versioned/typed/apis/v1alpha2/apis_client.go b/pkg/client/clientset/versioned/typed/apis/v1alpha2/apis_client.go index ff577d35e2..8431bb1688 100644 --- a/pkg/client/clientset/versioned/typed/apis/v1alpha2/apis_client.go +++ b/pkg/client/clientset/versioned/typed/apis/v1alpha2/apis_client.go @@ -28,6 +28,7 @@ import ( type GatewayV1alpha2Interface interface { RESTClient() rest.Interface + BackendLBPoliciesGetter GRPCRoutesGetter ReferenceGrantsGetter TCPRoutesGetter @@ -40,6 +41,10 @@ type GatewayV1alpha2Client struct { restClient rest.Interface } +func (c *GatewayV1alpha2Client) BackendLBPolicies(namespace string) BackendLBPolicyInterface { + return newBackendLBPolicies(c, namespace) +} + func (c *GatewayV1alpha2Client) GRPCRoutes(namespace string) GRPCRouteInterface { return newGRPCRoutes(c, namespace) } diff --git a/pkg/client/clientset/versioned/typed/apis/v1alpha2/backendlbpolicy.go b/pkg/client/clientset/versioned/typed/apis/v1alpha2/backendlbpolicy.go new file mode 100644 index 0000000000..514cac1e28 --- /dev/null +++ b/pkg/client/clientset/versioned/typed/apis/v1alpha2/backendlbpolicy.go @@ -0,0 +1,256 @@ +/* +Copyright The Kubernetes Authors. + +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. +*/ + +// Code generated by client-gen. DO NOT EDIT. + +package v1alpha2 + +import ( + "context" + json "encoding/json" + "fmt" + "time" + + v1 "k8s.io/apimachinery/pkg/apis/meta/v1" + types "k8s.io/apimachinery/pkg/types" + watch "k8s.io/apimachinery/pkg/watch" + rest "k8s.io/client-go/rest" + apisv1alpha2 "sigs.k8s.io/gateway-api/apis/applyconfiguration/apis/v1alpha2" + v1alpha2 "sigs.k8s.io/gateway-api/apis/v1alpha2" + scheme "sigs.k8s.io/gateway-api/pkg/client/clientset/versioned/scheme" +) + +// BackendLBPoliciesGetter has a method to return a BackendLBPolicyInterface. +// A group's client should implement this interface. +type BackendLBPoliciesGetter interface { + BackendLBPolicies(namespace string) BackendLBPolicyInterface +} + +// BackendLBPolicyInterface has methods to work with BackendLBPolicy resources. +type BackendLBPolicyInterface interface { + Create(ctx context.Context, backendLBPolicy *v1alpha2.BackendLBPolicy, opts v1.CreateOptions) (*v1alpha2.BackendLBPolicy, error) + Update(ctx context.Context, backendLBPolicy *v1alpha2.BackendLBPolicy, opts v1.UpdateOptions) (*v1alpha2.BackendLBPolicy, error) + UpdateStatus(ctx context.Context, backendLBPolicy *v1alpha2.BackendLBPolicy, opts v1.UpdateOptions) (*v1alpha2.BackendLBPolicy, error) + Delete(ctx context.Context, name string, opts v1.DeleteOptions) error + DeleteCollection(ctx context.Context, opts v1.DeleteOptions, listOpts v1.ListOptions) error + Get(ctx context.Context, name string, opts v1.GetOptions) (*v1alpha2.BackendLBPolicy, error) + List(ctx context.Context, opts v1.ListOptions) (*v1alpha2.BackendLBPolicyList, error) + Watch(ctx context.Context, opts v1.ListOptions) (watch.Interface, error) + Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts v1.PatchOptions, subresources ...string) (result *v1alpha2.BackendLBPolicy, err error) + Apply(ctx context.Context, backendLBPolicy *apisv1alpha2.BackendLBPolicyApplyConfiguration, opts v1.ApplyOptions) (result *v1alpha2.BackendLBPolicy, err error) + ApplyStatus(ctx context.Context, backendLBPolicy *apisv1alpha2.BackendLBPolicyApplyConfiguration, opts v1.ApplyOptions) (result *v1alpha2.BackendLBPolicy, err error) + BackendLBPolicyExpansion +} + +// backendLBPolicies implements BackendLBPolicyInterface +type backendLBPolicies struct { + client rest.Interface + ns string +} + +// newBackendLBPolicies returns a BackendLBPolicies +func newBackendLBPolicies(c *GatewayV1alpha2Client, namespace string) *backendLBPolicies { + return &backendLBPolicies{ + client: c.RESTClient(), + ns: namespace, + } +} + +// Get takes name of the backendLBPolicy, and returns the corresponding backendLBPolicy object, and an error if there is any. +func (c *backendLBPolicies) Get(ctx context.Context, name string, options v1.GetOptions) (result *v1alpha2.BackendLBPolicy, err error) { + result = &v1alpha2.BackendLBPolicy{} + err = c.client.Get(). + Namespace(c.ns). + Resource("backendlbpolicies"). + Name(name). + VersionedParams(&options, scheme.ParameterCodec). + Do(ctx). + Into(result) + return +} + +// List takes label and field selectors, and returns the list of BackendLBPolicies that match those selectors. +func (c *backendLBPolicies) List(ctx context.Context, opts v1.ListOptions) (result *v1alpha2.BackendLBPolicyList, err error) { + var timeout time.Duration + if opts.TimeoutSeconds != nil { + timeout = time.Duration(*opts.TimeoutSeconds) * time.Second + } + result = &v1alpha2.BackendLBPolicyList{} + err = c.client.Get(). + Namespace(c.ns). + Resource("backendlbpolicies"). + VersionedParams(&opts, scheme.ParameterCodec). + Timeout(timeout). + Do(ctx). + Into(result) + return +} + +// Watch returns a watch.Interface that watches the requested backendLBPolicies. +func (c *backendLBPolicies) Watch(ctx context.Context, opts v1.ListOptions) (watch.Interface, error) { + var timeout time.Duration + if opts.TimeoutSeconds != nil { + timeout = time.Duration(*opts.TimeoutSeconds) * time.Second + } + opts.Watch = true + return c.client.Get(). + Namespace(c.ns). + Resource("backendlbpolicies"). + VersionedParams(&opts, scheme.ParameterCodec). + Timeout(timeout). + Watch(ctx) +} + +// Create takes the representation of a backendLBPolicy and creates it. Returns the server's representation of the backendLBPolicy, and an error, if there is any. +func (c *backendLBPolicies) Create(ctx context.Context, backendLBPolicy *v1alpha2.BackendLBPolicy, opts v1.CreateOptions) (result *v1alpha2.BackendLBPolicy, err error) { + result = &v1alpha2.BackendLBPolicy{} + err = c.client.Post(). + Namespace(c.ns). + Resource("backendlbpolicies"). + VersionedParams(&opts, scheme.ParameterCodec). + Body(backendLBPolicy). + Do(ctx). + Into(result) + return +} + +// Update takes the representation of a backendLBPolicy and updates it. Returns the server's representation of the backendLBPolicy, and an error, if there is any. +func (c *backendLBPolicies) Update(ctx context.Context, backendLBPolicy *v1alpha2.BackendLBPolicy, opts v1.UpdateOptions) (result *v1alpha2.BackendLBPolicy, err error) { + result = &v1alpha2.BackendLBPolicy{} + err = c.client.Put(). + Namespace(c.ns). + Resource("backendlbpolicies"). + Name(backendLBPolicy.Name). + VersionedParams(&opts, scheme.ParameterCodec). + Body(backendLBPolicy). + Do(ctx). + Into(result) + return +} + +// UpdateStatus was generated because the type contains a Status member. +// Add a +genclient:noStatus comment above the type to avoid generating UpdateStatus(). +func (c *backendLBPolicies) UpdateStatus(ctx context.Context, backendLBPolicy *v1alpha2.BackendLBPolicy, opts v1.UpdateOptions) (result *v1alpha2.BackendLBPolicy, err error) { + result = &v1alpha2.BackendLBPolicy{} + err = c.client.Put(). + Namespace(c.ns). + Resource("backendlbpolicies"). + Name(backendLBPolicy.Name). + SubResource("status"). + VersionedParams(&opts, scheme.ParameterCodec). + Body(backendLBPolicy). + Do(ctx). + Into(result) + return +} + +// Delete takes name of the backendLBPolicy and deletes it. Returns an error if one occurs. +func (c *backendLBPolicies) Delete(ctx context.Context, name string, opts v1.DeleteOptions) error { + return c.client.Delete(). + Namespace(c.ns). + Resource("backendlbpolicies"). + Name(name). + Body(&opts). + Do(ctx). + Error() +} + +// DeleteCollection deletes a collection of objects. +func (c *backendLBPolicies) DeleteCollection(ctx context.Context, opts v1.DeleteOptions, listOpts v1.ListOptions) error { + var timeout time.Duration + if listOpts.TimeoutSeconds != nil { + timeout = time.Duration(*listOpts.TimeoutSeconds) * time.Second + } + return c.client.Delete(). + Namespace(c.ns). + Resource("backendlbpolicies"). + VersionedParams(&listOpts, scheme.ParameterCodec). + Timeout(timeout). + Body(&opts). + Do(ctx). + Error() +} + +// Patch applies the patch and returns the patched backendLBPolicy. +func (c *backendLBPolicies) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts v1.PatchOptions, subresources ...string) (result *v1alpha2.BackendLBPolicy, err error) { + result = &v1alpha2.BackendLBPolicy{} + err = c.client.Patch(pt). + Namespace(c.ns). + Resource("backendlbpolicies"). + Name(name). + SubResource(subresources...). + VersionedParams(&opts, scheme.ParameterCodec). + Body(data). + Do(ctx). + Into(result) + return +} + +// Apply takes the given apply declarative configuration, applies it and returns the applied backendLBPolicy. +func (c *backendLBPolicies) Apply(ctx context.Context, backendLBPolicy *apisv1alpha2.BackendLBPolicyApplyConfiguration, opts v1.ApplyOptions) (result *v1alpha2.BackendLBPolicy, err error) { + if backendLBPolicy == nil { + return nil, fmt.Errorf("backendLBPolicy provided to Apply must not be nil") + } + patchOpts := opts.ToPatchOptions() + data, err := json.Marshal(backendLBPolicy) + if err != nil { + return nil, err + } + name := backendLBPolicy.Name + if name == nil { + return nil, fmt.Errorf("backendLBPolicy.Name must be provided to Apply") + } + result = &v1alpha2.BackendLBPolicy{} + err = c.client.Patch(types.ApplyPatchType). + Namespace(c.ns). + Resource("backendlbpolicies"). + Name(*name). + VersionedParams(&patchOpts, scheme.ParameterCodec). + Body(data). + Do(ctx). + Into(result) + return +} + +// ApplyStatus was generated because the type contains a Status member. +// Add a +genclient:noStatus comment above the type to avoid generating ApplyStatus(). +func (c *backendLBPolicies) ApplyStatus(ctx context.Context, backendLBPolicy *apisv1alpha2.BackendLBPolicyApplyConfiguration, opts v1.ApplyOptions) (result *v1alpha2.BackendLBPolicy, err error) { + if backendLBPolicy == nil { + return nil, fmt.Errorf("backendLBPolicy provided to Apply must not be nil") + } + patchOpts := opts.ToPatchOptions() + data, err := json.Marshal(backendLBPolicy) + if err != nil { + return nil, err + } + + name := backendLBPolicy.Name + if name == nil { + return nil, fmt.Errorf("backendLBPolicy.Name must be provided to Apply") + } + + result = &v1alpha2.BackendLBPolicy{} + err = c.client.Patch(types.ApplyPatchType). + Namespace(c.ns). + Resource("backendlbpolicies"). + Name(*name). + SubResource("status"). + VersionedParams(&patchOpts, scheme.ParameterCodec). + Body(data). + Do(ctx). + Into(result) + return +} diff --git a/pkg/client/clientset/versioned/typed/apis/v1alpha2/fake/fake_apis_client.go b/pkg/client/clientset/versioned/typed/apis/v1alpha2/fake/fake_apis_client.go index a2e69883a0..7ea0de6477 100644 --- a/pkg/client/clientset/versioned/typed/apis/v1alpha2/fake/fake_apis_client.go +++ b/pkg/client/clientset/versioned/typed/apis/v1alpha2/fake/fake_apis_client.go @@ -28,6 +28,10 @@ type FakeGatewayV1alpha2 struct { *testing.Fake } +func (c *FakeGatewayV1alpha2) BackendLBPolicies(namespace string) v1alpha2.BackendLBPolicyInterface { + return &FakeBackendLBPolicies{c, namespace} +} + func (c *FakeGatewayV1alpha2) GRPCRoutes(namespace string) v1alpha2.GRPCRouteInterface { return &FakeGRPCRoutes{c, namespace} } diff --git a/pkg/client/clientset/versioned/typed/apis/v1alpha2/fake/fake_backendlbpolicy.go b/pkg/client/clientset/versioned/typed/apis/v1alpha2/fake/fake_backendlbpolicy.go new file mode 100644 index 0000000000..dab088600b --- /dev/null +++ b/pkg/client/clientset/versioned/typed/apis/v1alpha2/fake/fake_backendlbpolicy.go @@ -0,0 +1,189 @@ +/* +Copyright The Kubernetes Authors. + +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. +*/ + +// Code generated by client-gen. DO NOT EDIT. + +package fake + +import ( + "context" + json "encoding/json" + "fmt" + + v1 "k8s.io/apimachinery/pkg/apis/meta/v1" + labels "k8s.io/apimachinery/pkg/labels" + types "k8s.io/apimachinery/pkg/types" + watch "k8s.io/apimachinery/pkg/watch" + testing "k8s.io/client-go/testing" + apisv1alpha2 "sigs.k8s.io/gateway-api/apis/applyconfiguration/apis/v1alpha2" + v1alpha2 "sigs.k8s.io/gateway-api/apis/v1alpha2" +) + +// FakeBackendLBPolicies implements BackendLBPolicyInterface +type FakeBackendLBPolicies struct { + Fake *FakeGatewayV1alpha2 + ns string +} + +var backendlbpoliciesResource = v1alpha2.SchemeGroupVersion.WithResource("backendlbpolicies") + +var backendlbpoliciesKind = v1alpha2.SchemeGroupVersion.WithKind("BackendLBPolicy") + +// Get takes name of the backendLBPolicy, and returns the corresponding backendLBPolicy object, and an error if there is any. +func (c *FakeBackendLBPolicies) Get(ctx context.Context, name string, options v1.GetOptions) (result *v1alpha2.BackendLBPolicy, err error) { + obj, err := c.Fake. + Invokes(testing.NewGetAction(backendlbpoliciesResource, c.ns, name), &v1alpha2.BackendLBPolicy{}) + + if obj == nil { + return nil, err + } + return obj.(*v1alpha2.BackendLBPolicy), err +} + +// List takes label and field selectors, and returns the list of BackendLBPolicies that match those selectors. +func (c *FakeBackendLBPolicies) List(ctx context.Context, opts v1.ListOptions) (result *v1alpha2.BackendLBPolicyList, err error) { + obj, err := c.Fake. + Invokes(testing.NewListAction(backendlbpoliciesResource, backendlbpoliciesKind, c.ns, opts), &v1alpha2.BackendLBPolicyList{}) + + if obj == nil { + return nil, err + } + + label, _, _ := testing.ExtractFromListOptions(opts) + if label == nil { + label = labels.Everything() + } + list := &v1alpha2.BackendLBPolicyList{ListMeta: obj.(*v1alpha2.BackendLBPolicyList).ListMeta} + for _, item := range obj.(*v1alpha2.BackendLBPolicyList).Items { + if label.Matches(labels.Set(item.Labels)) { + list.Items = append(list.Items, item) + } + } + return list, err +} + +// Watch returns a watch.Interface that watches the requested backendLBPolicies. +func (c *FakeBackendLBPolicies) Watch(ctx context.Context, opts v1.ListOptions) (watch.Interface, error) { + return c.Fake. + InvokesWatch(testing.NewWatchAction(backendlbpoliciesResource, c.ns, opts)) + +} + +// Create takes the representation of a backendLBPolicy and creates it. Returns the server's representation of the backendLBPolicy, and an error, if there is any. +func (c *FakeBackendLBPolicies) Create(ctx context.Context, backendLBPolicy *v1alpha2.BackendLBPolicy, opts v1.CreateOptions) (result *v1alpha2.BackendLBPolicy, err error) { + obj, err := c.Fake. + Invokes(testing.NewCreateAction(backendlbpoliciesResource, c.ns, backendLBPolicy), &v1alpha2.BackendLBPolicy{}) + + if obj == nil { + return nil, err + } + return obj.(*v1alpha2.BackendLBPolicy), err +} + +// Update takes the representation of a backendLBPolicy and updates it. Returns the server's representation of the backendLBPolicy, and an error, if there is any. +func (c *FakeBackendLBPolicies) Update(ctx context.Context, backendLBPolicy *v1alpha2.BackendLBPolicy, opts v1.UpdateOptions) (result *v1alpha2.BackendLBPolicy, err error) { + obj, err := c.Fake. + Invokes(testing.NewUpdateAction(backendlbpoliciesResource, c.ns, backendLBPolicy), &v1alpha2.BackendLBPolicy{}) + + if obj == nil { + return nil, err + } + return obj.(*v1alpha2.BackendLBPolicy), err +} + +// UpdateStatus was generated because the type contains a Status member. +// Add a +genclient:noStatus comment above the type to avoid generating UpdateStatus(). +func (c *FakeBackendLBPolicies) UpdateStatus(ctx context.Context, backendLBPolicy *v1alpha2.BackendLBPolicy, opts v1.UpdateOptions) (*v1alpha2.BackendLBPolicy, error) { + obj, err := c.Fake. + Invokes(testing.NewUpdateSubresourceAction(backendlbpoliciesResource, "status", c.ns, backendLBPolicy), &v1alpha2.BackendLBPolicy{}) + + if obj == nil { + return nil, err + } + return obj.(*v1alpha2.BackendLBPolicy), err +} + +// Delete takes name of the backendLBPolicy and deletes it. Returns an error if one occurs. +func (c *FakeBackendLBPolicies) Delete(ctx context.Context, name string, opts v1.DeleteOptions) error { + _, err := c.Fake. + Invokes(testing.NewDeleteActionWithOptions(backendlbpoliciesResource, c.ns, name, opts), &v1alpha2.BackendLBPolicy{}) + + return err +} + +// DeleteCollection deletes a collection of objects. +func (c *FakeBackendLBPolicies) DeleteCollection(ctx context.Context, opts v1.DeleteOptions, listOpts v1.ListOptions) error { + action := testing.NewDeleteCollectionAction(backendlbpoliciesResource, c.ns, listOpts) + + _, err := c.Fake.Invokes(action, &v1alpha2.BackendLBPolicyList{}) + return err +} + +// Patch applies the patch and returns the patched backendLBPolicy. +func (c *FakeBackendLBPolicies) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts v1.PatchOptions, subresources ...string) (result *v1alpha2.BackendLBPolicy, err error) { + obj, err := c.Fake. + Invokes(testing.NewPatchSubresourceAction(backendlbpoliciesResource, c.ns, name, pt, data, subresources...), &v1alpha2.BackendLBPolicy{}) + + if obj == nil { + return nil, err + } + return obj.(*v1alpha2.BackendLBPolicy), err +} + +// Apply takes the given apply declarative configuration, applies it and returns the applied backendLBPolicy. +func (c *FakeBackendLBPolicies) Apply(ctx context.Context, backendLBPolicy *apisv1alpha2.BackendLBPolicyApplyConfiguration, opts v1.ApplyOptions) (result *v1alpha2.BackendLBPolicy, err error) { + if backendLBPolicy == nil { + return nil, fmt.Errorf("backendLBPolicy provided to Apply must not be nil") + } + data, err := json.Marshal(backendLBPolicy) + if err != nil { + return nil, err + } + name := backendLBPolicy.Name + if name == nil { + return nil, fmt.Errorf("backendLBPolicy.Name must be provided to Apply") + } + obj, err := c.Fake. + Invokes(testing.NewPatchSubresourceAction(backendlbpoliciesResource, c.ns, *name, types.ApplyPatchType, data), &v1alpha2.BackendLBPolicy{}) + + if obj == nil { + return nil, err + } + return obj.(*v1alpha2.BackendLBPolicy), err +} + +// ApplyStatus was generated because the type contains a Status member. +// Add a +genclient:noStatus comment above the type to avoid generating ApplyStatus(). +func (c *FakeBackendLBPolicies) ApplyStatus(ctx context.Context, backendLBPolicy *apisv1alpha2.BackendLBPolicyApplyConfiguration, opts v1.ApplyOptions) (result *v1alpha2.BackendLBPolicy, err error) { + if backendLBPolicy == nil { + return nil, fmt.Errorf("backendLBPolicy provided to Apply must not be nil") + } + data, err := json.Marshal(backendLBPolicy) + if err != nil { + return nil, err + } + name := backendLBPolicy.Name + if name == nil { + return nil, fmt.Errorf("backendLBPolicy.Name must be provided to Apply") + } + obj, err := c.Fake. + Invokes(testing.NewPatchSubresourceAction(backendlbpoliciesResource, c.ns, *name, types.ApplyPatchType, data, "status"), &v1alpha2.BackendLBPolicy{}) + + if obj == nil { + return nil, err + } + return obj.(*v1alpha2.BackendLBPolicy), err +} diff --git a/pkg/client/clientset/versioned/typed/apis/v1alpha2/generated_expansion.go b/pkg/client/clientset/versioned/typed/apis/v1alpha2/generated_expansion.go index c57afdec63..c0fe07b497 100644 --- a/pkg/client/clientset/versioned/typed/apis/v1alpha2/generated_expansion.go +++ b/pkg/client/clientset/versioned/typed/apis/v1alpha2/generated_expansion.go @@ -18,6 +18,8 @@ limitations under the License. package v1alpha2 +type BackendLBPolicyExpansion interface{} + type GRPCRouteExpansion interface{} type ReferenceGrantExpansion interface{} diff --git a/pkg/client/informers/externalversions/apis/v1alpha2/backendlbpolicy.go b/pkg/client/informers/externalversions/apis/v1alpha2/backendlbpolicy.go new file mode 100644 index 0000000000..e5cdbe7cb0 --- /dev/null +++ b/pkg/client/informers/externalversions/apis/v1alpha2/backendlbpolicy.go @@ -0,0 +1,90 @@ +/* +Copyright The Kubernetes Authors. + +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. +*/ + +// Code generated by informer-gen. DO NOT EDIT. + +package v1alpha2 + +import ( + "context" + time "time" + + v1 "k8s.io/apimachinery/pkg/apis/meta/v1" + runtime "k8s.io/apimachinery/pkg/runtime" + watch "k8s.io/apimachinery/pkg/watch" + cache "k8s.io/client-go/tools/cache" + apisv1alpha2 "sigs.k8s.io/gateway-api/apis/v1alpha2" + versioned "sigs.k8s.io/gateway-api/pkg/client/clientset/versioned" + internalinterfaces "sigs.k8s.io/gateway-api/pkg/client/informers/externalversions/internalinterfaces" + v1alpha2 "sigs.k8s.io/gateway-api/pkg/client/listers/apis/v1alpha2" +) + +// BackendLBPolicyInformer provides access to a shared informer and lister for +// BackendLBPolicies. +type BackendLBPolicyInformer interface { + Informer() cache.SharedIndexInformer + Lister() v1alpha2.BackendLBPolicyLister +} + +type backendLBPolicyInformer struct { + factory internalinterfaces.SharedInformerFactory + tweakListOptions internalinterfaces.TweakListOptionsFunc + namespace string +} + +// NewBackendLBPolicyInformer constructs a new informer for BackendLBPolicy type. +// Always prefer using an informer factory to get a shared informer instead of getting an independent +// one. This reduces memory footprint and number of connections to the server. +func NewBackendLBPolicyInformer(client versioned.Interface, namespace string, resyncPeriod time.Duration, indexers cache.Indexers) cache.SharedIndexInformer { + return NewFilteredBackendLBPolicyInformer(client, namespace, resyncPeriod, indexers, nil) +} + +// NewFilteredBackendLBPolicyInformer constructs a new informer for BackendLBPolicy type. +// Always prefer using an informer factory to get a shared informer instead of getting an independent +// one. This reduces memory footprint and number of connections to the server. +func NewFilteredBackendLBPolicyInformer(client versioned.Interface, namespace string, resyncPeriod time.Duration, indexers cache.Indexers, tweakListOptions internalinterfaces.TweakListOptionsFunc) cache.SharedIndexInformer { + return cache.NewSharedIndexInformer( + &cache.ListWatch{ + ListFunc: func(options v1.ListOptions) (runtime.Object, error) { + if tweakListOptions != nil { + tweakListOptions(&options) + } + return client.GatewayV1alpha2().BackendLBPolicies(namespace).List(context.TODO(), options) + }, + WatchFunc: func(options v1.ListOptions) (watch.Interface, error) { + if tweakListOptions != nil { + tweakListOptions(&options) + } + return client.GatewayV1alpha2().BackendLBPolicies(namespace).Watch(context.TODO(), options) + }, + }, + &apisv1alpha2.BackendLBPolicy{}, + resyncPeriod, + indexers, + ) +} + +func (f *backendLBPolicyInformer) defaultInformer(client versioned.Interface, resyncPeriod time.Duration) cache.SharedIndexInformer { + return NewFilteredBackendLBPolicyInformer(client, f.namespace, resyncPeriod, cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc}, f.tweakListOptions) +} + +func (f *backendLBPolicyInformer) Informer() cache.SharedIndexInformer { + return f.factory.InformerFor(&apisv1alpha2.BackendLBPolicy{}, f.defaultInformer) +} + +func (f *backendLBPolicyInformer) Lister() v1alpha2.BackendLBPolicyLister { + return v1alpha2.NewBackendLBPolicyLister(f.Informer().GetIndexer()) +} diff --git a/pkg/client/informers/externalversions/apis/v1alpha2/interface.go b/pkg/client/informers/externalversions/apis/v1alpha2/interface.go index 9e5c505ddc..8f21c3d8e6 100644 --- a/pkg/client/informers/externalversions/apis/v1alpha2/interface.go +++ b/pkg/client/informers/externalversions/apis/v1alpha2/interface.go @@ -24,6 +24,8 @@ import ( // Interface provides access to all the informers in this group version. type Interface interface { + // BackendLBPolicies returns a BackendLBPolicyInformer. + BackendLBPolicies() BackendLBPolicyInformer // GRPCRoutes returns a GRPCRouteInformer. GRPCRoutes() GRPCRouteInformer // ReferenceGrants returns a ReferenceGrantInformer. @@ -47,6 +49,11 @@ func New(f internalinterfaces.SharedInformerFactory, namespace string, tweakList return &version{factory: f, namespace: namespace, tweakListOptions: tweakListOptions} } +// BackendLBPolicies returns a BackendLBPolicyInformer. +func (v *version) BackendLBPolicies() BackendLBPolicyInformer { + return &backendLBPolicyInformer{factory: v.factory, namespace: v.namespace, tweakListOptions: v.tweakListOptions} +} + // GRPCRoutes returns a GRPCRouteInformer. func (v *version) GRPCRoutes() GRPCRouteInformer { return &gRPCRouteInformer{factory: v.factory, namespace: v.namespace, tweakListOptions: v.tweakListOptions} diff --git a/pkg/client/informers/externalversions/generic.go b/pkg/client/informers/externalversions/generic.go index 7a07e5ba38..283d2475b2 100644 --- a/pkg/client/informers/externalversions/generic.go +++ b/pkg/client/informers/externalversions/generic.go @@ -66,6 +66,8 @@ func (f *sharedInformerFactory) ForResource(resource schema.GroupVersionResource return &genericInformer{resource: resource.GroupResource(), informer: f.Gateway().V1().HTTPRoutes().Informer()}, nil // Group=gateway.networking.k8s.io, Version=v1alpha2 + case v1alpha2.SchemeGroupVersion.WithResource("backendlbpolicies"): + return &genericInformer{resource: resource.GroupResource(), informer: f.Gateway().V1alpha2().BackendLBPolicies().Informer()}, nil case v1alpha2.SchemeGroupVersion.WithResource("grpcroutes"): return &genericInformer{resource: resource.GroupResource(), informer: f.Gateway().V1alpha2().GRPCRoutes().Informer()}, nil case v1alpha2.SchemeGroupVersion.WithResource("referencegrants"): diff --git a/pkg/client/listers/apis/v1alpha2/backendlbpolicy.go b/pkg/client/listers/apis/v1alpha2/backendlbpolicy.go new file mode 100644 index 0000000000..1b01f4ec3f --- /dev/null +++ b/pkg/client/listers/apis/v1alpha2/backendlbpolicy.go @@ -0,0 +1,99 @@ +/* +Copyright The Kubernetes Authors. + +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. +*/ + +// Code generated by lister-gen. DO NOT EDIT. + +package v1alpha2 + +import ( + "k8s.io/apimachinery/pkg/api/errors" + "k8s.io/apimachinery/pkg/labels" + "k8s.io/client-go/tools/cache" + v1alpha2 "sigs.k8s.io/gateway-api/apis/v1alpha2" +) + +// BackendLBPolicyLister helps list BackendLBPolicies. +// All objects returned here must be treated as read-only. +type BackendLBPolicyLister interface { + // List lists all BackendLBPolicies in the indexer. + // Objects returned here must be treated as read-only. + List(selector labels.Selector) (ret []*v1alpha2.BackendLBPolicy, err error) + // BackendLBPolicies returns an object that can list and get BackendLBPolicies. + BackendLBPolicies(namespace string) BackendLBPolicyNamespaceLister + BackendLBPolicyListerExpansion +} + +// backendLBPolicyLister implements the BackendLBPolicyLister interface. +type backendLBPolicyLister struct { + indexer cache.Indexer +} + +// NewBackendLBPolicyLister returns a new BackendLBPolicyLister. +func NewBackendLBPolicyLister(indexer cache.Indexer) BackendLBPolicyLister { + return &backendLBPolicyLister{indexer: indexer} +} + +// List lists all BackendLBPolicies in the indexer. +func (s *backendLBPolicyLister) List(selector labels.Selector) (ret []*v1alpha2.BackendLBPolicy, err error) { + err = cache.ListAll(s.indexer, selector, func(m interface{}) { + ret = append(ret, m.(*v1alpha2.BackendLBPolicy)) + }) + return ret, err +} + +// BackendLBPolicies returns an object that can list and get BackendLBPolicies. +func (s *backendLBPolicyLister) BackendLBPolicies(namespace string) BackendLBPolicyNamespaceLister { + return backendLBPolicyNamespaceLister{indexer: s.indexer, namespace: namespace} +} + +// BackendLBPolicyNamespaceLister helps list and get BackendLBPolicies. +// All objects returned here must be treated as read-only. +type BackendLBPolicyNamespaceLister interface { + // List lists all BackendLBPolicies in the indexer for a given namespace. + // Objects returned here must be treated as read-only. + List(selector labels.Selector) (ret []*v1alpha2.BackendLBPolicy, err error) + // Get retrieves the BackendLBPolicy from the indexer for a given namespace and name. + // Objects returned here must be treated as read-only. + Get(name string) (*v1alpha2.BackendLBPolicy, error) + BackendLBPolicyNamespaceListerExpansion +} + +// backendLBPolicyNamespaceLister implements the BackendLBPolicyNamespaceLister +// interface. +type backendLBPolicyNamespaceLister struct { + indexer cache.Indexer + namespace string +} + +// List lists all BackendLBPolicies in the indexer for a given namespace. +func (s backendLBPolicyNamespaceLister) List(selector labels.Selector) (ret []*v1alpha2.BackendLBPolicy, err error) { + err = cache.ListAllByNamespace(s.indexer, s.namespace, selector, func(m interface{}) { + ret = append(ret, m.(*v1alpha2.BackendLBPolicy)) + }) + return ret, err +} + +// Get retrieves the BackendLBPolicy from the indexer for a given namespace and name. +func (s backendLBPolicyNamespaceLister) Get(name string) (*v1alpha2.BackendLBPolicy, error) { + obj, exists, err := s.indexer.GetByKey(s.namespace + "/" + name) + if err != nil { + return nil, err + } + if !exists { + return nil, errors.NewNotFound(v1alpha2.Resource("backendlbpolicy"), name) + } + return obj.(*v1alpha2.BackendLBPolicy), nil +} diff --git a/pkg/client/listers/apis/v1alpha2/expansion_generated.go b/pkg/client/listers/apis/v1alpha2/expansion_generated.go index a3ba069b9a..d311d49157 100644 --- a/pkg/client/listers/apis/v1alpha2/expansion_generated.go +++ b/pkg/client/listers/apis/v1alpha2/expansion_generated.go @@ -18,6 +18,14 @@ limitations under the License. package v1alpha2 +// BackendLBPolicyListerExpansion allows custom methods to be added to +// BackendLBPolicyLister. +type BackendLBPolicyListerExpansion interface{} + +// BackendLBPolicyNamespaceListerExpansion allows custom methods to be added to +// BackendLBPolicyNamespaceLister. +type BackendLBPolicyNamespaceListerExpansion interface{} + // GRPCRouteListerExpansion allows custom methods to be added to // GRPCRouteLister. type GRPCRouteListerExpansion interface{} diff --git a/pkg/generated/openapi/zz_generated.openapi.go b/pkg/generated/openapi/zz_generated.openapi.go index 5fa28eb71f..acc131b78e 100644 --- a/pkg/generated/openapi/zz_generated.openapi.go +++ b/pkg/generated/openapi/zz_generated.openapi.go @@ -87,6 +87,7 @@ func GetOpenAPIDefinitions(ref common.ReferenceCallback) map[string]common.OpenA "sigs.k8s.io/gateway-api/apis/v1.BackendObjectReference": schema_sigsk8sio_gateway_api_apis_v1_BackendObjectReference(ref), "sigs.k8s.io/gateway-api/apis/v1.BackendRef": schema_sigsk8sio_gateway_api_apis_v1_BackendRef(ref), "sigs.k8s.io/gateway-api/apis/v1.CommonRouteSpec": schema_sigsk8sio_gateway_api_apis_v1_CommonRouteSpec(ref), + "sigs.k8s.io/gateway-api/apis/v1.CookieConfig": schema_sigsk8sio_gateway_api_apis_v1_CookieConfig(ref), "sigs.k8s.io/gateway-api/apis/v1.FrontendTLSValidation": schema_sigsk8sio_gateway_api_apis_v1_FrontendTLSValidation(ref), "sigs.k8s.io/gateway-api/apis/v1.GRPCBackendRef": schema_sigsk8sio_gateway_api_apis_v1_GRPCBackendRef(ref), "sigs.k8s.io/gateway-api/apis/v1.GRPCHeaderMatch": schema_sigsk8sio_gateway_api_apis_v1_GRPCHeaderMatch(ref), @@ -140,6 +141,10 @@ func GetOpenAPIDefinitions(ref common.ReferenceCallback) map[string]common.OpenA "sigs.k8s.io/gateway-api/apis/v1.RouteParentStatus": schema_sigsk8sio_gateway_api_apis_v1_RouteParentStatus(ref), "sigs.k8s.io/gateway-api/apis/v1.RouteStatus": schema_sigsk8sio_gateway_api_apis_v1_RouteStatus(ref), "sigs.k8s.io/gateway-api/apis/v1.SecretObjectReference": schema_sigsk8sio_gateway_api_apis_v1_SecretObjectReference(ref), + "sigs.k8s.io/gateway-api/apis/v1.SessionPersistence": schema_sigsk8sio_gateway_api_apis_v1_SessionPersistence(ref), + "sigs.k8s.io/gateway-api/apis/v1alpha2.BackendLBPolicy": schema_sigsk8sio_gateway_api_apis_v1alpha2_BackendLBPolicy(ref), + "sigs.k8s.io/gateway-api/apis/v1alpha2.BackendLBPolicyList": schema_sigsk8sio_gateway_api_apis_v1alpha2_BackendLBPolicyList(ref), + "sigs.k8s.io/gateway-api/apis/v1alpha2.BackendLBPolicySpec": schema_sigsk8sio_gateway_api_apis_v1alpha2_BackendLBPolicySpec(ref), "sigs.k8s.io/gateway-api/apis/v1alpha2.GRPCRoute": schema_sigsk8sio_gateway_api_apis_v1alpha2_GRPCRoute(ref), "sigs.k8s.io/gateway-api/apis/v1alpha2.GRPCRouteList": schema_sigsk8sio_gateway_api_apis_v1alpha2_GRPCRouteList(ref), "sigs.k8s.io/gateway-api/apis/v1alpha2.LocalPolicyTargetReference": schema_sigsk8sio_gateway_api_apis_v1alpha2_LocalPolicyTargetReference(ref), @@ -2772,6 +2777,26 @@ func schema_sigsk8sio_gateway_api_apis_v1_CommonRouteSpec(ref common.ReferenceCa } } +func schema_sigsk8sio_gateway_api_apis_v1_CookieConfig(ref common.ReferenceCallback) common.OpenAPIDefinition { + return common.OpenAPIDefinition{ + Schema: spec.Schema{ + SchemaProps: spec.SchemaProps{ + Description: "CookieConfig defines the configuration for cookie-based session persistence.", + Type: []string{"object"}, + Properties: map[string]spec.Schema{ + "lifetimeType": { + SchemaProps: spec.SchemaProps{ + Description: "LifetimeType specifies whether the cookie has a permanent or session-based lifetime. A permanent cookie persists until its specified expiry time, defined by the Expires or Max-Age cookie attributes, while a session cookie is deleted when the current session ends.\n\nWhen set to \"Permanent\", AbsoluteTimeout indicates the cookie's lifetime via the Expires or Max-Age cookie attributes and is required.\n\nWhen set to \"Session\", AbsoluteTimeout indicates the absolute lifetime of the cookie tracked by the gateway and is optional.\n\nSupport: Core for \"Session\" type\n\nSupport: Extended for \"Permanent\" type", + Type: []string{"string"}, + Format: "", + }, + }, + }, + }, + }, + } +} + func schema_sigsk8sio_gateway_api_apis_v1_FrontendTLSValidation(ref common.ReferenceCallback) common.OpenAPIDefinition { return common.OpenAPIDefinition{ Schema: spec.Schema{ @@ -3183,11 +3208,17 @@ func schema_sigsk8sio_gateway_api_apis_v1_GRPCRouteRule(ref common.ReferenceCall }, }, }, + "sessionPersistence": { + SchemaProps: spec.SchemaProps{ + Description: "SessionPersistence defines and configures session persistence for the route rule.\n\nSupport: Extended\n\n", + Ref: ref("sigs.k8s.io/gateway-api/apis/v1.SessionPersistence"), + }, + }, }, }, }, Dependencies: []string{ - "sigs.k8s.io/gateway-api/apis/v1.GRPCBackendRef", "sigs.k8s.io/gateway-api/apis/v1.GRPCRouteFilter", "sigs.k8s.io/gateway-api/apis/v1.GRPCRouteMatch"}, + "sigs.k8s.io/gateway-api/apis/v1.GRPCBackendRef", "sigs.k8s.io/gateway-api/apis/v1.GRPCRouteFilter", "sigs.k8s.io/gateway-api/apis/v1.GRPCRouteMatch", "sigs.k8s.io/gateway-api/apis/v1.SessionPersistence"}, } } @@ -4556,11 +4587,17 @@ func schema_sigsk8sio_gateway_api_apis_v1_HTTPRouteRule(ref common.ReferenceCall Ref: ref("sigs.k8s.io/gateway-api/apis/v1.HTTPRouteTimeouts"), }, }, + "sessionPersistence": { + SchemaProps: spec.SchemaProps{ + Description: "SessionPersistence defines and configures session persistence for the route rule.\n\nSupport: Extended\n\n", + Ref: ref("sigs.k8s.io/gateway-api/apis/v1.SessionPersistence"), + }, + }, }, }, }, Dependencies: []string{ - "sigs.k8s.io/gateway-api/apis/v1.HTTPBackendRef", "sigs.k8s.io/gateway-api/apis/v1.HTTPRouteFilter", "sigs.k8s.io/gateway-api/apis/v1.HTTPRouteMatch", "sigs.k8s.io/gateway-api/apis/v1.HTTPRouteTimeouts"}, + "sigs.k8s.io/gateway-api/apis/v1.HTTPBackendRef", "sigs.k8s.io/gateway-api/apis/v1.HTTPRouteFilter", "sigs.k8s.io/gateway-api/apis/v1.HTTPRouteMatch", "sigs.k8s.io/gateway-api/apis/v1.HTTPRouteTimeouts", "sigs.k8s.io/gateway-api/apis/v1.SessionPersistence"}, } } @@ -5240,6 +5277,200 @@ func schema_sigsk8sio_gateway_api_apis_v1_SecretObjectReference(ref common.Refer } } +func schema_sigsk8sio_gateway_api_apis_v1_SessionPersistence(ref common.ReferenceCallback) common.OpenAPIDefinition { + return common.OpenAPIDefinition{ + Schema: spec.Schema{ + SchemaProps: spec.SchemaProps{ + Description: "SessionPersistence defines the desired state of SessionPersistence.", + Type: []string{"object"}, + Properties: map[string]spec.Schema{ + "sessionName": { + SchemaProps: spec.SchemaProps{ + Description: "SessionName defines the name of the persistent session token which may be reflected in the cookie or the header. Users should avoid reusing session names to prevent unintended consequences, such as rejection or unpredictable behavior.\n\nSupport: Implementation-specific", + Type: []string{"string"}, + Format: "", + }, + }, + "absoluteTimeout": { + SchemaProps: spec.SchemaProps{ + Description: "AbsoluteTimeout defines the absolute timeout of the persistent session. Once the AbsoluteTimeout duration has elapsed, the session becomes invalid.\n\nSupport: Extended", + Type: []string{"string"}, + Format: "", + }, + }, + "idleTimeout": { + SchemaProps: spec.SchemaProps{ + Description: "IdleTimeout defines the idle timeout of the persistent session. Once the session has been idle for more than the specified IdleTimeout duration, the session becomes invalid.\n\nSupport: Extended", + Type: []string{"string"}, + Format: "", + }, + }, + "type": { + SchemaProps: spec.SchemaProps{ + Description: "Type defines the type of session persistence such as through the use a header or cookie. Defaults to cookie based session persistence.\n\nSupport: Core for \"Cookie\" type\n\nSupport: Extended for \"Header\" type", + Type: []string{"string"}, + Format: "", + }, + }, + "cookieConfig": { + SchemaProps: spec.SchemaProps{ + Description: "CookieConfig provides configuration settings that are specific to cookie-based session persistence.\n\nSupport: Core", + Ref: ref("sigs.k8s.io/gateway-api/apis/v1.CookieConfig"), + }, + }, + }, + }, + }, + Dependencies: []string{ + "sigs.k8s.io/gateway-api/apis/v1.CookieConfig"}, + } +} + +func schema_sigsk8sio_gateway_api_apis_v1alpha2_BackendLBPolicy(ref common.ReferenceCallback) common.OpenAPIDefinition { + return common.OpenAPIDefinition{ + Schema: spec.Schema{ + SchemaProps: spec.SchemaProps{ + Description: "BackendLBPolicy provides a way to define load balancing rules for a backend.", + Type: []string{"object"}, + Properties: map[string]spec.Schema{ + "kind": { + SchemaProps: spec.SchemaProps{ + Description: "Kind is a string value representing the REST resource this object represents. Servers may infer this from the endpoint the client submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds", + Type: []string{"string"}, + Format: "", + }, + }, + "apiVersion": { + SchemaProps: spec.SchemaProps{ + Description: "APIVersion defines the versioned schema of this representation of an object. Servers should convert recognized schemas to the latest internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources", + Type: []string{"string"}, + Format: "", + }, + }, + "metadata": { + SchemaProps: spec.SchemaProps{ + Default: map[string]interface{}{}, + Ref: ref("k8s.io/apimachinery/pkg/apis/meta/v1.ObjectMeta"), + }, + }, + "spec": { + SchemaProps: spec.SchemaProps{ + Description: "Spec defines the desired state of BackendLBPolicy.", + Default: map[string]interface{}{}, + Ref: ref("sigs.k8s.io/gateway-api/apis/v1alpha2.BackendLBPolicySpec"), + }, + }, + "status": { + SchemaProps: spec.SchemaProps{ + Description: "Status defines the current state of BackendLBPolicy.", + Default: map[string]interface{}{}, + Ref: ref("sigs.k8s.io/gateway-api/apis/v1alpha2.PolicyStatus"), + }, + }, + }, + Required: []string{"spec"}, + }, + }, + Dependencies: []string{ + "k8s.io/apimachinery/pkg/apis/meta/v1.ObjectMeta", "sigs.k8s.io/gateway-api/apis/v1alpha2.BackendLBPolicySpec", "sigs.k8s.io/gateway-api/apis/v1alpha2.PolicyStatus"}, + } +} + +func schema_sigsk8sio_gateway_api_apis_v1alpha2_BackendLBPolicyList(ref common.ReferenceCallback) common.OpenAPIDefinition { + return common.OpenAPIDefinition{ + Schema: spec.Schema{ + SchemaProps: spec.SchemaProps{ + Description: "BackendLBPolicyList contains a list of BackendLBPolicies", + Type: []string{"object"}, + Properties: map[string]spec.Schema{ + "kind": { + SchemaProps: spec.SchemaProps{ + Description: "Kind is a string value representing the REST resource this object represents. Servers may infer this from the endpoint the client submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds", + Type: []string{"string"}, + Format: "", + }, + }, + "apiVersion": { + SchemaProps: spec.SchemaProps{ + Description: "APIVersion defines the versioned schema of this representation of an object. Servers should convert recognized schemas to the latest internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources", + Type: []string{"string"}, + Format: "", + }, + }, + "metadata": { + SchemaProps: spec.SchemaProps{ + Default: map[string]interface{}{}, + Ref: ref("k8s.io/apimachinery/pkg/apis/meta/v1.ListMeta"), + }, + }, + "items": { + SchemaProps: spec.SchemaProps{ + Type: []string{"array"}, + Items: &spec.SchemaOrArray{ + Schema: &spec.Schema{ + SchemaProps: spec.SchemaProps{ + Default: map[string]interface{}{}, + Ref: ref("sigs.k8s.io/gateway-api/apis/v1alpha2.BackendLBPolicy"), + }, + }, + }, + }, + }, + }, + Required: []string{"items"}, + }, + }, + Dependencies: []string{ + "k8s.io/apimachinery/pkg/apis/meta/v1.ListMeta", "sigs.k8s.io/gateway-api/apis/v1alpha2.BackendLBPolicy"}, + } +} + +func schema_sigsk8sio_gateway_api_apis_v1alpha2_BackendLBPolicySpec(ref common.ReferenceCallback) common.OpenAPIDefinition { + return common.OpenAPIDefinition{ + Schema: spec.Schema{ + SchemaProps: spec.SchemaProps{ + Description: "BackendLBPolicySpec defines the desired state of BackendLBPolicy. Note: there is no Override or Default policy configuration.", + Type: []string{"object"}, + Properties: map[string]spec.Schema{ + "targetRefs": { + VendorExtensible: spec.VendorExtensible{ + Extensions: spec.Extensions{ + "x-kubernetes-list-map-keys": []interface{}{ + "group", + "kind", + "name", + }, + "x-kubernetes-list-type": "map", + }, + }, + SchemaProps: spec.SchemaProps{ + Description: "TargetRef identifies an API object to apply policy to. Currently, Backends (i.e. Service, ServiceImport, or any implementation-specific backendRef) are the only valid API target references.", + Type: []string{"array"}, + Items: &spec.SchemaOrArray{ + Schema: &spec.Schema{ + SchemaProps: spec.SchemaProps{ + Default: map[string]interface{}{}, + Ref: ref("sigs.k8s.io/gateway-api/apis/v1alpha2.LocalPolicyTargetReference"), + }, + }, + }, + }, + }, + "sessionPersistence": { + SchemaProps: spec.SchemaProps{ + Description: "SessionPersistence defines and configures session persistence for the backend.\n\nSupport: Extended", + Ref: ref("sigs.k8s.io/gateway-api/apis/v1.SessionPersistence"), + }, + }, + }, + Required: []string{"targetRefs"}, + }, + }, + Dependencies: []string{ + "sigs.k8s.io/gateway-api/apis/v1.SessionPersistence", "sigs.k8s.io/gateway-api/apis/v1alpha2.LocalPolicyTargetReference"}, + } +} + func schema_sigsk8sio_gateway_api_apis_v1alpha2_GRPCRoute(ref common.ReferenceCallback) common.OpenAPIDefinition { return common.OpenAPIDefinition{ Schema: spec.Schema{ diff --git a/pkg/test/cel/backendlbpolicy_test.go b/pkg/test/cel/backendlbpolicy_test.go new file mode 100644 index 0000000000..10a1c08441 --- /dev/null +++ b/pkg/test/cel/backendlbpolicy_test.go @@ -0,0 +1,124 @@ +//go:build experimental +// +build experimental + +/* +Copyright 2024 The Kubernetes Authors. + +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 main + +import ( + "context" + "fmt" + "strings" + "testing" + "time" + + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + gatewayv1 "sigs.k8s.io/gateway-api/apis/v1" + gatewayv1a2 "sigs.k8s.io/gateway-api/apis/v1alpha2" +) + +func TestBackendLBPolicyConfig(t *testing.T) { + tests := []struct { + name string + wantErrors []string + sessionPersistence gatewayv1a2.SessionPersistence + }{ + { + name: "valid BackendLBPolicyConfig no cookie lifetimeType", + sessionPersistence: gatewayv1a2.SessionPersistence{ + SessionName: ptrTo("foo"), + AbsoluteTimeout: toDuration("1h"), + Type: ptrTo(gatewayv1.CookieBasedSessionPersistence), + }, + wantErrors: []string{}, + }, + { + name: "valid BackendLBPolicyConfig session cookie", + sessionPersistence: gatewayv1a2.SessionPersistence{ + SessionName: ptrTo("foo"), + Type: ptrTo(gatewayv1.CookieBasedSessionPersistence), + CookieConfig: &gatewayv1.CookieConfig{ + LifetimeType: ptrTo(gatewayv1.SessionCookieLifetimeType), + }, + }, + wantErrors: []string{}, + }, + { + name: "invalid BackendLBPolicyConfig permanent cookie", + sessionPersistence: gatewayv1a2.SessionPersistence{ + SessionName: ptrTo("foo"), + Type: ptrTo(gatewayv1.CookieBasedSessionPersistence), + CookieConfig: &gatewayv1.CookieConfig{ + LifetimeType: ptrTo(gatewayv1.PermanentCookieLifetimeType), + }, + }, + wantErrors: []string{"AbsoluteTimeout must be specified when cookie lifetimeType is Permanent"}, + }, + { + name: "valid BackendLBPolicyConfig permanent cookie", + sessionPersistence: gatewayv1a2.SessionPersistence{ + SessionName: ptrTo("foo"), + AbsoluteTimeout: toDuration("1h"), + Type: ptrTo(gatewayv1.CookieBasedSessionPersistence), + CookieConfig: &gatewayv1.CookieConfig{ + LifetimeType: ptrTo(gatewayv1.PermanentCookieLifetimeType), + }, + }, + wantErrors: []string{}, + }, + } + for _, tc := range tests { + t.Run(tc.name, func(t *testing.T) { + lbPolicy := &gatewayv1a2.BackendLBPolicy{ + ObjectMeta: metav1.ObjectMeta{ + Name: fmt.Sprintf("foo-%v", time.Now().UnixNano()), + Namespace: metav1.NamespaceDefault, + }, + Spec: gatewayv1a2.BackendLBPolicySpec{ + TargetRefs: []gatewayv1a2.LocalPolicyTargetReference{{ + Group: "group", + Kind: "kind", + Name: "name", + }}, + SessionPersistence: &tc.sessionPersistence, + }, + } + validateBackendLBPolicy(t, lbPolicy, tc.wantErrors) + }) + } +} + +func validateBackendLBPolicy(t *testing.T, lbPolicy *gatewayv1a2.BackendLBPolicy, wantErrors []string) { + t.Helper() + + ctx := context.Background() + err := k8sClient.Create(ctx, lbPolicy) + + if (len(wantErrors) != 0) != (err != nil) { + t.Fatalf("Unexpected response while creating BackendLBPolicy %q; got err=\n%v\n;want error=%v", fmt.Sprintf("%v/%v", lbPolicy.Namespace, lbPolicy.Name), err, wantErrors) + } + + var missingErrorStrings []string + for _, wantError := range wantErrors { + if !strings.Contains(strings.ToLower(err.Error()), strings.ToLower(wantError)) { + missingErrorStrings = append(missingErrorStrings, wantError) + } + } + if len(missingErrorStrings) != 0 { + t.Errorf("Unexpected response while creating BackendLBPolicy %q; got err=\n%v\n;missing strings within error=%q", fmt.Sprintf("%v/%v", lbPolicy.Namespace, lbPolicy.Name), err, missingErrorStrings) + } +}