From 9a1d2d8ab50263d3cd89b7266f4c6cddc9b9ec66 Mon Sep 17 00:00:00 2001 From: Matthias Bertschy Date: Mon, 8 Apr 2024 11:03:00 +0200 Subject: [PATCH] add NetworkNeighborhood as a collection of NetworkNeighbors Signed-off-by: Matthias Bertschy --- .dockerignore | 3 + artifacts/networkneighborhood/01-example.yaml | 42 +++ pkg/apis/softwarecomposition/network_types.go | 39 ++- .../networkpolicy/networkpolicy.go | 2 + pkg/apis/softwarecomposition/register.go | 2 + .../v1beta1/network_types.go | 39 ++- .../v1beta1/networkpolicy/networkpolicy.go | 2 + .../softwarecomposition/v1beta1/register.go | 2 + .../v1beta1/zz_generated.conversion.go | 140 ++++++++++ .../v1beta1/zz_generated.deepcopy.go | 133 ++++++++++ .../zz_generated.deepcopy.go | 133 ++++++++++ pkg/apiserver/apiserver.go | 2 + pkg/cleanup/cleanup.go | 9 +- .../v1beta1/fake/fake_networkneighborhood.go | 129 +++++++++ .../fake/fake_softwarecomposition_client.go | 4 + .../v1beta1/generated_expansion.go | 2 + .../v1beta1/networkneighborhood.go | 178 +++++++++++++ .../v1beta1/softwarecomposition_client.go | 5 + .../informers/externalversions/generic.go | 2 + .../softwarecomposition/v1beta1/interface.go | 7 + .../v1beta1/networkneighborhood.go | 90 +++++++ .../v1beta1/expansion_generated.go | 8 + .../v1beta1/networkneighborhood.go | 99 +++++++ pkg/generated/openapi/zz_generated.openapi.go | 248 +++++++++++++++++- .../networkneighborhood/etcd.go | 56 ++++ .../networkneighborhood/strategy.go | 129 +++++++++ .../networkneighborhood/strategy_test.go | 92 +++++++ 27 files changed, 1588 insertions(+), 9 deletions(-) create mode 100644 .dockerignore create mode 100644 artifacts/networkneighborhood/01-example.yaml create mode 100644 pkg/generated/clientset/versioned/typed/softwarecomposition/v1beta1/fake/fake_networkneighborhood.go create mode 100644 pkg/generated/clientset/versioned/typed/softwarecomposition/v1beta1/networkneighborhood.go create mode 100644 pkg/generated/informers/externalversions/softwarecomposition/v1beta1/networkneighborhood.go create mode 100644 pkg/generated/listers/softwarecomposition/v1beta1/networkneighborhood.go create mode 100644 pkg/registry/softwarecomposition/networkneighborhood/etcd.go create mode 100644 pkg/registry/softwarecomposition/networkneighborhood/strategy.go create mode 100644 pkg/registry/softwarecomposition/networkneighborhood/strategy_test.go diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 000000000..59f76d9a7 --- /dev/null +++ b/.dockerignore @@ -0,0 +1,3 @@ +**/.git +vendor +artifacts diff --git a/artifacts/networkneighborhood/01-example.yaml b/artifacts/networkneighborhood/01-example.yaml new file mode 100644 index 000000000..9f256bee4 --- /dev/null +++ b/artifacts/networkneighborhood/01-example.yaml @@ -0,0 +1,42 @@ +apiVersion: spdx.softwarecomposition.kubescape.io/v1beta1 +kind: NetworkNeighborhood +metadata: + name: deployment-nginx + annotations: + status: incomplete + labels: + "kubescape.io/workload-api-group": "apps" + "kubescape.io/workload-api-version": "v1" + "kubescape.io/workload-name": "nginx" + "kubescape.io/workload-kind": "deployment" + "kubescape.io/workload-namespace": "kubescape" + +spec: + matchLabels: + app: nginx + + containers: + - name: nginx + ingress: + - type: internal + identifier: bla + namespaceSelector: + matchLabels: + name: kubescape + podSelector: + matchLabels: + app: kubescape-ui + ports: + - name: TCP-6379 + protocol: TCP + port: 6379 + + egress: + - type: external + identifier: bla + ipAddress: 123.5.2.3 + dns: stripe.com + ports: + - name: TCP-5978 + protocol: TCP + port: 5978 diff --git a/pkg/apis/softwarecomposition/network_types.go b/pkg/apis/softwarecomposition/network_types.go index d91bf7e3f..656568deb 100644 --- a/pkg/apis/softwarecomposition/network_types.go +++ b/pkg/apis/softwarecomposition/network_types.go @@ -19,6 +19,7 @@ const ( // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object // NetworkNeighborsList is a list of NetworkNeighbors. +// DEPRECATED - use NetworkNeighborhoodList instead. type NetworkNeighborsList struct { metav1.TypeMeta metav1.ListMeta @@ -30,6 +31,7 @@ type NetworkNeighborsList struct { // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object // NetworkNeighbors represents a list of network communications for a specific workload. +// DEPRECATED - use NetworkNeighborhood instead. type NetworkNeighbors struct { metav1.TypeMeta metav1.ObjectMeta @@ -43,11 +45,46 @@ type NetworkNeighborsSpec struct { Egress []NetworkNeighbor } +// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object + +// NetworkNeighborhoodList is a list of NetworkNeighborhoods. +type NetworkNeighborhoodList struct { + metav1.TypeMeta + metav1.ListMeta + + Items []NetworkNeighborhood +} + +// +genclient +// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object + +// NetworkNeighborhood represents a list of network communications for a specific workload. +type NetworkNeighborhood struct { + metav1.TypeMeta + metav1.ObjectMeta + + Spec NetworkNeighborhoodSpec +} + +type NetworkNeighborhoodSpec struct { + metav1.LabelSelector // The labels which are inside spec.selector in the parent workload. + Containers []NetworkNeighborhoodContainer + InitContainers []NetworkNeighborhoodContainer + EphemeralContainers []NetworkNeighborhoodContainer +} + +type NetworkNeighborhoodContainer struct { + Name string + Ingress []NetworkNeighbor + Egress []NetworkNeighbor +} + // NetworkNeighbor represents a single network communication made by this resource. type NetworkNeighbor struct { Identifier string Type CommunicationType - DNS string + DNS string // DEPRECATED - use DNSNames instead. + DNSNames []string Ports []NetworkPort PodSelector *metav1.LabelSelector NamespaceSelector *metav1.LabelSelector diff --git a/pkg/apis/softwarecomposition/networkpolicy/networkpolicy.go b/pkg/apis/softwarecomposition/networkpolicy/networkpolicy.go index 300a22da4..e168439bd 100644 --- a/pkg/apis/softwarecomposition/networkpolicy/networkpolicy.go +++ b/pkg/apis/softwarecomposition/networkpolicy/networkpolicy.go @@ -24,6 +24,8 @@ const ( storageV1ApiVersion = "spdx.softwarecomposition.kubescape.io" ) +// FIXME add NetworkNeighborhood + func GenerateNetworkPolicy(networkNeighbors softwarecomposition.NetworkNeighbors, knownServers []softwarecomposition.KnownServer, timeProvider metav1.Time) (softwarecomposition.GeneratedNetworkPolicy, error) { if !IsAvailable(networkNeighbors) { return softwarecomposition.GeneratedNetworkPolicy{}, fmt.Errorf("networkNeighbors %s/%s status annotation is not ready", networkNeighbors.Namespace, networkNeighbors.Name) diff --git a/pkg/apis/softwarecomposition/register.go b/pkg/apis/softwarecomposition/register.go index 4dd6e4c11..2adff5328 100644 --- a/pkg/apis/softwarecomposition/register.go +++ b/pkg/apis/softwarecomposition/register.go @@ -69,6 +69,8 @@ func addKnownTypes(scheme *runtime.Scheme) error { &ApplicationActivityList{}, &NetworkNeighbors{}, &NetworkNeighborsList{}, + &NetworkNeighborhood{}, + &NetworkNeighborhoodList{}, &OpenVulnerabilityExchangeContainer{}, &OpenVulnerabilityExchangeContainerList{}, &GeneratedNetworkPolicyList{}, diff --git a/pkg/apis/softwarecomposition/v1beta1/network_types.go b/pkg/apis/softwarecomposition/v1beta1/network_types.go index 20fa8ec7a..32071a691 100644 --- a/pkg/apis/softwarecomposition/v1beta1/network_types.go +++ b/pkg/apis/softwarecomposition/v1beta1/network_types.go @@ -19,6 +19,7 @@ const ( // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object // NetworkNeighborsList is a list of NetworkNeighbors. +// DEPRECATED - use NetworkNeighborhoodList instead. type NetworkNeighborsList struct { metav1.TypeMeta `json:",inline"` metav1.ListMeta `json:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"` @@ -30,6 +31,7 @@ type NetworkNeighborsList struct { // +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object // NetworkNeighbors represents a list of network communications for a specific workload. +// DEPRECATED - use NetworkNeighborhood instead. type NetworkNeighbors struct { metav1.TypeMeta `json:",inline"` metav1.ObjectMeta `json:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"` @@ -47,11 +49,46 @@ type NetworkNeighborsSpec struct { Egress []NetworkNeighbor `json:"egress" patchStrategy:"merge" patchMergeKey:"identifier"` } +// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object + +// NetworkNeighborhoodList is a list of NetworkNeighborhoods. +type NetworkNeighborhoodList struct { + metav1.TypeMeta `json:",inline"` + metav1.ListMeta `json:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"` + + Items []NetworkNeighborhood `json:"items"` +} + +// +genclient +// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object + +// NetworkNeighborhood represents a list of network communications for a specific workload. +type NetworkNeighborhood struct { + metav1.TypeMeta `json:",inline"` + metav1.ObjectMeta `json:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"` + + Spec NetworkNeighborhoodSpec `json:"spec"` +} + +type NetworkNeighborhoodSpec struct { + metav1.LabelSelector `json:",inline"` + Containers []NetworkNeighborhoodContainer `json:"containers"` + InitContainers []NetworkNeighborhoodContainer `json:"initContainers"` + EphemeralContainers []NetworkNeighborhoodContainer `json:"ephemeralContainers"` +} + +type NetworkNeighborhoodContainer struct { + Name string `json:"name"` + Ingress []NetworkNeighbor `json:"ingress"` + Egress []NetworkNeighbor `json:"egress"` +} + // NetworkNeighbor represents a single network communication made by this resource. type NetworkNeighbor struct { Identifier string `json:"identifier"` // A unique identifier for this entry Type CommunicationType `json:"type"` - DNS string `json:"dns"` + DNS string `json:"dns"` // DEPRECATED - use DNSNames instead. + DNSNames []string `json:"dnsNames"` // +patchMergeKey=name // +patchStrategy=merge Ports []NetworkPort `json:"ports" patchStrategy:"merge" patchMergeKey:"name"` diff --git a/pkg/apis/softwarecomposition/v1beta1/networkpolicy/networkpolicy.go b/pkg/apis/softwarecomposition/v1beta1/networkpolicy/networkpolicy.go index 577d28ace..98cb102f3 100644 --- a/pkg/apis/softwarecomposition/v1beta1/networkpolicy/networkpolicy.go +++ b/pkg/apis/softwarecomposition/v1beta1/networkpolicy/networkpolicy.go @@ -11,6 +11,8 @@ const ( storageV1Beta1ApiVersion = "spdx.softwarecomposition.kubescape.io/v1beta1" ) +// FIXME add NetworkNeighborhood (maybe duplicate?) + func GenerateNetworkPolicy(networkNeighbors v1beta1.NetworkNeighbors, knownServers []v1beta1.KnownServer, timeProvider metav1.Time) (v1beta1.GeneratedNetworkPolicy, error) { networkNeighborsV1, err := convertNetworkNeighbors(&networkNeighbors) if err != nil { diff --git a/pkg/apis/softwarecomposition/v1beta1/register.go b/pkg/apis/softwarecomposition/v1beta1/register.go index 9bfb926f8..0ef15ef1e 100644 --- a/pkg/apis/softwarecomposition/v1beta1/register.go +++ b/pkg/apis/softwarecomposition/v1beta1/register.go @@ -71,6 +71,8 @@ func addKnownTypes(scheme *runtime.Scheme) error { &ApplicationActivityList{}, &NetworkNeighbors{}, &NetworkNeighborsList{}, + &NetworkNeighborhood{}, + &NetworkNeighborhoodList{}, &OpenVulnerabilityExchangeContainer{}, &OpenVulnerabilityExchangeContainerList{}, &GeneratedNetworkPolicyList{}, diff --git a/pkg/apis/softwarecomposition/v1beta1/zz_generated.conversion.go b/pkg/apis/softwarecomposition/v1beta1/zz_generated.conversion.go index 2818fbffb..653896650 100644 --- a/pkg/apis/softwarecomposition/v1beta1/zz_generated.conversion.go +++ b/pkg/apis/softwarecomposition/v1beta1/zz_generated.conversion.go @@ -779,6 +779,46 @@ func RegisterConversions(s *runtime.Scheme) error { }); err != nil { return err } + if err := s.AddGeneratedConversionFunc((*NetworkNeighborhood)(nil), (*softwarecomposition.NetworkNeighborhood)(nil), func(a, b interface{}, scope conversion.Scope) error { + return Convert_v1beta1_NetworkNeighborhood_To_softwarecomposition_NetworkNeighborhood(a.(*NetworkNeighborhood), b.(*softwarecomposition.NetworkNeighborhood), scope) + }); err != nil { + return err + } + if err := s.AddGeneratedConversionFunc((*softwarecomposition.NetworkNeighborhood)(nil), (*NetworkNeighborhood)(nil), func(a, b interface{}, scope conversion.Scope) error { + return Convert_softwarecomposition_NetworkNeighborhood_To_v1beta1_NetworkNeighborhood(a.(*softwarecomposition.NetworkNeighborhood), b.(*NetworkNeighborhood), scope) + }); err != nil { + return err + } + if err := s.AddGeneratedConversionFunc((*NetworkNeighborhoodContainer)(nil), (*softwarecomposition.NetworkNeighborhoodContainer)(nil), func(a, b interface{}, scope conversion.Scope) error { + return Convert_v1beta1_NetworkNeighborhoodContainer_To_softwarecomposition_NetworkNeighborhoodContainer(a.(*NetworkNeighborhoodContainer), b.(*softwarecomposition.NetworkNeighborhoodContainer), scope) + }); err != nil { + return err + } + if err := s.AddGeneratedConversionFunc((*softwarecomposition.NetworkNeighborhoodContainer)(nil), (*NetworkNeighborhoodContainer)(nil), func(a, b interface{}, scope conversion.Scope) error { + return Convert_softwarecomposition_NetworkNeighborhoodContainer_To_v1beta1_NetworkNeighborhoodContainer(a.(*softwarecomposition.NetworkNeighborhoodContainer), b.(*NetworkNeighborhoodContainer), scope) + }); err != nil { + return err + } + if err := s.AddGeneratedConversionFunc((*NetworkNeighborhoodList)(nil), (*softwarecomposition.NetworkNeighborhoodList)(nil), func(a, b interface{}, scope conversion.Scope) error { + return Convert_v1beta1_NetworkNeighborhoodList_To_softwarecomposition_NetworkNeighborhoodList(a.(*NetworkNeighborhoodList), b.(*softwarecomposition.NetworkNeighborhoodList), scope) + }); err != nil { + return err + } + if err := s.AddGeneratedConversionFunc((*softwarecomposition.NetworkNeighborhoodList)(nil), (*NetworkNeighborhoodList)(nil), func(a, b interface{}, scope conversion.Scope) error { + return Convert_softwarecomposition_NetworkNeighborhoodList_To_v1beta1_NetworkNeighborhoodList(a.(*softwarecomposition.NetworkNeighborhoodList), b.(*NetworkNeighborhoodList), scope) + }); err != nil { + return err + } + if err := s.AddGeneratedConversionFunc((*NetworkNeighborhoodSpec)(nil), (*softwarecomposition.NetworkNeighborhoodSpec)(nil), func(a, b interface{}, scope conversion.Scope) error { + return Convert_v1beta1_NetworkNeighborhoodSpec_To_softwarecomposition_NetworkNeighborhoodSpec(a.(*NetworkNeighborhoodSpec), b.(*softwarecomposition.NetworkNeighborhoodSpec), scope) + }); err != nil { + return err + } + if err := s.AddGeneratedConversionFunc((*softwarecomposition.NetworkNeighborhoodSpec)(nil), (*NetworkNeighborhoodSpec)(nil), func(a, b interface{}, scope conversion.Scope) error { + return Convert_softwarecomposition_NetworkNeighborhoodSpec_To_v1beta1_NetworkNeighborhoodSpec(a.(*softwarecomposition.NetworkNeighborhoodSpec), b.(*NetworkNeighborhoodSpec), scope) + }); err != nil { + return err + } if err := s.AddGeneratedConversionFunc((*NetworkNeighbors)(nil), (*softwarecomposition.NetworkNeighbors)(nil), func(a, b interface{}, scope conversion.Scope) error { return Convert_v1beta1_NetworkNeighbors_To_softwarecomposition_NetworkNeighbors(a.(*NetworkNeighbors), b.(*softwarecomposition.NetworkNeighbors), scope) }); err != nil { @@ -3656,6 +3696,7 @@ func autoConvert_v1beta1_NetworkNeighbor_To_softwarecomposition_NetworkNeighbor( out.Identifier = in.Identifier out.Type = softwarecomposition.CommunicationType(in.Type) out.DNS = in.DNS + out.DNSNames = *(*[]string)(unsafe.Pointer(&in.DNSNames)) out.Ports = *(*[]softwarecomposition.NetworkPort)(unsafe.Pointer(&in.Ports)) out.PodSelector = (*metav1.LabelSelector)(unsafe.Pointer(in.PodSelector)) out.NamespaceSelector = (*metav1.LabelSelector)(unsafe.Pointer(in.NamespaceSelector)) @@ -3672,6 +3713,7 @@ func autoConvert_softwarecomposition_NetworkNeighbor_To_v1beta1_NetworkNeighbor( out.Identifier = in.Identifier out.Type = CommunicationType(in.Type) out.DNS = in.DNS + out.DNSNames = *(*[]string)(unsafe.Pointer(&in.DNSNames)) out.Ports = *(*[]NetworkPort)(unsafe.Pointer(&in.Ports)) out.PodSelector = (*metav1.LabelSelector)(unsafe.Pointer(in.PodSelector)) out.NamespaceSelector = (*metav1.LabelSelector)(unsafe.Pointer(in.NamespaceSelector)) @@ -3684,6 +3726,104 @@ func Convert_softwarecomposition_NetworkNeighbor_To_v1beta1_NetworkNeighbor(in * return autoConvert_softwarecomposition_NetworkNeighbor_To_v1beta1_NetworkNeighbor(in, out, s) } +func autoConvert_v1beta1_NetworkNeighborhood_To_softwarecomposition_NetworkNeighborhood(in *NetworkNeighborhood, out *softwarecomposition.NetworkNeighborhood, s conversion.Scope) error { + out.ObjectMeta = in.ObjectMeta + if err := Convert_v1beta1_NetworkNeighborhoodSpec_To_softwarecomposition_NetworkNeighborhoodSpec(&in.Spec, &out.Spec, s); err != nil { + return err + } + return nil +} + +// Convert_v1beta1_NetworkNeighborhood_To_softwarecomposition_NetworkNeighborhood is an autogenerated conversion function. +func Convert_v1beta1_NetworkNeighborhood_To_softwarecomposition_NetworkNeighborhood(in *NetworkNeighborhood, out *softwarecomposition.NetworkNeighborhood, s conversion.Scope) error { + return autoConvert_v1beta1_NetworkNeighborhood_To_softwarecomposition_NetworkNeighborhood(in, out, s) +} + +func autoConvert_softwarecomposition_NetworkNeighborhood_To_v1beta1_NetworkNeighborhood(in *softwarecomposition.NetworkNeighborhood, out *NetworkNeighborhood, s conversion.Scope) error { + out.ObjectMeta = in.ObjectMeta + if err := Convert_softwarecomposition_NetworkNeighborhoodSpec_To_v1beta1_NetworkNeighborhoodSpec(&in.Spec, &out.Spec, s); err != nil { + return err + } + return nil +} + +// Convert_softwarecomposition_NetworkNeighborhood_To_v1beta1_NetworkNeighborhood is an autogenerated conversion function. +func Convert_softwarecomposition_NetworkNeighborhood_To_v1beta1_NetworkNeighborhood(in *softwarecomposition.NetworkNeighborhood, out *NetworkNeighborhood, s conversion.Scope) error { + return autoConvert_softwarecomposition_NetworkNeighborhood_To_v1beta1_NetworkNeighborhood(in, out, s) +} + +func autoConvert_v1beta1_NetworkNeighborhoodContainer_To_softwarecomposition_NetworkNeighborhoodContainer(in *NetworkNeighborhoodContainer, out *softwarecomposition.NetworkNeighborhoodContainer, s conversion.Scope) error { + out.Name = in.Name + out.Ingress = *(*[]softwarecomposition.NetworkNeighbor)(unsafe.Pointer(&in.Ingress)) + out.Egress = *(*[]softwarecomposition.NetworkNeighbor)(unsafe.Pointer(&in.Egress)) + return nil +} + +// Convert_v1beta1_NetworkNeighborhoodContainer_To_softwarecomposition_NetworkNeighborhoodContainer is an autogenerated conversion function. +func Convert_v1beta1_NetworkNeighborhoodContainer_To_softwarecomposition_NetworkNeighborhoodContainer(in *NetworkNeighborhoodContainer, out *softwarecomposition.NetworkNeighborhoodContainer, s conversion.Scope) error { + return autoConvert_v1beta1_NetworkNeighborhoodContainer_To_softwarecomposition_NetworkNeighborhoodContainer(in, out, s) +} + +func autoConvert_softwarecomposition_NetworkNeighborhoodContainer_To_v1beta1_NetworkNeighborhoodContainer(in *softwarecomposition.NetworkNeighborhoodContainer, out *NetworkNeighborhoodContainer, s conversion.Scope) error { + out.Name = in.Name + out.Ingress = *(*[]NetworkNeighbor)(unsafe.Pointer(&in.Ingress)) + out.Egress = *(*[]NetworkNeighbor)(unsafe.Pointer(&in.Egress)) + return nil +} + +// Convert_softwarecomposition_NetworkNeighborhoodContainer_To_v1beta1_NetworkNeighborhoodContainer is an autogenerated conversion function. +func Convert_softwarecomposition_NetworkNeighborhoodContainer_To_v1beta1_NetworkNeighborhoodContainer(in *softwarecomposition.NetworkNeighborhoodContainer, out *NetworkNeighborhoodContainer, s conversion.Scope) error { + return autoConvert_softwarecomposition_NetworkNeighborhoodContainer_To_v1beta1_NetworkNeighborhoodContainer(in, out, s) +} + +func autoConvert_v1beta1_NetworkNeighborhoodList_To_softwarecomposition_NetworkNeighborhoodList(in *NetworkNeighborhoodList, out *softwarecomposition.NetworkNeighborhoodList, s conversion.Scope) error { + out.ListMeta = in.ListMeta + out.Items = *(*[]softwarecomposition.NetworkNeighborhood)(unsafe.Pointer(&in.Items)) + return nil +} + +// Convert_v1beta1_NetworkNeighborhoodList_To_softwarecomposition_NetworkNeighborhoodList is an autogenerated conversion function. +func Convert_v1beta1_NetworkNeighborhoodList_To_softwarecomposition_NetworkNeighborhoodList(in *NetworkNeighborhoodList, out *softwarecomposition.NetworkNeighborhoodList, s conversion.Scope) error { + return autoConvert_v1beta1_NetworkNeighborhoodList_To_softwarecomposition_NetworkNeighborhoodList(in, out, s) +} + +func autoConvert_softwarecomposition_NetworkNeighborhoodList_To_v1beta1_NetworkNeighborhoodList(in *softwarecomposition.NetworkNeighborhoodList, out *NetworkNeighborhoodList, s conversion.Scope) error { + out.ListMeta = in.ListMeta + out.Items = *(*[]NetworkNeighborhood)(unsafe.Pointer(&in.Items)) + return nil +} + +// Convert_softwarecomposition_NetworkNeighborhoodList_To_v1beta1_NetworkNeighborhoodList is an autogenerated conversion function. +func Convert_softwarecomposition_NetworkNeighborhoodList_To_v1beta1_NetworkNeighborhoodList(in *softwarecomposition.NetworkNeighborhoodList, out *NetworkNeighborhoodList, s conversion.Scope) error { + return autoConvert_softwarecomposition_NetworkNeighborhoodList_To_v1beta1_NetworkNeighborhoodList(in, out, s) +} + +func autoConvert_v1beta1_NetworkNeighborhoodSpec_To_softwarecomposition_NetworkNeighborhoodSpec(in *NetworkNeighborhoodSpec, out *softwarecomposition.NetworkNeighborhoodSpec, s conversion.Scope) error { + out.LabelSelector = in.LabelSelector + out.Containers = *(*[]softwarecomposition.NetworkNeighborhoodContainer)(unsafe.Pointer(&in.Containers)) + out.InitContainers = *(*[]softwarecomposition.NetworkNeighborhoodContainer)(unsafe.Pointer(&in.InitContainers)) + out.EphemeralContainers = *(*[]softwarecomposition.NetworkNeighborhoodContainer)(unsafe.Pointer(&in.EphemeralContainers)) + return nil +} + +// Convert_v1beta1_NetworkNeighborhoodSpec_To_softwarecomposition_NetworkNeighborhoodSpec is an autogenerated conversion function. +func Convert_v1beta1_NetworkNeighborhoodSpec_To_softwarecomposition_NetworkNeighborhoodSpec(in *NetworkNeighborhoodSpec, out *softwarecomposition.NetworkNeighborhoodSpec, s conversion.Scope) error { + return autoConvert_v1beta1_NetworkNeighborhoodSpec_To_softwarecomposition_NetworkNeighborhoodSpec(in, out, s) +} + +func autoConvert_softwarecomposition_NetworkNeighborhoodSpec_To_v1beta1_NetworkNeighborhoodSpec(in *softwarecomposition.NetworkNeighborhoodSpec, out *NetworkNeighborhoodSpec, s conversion.Scope) error { + out.LabelSelector = in.LabelSelector + out.Containers = *(*[]NetworkNeighborhoodContainer)(unsafe.Pointer(&in.Containers)) + out.InitContainers = *(*[]NetworkNeighborhoodContainer)(unsafe.Pointer(&in.InitContainers)) + out.EphemeralContainers = *(*[]NetworkNeighborhoodContainer)(unsafe.Pointer(&in.EphemeralContainers)) + return nil +} + +// Convert_softwarecomposition_NetworkNeighborhoodSpec_To_v1beta1_NetworkNeighborhoodSpec is an autogenerated conversion function. +func Convert_softwarecomposition_NetworkNeighborhoodSpec_To_v1beta1_NetworkNeighborhoodSpec(in *softwarecomposition.NetworkNeighborhoodSpec, out *NetworkNeighborhoodSpec, s conversion.Scope) error { + return autoConvert_softwarecomposition_NetworkNeighborhoodSpec_To_v1beta1_NetworkNeighborhoodSpec(in, out, s) +} + func autoConvert_v1beta1_NetworkNeighbors_To_softwarecomposition_NetworkNeighbors(in *NetworkNeighbors, out *softwarecomposition.NetworkNeighbors, s conversion.Scope) error { out.ObjectMeta = in.ObjectMeta if err := Convert_v1beta1_NetworkNeighborsSpec_To_softwarecomposition_NetworkNeighborsSpec(&in.Spec, &out.Spec, s); err != nil { diff --git a/pkg/apis/softwarecomposition/v1beta1/zz_generated.deepcopy.go b/pkg/apis/softwarecomposition/v1beta1/zz_generated.deepcopy.go index 3740ccc87..59d523d40 100644 --- a/pkg/apis/softwarecomposition/v1beta1/zz_generated.deepcopy.go +++ b/pkg/apis/softwarecomposition/v1beta1/zz_generated.deepcopy.go @@ -1926,6 +1926,11 @@ func (in *Metadata) DeepCopy() *Metadata { // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *NetworkNeighbor) DeepCopyInto(out *NetworkNeighbor) { *out = *in + if in.DNSNames != nil { + in, out := &in.DNSNames, &out.DNSNames + *out = make([]string, len(*in)) + copy(*out, *in) + } if in.Ports != nil { in, out := &in.Ports, &out.Ports *out = make([]NetworkPort, len(*in)) @@ -1956,6 +1961,134 @@ func (in *NetworkNeighbor) DeepCopy() *NetworkNeighbor { return out } +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *NetworkNeighborhood) DeepCopyInto(out *NetworkNeighborhood) { + *out = *in + out.TypeMeta = in.TypeMeta + in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) + in.Spec.DeepCopyInto(&out.Spec) + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new NetworkNeighborhood. +func (in *NetworkNeighborhood) DeepCopy() *NetworkNeighborhood { + if in == nil { + return nil + } + out := new(NetworkNeighborhood) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *NetworkNeighborhood) 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 *NetworkNeighborhoodContainer) DeepCopyInto(out *NetworkNeighborhoodContainer) { + *out = *in + if in.Ingress != nil { + in, out := &in.Ingress, &out.Ingress + *out = make([]NetworkNeighbor, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } + if in.Egress != nil { + in, out := &in.Egress, &out.Egress + *out = make([]NetworkNeighbor, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new NetworkNeighborhoodContainer. +func (in *NetworkNeighborhoodContainer) DeepCopy() *NetworkNeighborhoodContainer { + if in == nil { + return nil + } + out := new(NetworkNeighborhoodContainer) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *NetworkNeighborhoodList) DeepCopyInto(out *NetworkNeighborhoodList) { + *out = *in + out.TypeMeta = in.TypeMeta + in.ListMeta.DeepCopyInto(&out.ListMeta) + if in.Items != nil { + in, out := &in.Items, &out.Items + *out = make([]NetworkNeighborhood, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new NetworkNeighborhoodList. +func (in *NetworkNeighborhoodList) DeepCopy() *NetworkNeighborhoodList { + if in == nil { + return nil + } + out := new(NetworkNeighborhoodList) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *NetworkNeighborhoodList) 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 *NetworkNeighborhoodSpec) DeepCopyInto(out *NetworkNeighborhoodSpec) { + *out = *in + in.LabelSelector.DeepCopyInto(&out.LabelSelector) + if in.Containers != nil { + in, out := &in.Containers, &out.Containers + *out = make([]NetworkNeighborhoodContainer, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } + if in.InitContainers != nil { + in, out := &in.InitContainers, &out.InitContainers + *out = make([]NetworkNeighborhoodContainer, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } + if in.EphemeralContainers != nil { + in, out := &in.EphemeralContainers, &out.EphemeralContainers + *out = make([]NetworkNeighborhoodContainer, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new NetworkNeighborhoodSpec. +func (in *NetworkNeighborhoodSpec) DeepCopy() *NetworkNeighborhoodSpec { + if in == nil { + return nil + } + out := new(NetworkNeighborhoodSpec) + in.DeepCopyInto(out) + return out +} + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *NetworkNeighbors) DeepCopyInto(out *NetworkNeighbors) { *out = *in diff --git a/pkg/apis/softwarecomposition/zz_generated.deepcopy.go b/pkg/apis/softwarecomposition/zz_generated.deepcopy.go index 62c797b6b..5a8b552d0 100644 --- a/pkg/apis/softwarecomposition/zz_generated.deepcopy.go +++ b/pkg/apis/softwarecomposition/zz_generated.deepcopy.go @@ -1926,6 +1926,11 @@ func (in *Metadata) DeepCopy() *Metadata { // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *NetworkNeighbor) DeepCopyInto(out *NetworkNeighbor) { *out = *in + if in.DNSNames != nil { + in, out := &in.DNSNames, &out.DNSNames + *out = make([]string, len(*in)) + copy(*out, *in) + } if in.Ports != nil { in, out := &in.Ports, &out.Ports *out = make([]NetworkPort, len(*in)) @@ -1956,6 +1961,134 @@ func (in *NetworkNeighbor) DeepCopy() *NetworkNeighbor { return out } +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *NetworkNeighborhood) DeepCopyInto(out *NetworkNeighborhood) { + *out = *in + out.TypeMeta = in.TypeMeta + in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) + in.Spec.DeepCopyInto(&out.Spec) + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new NetworkNeighborhood. +func (in *NetworkNeighborhood) DeepCopy() *NetworkNeighborhood { + if in == nil { + return nil + } + out := new(NetworkNeighborhood) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *NetworkNeighborhood) 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 *NetworkNeighborhoodContainer) DeepCopyInto(out *NetworkNeighborhoodContainer) { + *out = *in + if in.Ingress != nil { + in, out := &in.Ingress, &out.Ingress + *out = make([]NetworkNeighbor, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } + if in.Egress != nil { + in, out := &in.Egress, &out.Egress + *out = make([]NetworkNeighbor, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new NetworkNeighborhoodContainer. +func (in *NetworkNeighborhoodContainer) DeepCopy() *NetworkNeighborhoodContainer { + if in == nil { + return nil + } + out := new(NetworkNeighborhoodContainer) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *NetworkNeighborhoodList) DeepCopyInto(out *NetworkNeighborhoodList) { + *out = *in + out.TypeMeta = in.TypeMeta + in.ListMeta.DeepCopyInto(&out.ListMeta) + if in.Items != nil { + in, out := &in.Items, &out.Items + *out = make([]NetworkNeighborhood, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new NetworkNeighborhoodList. +func (in *NetworkNeighborhoodList) DeepCopy() *NetworkNeighborhoodList { + if in == nil { + return nil + } + out := new(NetworkNeighborhoodList) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *NetworkNeighborhoodList) 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 *NetworkNeighborhoodSpec) DeepCopyInto(out *NetworkNeighborhoodSpec) { + *out = *in + in.LabelSelector.DeepCopyInto(&out.LabelSelector) + if in.Containers != nil { + in, out := &in.Containers, &out.Containers + *out = make([]NetworkNeighborhoodContainer, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } + if in.InitContainers != nil { + in, out := &in.InitContainers, &out.InitContainers + *out = make([]NetworkNeighborhoodContainer, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } + if in.EphemeralContainers != nil { + in, out := &in.EphemeralContainers, &out.EphemeralContainers + *out = make([]NetworkNeighborhoodContainer, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new NetworkNeighborhoodSpec. +func (in *NetworkNeighborhoodSpec) DeepCopy() *NetworkNeighborhoodSpec { + if in == nil { + return nil + } + out := new(NetworkNeighborhoodSpec) + in.DeepCopyInto(out) + return out +} + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *NetworkNeighbors) DeepCopyInto(out *NetworkNeighbors) { *out = *in diff --git a/pkg/apiserver/apiserver.go b/pkg/apiserver/apiserver.go index a34546be6..3748999b0 100644 --- a/pkg/apiserver/apiserver.go +++ b/pkg/apiserver/apiserver.go @@ -22,6 +22,7 @@ import ( "github.com/kubescape/storage/pkg/registry/softwarecomposition/applicationprofile" "github.com/kubescape/storage/pkg/registry/softwarecomposition/generatednetworkpolicy" knownserver "github.com/kubescape/storage/pkg/registry/softwarecomposition/knownservers" + "github.com/kubescape/storage/pkg/registry/softwarecomposition/networkneighborhood" "github.com/kubescape/storage/pkg/registry/softwarecomposition/networkneighbors" "github.com/kubescape/storage/pkg/registry/softwarecomposition/openvulnerabilityexchange" "github.com/kubescape/storage/pkg/registry/softwarecomposition/sbomsyftfiltereds" @@ -170,6 +171,7 @@ func (c completedConfig) New() (*WardleServer, error) { v1beta1storage["applicationactivities"] = sbomregistry.RESTInPeace(applicationactivity.NewREST(Scheme, storageImpl, c.GenericConfig.RESTOptionsGetter)) v1beta1storage["networkneighborses"] = sbomregistry.RESTInPeace(networkneighbors.NewREST(Scheme, storageImpl, c.GenericConfig.RESTOptionsGetter)) + v1beta1storage["networkneighborhoods"] = sbomregistry.RESTInPeace(networkneighborhood.NewREST(Scheme, storageImpl, c.GenericConfig.RESTOptionsGetter)) v1beta1storage["openvulnerabilityexchangecontainers"] = sbomregistry.RESTInPeace(openvulnerabilityexchange.NewREST(Scheme, storageImpl, c.GenericConfig.RESTOptionsGetter)) v1beta1storage["generatednetworkpolicies"] = sbomregistry.RESTInPeace(generatednetworkpolicy.NewREST(Scheme, generatedNetworkPolicyStorage, c.GenericConfig.RESTOptionsGetter)) diff --git a/pkg/cleanup/cleanup.go b/pkg/cleanup/cleanup.go index 8afc20cd2..76779a441 100644 --- a/pkg/cleanup/cleanup.go +++ b/pkg/cleanup/cleanup.go @@ -25,10 +25,11 @@ type TypeCleanupHandlerFunc func(kind, path string, metadata *metav1.ObjectMeta, var resourceKindToHandler = map[string]TypeCleanupHandlerFunc{ // configurationscansummaries is virtual // vulnerabilitysummaries is virtual - "applicationactivities": deleteByTemplateHashOrWlid, - "applicationprofiles": deleteByTemplateHashOrWlid, - "applicationprofilesummaries": deleteDeprecated, - "networkneighborses": deleteByWlid, + "applicationactivities": deleteByTemplateHashOrWlid, + "applicationprofiles": deleteByTemplateHashOrWlid, + "applicationprofilesummaries": deleteDeprecated, + "networkneighborses": deleteByWlid, + // FIXME add NetworkNeighborhood "openvulnerabilityexchangecontainers": deleteByImageId, "sbomspdxv2p3filtereds": deleteDeprecated, "sbomspdxv2p3filtered": deleteDeprecated, diff --git a/pkg/generated/clientset/versioned/typed/softwarecomposition/v1beta1/fake/fake_networkneighborhood.go b/pkg/generated/clientset/versioned/typed/softwarecomposition/v1beta1/fake/fake_networkneighborhood.go new file mode 100644 index 000000000..0efb8b95c --- /dev/null +++ b/pkg/generated/clientset/versioned/typed/softwarecomposition/v1beta1/fake/fake_networkneighborhood.go @@ -0,0 +1,129 @@ +/* +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" + + v1beta1 "github.com/kubescape/storage/pkg/apis/softwarecomposition/v1beta1" + 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" +) + +// FakeNetworkNeighborhoods implements NetworkNeighborhoodInterface +type FakeNetworkNeighborhoods struct { + Fake *FakeSpdxV1beta1 + ns string +} + +var networkneighborhoodsResource = v1beta1.SchemeGroupVersion.WithResource("networkneighborhoods") + +var networkneighborhoodsKind = v1beta1.SchemeGroupVersion.WithKind("NetworkNeighborhood") + +// Get takes name of the networkNeighborhood, and returns the corresponding networkNeighborhood object, and an error if there is any. +func (c *FakeNetworkNeighborhoods) Get(ctx context.Context, name string, options v1.GetOptions) (result *v1beta1.NetworkNeighborhood, err error) { + obj, err := c.Fake. + Invokes(testing.NewGetAction(networkneighborhoodsResource, c.ns, name), &v1beta1.NetworkNeighborhood{}) + + if obj == nil { + return nil, err + } + return obj.(*v1beta1.NetworkNeighborhood), err +} + +// List takes label and field selectors, and returns the list of NetworkNeighborhoods that match those selectors. +func (c *FakeNetworkNeighborhoods) List(ctx context.Context, opts v1.ListOptions) (result *v1beta1.NetworkNeighborhoodList, err error) { + obj, err := c.Fake. + Invokes(testing.NewListAction(networkneighborhoodsResource, networkneighborhoodsKind, c.ns, opts), &v1beta1.NetworkNeighborhoodList{}) + + if obj == nil { + return nil, err + } + + label, _, _ := testing.ExtractFromListOptions(opts) + if label == nil { + label = labels.Everything() + } + list := &v1beta1.NetworkNeighborhoodList{ListMeta: obj.(*v1beta1.NetworkNeighborhoodList).ListMeta} + for _, item := range obj.(*v1beta1.NetworkNeighborhoodList).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 networkNeighborhoods. +func (c *FakeNetworkNeighborhoods) Watch(ctx context.Context, opts v1.ListOptions) (watch.Interface, error) { + return c.Fake. + InvokesWatch(testing.NewWatchAction(networkneighborhoodsResource, c.ns, opts)) + +} + +// Create takes the representation of a networkNeighborhood and creates it. Returns the server's representation of the networkNeighborhood, and an error, if there is any. +func (c *FakeNetworkNeighborhoods) Create(ctx context.Context, networkNeighborhood *v1beta1.NetworkNeighborhood, opts v1.CreateOptions) (result *v1beta1.NetworkNeighborhood, err error) { + obj, err := c.Fake. + Invokes(testing.NewCreateAction(networkneighborhoodsResource, c.ns, networkNeighborhood), &v1beta1.NetworkNeighborhood{}) + + if obj == nil { + return nil, err + } + return obj.(*v1beta1.NetworkNeighborhood), err +} + +// Update takes the representation of a networkNeighborhood and updates it. Returns the server's representation of the networkNeighborhood, and an error, if there is any. +func (c *FakeNetworkNeighborhoods) Update(ctx context.Context, networkNeighborhood *v1beta1.NetworkNeighborhood, opts v1.UpdateOptions) (result *v1beta1.NetworkNeighborhood, err error) { + obj, err := c.Fake. + Invokes(testing.NewUpdateAction(networkneighborhoodsResource, c.ns, networkNeighborhood), &v1beta1.NetworkNeighborhood{}) + + if obj == nil { + return nil, err + } + return obj.(*v1beta1.NetworkNeighborhood), err +} + +// Delete takes name of the networkNeighborhood and deletes it. Returns an error if one occurs. +func (c *FakeNetworkNeighborhoods) Delete(ctx context.Context, name string, opts v1.DeleteOptions) error { + _, err := c.Fake. + Invokes(testing.NewDeleteActionWithOptions(networkneighborhoodsResource, c.ns, name, opts), &v1beta1.NetworkNeighborhood{}) + + return err +} + +// DeleteCollection deletes a collection of objects. +func (c *FakeNetworkNeighborhoods) DeleteCollection(ctx context.Context, opts v1.DeleteOptions, listOpts v1.ListOptions) error { + action := testing.NewDeleteCollectionAction(networkneighborhoodsResource, c.ns, listOpts) + + _, err := c.Fake.Invokes(action, &v1beta1.NetworkNeighborhoodList{}) + return err +} + +// Patch applies the patch and returns the patched networkNeighborhood. +func (c *FakeNetworkNeighborhoods) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts v1.PatchOptions, subresources ...string) (result *v1beta1.NetworkNeighborhood, err error) { + obj, err := c.Fake. + Invokes(testing.NewPatchSubresourceAction(networkneighborhoodsResource, c.ns, name, pt, data, subresources...), &v1beta1.NetworkNeighborhood{}) + + if obj == nil { + return nil, err + } + return obj.(*v1beta1.NetworkNeighborhood), err +} diff --git a/pkg/generated/clientset/versioned/typed/softwarecomposition/v1beta1/fake/fake_softwarecomposition_client.go b/pkg/generated/clientset/versioned/typed/softwarecomposition/v1beta1/fake/fake_softwarecomposition_client.go index 3314fdaa5..8187b6825 100644 --- a/pkg/generated/clientset/versioned/typed/softwarecomposition/v1beta1/fake/fake_softwarecomposition_client.go +++ b/pkg/generated/clientset/versioned/typed/softwarecomposition/v1beta1/fake/fake_softwarecomposition_client.go @@ -48,6 +48,10 @@ func (c *FakeSpdxV1beta1) KnownServers(namespace string) v1beta1.KnownServerInte return &FakeKnownServers{c, namespace} } +func (c *FakeSpdxV1beta1) NetworkNeighborhoods(namespace string) v1beta1.NetworkNeighborhoodInterface { + return &FakeNetworkNeighborhoods{c, namespace} +} + func (c *FakeSpdxV1beta1) NetworkNeighborses(namespace string) v1beta1.NetworkNeighborsInterface { return &FakeNetworkNeighborses{c, namespace} } diff --git a/pkg/generated/clientset/versioned/typed/softwarecomposition/v1beta1/generated_expansion.go b/pkg/generated/clientset/versioned/typed/softwarecomposition/v1beta1/generated_expansion.go index 22f44b244..f33a11bf2 100644 --- a/pkg/generated/clientset/versioned/typed/softwarecomposition/v1beta1/generated_expansion.go +++ b/pkg/generated/clientset/versioned/typed/softwarecomposition/v1beta1/generated_expansion.go @@ -28,6 +28,8 @@ type GeneratedNetworkPolicyExpansion interface{} type KnownServerExpansion interface{} +type NetworkNeighborhoodExpansion interface{} + type NetworkNeighborsExpansion interface{} type OpenVulnerabilityExchangeContainerExpansion interface{} diff --git a/pkg/generated/clientset/versioned/typed/softwarecomposition/v1beta1/networkneighborhood.go b/pkg/generated/clientset/versioned/typed/softwarecomposition/v1beta1/networkneighborhood.go new file mode 100644 index 000000000..490ea8d3d --- /dev/null +++ b/pkg/generated/clientset/versioned/typed/softwarecomposition/v1beta1/networkneighborhood.go @@ -0,0 +1,178 @@ +/* +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 v1beta1 + +import ( + "context" + "time" + + v1beta1 "github.com/kubescape/storage/pkg/apis/softwarecomposition/v1beta1" + scheme "github.com/kubescape/storage/pkg/generated/clientset/versioned/scheme" + 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" +) + +// NetworkNeighborhoodsGetter has a method to return a NetworkNeighborhoodInterface. +// A group's client should implement this interface. +type NetworkNeighborhoodsGetter interface { + NetworkNeighborhoods(namespace string) NetworkNeighborhoodInterface +} + +// NetworkNeighborhoodInterface has methods to work with NetworkNeighborhood resources. +type NetworkNeighborhoodInterface interface { + Create(ctx context.Context, networkNeighborhood *v1beta1.NetworkNeighborhood, opts v1.CreateOptions) (*v1beta1.NetworkNeighborhood, error) + Update(ctx context.Context, networkNeighborhood *v1beta1.NetworkNeighborhood, opts v1.UpdateOptions) (*v1beta1.NetworkNeighborhood, 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) (*v1beta1.NetworkNeighborhood, error) + List(ctx context.Context, opts v1.ListOptions) (*v1beta1.NetworkNeighborhoodList, 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 *v1beta1.NetworkNeighborhood, err error) + NetworkNeighborhoodExpansion +} + +// networkNeighborhoods implements NetworkNeighborhoodInterface +type networkNeighborhoods struct { + client rest.Interface + ns string +} + +// newNetworkNeighborhoods returns a NetworkNeighborhoods +func newNetworkNeighborhoods(c *SpdxV1beta1Client, namespace string) *networkNeighborhoods { + return &networkNeighborhoods{ + client: c.RESTClient(), + ns: namespace, + } +} + +// Get takes name of the networkNeighborhood, and returns the corresponding networkNeighborhood object, and an error if there is any. +func (c *networkNeighborhoods) Get(ctx context.Context, name string, options v1.GetOptions) (result *v1beta1.NetworkNeighborhood, err error) { + result = &v1beta1.NetworkNeighborhood{} + err = c.client.Get(). + Namespace(c.ns). + Resource("networkneighborhoods"). + Name(name). + VersionedParams(&options, scheme.ParameterCodec). + Do(ctx). + Into(result) + return +} + +// List takes label and field selectors, and returns the list of NetworkNeighborhoods that match those selectors. +func (c *networkNeighborhoods) List(ctx context.Context, opts v1.ListOptions) (result *v1beta1.NetworkNeighborhoodList, err error) { + var timeout time.Duration + if opts.TimeoutSeconds != nil { + timeout = time.Duration(*opts.TimeoutSeconds) * time.Second + } + result = &v1beta1.NetworkNeighborhoodList{} + err = c.client.Get(). + Namespace(c.ns). + Resource("networkneighborhoods"). + VersionedParams(&opts, scheme.ParameterCodec). + Timeout(timeout). + Do(ctx). + Into(result) + return +} + +// Watch returns a watch.Interface that watches the requested networkNeighborhoods. +func (c *networkNeighborhoods) 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("networkneighborhoods"). + VersionedParams(&opts, scheme.ParameterCodec). + Timeout(timeout). + Watch(ctx) +} + +// Create takes the representation of a networkNeighborhood and creates it. Returns the server's representation of the networkNeighborhood, and an error, if there is any. +func (c *networkNeighborhoods) Create(ctx context.Context, networkNeighborhood *v1beta1.NetworkNeighborhood, opts v1.CreateOptions) (result *v1beta1.NetworkNeighborhood, err error) { + result = &v1beta1.NetworkNeighborhood{} + err = c.client.Post(). + Namespace(c.ns). + Resource("networkneighborhoods"). + VersionedParams(&opts, scheme.ParameterCodec). + Body(networkNeighborhood). + Do(ctx). + Into(result) + return +} + +// Update takes the representation of a networkNeighborhood and updates it. Returns the server's representation of the networkNeighborhood, and an error, if there is any. +func (c *networkNeighborhoods) Update(ctx context.Context, networkNeighborhood *v1beta1.NetworkNeighborhood, opts v1.UpdateOptions) (result *v1beta1.NetworkNeighborhood, err error) { + result = &v1beta1.NetworkNeighborhood{} + err = c.client.Put(). + Namespace(c.ns). + Resource("networkneighborhoods"). + Name(networkNeighborhood.Name). + VersionedParams(&opts, scheme.ParameterCodec). + Body(networkNeighborhood). + Do(ctx). + Into(result) + return +} + +// Delete takes name of the networkNeighborhood and deletes it. Returns an error if one occurs. +func (c *networkNeighborhoods) Delete(ctx context.Context, name string, opts v1.DeleteOptions) error { + return c.client.Delete(). + Namespace(c.ns). + Resource("networkneighborhoods"). + Name(name). + Body(&opts). + Do(ctx). + Error() +} + +// DeleteCollection deletes a collection of objects. +func (c *networkNeighborhoods) 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("networkneighborhoods"). + VersionedParams(&listOpts, scheme.ParameterCodec). + Timeout(timeout). + Body(&opts). + Do(ctx). + Error() +} + +// Patch applies the patch and returns the patched networkNeighborhood. +func (c *networkNeighborhoods) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts v1.PatchOptions, subresources ...string) (result *v1beta1.NetworkNeighborhood, err error) { + result = &v1beta1.NetworkNeighborhood{} + err = c.client.Patch(pt). + Namespace(c.ns). + Resource("networkneighborhoods"). + Name(name). + SubResource(subresources...). + VersionedParams(&opts, scheme.ParameterCodec). + Body(data). + Do(ctx). + Into(result) + return +} diff --git a/pkg/generated/clientset/versioned/typed/softwarecomposition/v1beta1/softwarecomposition_client.go b/pkg/generated/clientset/versioned/typed/softwarecomposition/v1beta1/softwarecomposition_client.go index 66c2bb051..9a2606342 100644 --- a/pkg/generated/clientset/versioned/typed/softwarecomposition/v1beta1/softwarecomposition_client.go +++ b/pkg/generated/clientset/versioned/typed/softwarecomposition/v1beta1/softwarecomposition_client.go @@ -33,6 +33,7 @@ type SpdxV1beta1Interface interface { ConfigurationScanSummariesGetter GeneratedNetworkPoliciesGetter KnownServersGetter + NetworkNeighborhoodsGetter NetworkNeighborsesGetter OpenVulnerabilityExchangeContainersGetter SBOMSPDXv2p3sGetter @@ -71,6 +72,10 @@ func (c *SpdxV1beta1Client) KnownServers(namespace string) KnownServerInterface return newKnownServers(c, namespace) } +func (c *SpdxV1beta1Client) NetworkNeighborhoods(namespace string) NetworkNeighborhoodInterface { + return newNetworkNeighborhoods(c, namespace) +} + func (c *SpdxV1beta1Client) NetworkNeighborses(namespace string) NetworkNeighborsInterface { return newNetworkNeighborses(c, namespace) } diff --git a/pkg/generated/informers/externalversions/generic.go b/pkg/generated/informers/externalversions/generic.go index b74bc6aa7..b84f3f961 100644 --- a/pkg/generated/informers/externalversions/generic.go +++ b/pkg/generated/informers/externalversions/generic.go @@ -63,6 +63,8 @@ func (f *sharedInformerFactory) ForResource(resource schema.GroupVersionResource return &genericInformer{resource: resource.GroupResource(), informer: f.Spdx().V1beta1().GeneratedNetworkPolicies().Informer()}, nil case v1beta1.SchemeGroupVersion.WithResource("knownservers"): return &genericInformer{resource: resource.GroupResource(), informer: f.Spdx().V1beta1().KnownServers().Informer()}, nil + case v1beta1.SchemeGroupVersion.WithResource("networkneighborhoods"): + return &genericInformer{resource: resource.GroupResource(), informer: f.Spdx().V1beta1().NetworkNeighborhoods().Informer()}, nil case v1beta1.SchemeGroupVersion.WithResource("networkneighborses"): return &genericInformer{resource: resource.GroupResource(), informer: f.Spdx().V1beta1().NetworkNeighborses().Informer()}, nil case v1beta1.SchemeGroupVersion.WithResource("openvulnerabilityexchangecontainers"): diff --git a/pkg/generated/informers/externalversions/softwarecomposition/v1beta1/interface.go b/pkg/generated/informers/externalversions/softwarecomposition/v1beta1/interface.go index dc712585c..f0846341b 100644 --- a/pkg/generated/informers/externalversions/softwarecomposition/v1beta1/interface.go +++ b/pkg/generated/informers/externalversions/softwarecomposition/v1beta1/interface.go @@ -34,6 +34,8 @@ type Interface interface { GeneratedNetworkPolicies() GeneratedNetworkPolicyInformer // KnownServers returns a KnownServerInformer. KnownServers() KnownServerInformer + // NetworkNeighborhoods returns a NetworkNeighborhoodInformer. + NetworkNeighborhoods() NetworkNeighborhoodInformer // NetworkNeighborses returns a NetworkNeighborsInformer. NetworkNeighborses() NetworkNeighborsInformer // OpenVulnerabilityExchangeContainers returns a OpenVulnerabilityExchangeContainerInformer. @@ -94,6 +96,11 @@ func (v *version) KnownServers() KnownServerInformer { return &knownServerInformer{factory: v.factory, namespace: v.namespace, tweakListOptions: v.tweakListOptions} } +// NetworkNeighborhoods returns a NetworkNeighborhoodInformer. +func (v *version) NetworkNeighborhoods() NetworkNeighborhoodInformer { + return &networkNeighborhoodInformer{factory: v.factory, namespace: v.namespace, tweakListOptions: v.tweakListOptions} +} + // NetworkNeighborses returns a NetworkNeighborsInformer. func (v *version) NetworkNeighborses() NetworkNeighborsInformer { return &networkNeighborsInformer{factory: v.factory, namespace: v.namespace, tweakListOptions: v.tweakListOptions} diff --git a/pkg/generated/informers/externalversions/softwarecomposition/v1beta1/networkneighborhood.go b/pkg/generated/informers/externalversions/softwarecomposition/v1beta1/networkneighborhood.go new file mode 100644 index 000000000..9f237bd04 --- /dev/null +++ b/pkg/generated/informers/externalversions/softwarecomposition/v1beta1/networkneighborhood.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 v1beta1 + +import ( + "context" + time "time" + + softwarecompositionv1beta1 "github.com/kubescape/storage/pkg/apis/softwarecomposition/v1beta1" + versioned "github.com/kubescape/storage/pkg/generated/clientset/versioned" + internalinterfaces "github.com/kubescape/storage/pkg/generated/informers/externalversions/internalinterfaces" + v1beta1 "github.com/kubescape/storage/pkg/generated/listers/softwarecomposition/v1beta1" + 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" +) + +// NetworkNeighborhoodInformer provides access to a shared informer and lister for +// NetworkNeighborhoods. +type NetworkNeighborhoodInformer interface { + Informer() cache.SharedIndexInformer + Lister() v1beta1.NetworkNeighborhoodLister +} + +type networkNeighborhoodInformer struct { + factory internalinterfaces.SharedInformerFactory + tweakListOptions internalinterfaces.TweakListOptionsFunc + namespace string +} + +// NewNetworkNeighborhoodInformer constructs a new informer for NetworkNeighborhood 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 NewNetworkNeighborhoodInformer(client versioned.Interface, namespace string, resyncPeriod time.Duration, indexers cache.Indexers) cache.SharedIndexInformer { + return NewFilteredNetworkNeighborhoodInformer(client, namespace, resyncPeriod, indexers, nil) +} + +// NewFilteredNetworkNeighborhoodInformer constructs a new informer for NetworkNeighborhood 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 NewFilteredNetworkNeighborhoodInformer(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.SpdxV1beta1().NetworkNeighborhoods(namespace).List(context.TODO(), options) + }, + WatchFunc: func(options v1.ListOptions) (watch.Interface, error) { + if tweakListOptions != nil { + tweakListOptions(&options) + } + return client.SpdxV1beta1().NetworkNeighborhoods(namespace).Watch(context.TODO(), options) + }, + }, + &softwarecompositionv1beta1.NetworkNeighborhood{}, + resyncPeriod, + indexers, + ) +} + +func (f *networkNeighborhoodInformer) defaultInformer(client versioned.Interface, resyncPeriod time.Duration) cache.SharedIndexInformer { + return NewFilteredNetworkNeighborhoodInformer(client, f.namespace, resyncPeriod, cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc}, f.tweakListOptions) +} + +func (f *networkNeighborhoodInformer) Informer() cache.SharedIndexInformer { + return f.factory.InformerFor(&softwarecompositionv1beta1.NetworkNeighborhood{}, f.defaultInformer) +} + +func (f *networkNeighborhoodInformer) Lister() v1beta1.NetworkNeighborhoodLister { + return v1beta1.NewNetworkNeighborhoodLister(f.Informer().GetIndexer()) +} diff --git a/pkg/generated/listers/softwarecomposition/v1beta1/expansion_generated.go b/pkg/generated/listers/softwarecomposition/v1beta1/expansion_generated.go index 6786a10b3..363de564d 100644 --- a/pkg/generated/listers/softwarecomposition/v1beta1/expansion_generated.go +++ b/pkg/generated/listers/softwarecomposition/v1beta1/expansion_generated.go @@ -58,6 +58,14 @@ type KnownServerListerExpansion interface{} // KnownServerNamespaceLister. type KnownServerNamespaceListerExpansion interface{} +// NetworkNeighborhoodListerExpansion allows custom methods to be added to +// NetworkNeighborhoodLister. +type NetworkNeighborhoodListerExpansion interface{} + +// NetworkNeighborhoodNamespaceListerExpansion allows custom methods to be added to +// NetworkNeighborhoodNamespaceLister. +type NetworkNeighborhoodNamespaceListerExpansion interface{} + // NetworkNeighborsListerExpansion allows custom methods to be added to // NetworkNeighborsLister. type NetworkNeighborsListerExpansion interface{} diff --git a/pkg/generated/listers/softwarecomposition/v1beta1/networkneighborhood.go b/pkg/generated/listers/softwarecomposition/v1beta1/networkneighborhood.go new file mode 100644 index 000000000..9ec4a3316 --- /dev/null +++ b/pkg/generated/listers/softwarecomposition/v1beta1/networkneighborhood.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 v1beta1 + +import ( + v1beta1 "github.com/kubescape/storage/pkg/apis/softwarecomposition/v1beta1" + "k8s.io/apimachinery/pkg/api/errors" + "k8s.io/apimachinery/pkg/labels" + "k8s.io/client-go/tools/cache" +) + +// NetworkNeighborhoodLister helps list NetworkNeighborhoods. +// All objects returned here must be treated as read-only. +type NetworkNeighborhoodLister interface { + // List lists all NetworkNeighborhoods in the indexer. + // Objects returned here must be treated as read-only. + List(selector labels.Selector) (ret []*v1beta1.NetworkNeighborhood, err error) + // NetworkNeighborhoods returns an object that can list and get NetworkNeighborhoods. + NetworkNeighborhoods(namespace string) NetworkNeighborhoodNamespaceLister + NetworkNeighborhoodListerExpansion +} + +// networkNeighborhoodLister implements the NetworkNeighborhoodLister interface. +type networkNeighborhoodLister struct { + indexer cache.Indexer +} + +// NewNetworkNeighborhoodLister returns a new NetworkNeighborhoodLister. +func NewNetworkNeighborhoodLister(indexer cache.Indexer) NetworkNeighborhoodLister { + return &networkNeighborhoodLister{indexer: indexer} +} + +// List lists all NetworkNeighborhoods in the indexer. +func (s *networkNeighborhoodLister) List(selector labels.Selector) (ret []*v1beta1.NetworkNeighborhood, err error) { + err = cache.ListAll(s.indexer, selector, func(m interface{}) { + ret = append(ret, m.(*v1beta1.NetworkNeighborhood)) + }) + return ret, err +} + +// NetworkNeighborhoods returns an object that can list and get NetworkNeighborhoods. +func (s *networkNeighborhoodLister) NetworkNeighborhoods(namespace string) NetworkNeighborhoodNamespaceLister { + return networkNeighborhoodNamespaceLister{indexer: s.indexer, namespace: namespace} +} + +// NetworkNeighborhoodNamespaceLister helps list and get NetworkNeighborhoods. +// All objects returned here must be treated as read-only. +type NetworkNeighborhoodNamespaceLister interface { + // List lists all NetworkNeighborhoods in the indexer for a given namespace. + // Objects returned here must be treated as read-only. + List(selector labels.Selector) (ret []*v1beta1.NetworkNeighborhood, err error) + // Get retrieves the NetworkNeighborhood from the indexer for a given namespace and name. + // Objects returned here must be treated as read-only. + Get(name string) (*v1beta1.NetworkNeighborhood, error) + NetworkNeighborhoodNamespaceListerExpansion +} + +// networkNeighborhoodNamespaceLister implements the NetworkNeighborhoodNamespaceLister +// interface. +type networkNeighborhoodNamespaceLister struct { + indexer cache.Indexer + namespace string +} + +// List lists all NetworkNeighborhoods in the indexer for a given namespace. +func (s networkNeighborhoodNamespaceLister) List(selector labels.Selector) (ret []*v1beta1.NetworkNeighborhood, err error) { + err = cache.ListAllByNamespace(s.indexer, s.namespace, selector, func(m interface{}) { + ret = append(ret, m.(*v1beta1.NetworkNeighborhood)) + }) + return ret, err +} + +// Get retrieves the NetworkNeighborhood from the indexer for a given namespace and name. +func (s networkNeighborhoodNamespaceLister) Get(name string) (*v1beta1.NetworkNeighborhood, error) { + obj, exists, err := s.indexer.GetByKey(s.namespace + "/" + name) + if err != nil { + return nil, err + } + if !exists { + return nil, errors.NewNotFound(v1beta1.Resource("networkneighborhood"), name) + } + return obj.(*v1beta1.NetworkNeighborhood), nil +} diff --git a/pkg/generated/openapi/zz_generated.openapi.go b/pkg/generated/openapi/zz_generated.openapi.go index 4b7323d74..ccb167da9 100644 --- a/pkg/generated/openapi/zz_generated.openapi.go +++ b/pkg/generated/openapi/zz_generated.openapi.go @@ -105,6 +105,10 @@ func GetOpenAPIDefinitions(ref common.ReferenceCallback) map[string]common.OpenA "github.com/kubescape/storage/pkg/apis/softwarecomposition/v1beta1.MatchDetails": schema_pkg_apis_softwarecomposition_v1beta1_MatchDetails(ref), "github.com/kubescape/storage/pkg/apis/softwarecomposition/v1beta1.Metadata": schema_pkg_apis_softwarecomposition_v1beta1_Metadata(ref), "github.com/kubescape/storage/pkg/apis/softwarecomposition/v1beta1.NetworkNeighbor": schema_pkg_apis_softwarecomposition_v1beta1_NetworkNeighbor(ref), + "github.com/kubescape/storage/pkg/apis/softwarecomposition/v1beta1.NetworkNeighborhood": schema_pkg_apis_softwarecomposition_v1beta1_NetworkNeighborhood(ref), + "github.com/kubescape/storage/pkg/apis/softwarecomposition/v1beta1.NetworkNeighborhoodContainer": schema_pkg_apis_softwarecomposition_v1beta1_NetworkNeighborhoodContainer(ref), + "github.com/kubescape/storage/pkg/apis/softwarecomposition/v1beta1.NetworkNeighborhoodList": schema_pkg_apis_softwarecomposition_v1beta1_NetworkNeighborhoodList(ref), + "github.com/kubescape/storage/pkg/apis/softwarecomposition/v1beta1.NetworkNeighborhoodSpec": schema_pkg_apis_softwarecomposition_v1beta1_NetworkNeighborhoodSpec(ref), "github.com/kubescape/storage/pkg/apis/softwarecomposition/v1beta1.NetworkNeighbors": schema_pkg_apis_softwarecomposition_v1beta1_NetworkNeighbors(ref), "github.com/kubescape/storage/pkg/apis/softwarecomposition/v1beta1.NetworkNeighborsList": schema_pkg_apis_softwarecomposition_v1beta1_NetworkNeighborsList(ref), "github.com/kubescape/storage/pkg/apis/softwarecomposition/v1beta1.NetworkNeighborsSpec": schema_pkg_apis_softwarecomposition_v1beta1_NetworkNeighborsSpec(ref), @@ -3654,6 +3658,21 @@ func schema_pkg_apis_softwarecomposition_v1beta1_NetworkNeighbor(ref common.Refe Format: "", }, }, + "dnsNames": { + SchemaProps: spec.SchemaProps{ + Description: "DEPRECATED - use DNSNames instead.", + Type: []string{"array"}, + Items: &spec.SchemaOrArray{ + Schema: &spec.Schema{ + SchemaProps: spec.SchemaProps{ + Default: "", + Type: []string{"string"}, + Format: "", + }, + }, + }, + }, + }, "ports": { VendorExtensible: spec.VendorExtensible{ Extensions: spec.Extensions{ @@ -3691,7 +3710,7 @@ func schema_pkg_apis_softwarecomposition_v1beta1_NetworkNeighbor(ref common.Refe }, }, }, - Required: []string{"identifier", "type", "dns", "ports", "podSelector", "namespaceSelector", "ipAddress"}, + Required: []string{"identifier", "type", "dns", "dnsNames", "ports", "podSelector", "namespaceSelector", "ipAddress"}, }, }, Dependencies: []string{ @@ -3699,11 +3718,234 @@ func schema_pkg_apis_softwarecomposition_v1beta1_NetworkNeighbor(ref common.Refe } } +func schema_pkg_apis_softwarecomposition_v1beta1_NetworkNeighborhood(ref common.ReferenceCallback) common.OpenAPIDefinition { + return common.OpenAPIDefinition{ + Schema: spec.Schema{ + SchemaProps: spec.SchemaProps{ + Description: "NetworkNeighborhood represents a list of network communications for a specific workload.", + 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{ + Default: map[string]interface{}{}, + Ref: ref("github.com/kubescape/storage/pkg/apis/softwarecomposition/v1beta1.NetworkNeighborhoodSpec"), + }, + }, + }, + Required: []string{"spec"}, + }, + }, + Dependencies: []string{ + "github.com/kubescape/storage/pkg/apis/softwarecomposition/v1beta1.NetworkNeighborhoodSpec", "k8s.io/apimachinery/pkg/apis/meta/v1.ObjectMeta"}, + } +} + +func schema_pkg_apis_softwarecomposition_v1beta1_NetworkNeighborhoodContainer(ref common.ReferenceCallback) common.OpenAPIDefinition { + return common.OpenAPIDefinition{ + Schema: spec.Schema{ + SchemaProps: spec.SchemaProps{ + Type: []string{"object"}, + Properties: map[string]spec.Schema{ + "name": { + SchemaProps: spec.SchemaProps{ + Default: "", + Type: []string{"string"}, + Format: "", + }, + }, + "ingress": { + SchemaProps: spec.SchemaProps{ + Type: []string{"array"}, + Items: &spec.SchemaOrArray{ + Schema: &spec.Schema{ + SchemaProps: spec.SchemaProps{ + Default: map[string]interface{}{}, + Ref: ref("github.com/kubescape/storage/pkg/apis/softwarecomposition/v1beta1.NetworkNeighbor"), + }, + }, + }, + }, + }, + "egress": { + SchemaProps: spec.SchemaProps{ + Type: []string{"array"}, + Items: &spec.SchemaOrArray{ + Schema: &spec.Schema{ + SchemaProps: spec.SchemaProps{ + Default: map[string]interface{}{}, + Ref: ref("github.com/kubescape/storage/pkg/apis/softwarecomposition/v1beta1.NetworkNeighbor"), + }, + }, + }, + }, + }, + }, + Required: []string{"name", "ingress", "egress"}, + }, + }, + Dependencies: []string{ + "github.com/kubescape/storage/pkg/apis/softwarecomposition/v1beta1.NetworkNeighbor"}, + } +} + +func schema_pkg_apis_softwarecomposition_v1beta1_NetworkNeighborhoodList(ref common.ReferenceCallback) common.OpenAPIDefinition { + return common.OpenAPIDefinition{ + Schema: spec.Schema{ + SchemaProps: spec.SchemaProps{ + Description: "NetworkNeighborhoodList is a list of NetworkNeighborhoods.", + 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("github.com/kubescape/storage/pkg/apis/softwarecomposition/v1beta1.NetworkNeighborhood"), + }, + }, + }, + }, + }, + }, + Required: []string{"items"}, + }, + }, + Dependencies: []string{ + "github.com/kubescape/storage/pkg/apis/softwarecomposition/v1beta1.NetworkNeighborhood", "k8s.io/apimachinery/pkg/apis/meta/v1.ListMeta"}, + } +} + +func schema_pkg_apis_softwarecomposition_v1beta1_NetworkNeighborhoodSpec(ref common.ReferenceCallback) common.OpenAPIDefinition { + return common.OpenAPIDefinition{ + Schema: spec.Schema{ + SchemaProps: spec.SchemaProps{ + Type: []string{"object"}, + Properties: map[string]spec.Schema{ + "matchLabels": { + SchemaProps: spec.SchemaProps{ + Description: "matchLabels is a map of {key,value} pairs. A single {key,value} in the matchLabels map is equivalent to an element of matchExpressions, whose key field is \"key\", the operator is \"In\", and the values array contains only \"value\". The requirements are ANDed.", + Type: []string{"object"}, + AdditionalProperties: &spec.SchemaOrBool{ + Allows: true, + Schema: &spec.Schema{ + SchemaProps: spec.SchemaProps{ + Default: "", + Type: []string{"string"}, + Format: "", + }, + }, + }, + }, + }, + "matchExpressions": { + SchemaProps: spec.SchemaProps{ + Description: "matchExpressions is a list of label selector requirements. The requirements are ANDed.", + Type: []string{"array"}, + Items: &spec.SchemaOrArray{ + Schema: &spec.Schema{ + SchemaProps: spec.SchemaProps{ + Default: map[string]interface{}{}, + Ref: ref("k8s.io/apimachinery/pkg/apis/meta/v1.LabelSelectorRequirement"), + }, + }, + }, + }, + }, + "containers": { + SchemaProps: spec.SchemaProps{ + Type: []string{"array"}, + Items: &spec.SchemaOrArray{ + Schema: &spec.Schema{ + SchemaProps: spec.SchemaProps{ + Default: map[string]interface{}{}, + Ref: ref("github.com/kubescape/storage/pkg/apis/softwarecomposition/v1beta1.NetworkNeighborhoodContainer"), + }, + }, + }, + }, + }, + "initContainers": { + SchemaProps: spec.SchemaProps{ + Type: []string{"array"}, + Items: &spec.SchemaOrArray{ + Schema: &spec.Schema{ + SchemaProps: spec.SchemaProps{ + Default: map[string]interface{}{}, + Ref: ref("github.com/kubescape/storage/pkg/apis/softwarecomposition/v1beta1.NetworkNeighborhoodContainer"), + }, + }, + }, + }, + }, + "ephemeralContainers": { + SchemaProps: spec.SchemaProps{ + Type: []string{"array"}, + Items: &spec.SchemaOrArray{ + Schema: &spec.Schema{ + SchemaProps: spec.SchemaProps{ + Default: map[string]interface{}{}, + Ref: ref("github.com/kubescape/storage/pkg/apis/softwarecomposition/v1beta1.NetworkNeighborhoodContainer"), + }, + }, + }, + }, + }, + }, + Required: []string{"containers", "initContainers", "ephemeralContainers"}, + }, + }, + Dependencies: []string{ + "github.com/kubescape/storage/pkg/apis/softwarecomposition/v1beta1.NetworkNeighborhoodContainer", "k8s.io/apimachinery/pkg/apis/meta/v1.LabelSelectorRequirement"}, + } +} + func schema_pkg_apis_softwarecomposition_v1beta1_NetworkNeighbors(ref common.ReferenceCallback) common.OpenAPIDefinition { return common.OpenAPIDefinition{ Schema: spec.Schema{ SchemaProps: spec.SchemaProps{ - Description: "NetworkNeighbors represents a list of network communications for a specific workload.", + Description: "NetworkNeighbors represents a list of network communications for a specific workload. DEPRECATED - use NetworkNeighborhood instead.", Type: []string{"object"}, Properties: map[string]spec.Schema{ "kind": { @@ -3745,7 +3987,7 @@ func schema_pkg_apis_softwarecomposition_v1beta1_NetworkNeighborsList(ref common return common.OpenAPIDefinition{ Schema: spec.Schema{ SchemaProps: spec.SchemaProps{ - Description: "NetworkNeighborsList is a list of NetworkNeighbors.", + Description: "NetworkNeighborsList is a list of NetworkNeighbors. DEPRECATED - use NetworkNeighborhoodList instead.", Type: []string{"object"}, Properties: map[string]spec.Schema{ "kind": { diff --git a/pkg/registry/softwarecomposition/networkneighborhood/etcd.go b/pkg/registry/softwarecomposition/networkneighborhood/etcd.go new file mode 100644 index 000000000..15e8c880c --- /dev/null +++ b/pkg/registry/softwarecomposition/networkneighborhood/etcd.go @@ -0,0 +1,56 @@ +/* +Copyright 2017 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 networkneighborhood + +import ( + "github.com/kubescape/storage/pkg/apis/softwarecomposition" + "github.com/kubescape/storage/pkg/registry" + "k8s.io/apimachinery/pkg/runtime" + "k8s.io/apiserver/pkg/registry/generic" + genericregistry "k8s.io/apiserver/pkg/registry/generic/registry" + "k8s.io/apiserver/pkg/registry/rest" + "k8s.io/apiserver/pkg/storage" +) + +// NewREST returns a RESTStorage object that will work against API services. +func NewREST(scheme *runtime.Scheme, storageImpl storage.Interface, optsGetter generic.RESTOptionsGetter) (*registry.REST, error) { + strategy := NewStrategy(scheme) + + dryRunnableStorage := genericregistry.DryRunnableStorage{Codec: nil, Storage: storageImpl} + + store := &genericregistry.Store{ + NewFunc: func() runtime.Object { return &softwarecomposition.NetworkNeighborhood{} }, + NewListFunc: func() runtime.Object { return &softwarecomposition.NetworkNeighborhoodList{} }, + PredicateFunc: MatchNetworkNeighborhood, + DefaultQualifiedResource: softwarecomposition.Resource("networkneighborhoods"), + SingularQualifiedResource: softwarecomposition.Resource("networkneighborhood"), + + Storage: dryRunnableStorage, + + CreateStrategy: strategy, + UpdateStrategy: strategy, + DeleteStrategy: strategy, + + // TODO: define table converter that exposes more than name/creation timestamp + TableConvertor: rest.NewDefaultTableConvertor(softwarecomposition.Resource("networkneighborhoods")), + } + options := &generic.StoreOptions{RESTOptions: optsGetter, AttrFunc: GetAttrs} + if err := store.CompleteWithOptions(options); err != nil { + return nil, err + } + return ®istry.REST{Store: store}, nil +} diff --git a/pkg/registry/softwarecomposition/networkneighborhood/strategy.go b/pkg/registry/softwarecomposition/networkneighborhood/strategy.go new file mode 100644 index 000000000..848a95885 --- /dev/null +++ b/pkg/registry/softwarecomposition/networkneighborhood/strategy.go @@ -0,0 +1,129 @@ +package networkneighborhood + +import ( + "context" + "fmt" + + "k8s.io/apimachinery/pkg/fields" + "k8s.io/apimachinery/pkg/labels" + "k8s.io/apimachinery/pkg/runtime" + "k8s.io/apimachinery/pkg/util/validation/field" + "k8s.io/apiserver/pkg/registry/generic" + "k8s.io/apiserver/pkg/storage" + "k8s.io/apiserver/pkg/storage/names" + + "github.com/kubescape/k8s-interface/instanceidhandler/v1/helpers" + "github.com/kubescape/storage/pkg/apis/softwarecomposition" + "github.com/kubescape/storage/pkg/utils" +) + +// NewStrategy creates and returns a NetworkNeighborhoodStrategy instance +func NewStrategy(typer runtime.ObjectTyper) NetworkNeighborhoodStrategy { + return NetworkNeighborhoodStrategy{typer, names.SimpleNameGenerator} +} + +// GetAttrs returns labels.Set, fields.Set, and error in case the given runtime.Object is not a Flunder +func GetAttrs(obj runtime.Object) (labels.Set, fields.Set, error) { + apiserver, ok := obj.(*softwarecomposition.NetworkNeighborhood) + if !ok { + return nil, nil, fmt.Errorf("given object is not a NetworkNeighborhood") + } + return labels.Set(apiserver.ObjectMeta.Labels), SelectableFields(apiserver), nil +} + +// MatchNetworkNeighborhood is the filter used by the generic etcd backend to watch events +// from etcd to clients of the apiserver only interested in specific labels/fields. +func MatchNetworkNeighborhood(label labels.Selector, field fields.Selector) storage.SelectionPredicate { + return storage.SelectionPredicate{ + Label: label, + Field: field, + GetAttrs: GetAttrs, + } +} + +// SelectableFields returns a field set that represents the object. +func SelectableFields(obj *softwarecomposition.NetworkNeighborhood) fields.Set { + return generic.ObjectMetaFieldsSet(&obj.ObjectMeta, true) +} + +type NetworkNeighborhoodStrategy struct { + runtime.ObjectTyper + names.NameGenerator +} + +func (NetworkNeighborhoodStrategy) NamespaceScoped() bool { + return true +} + +func (NetworkNeighborhoodStrategy) PrepareForCreate(ctx context.Context, obj runtime.Object) { +} + +func (NetworkNeighborhoodStrategy) PrepareForUpdate(ctx context.Context, obj, old runtime.Object) { + newAP := obj.(*softwarecomposition.NetworkNeighborhood) + oldAP := old.(*softwarecomposition.NetworkNeighborhood) + + // completion status cannot be transitioned from 'complete' -> 'partial' + // in such case, we reject status updates + if oldAP.Annotations[helpers.CompletionMetadataKey] == helpers.Complete && newAP.Annotations[helpers.CompletionMetadataKey] == helpers.Partial { + newAP.Annotations[helpers.CompletionMetadataKey] = helpers.Complete + + if v, ok := oldAP.Annotations[helpers.StatusMetadataKey]; ok { + newAP.Annotations[helpers.StatusMetadataKey] = v + } else { + delete(newAP.Annotations, helpers.StatusMetadataKey) + } + } +} + +func (NetworkNeighborhoodStrategy) Validate(ctx context.Context, obj runtime.Object) field.ErrorList { + ap := obj.(*softwarecomposition.NetworkNeighborhood) + + allErrors := field.ErrorList{} + + if err := utils.ValidateCompletionAnnotation(ap.Annotations); err != nil { + allErrors = append(allErrors, err) + } + + if err := utils.ValidateStatusAnnotation(ap.Annotations); err != nil { + allErrors = append(allErrors, err) + } + + return allErrors +} + +// WarningsOnCreate returns warnings for the creation of the given object. +func (NetworkNeighborhoodStrategy) WarningsOnCreate(ctx context.Context, obj runtime.Object) []string { + return nil +} + +func (NetworkNeighborhoodStrategy) AllowCreateOnUpdate() bool { + return false +} + +func (NetworkNeighborhoodStrategy) AllowUnconditionalUpdate() bool { + return false +} + +func (NetworkNeighborhoodStrategy) Canonicalize(obj runtime.Object) { +} + +func (NetworkNeighborhoodStrategy) ValidateUpdate(ctx context.Context, obj, old runtime.Object) field.ErrorList { + ap := obj.(*softwarecomposition.NetworkNeighborhood) + + allErrors := field.ErrorList{} + + if err := utils.ValidateCompletionAnnotation(ap.Annotations); err != nil { + allErrors = append(allErrors, err) + } + + if err := utils.ValidateStatusAnnotation(ap.Annotations); err != nil { + allErrors = append(allErrors, err) + } + + return allErrors +} + +// WarningsOnUpdate returns warnings for the given update. +func (NetworkNeighborhoodStrategy) WarningsOnUpdate(ctx context.Context, obj, old runtime.Object) []string { + return nil +} diff --git a/pkg/registry/softwarecomposition/networkneighborhood/strategy_test.go b/pkg/registry/softwarecomposition/networkneighborhood/strategy_test.go new file mode 100644 index 000000000..c356d37c7 --- /dev/null +++ b/pkg/registry/softwarecomposition/networkneighborhood/strategy_test.go @@ -0,0 +1,92 @@ +package networkneighborhood + +import ( + "context" + "reflect" + "testing" + + "github.com/kubescape/k8s-interface/instanceidhandler/v1/helpers" + "github.com/kubescape/storage/pkg/apis/softwarecomposition" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" +) + +func TestPrepareForUpdate(t *testing.T) { + tests := []struct { + name string + oldAnnotations map[string]string + newAnnotations map[string]string + expected map[string]string + }{ + { + name: "transition from complete (with status) to partial - rejected", + oldAnnotations: map[string]string{ + helpers.CompletionMetadataKey: "complete", + helpers.StatusMetadataKey: "initializing", + }, + newAnnotations: map[string]string{ + helpers.CompletionMetadataKey: "partial", + helpers.StatusMetadataKey: "ready", + }, + expected: map[string]string{ + helpers.CompletionMetadataKey: "complete", + helpers.StatusMetadataKey: "initializing", + }, + }, + { + name: "transition from partial (with status) to complete - accepted", + oldAnnotations: map[string]string{ + helpers.CompletionMetadataKey: "partial", + helpers.StatusMetadataKey: "initializing", + }, + newAnnotations: map[string]string{ + helpers.CompletionMetadataKey: "partial", + helpers.StatusMetadataKey: "ready", + }, + expected: map[string]string{ + helpers.CompletionMetadataKey: "partial", + helpers.StatusMetadataKey: "ready", + }, + }, + { + name: "transition from partial (without status) to complete - accepted", + oldAnnotations: map[string]string{ + helpers.CompletionMetadataKey: "partial", + }, + newAnnotations: map[string]string{ + helpers.CompletionMetadataKey: "complete", + helpers.StatusMetadataKey: "ready", + }, + expected: map[string]string{ + helpers.CompletionMetadataKey: "complete", + helpers.StatusMetadataKey: "ready", + }, + }, + { + name: "transition from complete (without status) to partial - rejected", + oldAnnotations: map[string]string{ + helpers.CompletionMetadataKey: "complete", + }, + newAnnotations: map[string]string{ + helpers.CompletionMetadataKey: "partial", + helpers.StatusMetadataKey: "initializing", + }, + expected: map[string]string{ + helpers.CompletionMetadataKey: "complete", + }, + }, + } + + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + s := NetworkNeighborhoodStrategy{} + + obj := &softwarecomposition.NetworkNeighborhood{ObjectMeta: metav1.ObjectMeta{Annotations: tt.newAnnotations}} + old := &softwarecomposition.NetworkNeighborhood{ObjectMeta: metav1.ObjectMeta{Annotations: tt.oldAnnotations}} + + s.PrepareForUpdate(context.Background(), obj, old) + if !reflect.DeepEqual(obj.Annotations, tt.expected) { + t.Errorf("PrepareForUpdate() = %v, want %v", obj.Annotations, tt.expected) + } + }) + } +}