From 6235a9ef3154dfc74649152ebdedd1058f4f936f Mon Sep 17 00:00:00 2001 From: Kajol Asabe Date: Mon, 17 Jun 2024 14:25:14 +0530 Subject: [PATCH 1/2] Add network PeeringPrefix type and its validation --- api/networking/v1alpha1/network_type.go | 33 ++++ .../v1alpha1/zz_generated.deepcopy.go | 79 ++++++++- .../applyconfigurations/internal/internal.go | 46 +++++ .../networking/v1alpha1/networkpeering.go | 14 ++ .../v1alpha1/networkpeeringstatus.go | 18 +- .../networking/v1alpha1/peeringprefix.go | 48 +++++ .../networking/v1alpha1/peeringprefixes.go | 48 +++++ .../networking/v1alpha1/peeringprefixref.go | 35 ++++ .../v1alpha1/peeringprefixstatus.go | 39 +++++ client-go/applyconfigurations/utils.go | 6 + client-go/openapi/api_violations.report | 2 + client-go/openapi/zz_generated.openapi.go | 130 +++++++++++++- docs/api-reference/networking.md | 165 ++++++++++++++++++ internal/apis/networking/network_type.go | 33 ++++ .../v1alpha1/zz_generated.conversion.go | 106 +++++++++++ .../apis/networking/validation/network.go | 53 ++++++ .../networking/validation/network_test.go | 39 +++++ .../apis/networking/zz_generated.deepcopy.go | 79 ++++++++- 18 files changed, 966 insertions(+), 7 deletions(-) create mode 100644 client-go/applyconfigurations/networking/v1alpha1/peeringprefix.go create mode 100644 client-go/applyconfigurations/networking/v1alpha1/peeringprefixes.go create mode 100644 client-go/applyconfigurations/networking/v1alpha1/peeringprefixref.go create mode 100644 client-go/applyconfigurations/networking/v1alpha1/peeringprefixstatus.go diff --git a/api/networking/v1alpha1/network_type.go b/api/networking/v1alpha1/network_type.go index b3dbe43e2..6b6ea0358 100644 --- a/api/networking/v1alpha1/network_type.go +++ b/api/networking/v1alpha1/network_type.go @@ -4,6 +4,7 @@ package v1alpha1 import ( + commonv1alpha1 "github.com/ironcore-dev/ironcore/api/common/v1alpha1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/types" ) @@ -51,6 +52,28 @@ type NetworkPeering struct { // NetworkRef is the reference to the network to peer with. // An empty namespace indicates that the target network resides in the same namespace as the source network. NetworkRef NetworkPeeringNetworkRef `json:"networkRef"` + // Prefixes is a list of prefixes that we want only to be exposed + // to the peered network, if no prefixes are specified no filtering will be done. + Prefixes []PeeringPrefix `json:"prefixes,omitempty"` +} + +// PeeringPrefixes defines prefixes to be exposed to the peered network +type PeeringPrefix struct { + // Name is the semantical name of the peering prefixes + Name string `json:"name"` + // CIDR to be exposed to the peered network + Prefix *commonv1alpha1.IPPrefix `json:"prefix,omitempty"` + // PrefixRef is the reference to the prefix to be exposed to peered network + // An empty namespace indicates that the prefix resides in the same namespace as the source network. + PrefixRef PeeringPrefixRef `json:"prefixRef,omitempty"` +} + +type PeeringPrefixRef struct { + // Namespace is the namespace of the referenced entity. If empty, + // the same namespace as the referring resource is implied. + Namespace string `json:"namespace,omitempty"` + // Name is the name of the referenced entity. + Name string `json:"name"` } // NetworkStatus defines the observed state of Network @@ -86,6 +109,16 @@ type NetworkPeeringStatus struct { Name string `json:"name"` // State represents the network peering state State NetworkPeeringState `json:"state,omitempty"` + // Prefixes contains the prefixes exposed to the peered network + Prefixes []PeeringPrefixStatus `json:"prefixes,omitempty"` +} + +// PeeringPrefixStatus lists prefixes exposed to peered network +type PeeringPrefixStatus struct { + // Name is the name of the peering prefix + Name string `json:"name"` + // CIDR exposed to the peered network + Prefix *commonv1alpha1.IPPrefix `json:"prefix,omitempty"` } const ( diff --git a/api/networking/v1alpha1/zz_generated.deepcopy.go b/api/networking/v1alpha1/zz_generated.deepcopy.go index 5970f5240..3d068d091 100644 --- a/api/networking/v1alpha1/zz_generated.deepcopy.go +++ b/api/networking/v1alpha1/zz_generated.deepcopy.go @@ -705,6 +705,13 @@ func (in *NetworkList) DeepCopyObject() runtime.Object { func (in *NetworkPeering) DeepCopyInto(out *NetworkPeering) { *out = *in out.NetworkRef = in.NetworkRef + if in.Prefixes != nil { + in, out := &in.Prefixes, &out.Prefixes + *out = make([]PeeringPrefix, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } return } @@ -753,6 +760,13 @@ func (in *NetworkPeeringNetworkRef) DeepCopy() *NetworkPeeringNetworkRef { // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *NetworkPeeringStatus) DeepCopyInto(out *NetworkPeeringStatus) { *out = *in + if in.Prefixes != nil { + in, out := &in.Prefixes, &out.Prefixes + *out = make([]PeeringPrefixStatus, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } return } @@ -1022,7 +1036,9 @@ func (in *NetworkSpec) DeepCopyInto(out *NetworkSpec) { if in.Peerings != nil { in, out := &in.Peerings, &out.Peerings *out = make([]NetworkPeering, len(*in)) - copy(*out, *in) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } } if in.PeeringClaimRefs != nil { in, out := &in.PeeringClaimRefs, &out.PeeringClaimRefs @@ -1048,7 +1064,9 @@ func (in *NetworkStatus) DeepCopyInto(out *NetworkStatus) { if in.Peerings != nil { in, out := &in.Peerings, &out.Peerings *out = make([]NetworkPeeringStatus, len(*in)) - copy(*out, *in) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } } return } @@ -1063,6 +1081,63 @@ func (in *NetworkStatus) DeepCopy() *NetworkStatus { return out } +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *PeeringPrefix) DeepCopyInto(out *PeeringPrefix) { + *out = *in + if in.Prefix != nil { + in, out := &in.Prefix, &out.Prefix + *out = (*in).DeepCopy() + } + out.PrefixRef = in.PrefixRef + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new PeeringPrefix. +func (in *PeeringPrefix) DeepCopy() *PeeringPrefix { + if in == nil { + return nil + } + out := new(PeeringPrefix) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *PeeringPrefixRef) DeepCopyInto(out *PeeringPrefixRef) { + *out = *in + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new PeeringPrefixRef. +func (in *PeeringPrefixRef) DeepCopy() *PeeringPrefixRef { + if in == nil { + return nil + } + out := new(PeeringPrefixRef) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *PeeringPrefixStatus) DeepCopyInto(out *PeeringPrefixStatus) { + *out = *in + if in.Prefix != nil { + in, out := &in.Prefix, &out.Prefix + *out = (*in).DeepCopy() + } + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new PeeringPrefixStatus. +func (in *PeeringPrefixStatus) DeepCopy() *PeeringPrefixStatus { + if in == nil { + return nil + } + out := new(PeeringPrefixStatus) + in.DeepCopyInto(out) + return out +} + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *PrefixSource) DeepCopyInto(out *PrefixSource) { *out = *in diff --git a/client-go/applyconfigurations/internal/internal.go b/client-go/applyconfigurations/internal/internal.go index edc14f8e5..006ad46e7 100644 --- a/client-go/applyconfigurations/internal/internal.go +++ b/client-go/applyconfigurations/internal/internal.go @@ -964,6 +964,12 @@ var schemaYAML = typed.YAMLObject(`types: type: namedType: com.github.ironcore-dev.ironcore.api.networking.v1alpha1.NetworkPeeringNetworkRef default: {} + - name: prefixes + type: + list: + elementType: + namedType: com.github.ironcore-dev.ironcore.api.networking.v1alpha1.PeeringPrefix + elementRelationship: atomic - name: com.github.ironcore-dev.ironcore.api.networking.v1alpha1.NetworkPeeringClaimRef map: fields: @@ -994,6 +1000,12 @@ var schemaYAML = typed.YAMLObject(`types: type: scalar: string default: "" + - name: prefixes + type: + list: + elementType: + namedType: com.github.ironcore-dev.ironcore.api.networking.v1alpha1.PeeringPrefixStatus + elementRelationship: atomic - name: state type: scalar: string @@ -1168,6 +1180,40 @@ var schemaYAML = typed.YAMLObject(`types: - name: state type: scalar: string +- name: com.github.ironcore-dev.ironcore.api.networking.v1alpha1.PeeringPrefix + map: + fields: + - name: name + type: + scalar: string + default: "" + - name: prefix + type: + namedType: com.github.ironcore-dev.ironcore.api.common.v1alpha1.IPPrefix + - name: prefixRef + type: + namedType: com.github.ironcore-dev.ironcore.api.networking.v1alpha1.PeeringPrefixRef + default: {} +- name: com.github.ironcore-dev.ironcore.api.networking.v1alpha1.PeeringPrefixRef + map: + fields: + - name: name + type: + scalar: string + default: "" + - name: namespace + type: + scalar: string +- name: com.github.ironcore-dev.ironcore.api.networking.v1alpha1.PeeringPrefixStatus + map: + fields: + - name: name + type: + scalar: string + default: "" + - name: prefix + type: + namedType: com.github.ironcore-dev.ironcore.api.common.v1alpha1.IPPrefix - name: com.github.ironcore-dev.ironcore.api.networking.v1alpha1.PrefixSource map: fields: diff --git a/client-go/applyconfigurations/networking/v1alpha1/networkpeering.go b/client-go/applyconfigurations/networking/v1alpha1/networkpeering.go index 4a8b92b14..261e69e94 100644 --- a/client-go/applyconfigurations/networking/v1alpha1/networkpeering.go +++ b/client-go/applyconfigurations/networking/v1alpha1/networkpeering.go @@ -10,6 +10,7 @@ package v1alpha1 type NetworkPeeringApplyConfiguration struct { Name *string `json:"name,omitempty"` NetworkRef *NetworkPeeringNetworkRefApplyConfiguration `json:"networkRef,omitempty"` + Prefixes []PeeringPrefixApplyConfiguration `json:"prefixes,omitempty"` } // NetworkPeeringApplyConfiguration constructs an declarative configuration of the NetworkPeering type for use with @@ -33,3 +34,16 @@ func (b *NetworkPeeringApplyConfiguration) WithNetworkRef(value *NetworkPeeringN b.NetworkRef = value return b } + +// WithPrefixes adds the given value to the Prefixes 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 Prefixes field. +func (b *NetworkPeeringApplyConfiguration) WithPrefixes(values ...*PeeringPrefixApplyConfiguration) *NetworkPeeringApplyConfiguration { + for i := range values { + if values[i] == nil { + panic("nil value passed to WithPrefixes") + } + b.Prefixes = append(b.Prefixes, *values[i]) + } + return b +} diff --git a/client-go/applyconfigurations/networking/v1alpha1/networkpeeringstatus.go b/client-go/applyconfigurations/networking/v1alpha1/networkpeeringstatus.go index b89d0e54c..1433e3d42 100644 --- a/client-go/applyconfigurations/networking/v1alpha1/networkpeeringstatus.go +++ b/client-go/applyconfigurations/networking/v1alpha1/networkpeeringstatus.go @@ -12,8 +12,9 @@ import ( // NetworkPeeringStatusApplyConfiguration represents an declarative configuration of the NetworkPeeringStatus type for use // with apply. type NetworkPeeringStatusApplyConfiguration struct { - Name *string `json:"name,omitempty"` - State *v1alpha1.NetworkPeeringState `json:"state,omitempty"` + Name *string `json:"name,omitempty"` + State *v1alpha1.NetworkPeeringState `json:"state,omitempty"` + Prefixes []PeeringPrefixStatusApplyConfiguration `json:"prefixes,omitempty"` } // NetworkPeeringStatusApplyConfiguration constructs an declarative configuration of the NetworkPeeringStatus type for use with @@ -37,3 +38,16 @@ func (b *NetworkPeeringStatusApplyConfiguration) WithState(value v1alpha1.Networ b.State = &value return b } + +// WithPrefixes adds the given value to the Prefixes 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 Prefixes field. +func (b *NetworkPeeringStatusApplyConfiguration) WithPrefixes(values ...*PeeringPrefixStatusApplyConfiguration) *NetworkPeeringStatusApplyConfiguration { + for i := range values { + if values[i] == nil { + panic("nil value passed to WithPrefixes") + } + b.Prefixes = append(b.Prefixes, *values[i]) + } + return b +} diff --git a/client-go/applyconfigurations/networking/v1alpha1/peeringprefix.go b/client-go/applyconfigurations/networking/v1alpha1/peeringprefix.go new file mode 100644 index 000000000..db24de96a --- /dev/null +++ b/client-go/applyconfigurations/networking/v1alpha1/peeringprefix.go @@ -0,0 +1,48 @@ +// SPDX-FileCopyrightText: 2023 SAP SE or an SAP affiliate company and IronCore contributors +// SPDX-License-Identifier: Apache-2.0 + +// Code generated by applyconfiguration-gen. DO NOT EDIT. + +package v1alpha1 + +import ( + v1alpha1 "github.com/ironcore-dev/ironcore/api/common/v1alpha1" +) + +// PeeringPrefixApplyConfiguration represents an declarative configuration of the PeeringPrefix type for use +// with apply. +type PeeringPrefixApplyConfiguration struct { + Name *string `json:"name,omitempty"` + Prefix *v1alpha1.IPPrefix `json:"prefix,omitempty"` + PrefixRef *PeeringPrefixRefApplyConfiguration `json:"prefixRef,omitempty"` +} + +// PeeringPrefixApplyConfiguration constructs an declarative configuration of the PeeringPrefix type for use with +// apply. +func PeeringPrefix() *PeeringPrefixApplyConfiguration { + return &PeeringPrefixApplyConfiguration{} +} + +// 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 *PeeringPrefixApplyConfiguration) WithName(value string) *PeeringPrefixApplyConfiguration { + b.Name = &value + return b +} + +// WithPrefix sets the Prefix 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 Prefix field is set to the value of the last call. +func (b *PeeringPrefixApplyConfiguration) WithPrefix(value v1alpha1.IPPrefix) *PeeringPrefixApplyConfiguration { + b.Prefix = &value + return b +} + +// WithPrefixRef sets the PrefixRef 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 PrefixRef field is set to the value of the last call. +func (b *PeeringPrefixApplyConfiguration) WithPrefixRef(value *PeeringPrefixRefApplyConfiguration) *PeeringPrefixApplyConfiguration { + b.PrefixRef = value + return b +} diff --git a/client-go/applyconfigurations/networking/v1alpha1/peeringprefixes.go b/client-go/applyconfigurations/networking/v1alpha1/peeringprefixes.go new file mode 100644 index 000000000..d3c65ae8e --- /dev/null +++ b/client-go/applyconfigurations/networking/v1alpha1/peeringprefixes.go @@ -0,0 +1,48 @@ +// SPDX-FileCopyrightText: 2023 SAP SE or an SAP affiliate company and IronCore contributors +// SPDX-License-Identifier: Apache-2.0 + +// Code generated by applyconfiguration-gen. DO NOT EDIT. + +package v1alpha1 + +import ( + v1alpha1 "github.com/ironcore-dev/ironcore/api/common/v1alpha1" +) + +// PeeringPrefixesApplyConfiguration represents an declarative configuration of the PeeringPrefixes type for use +// with apply. +type PeeringPrefixesApplyConfiguration struct { + Name *string `json:"name,omitempty"` + Prefix *v1alpha1.IPPrefix `json:"prefix,omitempty"` + PrefixRef *PeeringPrefixRefApplyConfiguration `json:"prefixRef,omitempty"` +} + +// PeeringPrefixesApplyConfiguration constructs an declarative configuration of the PeeringPrefixes type for use with +// apply. +func PeeringPrefixes() *PeeringPrefixesApplyConfiguration { + return &PeeringPrefixesApplyConfiguration{} +} + +// 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 *PeeringPrefixesApplyConfiguration) WithName(value string) *PeeringPrefixesApplyConfiguration { + b.Name = &value + return b +} + +// WithPrefix sets the Prefix 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 Prefix field is set to the value of the last call. +func (b *PeeringPrefixesApplyConfiguration) WithPrefix(value v1alpha1.IPPrefix) *PeeringPrefixesApplyConfiguration { + b.Prefix = &value + return b +} + +// WithPrefixRef sets the PrefixRef 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 PrefixRef field is set to the value of the last call. +func (b *PeeringPrefixesApplyConfiguration) WithPrefixRef(value *PeeringPrefixRefApplyConfiguration) *PeeringPrefixesApplyConfiguration { + b.PrefixRef = value + return b +} diff --git a/client-go/applyconfigurations/networking/v1alpha1/peeringprefixref.go b/client-go/applyconfigurations/networking/v1alpha1/peeringprefixref.go new file mode 100644 index 000000000..0abae6c3a --- /dev/null +++ b/client-go/applyconfigurations/networking/v1alpha1/peeringprefixref.go @@ -0,0 +1,35 @@ +// SPDX-FileCopyrightText: 2023 SAP SE or an SAP affiliate company and IronCore contributors +// SPDX-License-Identifier: Apache-2.0 + +// Code generated by applyconfiguration-gen. DO NOT EDIT. + +package v1alpha1 + +// PeeringPrefixRefApplyConfiguration represents an declarative configuration of the PeeringPrefixRef type for use +// with apply. +type PeeringPrefixRefApplyConfiguration struct { + Namespace *string `json:"namespace,omitempty"` + Name *string `json:"name,omitempty"` +} + +// PeeringPrefixRefApplyConfiguration constructs an declarative configuration of the PeeringPrefixRef type for use with +// apply. +func PeeringPrefixRef() *PeeringPrefixRefApplyConfiguration { + return &PeeringPrefixRefApplyConfiguration{} +} + +// 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 *PeeringPrefixRefApplyConfiguration) WithNamespace(value string) *PeeringPrefixRefApplyConfiguration { + b.Namespace = &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 *PeeringPrefixRefApplyConfiguration) WithName(value string) *PeeringPrefixRefApplyConfiguration { + b.Name = &value + return b +} diff --git a/client-go/applyconfigurations/networking/v1alpha1/peeringprefixstatus.go b/client-go/applyconfigurations/networking/v1alpha1/peeringprefixstatus.go new file mode 100644 index 000000000..0629b942a --- /dev/null +++ b/client-go/applyconfigurations/networking/v1alpha1/peeringprefixstatus.go @@ -0,0 +1,39 @@ +// SPDX-FileCopyrightText: 2023 SAP SE or an SAP affiliate company and IronCore contributors +// SPDX-License-Identifier: Apache-2.0 + +// Code generated by applyconfiguration-gen. DO NOT EDIT. + +package v1alpha1 + +import ( + v1alpha1 "github.com/ironcore-dev/ironcore/api/common/v1alpha1" +) + +// PeeringPrefixStatusApplyConfiguration represents an declarative configuration of the PeeringPrefixStatus type for use +// with apply. +type PeeringPrefixStatusApplyConfiguration struct { + Name *string `json:"name,omitempty"` + Prefix *v1alpha1.IPPrefix `json:"prefix,omitempty"` +} + +// PeeringPrefixStatusApplyConfiguration constructs an declarative configuration of the PeeringPrefixStatus type for use with +// apply. +func PeeringPrefixStatus() *PeeringPrefixStatusApplyConfiguration { + return &PeeringPrefixStatusApplyConfiguration{} +} + +// 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 *PeeringPrefixStatusApplyConfiguration) WithName(value string) *PeeringPrefixStatusApplyConfiguration { + b.Name = &value + return b +} + +// WithPrefix sets the Prefix 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 Prefix field is set to the value of the last call. +func (b *PeeringPrefixStatusApplyConfiguration) WithPrefix(value v1alpha1.IPPrefix) *PeeringPrefixStatusApplyConfiguration { + b.Prefix = &value + return b +} diff --git a/client-go/applyconfigurations/utils.go b/client-go/applyconfigurations/utils.go index 22cfff1b2..ea445118c 100644 --- a/client-go/applyconfigurations/utils.go +++ b/client-go/applyconfigurations/utils.go @@ -192,6 +192,12 @@ func ForKind(kind schema.GroupVersionKind) interface{} { return &applyconfigurationsnetworkingv1alpha1.NetworkSpecApplyConfiguration{} case networkingv1alpha1.SchemeGroupVersion.WithKind("NetworkStatus"): return &applyconfigurationsnetworkingv1alpha1.NetworkStatusApplyConfiguration{} + case networkingv1alpha1.SchemeGroupVersion.WithKind("PeeringPrefix"): + return &applyconfigurationsnetworkingv1alpha1.PeeringPrefixApplyConfiguration{} + case networkingv1alpha1.SchemeGroupVersion.WithKind("PeeringPrefixRef"): + return &applyconfigurationsnetworkingv1alpha1.PeeringPrefixRefApplyConfiguration{} + case networkingv1alpha1.SchemeGroupVersion.WithKind("PeeringPrefixStatus"): + return &applyconfigurationsnetworkingv1alpha1.PeeringPrefixStatusApplyConfiguration{} case networkingv1alpha1.SchemeGroupVersion.WithKind("PrefixSource"): return &applyconfigurationsnetworkingv1alpha1.PrefixSourceApplyConfiguration{} case networkingv1alpha1.SchemeGroupVersion.WithKind("VirtualIP"): diff --git a/client-go/openapi/api_violations.report b/client-go/openapi/api_violations.report index ae44727b3..e90a1b980 100644 --- a/client-go/openapi/api_violations.report +++ b/client-go/openapi/api_violations.report @@ -24,6 +24,8 @@ API rule violation: list_type_missing,github.com/ironcore-dev/ironcore/api/netwo API rule violation: list_type_missing,github.com/ironcore-dev/ironcore/api/networking/v1alpha1,NetworkInterfaceSpec,Prefixes API rule violation: list_type_missing,github.com/ironcore-dev/ironcore/api/networking/v1alpha1,NetworkInterfaceStatus,IPs API rule violation: list_type_missing,github.com/ironcore-dev/ironcore/api/networking/v1alpha1,NetworkInterfaceStatus,Prefixes +API rule violation: list_type_missing,github.com/ironcore-dev/ironcore/api/networking/v1alpha1,NetworkPeering,Prefixes +API rule violation: list_type_missing,github.com/ironcore-dev/ironcore/api/networking/v1alpha1,NetworkPeeringStatus,Prefixes API rule violation: list_type_missing,github.com/ironcore-dev/ironcore/api/networking/v1alpha1,NetworkPolicyEgressRule,Ports API rule violation: list_type_missing,github.com/ironcore-dev/ironcore/api/networking/v1alpha1,NetworkPolicyEgressRule,To API rule violation: list_type_missing,github.com/ironcore-dev/ironcore/api/networking/v1alpha1,NetworkPolicyIngressRule,From diff --git a/client-go/openapi/zz_generated.openapi.go b/client-go/openapi/zz_generated.openapi.go index e8fb61558..a9012e0a6 100644 --- a/client-go/openapi/zz_generated.openapi.go +++ b/client-go/openapi/zz_generated.openapi.go @@ -109,6 +109,9 @@ func GetOpenAPIDefinitions(ref common.ReferenceCallback) map[string]common.OpenA "github.com/ironcore-dev/ironcore/api/networking/v1alpha1.NetworkPolicyStatus": schema_ironcore_api_networking_v1alpha1_NetworkPolicyStatus(ref), "github.com/ironcore-dev/ironcore/api/networking/v1alpha1.NetworkSpec": schema_ironcore_api_networking_v1alpha1_NetworkSpec(ref), "github.com/ironcore-dev/ironcore/api/networking/v1alpha1.NetworkStatus": schema_ironcore_api_networking_v1alpha1_NetworkStatus(ref), + "github.com/ironcore-dev/ironcore/api/networking/v1alpha1.PeeringPrefix": schema_ironcore_api_networking_v1alpha1_PeeringPrefix(ref), + "github.com/ironcore-dev/ironcore/api/networking/v1alpha1.PeeringPrefixRef": schema_ironcore_api_networking_v1alpha1_PeeringPrefixRef(ref), + "github.com/ironcore-dev/ironcore/api/networking/v1alpha1.PeeringPrefixStatus": schema_ironcore_api_networking_v1alpha1_PeeringPrefixStatus(ref), "github.com/ironcore-dev/ironcore/api/networking/v1alpha1.PrefixSource": schema_ironcore_api_networking_v1alpha1_PrefixSource(ref), "github.com/ironcore-dev/ironcore/api/networking/v1alpha1.VirtualIP": schema_ironcore_api_networking_v1alpha1_VirtualIP(ref), "github.com/ironcore-dev/ironcore/api/networking/v1alpha1.VirtualIPList": schema_ironcore_api_networking_v1alpha1_VirtualIPList(ref), @@ -3620,12 +3623,26 @@ func schema_ironcore_api_networking_v1alpha1_NetworkPeering(ref common.Reference Ref: ref("github.com/ironcore-dev/ironcore/api/networking/v1alpha1.NetworkPeeringNetworkRef"), }, }, + "prefixes": { + SchemaProps: spec.SchemaProps{ + Description: "Prefixes is a list of prefixes that we want only to be exposed to the peered network, if no prefixes are specified no filtering will be done.", + Type: []string{"array"}, + Items: &spec.SchemaOrArray{ + Schema: &spec.Schema{ + SchemaProps: spec.SchemaProps{ + Default: map[string]interface{}{}, + Ref: ref("github.com/ironcore-dev/ironcore/api/networking/v1alpha1.PeeringPrefix"), + }, + }, + }, + }, + }, }, Required: []string{"name", "networkRef"}, }, }, Dependencies: []string{ - "github.com/ironcore-dev/ironcore/api/networking/v1alpha1.NetworkPeeringNetworkRef"}, + "github.com/ironcore-dev/ironcore/api/networking/v1alpha1.NetworkPeeringNetworkRef", "github.com/ironcore-dev/ironcore/api/networking/v1alpha1.PeeringPrefix"}, } } @@ -3715,10 +3732,26 @@ func schema_ironcore_api_networking_v1alpha1_NetworkPeeringStatus(ref common.Ref Format: "", }, }, + "prefixes": { + SchemaProps: spec.SchemaProps{ + Description: "Prefixes contains the prefixes exposed to the peered network", + Type: []string{"array"}, + Items: &spec.SchemaOrArray{ + Schema: &spec.Schema{ + SchemaProps: spec.SchemaProps{ + Default: map[string]interface{}{}, + Ref: ref("github.com/ironcore-dev/ironcore/api/networking/v1alpha1.PeeringPrefixStatus"), + }, + }, + }, + }, + }, }, Required: []string{"name"}, }, }, + Dependencies: []string{ + "github.com/ironcore-dev/ironcore/api/networking/v1alpha1.PeeringPrefixStatus"}, } } @@ -4234,6 +4267,101 @@ func schema_ironcore_api_networking_v1alpha1_NetworkStatus(ref common.ReferenceC } } +func schema_ironcore_api_networking_v1alpha1_PeeringPrefix(ref common.ReferenceCallback) common.OpenAPIDefinition { + return common.OpenAPIDefinition{ + Schema: spec.Schema{ + SchemaProps: spec.SchemaProps{ + Description: "PeeringPrefixes defines prefixes to be exposed to the peered network", + Type: []string{"object"}, + Properties: map[string]spec.Schema{ + "name": { + SchemaProps: spec.SchemaProps{ + Description: "Name is the semantical name of the peering prefixes", + Default: "", + Type: []string{"string"}, + Format: "", + }, + }, + "prefix": { + SchemaProps: spec.SchemaProps{ + Description: "CIDR to be exposed to the peered network", + Ref: ref("github.com/ironcore-dev/ironcore/api/common/v1alpha1.IPPrefix"), + }, + }, + "prefixRef": { + SchemaProps: spec.SchemaProps{ + Description: "PrefixRef is the reference to the prefix to be exposed to peered network An empty namespace indicates that the prefix resides in the same namespace as the source network.", + Default: map[string]interface{}{}, + Ref: ref("github.com/ironcore-dev/ironcore/api/networking/v1alpha1.PeeringPrefixRef"), + }, + }, + }, + Required: []string{"name"}, + }, + }, + Dependencies: []string{ + "github.com/ironcore-dev/ironcore/api/common/v1alpha1.IPPrefix", "github.com/ironcore-dev/ironcore/api/networking/v1alpha1.PeeringPrefixRef"}, + } +} + +func schema_ironcore_api_networking_v1alpha1_PeeringPrefixRef(ref common.ReferenceCallback) common.OpenAPIDefinition { + return common.OpenAPIDefinition{ + Schema: spec.Schema{ + SchemaProps: spec.SchemaProps{ + Type: []string{"object"}, + Properties: map[string]spec.Schema{ + "namespace": { + SchemaProps: spec.SchemaProps{ + Description: "Namespace is the namespace of the referenced entity. If empty, the same namespace as the referring resource is implied.", + Type: []string{"string"}, + Format: "", + }, + }, + "name": { + SchemaProps: spec.SchemaProps{ + Description: "Name is the name of the referenced entity.", + Default: "", + Type: []string{"string"}, + Format: "", + }, + }, + }, + Required: []string{"name"}, + }, + }, + } +} + +func schema_ironcore_api_networking_v1alpha1_PeeringPrefixStatus(ref common.ReferenceCallback) common.OpenAPIDefinition { + return common.OpenAPIDefinition{ + Schema: spec.Schema{ + SchemaProps: spec.SchemaProps{ + Description: "PeeringPrefixStatus lists prefixes exposed to peered network", + Type: []string{"object"}, + Properties: map[string]spec.Schema{ + "name": { + SchemaProps: spec.SchemaProps{ + Description: "Name is the name of the peering prefix", + Default: "", + Type: []string{"string"}, + Format: "", + }, + }, + "prefix": { + SchemaProps: spec.SchemaProps{ + Description: "CIDR exposed to the peered network", + Ref: ref("github.com/ironcore-dev/ironcore/api/common/v1alpha1.IPPrefix"), + }, + }, + }, + Required: []string{"name"}, + }, + }, + Dependencies: []string{ + "github.com/ironcore-dev/ironcore/api/common/v1alpha1.IPPrefix"}, + } +} + func schema_ironcore_api_networking_v1alpha1_PrefixSource(ref common.ReferenceCallback) common.OpenAPIDefinition { return common.OpenAPIDefinition{ Schema: spec.Schema{ diff --git a/docs/api-reference/networking.md b/docs/api-reference/networking.md index fc147fdc6..92e44dd51 100644 --- a/docs/api-reference/networking.md +++ b/docs/api-reference/networking.md @@ -1907,6 +1907,20 @@ NetworkPeeringNetworkRef An empty namespace indicates that the target network resides in the same namespace as the source network.

+ + +prefixes
+ + +[]PeeringPrefix + + + + +

Prefixes is a list of prefixes that we want only to be exposed +to the peered network, if no prefixes are specified no filtering will be done.

+ +

NetworkPeeringClaimRef @@ -2069,6 +2083,19 @@ NetworkPeeringState

State represents the network peering state

+ + +prefixes
+ + +[]PeeringPrefixStatus + + + + +

Prefixes contains the prefixes exposed to the peered network

+ +

NetworkPolicyCondition @@ -2610,6 +2637,144 @@ NetworkState +

PeeringPrefix +

+

+(Appears on:NetworkPeering) +

+
+

PeeringPrefixes defines prefixes to be exposed to the peered network

+
+ + + + + + + + + + + + + + + + + + + + + +
FieldDescription
+name
+ +string + +
+

Name is the semantical name of the peering prefixes

+
+prefix
+ + +github.com/ironcore-dev/ironcore/api/common/v1alpha1.IPPrefix + + +
+

CIDR to be exposed to the peered network

+
+prefixRef
+ + +PeeringPrefixRef + + +
+

PrefixRef is the reference to the prefix to be exposed to peered network +An empty namespace indicates that the prefix resides in the same namespace as the source network.

+
+

PeeringPrefixRef +

+

+(Appears on:PeeringPrefix) +

+
+
+ + + + + + + + + + + + + + + + + +
FieldDescription
+namespace
+ +string + +
+

Namespace is the namespace of the referenced entity. If empty, +the same namespace as the referring resource is implied.

+
+name
+ +string + +
+

Name is the name of the referenced entity.

+
+

PeeringPrefixStatus +

+

+(Appears on:NetworkPeeringStatus) +

+
+

PeeringPrefixStatus lists prefixes exposed to peered network

+
+ + + + + + + + + + + + + + + + + +
FieldDescription
+name
+ +string + +
+

Name is the name of the peering prefix

+
+prefix
+ + +github.com/ironcore-dev/ironcore/api/common/v1alpha1.IPPrefix + + +
+

CIDR exposed to the peered network

+

PolicyType (string alias)

diff --git a/internal/apis/networking/network_type.go b/internal/apis/networking/network_type.go index d6ded9fc1..75c167690 100644 --- a/internal/apis/networking/network_type.go +++ b/internal/apis/networking/network_type.go @@ -4,6 +4,7 @@ package networking import ( + commonv1alpha1 "github.com/ironcore-dev/ironcore/api/common/v1alpha1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/types" ) @@ -51,6 +52,28 @@ type NetworkPeering struct { // NetworkRef is the reference to the network to peer with. // An empty namespace indicates that the target network resides in the same namespace as the source network. NetworkRef NetworkPeeringNetworkRef + // Prefixes is a list of prefixes that we want only to be exposed + // to the peered network, if no prefixes are specified no filtering will be done. + Prefixes []PeeringPrefix +} + +// PeeringPrefixes defines prefixes to be exposed to the peered network +type PeeringPrefix struct { + // Name is the semantical name of the peering prefixes + Name string + // CIDR to be exposed to the peered network + Prefix *commonv1alpha1.IPPrefix + // PrefixRef is the reference to the prefix to be exposed to peered network + // An empty namespace indicates that the prefix resides in the same namespace as the source network. + PrefixRef PeeringPrefixRef +} + +type PeeringPrefixRef struct { + // Namespace is the namespace of the referenced entity. If empty, + // the same namespace as the referring resource is implied. + Namespace string + // Name is the name of the referenced entity. + Name string } // NetworkStatus defines the observed state of Network @@ -86,6 +109,16 @@ type NetworkPeeringStatus struct { Name string // State represents the network peering state State NetworkPeeringState + // Prefixes contains the prefixes exposed to the peered network + Prefixes []PeeringPrefixStatus +} + +// PeeringPrefixStatus lists prefixes exposed to peered network +type PeeringPrefixStatus struct { + // Name is the name of the peering prefix + Name string + // CIDR exposed to the peered network + Prefix *commonv1alpha1.IPPrefix } const ( diff --git a/internal/apis/networking/v1alpha1/zz_generated.conversion.go b/internal/apis/networking/v1alpha1/zz_generated.conversion.go index 6231d2651..67e66236e 100644 --- a/internal/apis/networking/v1alpha1/zz_generated.conversion.go +++ b/internal/apis/networking/v1alpha1/zz_generated.conversion.go @@ -422,6 +422,36 @@ func RegisterConversions(s *runtime.Scheme) error { }); err != nil { return err } + if err := s.AddGeneratedConversionFunc((*v1alpha1.PeeringPrefix)(nil), (*networking.PeeringPrefix)(nil), func(a, b interface{}, scope conversion.Scope) error { + return Convert_v1alpha1_PeeringPrefix_To_networking_PeeringPrefix(a.(*v1alpha1.PeeringPrefix), b.(*networking.PeeringPrefix), scope) + }); err != nil { + return err + } + if err := s.AddGeneratedConversionFunc((*networking.PeeringPrefix)(nil), (*v1alpha1.PeeringPrefix)(nil), func(a, b interface{}, scope conversion.Scope) error { + return Convert_networking_PeeringPrefix_To_v1alpha1_PeeringPrefix(a.(*networking.PeeringPrefix), b.(*v1alpha1.PeeringPrefix), scope) + }); err != nil { + return err + } + if err := s.AddGeneratedConversionFunc((*v1alpha1.PeeringPrefixRef)(nil), (*networking.PeeringPrefixRef)(nil), func(a, b interface{}, scope conversion.Scope) error { + return Convert_v1alpha1_PeeringPrefixRef_To_networking_PeeringPrefixRef(a.(*v1alpha1.PeeringPrefixRef), b.(*networking.PeeringPrefixRef), scope) + }); err != nil { + return err + } + if err := s.AddGeneratedConversionFunc((*networking.PeeringPrefixRef)(nil), (*v1alpha1.PeeringPrefixRef)(nil), func(a, b interface{}, scope conversion.Scope) error { + return Convert_networking_PeeringPrefixRef_To_v1alpha1_PeeringPrefixRef(a.(*networking.PeeringPrefixRef), b.(*v1alpha1.PeeringPrefixRef), scope) + }); err != nil { + return err + } + if err := s.AddGeneratedConversionFunc((*v1alpha1.PeeringPrefixStatus)(nil), (*networking.PeeringPrefixStatus)(nil), func(a, b interface{}, scope conversion.Scope) error { + return Convert_v1alpha1_PeeringPrefixStatus_To_networking_PeeringPrefixStatus(a.(*v1alpha1.PeeringPrefixStatus), b.(*networking.PeeringPrefixStatus), scope) + }); err != nil { + return err + } + if err := s.AddGeneratedConversionFunc((*networking.PeeringPrefixStatus)(nil), (*v1alpha1.PeeringPrefixStatus)(nil), func(a, b interface{}, scope conversion.Scope) error { + return Convert_networking_PeeringPrefixStatus_To_v1alpha1_PeeringPrefixStatus(a.(*networking.PeeringPrefixStatus), b.(*v1alpha1.PeeringPrefixStatus), scope) + }); err != nil { + return err + } if err := s.AddGeneratedConversionFunc((*v1alpha1.PrefixSource)(nil), (*networking.PrefixSource)(nil), func(a, b interface{}, scope conversion.Scope) error { return Convert_v1alpha1_PrefixSource_To_networking_PrefixSource(a.(*v1alpha1.PrefixSource), b.(*networking.PrefixSource), scope) }); err != nil { @@ -1100,6 +1130,7 @@ func autoConvert_v1alpha1_NetworkPeering_To_networking_NetworkPeering(in *v1alph if err := Convert_v1alpha1_NetworkPeeringNetworkRef_To_networking_NetworkPeeringNetworkRef(&in.NetworkRef, &out.NetworkRef, s); err != nil { return err } + out.Prefixes = *(*[]networking.PeeringPrefix)(unsafe.Pointer(&in.Prefixes)) return nil } @@ -1113,6 +1144,7 @@ func autoConvert_networking_NetworkPeering_To_v1alpha1_NetworkPeering(in *networ if err := Convert_networking_NetworkPeeringNetworkRef_To_v1alpha1_NetworkPeeringNetworkRef(&in.NetworkRef, &out.NetworkRef, s); err != nil { return err } + out.Prefixes = *(*[]v1alpha1.PeeringPrefix)(unsafe.Pointer(&in.Prefixes)) return nil } @@ -1170,6 +1202,7 @@ func Convert_networking_NetworkPeeringNetworkRef_To_v1alpha1_NetworkPeeringNetwo func autoConvert_v1alpha1_NetworkPeeringStatus_To_networking_NetworkPeeringStatus(in *v1alpha1.NetworkPeeringStatus, out *networking.NetworkPeeringStatus, s conversion.Scope) error { out.Name = in.Name out.State = networking.NetworkPeeringState(in.State) + out.Prefixes = *(*[]networking.PeeringPrefixStatus)(unsafe.Pointer(&in.Prefixes)) return nil } @@ -1181,6 +1214,7 @@ func Convert_v1alpha1_NetworkPeeringStatus_To_networking_NetworkPeeringStatus(in func autoConvert_networking_NetworkPeeringStatus_To_v1alpha1_NetworkPeeringStatus(in *networking.NetworkPeeringStatus, out *v1alpha1.NetworkPeeringStatus, s conversion.Scope) error { out.Name = in.Name out.State = v1alpha1.NetworkPeeringState(in.State) + out.Prefixes = *(*[]v1alpha1.PeeringPrefixStatus)(unsafe.Pointer(&in.Prefixes)) return nil } @@ -1457,6 +1491,78 @@ func Convert_networking_NetworkStatus_To_v1alpha1_NetworkStatus(in *networking.N return autoConvert_networking_NetworkStatus_To_v1alpha1_NetworkStatus(in, out, s) } +func autoConvert_v1alpha1_PeeringPrefix_To_networking_PeeringPrefix(in *v1alpha1.PeeringPrefix, out *networking.PeeringPrefix, s conversion.Scope) error { + out.Name = in.Name + out.Prefix = (*commonv1alpha1.IPPrefix)(unsafe.Pointer(in.Prefix)) + if err := Convert_v1alpha1_PeeringPrefixRef_To_networking_PeeringPrefixRef(&in.PrefixRef, &out.PrefixRef, s); err != nil { + return err + } + return nil +} + +// Convert_v1alpha1_PeeringPrefix_To_networking_PeeringPrefix is an autogenerated conversion function. +func Convert_v1alpha1_PeeringPrefix_To_networking_PeeringPrefix(in *v1alpha1.PeeringPrefix, out *networking.PeeringPrefix, s conversion.Scope) error { + return autoConvert_v1alpha1_PeeringPrefix_To_networking_PeeringPrefix(in, out, s) +} + +func autoConvert_networking_PeeringPrefix_To_v1alpha1_PeeringPrefix(in *networking.PeeringPrefix, out *v1alpha1.PeeringPrefix, s conversion.Scope) error { + out.Name = in.Name + out.Prefix = (*commonv1alpha1.IPPrefix)(unsafe.Pointer(in.Prefix)) + if err := Convert_networking_PeeringPrefixRef_To_v1alpha1_PeeringPrefixRef(&in.PrefixRef, &out.PrefixRef, s); err != nil { + return err + } + return nil +} + +// Convert_networking_PeeringPrefix_To_v1alpha1_PeeringPrefix is an autogenerated conversion function. +func Convert_networking_PeeringPrefix_To_v1alpha1_PeeringPrefix(in *networking.PeeringPrefix, out *v1alpha1.PeeringPrefix, s conversion.Scope) error { + return autoConvert_networking_PeeringPrefix_To_v1alpha1_PeeringPrefix(in, out, s) +} + +func autoConvert_v1alpha1_PeeringPrefixRef_To_networking_PeeringPrefixRef(in *v1alpha1.PeeringPrefixRef, out *networking.PeeringPrefixRef, s conversion.Scope) error { + out.Namespace = in.Namespace + out.Name = in.Name + return nil +} + +// Convert_v1alpha1_PeeringPrefixRef_To_networking_PeeringPrefixRef is an autogenerated conversion function. +func Convert_v1alpha1_PeeringPrefixRef_To_networking_PeeringPrefixRef(in *v1alpha1.PeeringPrefixRef, out *networking.PeeringPrefixRef, s conversion.Scope) error { + return autoConvert_v1alpha1_PeeringPrefixRef_To_networking_PeeringPrefixRef(in, out, s) +} + +func autoConvert_networking_PeeringPrefixRef_To_v1alpha1_PeeringPrefixRef(in *networking.PeeringPrefixRef, out *v1alpha1.PeeringPrefixRef, s conversion.Scope) error { + out.Namespace = in.Namespace + out.Name = in.Name + return nil +} + +// Convert_networking_PeeringPrefixRef_To_v1alpha1_PeeringPrefixRef is an autogenerated conversion function. +func Convert_networking_PeeringPrefixRef_To_v1alpha1_PeeringPrefixRef(in *networking.PeeringPrefixRef, out *v1alpha1.PeeringPrefixRef, s conversion.Scope) error { + return autoConvert_networking_PeeringPrefixRef_To_v1alpha1_PeeringPrefixRef(in, out, s) +} + +func autoConvert_v1alpha1_PeeringPrefixStatus_To_networking_PeeringPrefixStatus(in *v1alpha1.PeeringPrefixStatus, out *networking.PeeringPrefixStatus, s conversion.Scope) error { + out.Name = in.Name + out.Prefix = (*commonv1alpha1.IPPrefix)(unsafe.Pointer(in.Prefix)) + return nil +} + +// Convert_v1alpha1_PeeringPrefixStatus_To_networking_PeeringPrefixStatus is an autogenerated conversion function. +func Convert_v1alpha1_PeeringPrefixStatus_To_networking_PeeringPrefixStatus(in *v1alpha1.PeeringPrefixStatus, out *networking.PeeringPrefixStatus, s conversion.Scope) error { + return autoConvert_v1alpha1_PeeringPrefixStatus_To_networking_PeeringPrefixStatus(in, out, s) +} + +func autoConvert_networking_PeeringPrefixStatus_To_v1alpha1_PeeringPrefixStatus(in *networking.PeeringPrefixStatus, out *v1alpha1.PeeringPrefixStatus, s conversion.Scope) error { + out.Name = in.Name + out.Prefix = (*commonv1alpha1.IPPrefix)(unsafe.Pointer(in.Prefix)) + return nil +} + +// Convert_networking_PeeringPrefixStatus_To_v1alpha1_PeeringPrefixStatus is an autogenerated conversion function. +func Convert_networking_PeeringPrefixStatus_To_v1alpha1_PeeringPrefixStatus(in *networking.PeeringPrefixStatus, out *v1alpha1.PeeringPrefixStatus, s conversion.Scope) error { + return autoConvert_networking_PeeringPrefixStatus_To_v1alpha1_PeeringPrefixStatus(in, out, s) +} + func autoConvert_v1alpha1_PrefixSource_To_networking_PrefixSource(in *v1alpha1.PrefixSource, out *networking.PrefixSource, s conversion.Scope) error { out.Value = (*commonv1alpha1.IPPrefix)(unsafe.Pointer(in.Value)) out.Ephemeral = (*networking.EphemeralPrefixSource)(unsafe.Pointer(in.Ephemeral)) diff --git a/internal/apis/networking/validation/network.go b/internal/apis/networking/validation/network.go index 9631d40b7..51aa42afc 100644 --- a/internal/apis/networking/validation/network.go +++ b/internal/apis/networking/validation/network.go @@ -28,6 +28,9 @@ func validateNetworkSpec(namespace, name string, spec *networking.NetworkSpec, f seenNames := sets.New[string]() seenPeeringNetworkKeys := sets.New[client.ObjectKey]() + seenPrefixNames := sets.New[string]() + seenPeeringPrefixKeys := sets.New[client.ObjectKey]() + for i, peering := range spec.Peerings { fldPath := fldPath.Child("peerings").Index(i) if seenNames.Has(peering.Name) { @@ -51,6 +54,37 @@ func validateNetworkSpec(namespace, name string, spec *networking.NetworkSpec, f seenPeeringNetworkKeys.Insert(peeringNetworkKey) } + for j, prefix := range peering.Prefixes { + fldPath := fldPath.Child("prefixes").Index(j) + + if seenPrefixNames.Has(prefix.Name) { + allErrs = append(allErrs, field.Duplicate(fldPath.Child("name"), prefix.Name)) + } else { + seenPrefixNames.Insert(prefix.Name) + } + + if peeringPrefix := prefix.Prefix; peeringPrefix != nil { + if !peeringPrefix.IsSingleIP() { + allErrs = append(allErrs, field.Forbidden(fldPath.Child("prefix"), "must be a single IP")) + } + } + + peeringPrefixNamespace := prefix.PrefixRef.Namespace + if peeringPrefixNamespace == "" { + peeringPrefixNamespace = namespace + } + + peeringPrefixKey := client.ObjectKey{Namespace: peeringPrefixNamespace, Name: prefix.PrefixRef.Name} + + if seenPeeringPrefixKeys.Has(peeringPrefixKey) { + allErrs = append(allErrs, field.Duplicate(fldPath.Child("prefixRef"), prefix.PrefixRef)) + } else { + seenPeeringPrefixKeys.Insert(peeringPrefixKey) + } + + allErrs = append(allErrs, validatePeeringPrefix(prefix, fldPath)...) + } + allErrs = append(allErrs, validateNetworkPeering(peering, fldPath)...) } @@ -116,6 +150,25 @@ func validatePeeringClaimRef(peeringClaimRef networking.NetworkPeeringClaimRef, allErrs = append(allErrs, field.Invalid(fldPath.Child("namespace"), peeringClaimRef.Namespace, msg)) } } + return allErrs +} + +func validatePeeringPrefix(prefix networking.PeeringPrefix, fldPath *field.Path) field.ErrorList { + var allErrs field.ErrorList + + for _, msg := range apivalidation.NameIsDNSLabel(prefix.Name, false) { + allErrs = append(allErrs, field.Invalid(fldPath.Child("name"), prefix.Name, msg)) + } + + prefixRef := prefix.PrefixRef + if prefixRef.Namespace != "" { + for _, msg := range apivalidation.NameIsDNSLabel(prefixRef.Namespace, false) { + allErrs = append(allErrs, field.Invalid(fldPath.Child("prefixRef", "namespace"), prefixRef.Namespace, msg)) + } + } + for _, msg := range apivalidation.NameIsDNSLabel(prefixRef.Name, false) { + allErrs = append(allErrs, field.Invalid(fldPath.Child("prefixRef", "name"), prefixRef.Name, msg)) + } return allErrs } diff --git a/internal/apis/networking/validation/network_test.go b/internal/apis/networking/validation/network_test.go index e9166bcb7..cf12ab323 100644 --- a/internal/apis/networking/validation/network_test.go +++ b/internal/apis/networking/validation/network_test.go @@ -4,6 +4,7 @@ package validation import ( + commonv1alpha1 "github.com/ironcore-dev/ironcore/api/common/v1alpha1" "github.com/ironcore-dev/ironcore/internal/apis/networking" . "github.com/ironcore-dev/ironcore/internal/testutils/validation" . "github.com/onsi/ginkgo/v2" @@ -114,6 +115,44 @@ var _ = Describe("Network", func() { ContainElements(InvalidField("spec.incomingPeerings[0].namespace"), RequiredField("spec.incomingPeerings[0].name")), ), + Entry("duplicate peering prefix name", + &networking.Network{ + Spec: networking.NetworkSpec{ + Peerings: []networking.NetworkPeering{{ + Prefixes: []networking.PeeringPrefix{ + {Name: "peering"}, + {Name: "peering"}, + }}, + }, + }, + }, + ContainElement(DuplicateField("spec.peerings[0].prefixes[1].name")), + ), + Entry("bad peering prefix cidr", + &networking.Network{ + Spec: networking.NetworkSpec{ + Peerings: []networking.NetworkPeering{{ + Prefixes: []networking.PeeringPrefix{ + {Prefix: &commonv1alpha1.IPPrefix{}}, + }}, + }, + }, + }, + ContainElement(ForbiddenField("spec.peerings[0].prefixes[0].prefix")), + ), + Entry("duplicate peering prefix ref", + &networking.Network{ + Spec: networking.NetworkSpec{ + Peerings: []networking.NetworkPeering{{ + Prefixes: []networking.PeeringPrefix{ + {PrefixRef: networking.PeeringPrefixRef{Name: "foo"}}, + {PrefixRef: networking.PeeringPrefixRef{Name: "foo"}}, + }}, + }, + }, + }, + ContainElement(DuplicateField("spec.peerings[0].prefixes[1].prefixRef")), + ), ) DescribeTable("ValidateNetworkUpdate", diff --git a/internal/apis/networking/zz_generated.deepcopy.go b/internal/apis/networking/zz_generated.deepcopy.go index ba7bee4b3..f131e9eb0 100644 --- a/internal/apis/networking/zz_generated.deepcopy.go +++ b/internal/apis/networking/zz_generated.deepcopy.go @@ -705,6 +705,13 @@ func (in *NetworkList) DeepCopyObject() runtime.Object { func (in *NetworkPeering) DeepCopyInto(out *NetworkPeering) { *out = *in out.NetworkRef = in.NetworkRef + if in.Prefixes != nil { + in, out := &in.Prefixes, &out.Prefixes + *out = make([]PeeringPrefix, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } return } @@ -753,6 +760,13 @@ func (in *NetworkPeeringNetworkRef) DeepCopy() *NetworkPeeringNetworkRef { // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *NetworkPeeringStatus) DeepCopyInto(out *NetworkPeeringStatus) { *out = *in + if in.Prefixes != nil { + in, out := &in.Prefixes, &out.Prefixes + *out = make([]PeeringPrefixStatus, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } return } @@ -1022,7 +1036,9 @@ func (in *NetworkSpec) DeepCopyInto(out *NetworkSpec) { if in.Peerings != nil { in, out := &in.Peerings, &out.Peerings *out = make([]NetworkPeering, len(*in)) - copy(*out, *in) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } } if in.PeeringClaimRefs != nil { in, out := &in.PeeringClaimRefs, &out.PeeringClaimRefs @@ -1048,7 +1064,9 @@ func (in *NetworkStatus) DeepCopyInto(out *NetworkStatus) { if in.Peerings != nil { in, out := &in.Peerings, &out.Peerings *out = make([]NetworkPeeringStatus, len(*in)) - copy(*out, *in) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } } return } @@ -1063,6 +1081,63 @@ func (in *NetworkStatus) DeepCopy() *NetworkStatus { return out } +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *PeeringPrefix) DeepCopyInto(out *PeeringPrefix) { + *out = *in + if in.Prefix != nil { + in, out := &in.Prefix, &out.Prefix + *out = (*in).DeepCopy() + } + out.PrefixRef = in.PrefixRef + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new PeeringPrefix. +func (in *PeeringPrefix) DeepCopy() *PeeringPrefix { + if in == nil { + return nil + } + out := new(PeeringPrefix) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *PeeringPrefixRef) DeepCopyInto(out *PeeringPrefixRef) { + *out = *in + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new PeeringPrefixRef. +func (in *PeeringPrefixRef) DeepCopy() *PeeringPrefixRef { + if in == nil { + return nil + } + out := new(PeeringPrefixRef) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *PeeringPrefixStatus) DeepCopyInto(out *PeeringPrefixStatus) { + *out = *in + if in.Prefix != nil { + in, out := &in.Prefix, &out.Prefix + *out = (*in).DeepCopy() + } + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new PeeringPrefixStatus. +func (in *PeeringPrefixStatus) DeepCopy() *PeeringPrefixStatus { + if in == nil { + return nil + } + out := new(PeeringPrefixStatus) + in.DeepCopyInto(out) + return out +} + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *PrefixSource) DeepCopyInto(out *PrefixSource) { *out = *in From 96690d10a2ce0bda7e76401cb5e2189fde6989da Mon Sep 17 00:00:00 2001 From: Kajol Asabe Date: Mon, 1 Jul 2024 14:03:19 +0530 Subject: [PATCH 2/2] Change PrefixRef type to LocalObjectReference --- api/networking/v1alpha1/network_type.go | 11 +---- .../v1alpha1/zz_generated.deepcopy.go | 16 ------- .../applyconfigurations/internal/internal.go | 12 +---- .../networking/v1alpha1/peeringprefix.go | 11 ++--- client-go/applyconfigurations/utils.go | 2 - client-go/openapi/zz_generated.openapi.go | 33 +------------- docs/api-reference/networking.md | 44 +------------------ internal/apis/networking/network_type.go | 11 +---- .../v1alpha1/zz_generated.conversion.go | 40 +---------------- .../apis/networking/validation/network.go | 12 +---- .../networking/validation/network_test.go | 5 ++- .../apis/networking/zz_generated.deepcopy.go | 16 ------- 12 files changed, 21 insertions(+), 192 deletions(-) diff --git a/api/networking/v1alpha1/network_type.go b/api/networking/v1alpha1/network_type.go index 6b6ea0358..8865c5650 100644 --- a/api/networking/v1alpha1/network_type.go +++ b/api/networking/v1alpha1/network_type.go @@ -5,6 +5,7 @@ package v1alpha1 import ( commonv1alpha1 "github.com/ironcore-dev/ironcore/api/common/v1alpha1" + corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/types" ) @@ -65,15 +66,7 @@ type PeeringPrefix struct { Prefix *commonv1alpha1.IPPrefix `json:"prefix,omitempty"` // PrefixRef is the reference to the prefix to be exposed to peered network // An empty namespace indicates that the prefix resides in the same namespace as the source network. - PrefixRef PeeringPrefixRef `json:"prefixRef,omitempty"` -} - -type PeeringPrefixRef struct { - // Namespace is the namespace of the referenced entity. If empty, - // the same namespace as the referring resource is implied. - Namespace string `json:"namespace,omitempty"` - // Name is the name of the referenced entity. - Name string `json:"name"` + PrefixRef corev1.LocalObjectReference `json:"prefixRef,omitempty"` } // NetworkStatus defines the observed state of Network diff --git a/api/networking/v1alpha1/zz_generated.deepcopy.go b/api/networking/v1alpha1/zz_generated.deepcopy.go index 3d068d091..cf63e51e2 100644 --- a/api/networking/v1alpha1/zz_generated.deepcopy.go +++ b/api/networking/v1alpha1/zz_generated.deepcopy.go @@ -1102,22 +1102,6 @@ func (in *PeeringPrefix) DeepCopy() *PeeringPrefix { return out } -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *PeeringPrefixRef) DeepCopyInto(out *PeeringPrefixRef) { - *out = *in - return -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new PeeringPrefixRef. -func (in *PeeringPrefixRef) DeepCopy() *PeeringPrefixRef { - if in == nil { - return nil - } - out := new(PeeringPrefixRef) - in.DeepCopyInto(out) - return out -} - // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *PeeringPrefixStatus) DeepCopyInto(out *PeeringPrefixStatus) { *out = *in diff --git a/client-go/applyconfigurations/internal/internal.go b/client-go/applyconfigurations/internal/internal.go index 006ad46e7..9e2203f54 100644 --- a/client-go/applyconfigurations/internal/internal.go +++ b/client-go/applyconfigurations/internal/internal.go @@ -1192,18 +1192,8 @@ var schemaYAML = typed.YAMLObject(`types: namedType: com.github.ironcore-dev.ironcore.api.common.v1alpha1.IPPrefix - name: prefixRef type: - namedType: com.github.ironcore-dev.ironcore.api.networking.v1alpha1.PeeringPrefixRef + namedType: io.k8s.api.core.v1.LocalObjectReference default: {} -- name: com.github.ironcore-dev.ironcore.api.networking.v1alpha1.PeeringPrefixRef - map: - fields: - - name: name - type: - scalar: string - default: "" - - name: namespace - type: - scalar: string - name: com.github.ironcore-dev.ironcore.api.networking.v1alpha1.PeeringPrefixStatus map: fields: diff --git a/client-go/applyconfigurations/networking/v1alpha1/peeringprefix.go b/client-go/applyconfigurations/networking/v1alpha1/peeringprefix.go index db24de96a..5c25772fb 100644 --- a/client-go/applyconfigurations/networking/v1alpha1/peeringprefix.go +++ b/client-go/applyconfigurations/networking/v1alpha1/peeringprefix.go @@ -7,14 +7,15 @@ package v1alpha1 import ( v1alpha1 "github.com/ironcore-dev/ironcore/api/common/v1alpha1" + v1 "k8s.io/api/core/v1" ) // PeeringPrefixApplyConfiguration represents an declarative configuration of the PeeringPrefix type for use // with apply. type PeeringPrefixApplyConfiguration struct { - Name *string `json:"name,omitempty"` - Prefix *v1alpha1.IPPrefix `json:"prefix,omitempty"` - PrefixRef *PeeringPrefixRefApplyConfiguration `json:"prefixRef,omitempty"` + Name *string `json:"name,omitempty"` + Prefix *v1alpha1.IPPrefix `json:"prefix,omitempty"` + PrefixRef *v1.LocalObjectReference `json:"prefixRef,omitempty"` } // PeeringPrefixApplyConfiguration constructs an declarative configuration of the PeeringPrefix type for use with @@ -42,7 +43,7 @@ func (b *PeeringPrefixApplyConfiguration) WithPrefix(value v1alpha1.IPPrefix) *P // WithPrefixRef sets the PrefixRef 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 PrefixRef field is set to the value of the last call. -func (b *PeeringPrefixApplyConfiguration) WithPrefixRef(value *PeeringPrefixRefApplyConfiguration) *PeeringPrefixApplyConfiguration { - b.PrefixRef = value +func (b *PeeringPrefixApplyConfiguration) WithPrefixRef(value v1.LocalObjectReference) *PeeringPrefixApplyConfiguration { + b.PrefixRef = &value return b } diff --git a/client-go/applyconfigurations/utils.go b/client-go/applyconfigurations/utils.go index ea445118c..4c775f14d 100644 --- a/client-go/applyconfigurations/utils.go +++ b/client-go/applyconfigurations/utils.go @@ -194,8 +194,6 @@ func ForKind(kind schema.GroupVersionKind) interface{} { return &applyconfigurationsnetworkingv1alpha1.NetworkStatusApplyConfiguration{} case networkingv1alpha1.SchemeGroupVersion.WithKind("PeeringPrefix"): return &applyconfigurationsnetworkingv1alpha1.PeeringPrefixApplyConfiguration{} - case networkingv1alpha1.SchemeGroupVersion.WithKind("PeeringPrefixRef"): - return &applyconfigurationsnetworkingv1alpha1.PeeringPrefixRefApplyConfiguration{} case networkingv1alpha1.SchemeGroupVersion.WithKind("PeeringPrefixStatus"): return &applyconfigurationsnetworkingv1alpha1.PeeringPrefixStatusApplyConfiguration{} case networkingv1alpha1.SchemeGroupVersion.WithKind("PrefixSource"): diff --git a/client-go/openapi/zz_generated.openapi.go b/client-go/openapi/zz_generated.openapi.go index a9012e0a6..14b0a9c52 100644 --- a/client-go/openapi/zz_generated.openapi.go +++ b/client-go/openapi/zz_generated.openapi.go @@ -110,7 +110,6 @@ func GetOpenAPIDefinitions(ref common.ReferenceCallback) map[string]common.OpenA "github.com/ironcore-dev/ironcore/api/networking/v1alpha1.NetworkSpec": schema_ironcore_api_networking_v1alpha1_NetworkSpec(ref), "github.com/ironcore-dev/ironcore/api/networking/v1alpha1.NetworkStatus": schema_ironcore_api_networking_v1alpha1_NetworkStatus(ref), "github.com/ironcore-dev/ironcore/api/networking/v1alpha1.PeeringPrefix": schema_ironcore_api_networking_v1alpha1_PeeringPrefix(ref), - "github.com/ironcore-dev/ironcore/api/networking/v1alpha1.PeeringPrefixRef": schema_ironcore_api_networking_v1alpha1_PeeringPrefixRef(ref), "github.com/ironcore-dev/ironcore/api/networking/v1alpha1.PeeringPrefixStatus": schema_ironcore_api_networking_v1alpha1_PeeringPrefixStatus(ref), "github.com/ironcore-dev/ironcore/api/networking/v1alpha1.PrefixSource": schema_ironcore_api_networking_v1alpha1_PrefixSource(ref), "github.com/ironcore-dev/ironcore/api/networking/v1alpha1.VirtualIP": schema_ironcore_api_networking_v1alpha1_VirtualIP(ref), @@ -4292,7 +4291,7 @@ func schema_ironcore_api_networking_v1alpha1_PeeringPrefix(ref common.ReferenceC SchemaProps: spec.SchemaProps{ Description: "PrefixRef is the reference to the prefix to be exposed to peered network An empty namespace indicates that the prefix resides in the same namespace as the source network.", Default: map[string]interface{}{}, - Ref: ref("github.com/ironcore-dev/ironcore/api/networking/v1alpha1.PeeringPrefixRef"), + Ref: ref("k8s.io/api/core/v1.LocalObjectReference"), }, }, }, @@ -4300,35 +4299,7 @@ func schema_ironcore_api_networking_v1alpha1_PeeringPrefix(ref common.ReferenceC }, }, Dependencies: []string{ - "github.com/ironcore-dev/ironcore/api/common/v1alpha1.IPPrefix", "github.com/ironcore-dev/ironcore/api/networking/v1alpha1.PeeringPrefixRef"}, - } -} - -func schema_ironcore_api_networking_v1alpha1_PeeringPrefixRef(ref common.ReferenceCallback) common.OpenAPIDefinition { - return common.OpenAPIDefinition{ - Schema: spec.Schema{ - SchemaProps: spec.SchemaProps{ - Type: []string{"object"}, - Properties: map[string]spec.Schema{ - "namespace": { - SchemaProps: spec.SchemaProps{ - Description: "Namespace is the namespace of the referenced entity. If empty, the same namespace as the referring resource is implied.", - Type: []string{"string"}, - Format: "", - }, - }, - "name": { - SchemaProps: spec.SchemaProps{ - Description: "Name is the name of the referenced entity.", - Default: "", - Type: []string{"string"}, - Format: "", - }, - }, - }, - Required: []string{"name"}, - }, - }, + "github.com/ironcore-dev/ironcore/api/common/v1alpha1.IPPrefix", "k8s.io/api/core/v1.LocalObjectReference"}, } } diff --git a/docs/api-reference/networking.md b/docs/api-reference/networking.md index 92e44dd51..9558dfdf1 100644 --- a/docs/api-reference/networking.md +++ b/docs/api-reference/networking.md @@ -2681,8 +2681,8 @@ github.com/ironcore-dev/ironcore/api/common/v1alpha1.IPPrefix prefixRef
- -PeeringPrefixRef + +Kubernetes core/v1.LocalObjectReference @@ -2693,46 +2693,6 @@ An empty namespace indicates that the prefix resides in the same namespace as th -

PeeringPrefixRef -

-

-(Appears on:PeeringPrefix) -

-
-
- - - - - - - - - - - - - - - - - -
FieldDescription
-namespace
- -string - -
-

Namespace is the namespace of the referenced entity. If empty, -the same namespace as the referring resource is implied.

-
-name
- -string - -
-

Name is the name of the referenced entity.

-

PeeringPrefixStatus

diff --git a/internal/apis/networking/network_type.go b/internal/apis/networking/network_type.go index 75c167690..49202ecaa 100644 --- a/internal/apis/networking/network_type.go +++ b/internal/apis/networking/network_type.go @@ -5,6 +5,7 @@ package networking import ( commonv1alpha1 "github.com/ironcore-dev/ironcore/api/common/v1alpha1" + corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/types" ) @@ -65,15 +66,7 @@ type PeeringPrefix struct { Prefix *commonv1alpha1.IPPrefix // PrefixRef is the reference to the prefix to be exposed to peered network // An empty namespace indicates that the prefix resides in the same namespace as the source network. - PrefixRef PeeringPrefixRef -} - -type PeeringPrefixRef struct { - // Namespace is the namespace of the referenced entity. If empty, - // the same namespace as the referring resource is implied. - Namespace string - // Name is the name of the referenced entity. - Name string + PrefixRef corev1.LocalObjectReference } // NetworkStatus defines the observed state of Network diff --git a/internal/apis/networking/v1alpha1/zz_generated.conversion.go b/internal/apis/networking/v1alpha1/zz_generated.conversion.go index 67e66236e..60bd7b58d 100644 --- a/internal/apis/networking/v1alpha1/zz_generated.conversion.go +++ b/internal/apis/networking/v1alpha1/zz_generated.conversion.go @@ -432,16 +432,6 @@ func RegisterConversions(s *runtime.Scheme) error { }); err != nil { return err } - if err := s.AddGeneratedConversionFunc((*v1alpha1.PeeringPrefixRef)(nil), (*networking.PeeringPrefixRef)(nil), func(a, b interface{}, scope conversion.Scope) error { - return Convert_v1alpha1_PeeringPrefixRef_To_networking_PeeringPrefixRef(a.(*v1alpha1.PeeringPrefixRef), b.(*networking.PeeringPrefixRef), scope) - }); err != nil { - return err - } - if err := s.AddGeneratedConversionFunc((*networking.PeeringPrefixRef)(nil), (*v1alpha1.PeeringPrefixRef)(nil), func(a, b interface{}, scope conversion.Scope) error { - return Convert_networking_PeeringPrefixRef_To_v1alpha1_PeeringPrefixRef(a.(*networking.PeeringPrefixRef), b.(*v1alpha1.PeeringPrefixRef), scope) - }); err != nil { - return err - } if err := s.AddGeneratedConversionFunc((*v1alpha1.PeeringPrefixStatus)(nil), (*networking.PeeringPrefixStatus)(nil), func(a, b interface{}, scope conversion.Scope) error { return Convert_v1alpha1_PeeringPrefixStatus_To_networking_PeeringPrefixStatus(a.(*v1alpha1.PeeringPrefixStatus), b.(*networking.PeeringPrefixStatus), scope) }); err != nil { @@ -1494,9 +1484,7 @@ func Convert_networking_NetworkStatus_To_v1alpha1_NetworkStatus(in *networking.N func autoConvert_v1alpha1_PeeringPrefix_To_networking_PeeringPrefix(in *v1alpha1.PeeringPrefix, out *networking.PeeringPrefix, s conversion.Scope) error { out.Name = in.Name out.Prefix = (*commonv1alpha1.IPPrefix)(unsafe.Pointer(in.Prefix)) - if err := Convert_v1alpha1_PeeringPrefixRef_To_networking_PeeringPrefixRef(&in.PrefixRef, &out.PrefixRef, s); err != nil { - return err - } + out.PrefixRef = in.PrefixRef return nil } @@ -1508,9 +1496,7 @@ func Convert_v1alpha1_PeeringPrefix_To_networking_PeeringPrefix(in *v1alpha1.Pee func autoConvert_networking_PeeringPrefix_To_v1alpha1_PeeringPrefix(in *networking.PeeringPrefix, out *v1alpha1.PeeringPrefix, s conversion.Scope) error { out.Name = in.Name out.Prefix = (*commonv1alpha1.IPPrefix)(unsafe.Pointer(in.Prefix)) - if err := Convert_networking_PeeringPrefixRef_To_v1alpha1_PeeringPrefixRef(&in.PrefixRef, &out.PrefixRef, s); err != nil { - return err - } + out.PrefixRef = in.PrefixRef return nil } @@ -1519,28 +1505,6 @@ func Convert_networking_PeeringPrefix_To_v1alpha1_PeeringPrefix(in *networking.P return autoConvert_networking_PeeringPrefix_To_v1alpha1_PeeringPrefix(in, out, s) } -func autoConvert_v1alpha1_PeeringPrefixRef_To_networking_PeeringPrefixRef(in *v1alpha1.PeeringPrefixRef, out *networking.PeeringPrefixRef, s conversion.Scope) error { - out.Namespace = in.Namespace - out.Name = in.Name - return nil -} - -// Convert_v1alpha1_PeeringPrefixRef_To_networking_PeeringPrefixRef is an autogenerated conversion function. -func Convert_v1alpha1_PeeringPrefixRef_To_networking_PeeringPrefixRef(in *v1alpha1.PeeringPrefixRef, out *networking.PeeringPrefixRef, s conversion.Scope) error { - return autoConvert_v1alpha1_PeeringPrefixRef_To_networking_PeeringPrefixRef(in, out, s) -} - -func autoConvert_networking_PeeringPrefixRef_To_v1alpha1_PeeringPrefixRef(in *networking.PeeringPrefixRef, out *v1alpha1.PeeringPrefixRef, s conversion.Scope) error { - out.Namespace = in.Namespace - out.Name = in.Name - return nil -} - -// Convert_networking_PeeringPrefixRef_To_v1alpha1_PeeringPrefixRef is an autogenerated conversion function. -func Convert_networking_PeeringPrefixRef_To_v1alpha1_PeeringPrefixRef(in *networking.PeeringPrefixRef, out *v1alpha1.PeeringPrefixRef, s conversion.Scope) error { - return autoConvert_networking_PeeringPrefixRef_To_v1alpha1_PeeringPrefixRef(in, out, s) -} - func autoConvert_v1alpha1_PeeringPrefixStatus_To_networking_PeeringPrefixStatus(in *v1alpha1.PeeringPrefixStatus, out *networking.PeeringPrefixStatus, s conversion.Scope) error { out.Name = in.Name out.Prefix = (*commonv1alpha1.IPPrefix)(unsafe.Pointer(in.Prefix)) diff --git a/internal/apis/networking/validation/network.go b/internal/apis/networking/validation/network.go index 51aa42afc..693266ffe 100644 --- a/internal/apis/networking/validation/network.go +++ b/internal/apis/networking/validation/network.go @@ -69,12 +69,7 @@ func validateNetworkSpec(namespace, name string, spec *networking.NetworkSpec, f } } - peeringPrefixNamespace := prefix.PrefixRef.Namespace - if peeringPrefixNamespace == "" { - peeringPrefixNamespace = namespace - } - - peeringPrefixKey := client.ObjectKey{Namespace: peeringPrefixNamespace, Name: prefix.PrefixRef.Name} + peeringPrefixKey := client.ObjectKey{Namespace: namespace, Name: prefix.PrefixRef.Name} if seenPeeringPrefixKeys.Has(peeringPrefixKey) { allErrs = append(allErrs, field.Duplicate(fldPath.Child("prefixRef"), prefix.PrefixRef)) @@ -161,11 +156,6 @@ func validatePeeringPrefix(prefix networking.PeeringPrefix, fldPath *field.Path) } prefixRef := prefix.PrefixRef - if prefixRef.Namespace != "" { - for _, msg := range apivalidation.NameIsDNSLabel(prefixRef.Namespace, false) { - allErrs = append(allErrs, field.Invalid(fldPath.Child("prefixRef", "namespace"), prefixRef.Namespace, msg)) - } - } for _, msg := range apivalidation.NameIsDNSLabel(prefixRef.Name, false) { allErrs = append(allErrs, field.Invalid(fldPath.Child("prefixRef", "name"), prefixRef.Name, msg)) } diff --git a/internal/apis/networking/validation/network_test.go b/internal/apis/networking/validation/network_test.go index cf12ab323..e20926872 100644 --- a/internal/apis/networking/validation/network_test.go +++ b/internal/apis/networking/validation/network_test.go @@ -10,6 +10,7 @@ import ( . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" "github.com/onsi/gomega/types" + corev1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" ) @@ -145,8 +146,8 @@ var _ = Describe("Network", func() { Spec: networking.NetworkSpec{ Peerings: []networking.NetworkPeering{{ Prefixes: []networking.PeeringPrefix{ - {PrefixRef: networking.PeeringPrefixRef{Name: "foo"}}, - {PrefixRef: networking.PeeringPrefixRef{Name: "foo"}}, + {PrefixRef: corev1.LocalObjectReference{Name: "foo"}}, + {PrefixRef: corev1.LocalObjectReference{Name: "foo"}}, }}, }, }, diff --git a/internal/apis/networking/zz_generated.deepcopy.go b/internal/apis/networking/zz_generated.deepcopy.go index f131e9eb0..fd14a5a62 100644 --- a/internal/apis/networking/zz_generated.deepcopy.go +++ b/internal/apis/networking/zz_generated.deepcopy.go @@ -1102,22 +1102,6 @@ func (in *PeeringPrefix) DeepCopy() *PeeringPrefix { return out } -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *PeeringPrefixRef) DeepCopyInto(out *PeeringPrefixRef) { - *out = *in - return -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new PeeringPrefixRef. -func (in *PeeringPrefixRef) DeepCopy() *PeeringPrefixRef { - if in == nil { - return nil - } - out := new(PeeringPrefixRef) - in.DeepCopyInto(out) - return out -} - // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *PeeringPrefixStatus) DeepCopyInto(out *PeeringPrefixStatus) { *out = *in