diff --git a/build/yamls/base/core-crds.yml b/build/yamls/base/core-crds.yml new file mode 100644 index 00000000000..432da29b4ef --- /dev/null +++ b/build/yamls/base/core-crds.yml @@ -0,0 +1,48 @@ +--- +apiVersion: apiextensions.k8s.io/v1beta1 +kind: CustomResourceDefinition +metadata: + name: externalentities.core.antrea.tanzu.vmware.com +spec: + group: core.antrea.tanzu.vmware.com + versions: + - name: v1alpha1 + served: true + storage: true + scope: Namespaced + names: + plural: externalentities + singular: externalentity + kind: ExternalEntity + shortNames: + - ee + # Prune any unknown fields + preserveUnknownFields: false + validation: + openAPIV3Schema: + type: object + properties: + spec: + type: object + properties: + endpoints: + type: array + items: + type: object + properties: + ip: + type: string + format: ipv4 + name: + type: string + ports: + type: array + items: + type: object + properties: + protocol: + type: string + port: + x-kubernetes-int-or-string: true + externalNode: + type: string diff --git a/build/yamls/base/security-crds.yml b/build/yamls/base/security-crds.yml new file mode 100644 index 00000000000..a19ae219cef --- /dev/null +++ b/build/yamls/base/security-crds.yml @@ -0,0 +1,121 @@ +--- +apiVersion: apiextensions.k8s.io/v1beta1 +kind: CustomResourceDefinition +metadata: + name: networkpolicies.security.antrea.tanzu.vmware.com +spec: + group: security.antrea.tanzu.vmware.com + versions: + - name: v1alpha1 + served: true + storage: true + scope: Namespaced + names: + plural: networkpolicies + singular: networkpolicy + kind: NetworkPolicy + shortNames: + - anp + # Prune any unknown fields + preserveUnknownFields: false + validation: + openAPIV3Schema: + type: object + properties: + spec: + # Ensure that Spec.AppliedTo and Spec.Priority fields are set + required: + - appliedTo + - priority + type: object + properties: + priority: + type: number + format: float + # Ensure that Spec.Priority field is between 1 and 10000 + minimum: 1.0 + maximum: 10000.0 + appliedTo: + type: array + items: + type: object + # Ensure that Spec.AppliedTo does not allow NamespaceSelector/IPBlock field + properties: + podSelector: + type: object + additionalProperties: + type: object + externalEntitySelector: + type: object + additionalProperties: + type: object + ingress: + type: array + items: + type: object + required: + - action + properties: + # Ensure that Action field allows only ALLOW and DROP values + action: + type: string + pattern: '\bALLOW|\bAllow|\ballow|\bDROP|\bDrop|\bdrop' + ports: + type: array + items: + type: object + properties: + protocol: + type: string + port: + x-kubernetes-int-or-string: true + from: + type: array + items: + type: object + properties: + podSelector: + x-kubernetes-preserve-unknown-fields: true + namespaceSelector: + x-kubernetes-preserve-unknown-fields: true + ipBlock: + type: object + properties: + cidr: + type: string + format: cidr + egress: + type: array + items: + type: object + required: + - action + properties: + # Ensure that Action field allows only ALLOW and DROP values + action: + type: string + pattern: '\bALLOW|\bAllow|\ballow|\bDROP|\bDrop|\bdrop' + ports: + type: array + items: + type: object + properties: + protocol: + type: string + port: + x-kubernetes-int-or-string: true + to: + type: array + items: + type: object + properties: + podSelector: + x-kubernetes-preserve-unknown-fields: true + namespaceSelector: + x-kubernetes-preserve-unknown-fields: true + ipBlock: + type: object + properties: + cidr: + type: string + format: cidr diff --git a/build/yamls/patches/np/npRbac.yml b/build/yamls/patches/np/npRbac.yml new file mode 100644 index 00000000000..7e3af1eab74 --- /dev/null +++ b/build/yamls/patches/np/npRbac.yml @@ -0,0 +1,22 @@ +--- +kind: ClusterRole +apiVersion: rbac.authorization.k8s.io/v1 +metadata: + name: antrea-controller +rules: + - apiGroups: + - security.antrea.tanzu.vmware.com + resources: + - networkpolicies + verbs: + - get + - watch + - list + - apiGroups: + - core.antrea.tanzu.vmware.com + resources: + - externalentities + verbs: + - get + - watch + - list diff --git a/hack/generate-manifest.sh b/hack/generate-manifest.sh index a30aa1a39f2..d81ade420d4 100755 --- a/hack/generate-manifest.sh +++ b/hack/generate-manifest.sh @@ -27,6 +27,7 @@ Generate a YAML manifest for Antrea using Kustomize and print it to stdout. --kind Generate a manifest appropriate for running Antrea in a Kind cluster --cloud Generate a manifest appropriate for running Antrea in Public Cloud --ipsec Generate a manifest with IPSec encryption of tunnel traffic enabled + --np Generate a manifest with Namespaced Antrea NetworkPolicy CRDs enabled --keep Debug flag which will preserve the generated kustomization.yml --help, -h Print this message and exit @@ -48,6 +49,7 @@ function print_help { MODE="dev" KIND=false IPSEC=false +NP=false KEEP=false ENCAP_MODE="" CLOUD="" @@ -77,6 +79,10 @@ case $key in IPSEC=true shift ;; + --np) + NP=true + shift + ;; --keep) KEEP=true shift @@ -173,6 +179,23 @@ if $IPSEC; then cd .. fi +if $NP; then + mkdir np && cd np + cp ../../patches/np/*.yml . + cp ../../base/security-crds.yml . + cp ../../base/core-crds.yml . + touch kustomization.yml + $KUSTOMIZE edit add base $BASE + # add RBAC to antrea-controller for NP CRD access. + $KUSTOMIZE edit add patch npRbac.yml + # create NetworkPolicy related CRDs. + $KUSTOMIZE edit add resource security-crds.yml + # create ExternalEntity related CRDs. + $KUSTOMIZE edit add resource core-crds.yml + BASE=../np + cd .. +fi + if [[ $ENCAP_MODE == "networkPolicyOnly" ]] ; then mkdir chaining && cd chaining cp ../../patches/chaining/*.yml . diff --git a/hack/update-codegen-dockerized.sh b/hack/update-codegen-dockerized.sh index 5fa166fbe70..fe645e8cf7a 100755 --- a/hack/update-codegen-dockerized.sh +++ b/hack/update-codegen-dockerized.sh @@ -32,14 +32,32 @@ $GOPATH/bin/client-gen \ --input "clusterinformation/v1beta1" \ --input "networking/v1beta1" \ --input "system/v1beta1" \ + --input "security/v1alpha1" \ + --input "core/v1alpha1" \ --output-package "${ANTREA_PKG}/pkg/client/clientset" \ --go-header-file hack/boilerplate/license_header.go.txt +# Generate listers with K8s codegen tools. +$GOPATH/bin/lister-gen \ + --input-dirs "${ANTREA_PKG}/pkg/apis/security/v1alpha1,${ANTREA_PKG}/pkg/apis/core/v1alpha1" \ + --output-package "${ANTREA_PKG}/pkg/client/listers" \ + --go-header-file hack/boilerplate/license_header.go.txt + +# Generate informers with K8s codegen tools. +$GOPATH/bin/informer-gen \ + --input-dirs "${ANTREA_PKG}/pkg/apis/security/v1alpha1,${ANTREA_PKG}/pkg/apis/core/v1alpha1" \ + --versioned-clientset-package "${ANTREA_PKG}/pkg/client/clientset/versioned" \ + --listers-package "${ANTREA_PKG}/pkg/client/listers" \ + --output-package "${ANTREA_PKG}/pkg/client/informers" \ + --go-header-file hack/boilerplate/license_header.go.txt + $GOPATH/bin/deepcopy-gen \ --input-dirs "${ANTREA_PKG}/pkg/apis/clusterinformation/v1beta1" \ --input-dirs "${ANTREA_PKG}/pkg/apis/networking" \ --input-dirs "${ANTREA_PKG}/pkg/apis/networking/v1beta1" \ --input-dirs "${ANTREA_PKG}/pkg/apis/system/v1beta1" \ + --input-dirs "${ANTREA_PKG}/pkg/apis/security/v1alpha1" \ + --input-dirs "${ANTREA_PKG}/pkg/apis/core/v1alpha1" \ -O zz_generated.deepcopy \ --go-header-file hack/boilerplate/license_header.go.txt diff --git a/pkg/apis/core/doc.go b/pkg/apis/core/doc.go new file mode 100644 index 00000000000..cb62e03041a --- /dev/null +++ b/pkg/apis/core/doc.go @@ -0,0 +1,18 @@ +// Copyright 2020 Antrea 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. + +// +k8s:deepcopy-gen=package +// +groupName=core.antrea.tanzu.vmware.com + +package core diff --git a/pkg/apis/core/register.go b/pkg/apis/core/register.go new file mode 100644 index 00000000000..7948c385555 --- /dev/null +++ b/pkg/apis/core/register.go @@ -0,0 +1,20 @@ +// Copyright 2020 Antrea 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 core + +// GroupName is the group name used in this package +const ( + GroupName = "core.antrea.tanzu.vmware.com" +) diff --git a/pkg/apis/core/v1alpha1/doc.go b/pkg/apis/core/v1alpha1/doc.go new file mode 100644 index 00000000000..f5d07eb31f6 --- /dev/null +++ b/pkg/apis/core/v1alpha1/doc.go @@ -0,0 +1,19 @@ +// Copyright 2020 Antrea 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. + +// +k8s:openapi-gen=true +// +k8s:deepcopy-gen=package +// +groupName=core.antrea.tanzu.vmware.com + +package v1alpha1 // import "github.com/vmware-tanzu/antrea/pkg/apis/core/v1alpha1" diff --git a/pkg/apis/core/v1alpha1/register.go b/pkg/apis/core/v1alpha1/register.go new file mode 100644 index 00000000000..7c2044145d0 --- /dev/null +++ b/pkg/apis/core/v1alpha1/register.go @@ -0,0 +1,53 @@ +// Copyright 2020 Antrea 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 v1alpha1 + +import ( + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/runtime" + "k8s.io/apimachinery/pkg/runtime/schema" +) + +// GroupName is the group name used in this package. +const GroupName = "core.antrea.tanzu.vmware.com" + +// SchemeGroupVersion is group version used to register these objects. +var SchemeGroupVersion = schema.GroupVersion{Group: GroupName, Version: "v1alpha1"} + +// Kind takes an unqualified kind and returns back a Group qualified GroupKind +func Kind(kind string) schema.GroupKind { + return SchemeGroupVersion.WithKind(kind).GroupKind() +} + +// Resource takes an unqualified resource and returns a Group qualified GroupResource. +func Resource(resource string) schema.GroupResource { + return SchemeGroupVersion.WithResource(resource).GroupResource() +} + +var ( + SchemeBuilder = runtime.NewSchemeBuilder(addKnownTypes) + AddToScheme = SchemeBuilder.AddToScheme +) + +// Adds the list of known types to the given scheme. +func addKnownTypes(scheme *runtime.Scheme) error { + scheme.AddKnownTypes(SchemeGroupVersion, + &ExternalEntity{}, + &ExternalEntityList{}, + ) + + metav1.AddToGroupVersion(scheme, SchemeGroupVersion) + return nil +} diff --git a/pkg/apis/core/v1alpha1/types.go b/pkg/apis/core/v1alpha1/types.go new file mode 100644 index 00000000000..ec4b0657e4d --- /dev/null +++ b/pkg/apis/core/v1alpha1/types.go @@ -0,0 +1,76 @@ +// Copyright 2020 Antrea 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 v1alpha1 + +import ( + v1 "k8s.io/api/core/v1" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" +) + +// +genclient +// +genclient:noStatus +// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object + +type ExternalEntity struct { + metav1.TypeMeta `json:",inline"` + // Standard metadata of the object. + metav1.ObjectMeta `json:"metadata,omitempty"` + // Desired state of the external entity. + Spec ExternalEntitySpec `json:"spec,omitempty"` +} + +// ExternalEntitySpec defines the desired state for ExternalEntity. +type ExternalEntitySpec struct { + // Endpoints is a list of external endpoints associated with this entity. + Endpoints []Endpoint `json:"endpoints,omitempty"` + // ExternalNode is the opaque identifier of the agent/controller responsible + // for additional processing or handling of this external entity. + ExternalNode string `json:"externalNode,omitempty"` +} + +// Endpoint refers to an endpoint associated with the ExternalEntity. +type Endpoint struct { + // IP associated with this endpoint. + IP string `json:"ip,omitempty"` + // Name identifies this endpoint. Could be the interface name in case of VMs. + // +optional + Name string `json:"name,omitempty"` + // Ports maintain the list of named ports. + Ports []NamedPort `json:"ports,omitempty"` +} + +// NamedPort describes the port and protocol to match in a rule. +type NamedPort struct { + // The protocol (TCP, UDP, or SCTP) which traffic must match. + // If not specified, this field defaults to TCP. + // +optional + Protocol v1.Protocol `json:"protocol,omitempty"` + // The port on the given protocol. + // +optional + Port int32 `json:"port,omitempty"` + // Name associated with the Port. + // +optional + Name string `json:"name,omitempty"` +} + +// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object + +type ExternalEntityList struct { + metav1.TypeMeta `json:",inline"` + // +optional + metav1.ListMeta `json:"metadata,omitempty"` + + Items []ExternalEntity `json:"items,omitempty"` +} diff --git a/pkg/apis/core/v1alpha1/webhook.go b/pkg/apis/core/v1alpha1/webhook.go new file mode 100644 index 00000000000..579502f9412 --- /dev/null +++ b/pkg/apis/core/v1alpha1/webhook.go @@ -0,0 +1,81 @@ +// Copyright 2020 Antrea 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 v1alpha1 + +import ( + "fmt" + "reflect" + + "k8s.io/apimachinery/pkg/runtime" +) + +// WebhookImpl implements webhook validator of a resource. +type WebhookImpl interface { + Default(in *ExternalEntity) + ValidateCreate(in *ExternalEntity) error + ValidateUpdate(in *ExternalEntity, old runtime.Object) error + ValidateDelete(in *ExternalEntity) error +} + +var ( + externalEntityWebhook WebhookImpl +) + +// RegisterWebhook registers webhook implementation of a resource. +func RegisterWebhook(in runtime.Object, webhook WebhookImpl) error { + switch in.(type) { + case *ExternalEntity: + if externalEntityWebhook != nil { + return fmt.Errorf("externalEntityWebhook already registered") + } + externalEntityWebhook = webhook + default: + return fmt.Errorf("unknown type %s to register webhook", reflect.TypeOf(in).Elem().Name()) + } + return nil +} + +// Default implements webhook Defaulter. +func (in *ExternalEntity) Default() { + if externalEntityWebhook != nil { + externalEntityWebhook.Default(in) + } + return +} + +// ValidateCreate implements webhook Validator. +func (in *ExternalEntity) ValidateCreate() error { + if externalEntityWebhook != nil { + return externalEntityWebhook.ValidateCreate(in) + } + return nil +} + +// ValidateUpdate implements webhook Validator. +func (in *ExternalEntity) ValidateUpdate(old runtime.Object) error { + if externalEntityWebhook != nil { + return externalEntityWebhook.ValidateUpdate(in, old) + } + + return nil +} + +// ValidateDelete implements webhook Validator. +func (in *ExternalEntity) ValidateDelete() error { + if externalEntityWebhook != nil { + return externalEntityWebhook.ValidateDelete(in) + } + return nil +} diff --git a/pkg/apis/core/v1alpha1/zz_generated.deepcopy.go b/pkg/apis/core/v1alpha1/zz_generated.deepcopy.go new file mode 100644 index 00000000000..670754f1ac4 --- /dev/null +++ b/pkg/apis/core/v1alpha1/zz_generated.deepcopy.go @@ -0,0 +1,143 @@ +// +build !ignore_autogenerated + +// Copyright 2020 Antrea 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 deepcopy-gen. DO NOT EDIT. + +package v1alpha1 + +import ( + runtime "k8s.io/apimachinery/pkg/runtime" +) + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *Endpoint) DeepCopyInto(out *Endpoint) { + *out = *in + if in.Ports != nil { + in, out := &in.Ports, &out.Ports + *out = make([]NamedPort, len(*in)) + copy(*out, *in) + } + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Endpoint. +func (in *Endpoint) DeepCopy() *Endpoint { + if in == nil { + return nil + } + out := new(Endpoint) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *ExternalEntity) DeepCopyInto(out *ExternalEntity) { + *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 ExternalEntity. +func (in *ExternalEntity) DeepCopy() *ExternalEntity { + if in == nil { + return nil + } + out := new(ExternalEntity) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *ExternalEntity) 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 *ExternalEntityList) DeepCopyInto(out *ExternalEntityList) { + *out = *in + out.TypeMeta = in.TypeMeta + in.ListMeta.DeepCopyInto(&out.ListMeta) + if in.Items != nil { + in, out := &in.Items, &out.Items + *out = make([]ExternalEntity, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ExternalEntityList. +func (in *ExternalEntityList) DeepCopy() *ExternalEntityList { + if in == nil { + return nil + } + out := new(ExternalEntityList) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *ExternalEntityList) 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 *ExternalEntitySpec) DeepCopyInto(out *ExternalEntitySpec) { + *out = *in + if in.Endpoints != nil { + in, out := &in.Endpoints, &out.Endpoints + *out = make([]Endpoint, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ExternalEntitySpec. +func (in *ExternalEntitySpec) DeepCopy() *ExternalEntitySpec { + if in == nil { + return nil + } + out := new(ExternalEntitySpec) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *NamedPort) DeepCopyInto(out *NamedPort) { + *out = *in + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new NamedPort. +func (in *NamedPort) DeepCopy() *NamedPort { + if in == nil { + return nil + } + out := new(NamedPort) + in.DeepCopyInto(out) + return out +} diff --git a/pkg/apis/security/doc.go b/pkg/apis/security/doc.go new file mode 100644 index 00000000000..4db6c7e2e35 --- /dev/null +++ b/pkg/apis/security/doc.go @@ -0,0 +1,18 @@ +// Copyright 2020 Antrea 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. + +// +k8s:deepcopy-gen=package +// +groupName=security.antrea.tanzu.vmware.com + +package security diff --git a/pkg/apis/security/register.go b/pkg/apis/security/register.go new file mode 100644 index 00000000000..ae9e808c67e --- /dev/null +++ b/pkg/apis/security/register.go @@ -0,0 +1,20 @@ +// Copyright 2020 Antrea 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 security + +// GroupName is the group name used in this package +const ( + GroupName = "security.antrea.tanzu.vmware.com" +) diff --git a/pkg/apis/security/v1alpha1/doc.go b/pkg/apis/security/v1alpha1/doc.go new file mode 100644 index 00000000000..e5978be0f25 --- /dev/null +++ b/pkg/apis/security/v1alpha1/doc.go @@ -0,0 +1,19 @@ +// Copyright 2020 Antrea 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. + +// +k8s:openapi-gen=true +// +k8s:deepcopy-gen=package +// +groupName=security.antrea.tanzu.vmware.com + +package v1alpha1 // import "github.com/vmware-tanzu/antrea/pkg/apis/security/v1alpha1" diff --git a/pkg/apis/security/v1alpha1/register.go b/pkg/apis/security/v1alpha1/register.go new file mode 100644 index 00000000000..e8b119bba1d --- /dev/null +++ b/pkg/apis/security/v1alpha1/register.go @@ -0,0 +1,53 @@ +// Copyright 2020 Antrea 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 v1alpha1 + +import ( + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/runtime" + "k8s.io/apimachinery/pkg/runtime/schema" +) + +// GroupName is the group name used in this package. +const GroupName = "security.antrea.tanzu.vmware.com" + +// SchemeGroupVersion is group version used to register these objects. +var SchemeGroupVersion = schema.GroupVersion{Group: GroupName, Version: "v1alpha1"} + +// Kind takes an unqualified kind and returns back a Group qualified GroupKind +func Kind(kind string) schema.GroupKind { + return SchemeGroupVersion.WithKind(kind).GroupKind() +} + +// Resource takes an unqualified resource and returns a Group qualified GroupResource. +func Resource(resource string) schema.GroupResource { + return SchemeGroupVersion.WithResource(resource).GroupResource() +} + +var ( + SchemeBuilder = runtime.NewSchemeBuilder(addKnownTypes) + AddToScheme = SchemeBuilder.AddToScheme +) + +// Adds the list of known types to the given scheme. +func addKnownTypes(scheme *runtime.Scheme) error { + scheme.AddKnownTypes(SchemeGroupVersion, + &NetworkPolicy{}, + &NetworkPolicyList{}, + ) + + metav1.AddToGroupVersion(scheme, SchemeGroupVersion) + return nil +} diff --git a/pkg/apis/security/v1alpha1/types.go b/pkg/apis/security/v1alpha1/types.go new file mode 100644 index 00000000000..542a8816f3c --- /dev/null +++ b/pkg/apis/security/v1alpha1/types.go @@ -0,0 +1,144 @@ +// Copyright 2020 Antrea 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 v1alpha1 + +import ( + v1 "k8s.io/api/core/v1" + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + "k8s.io/apimachinery/pkg/util/intstr" +) + +// +genclient +// +genclient:noStatus +// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object + +type NetworkPolicy struct { + metav1.TypeMeta `json:",inline"` + // Standard metadata of the object. + metav1.ObjectMeta `json:"metadata,omitempty"` + + // Specification of the desired behavior of NetworkPolicy. + Spec NetworkPolicySpec `json:"spec"` +} + +// NetworkPolicySpec defines the desired state for NetworkPolicy. +type NetworkPolicySpec struct { + // Priority specfies the order of the NetworkPolicy relative to other + // NetworkPolicies. + Priority float64 `json:"priority"` + // Select workloads on which the rules will be applied to. + AppliedTo []NetworkPolicyPeer `json:"appliedTo"` + // Set of ingress rules evaluated based on the order in which they are set. + // Currently Ingress rule supports setting the `From` field but not the `To` + // field within a Rule. + // +optional + Ingress []Rule `json:"ingress"` + // Set of egress rules evaluated based on the order in which they are set. + // Currently Egress rule supports setting the `To` field but not the `From` + // field within a Rule. + // +optional + Egress []Rule `json:"egress"` +} + +// Rule describes the traffic allowed to/from the workloads selected by +// Spec.AppliedTo. Based on the action specified in the rule, traffic is either +// allowed or denied which exactly match the specified ports and protocol. +type Rule struct { + // Action specifies the action to be applied on the rule. + Action *RuleAction `json:"action"` + // Set of port and protocol allowed/denied by the rule. If this field is unset + // or empty, this rule matches all ports. + // +optional + Ports []NetworkPolicyPort `json:"ports"` + // Rule is matched if traffic originates from workloads selected by + // this field. If this field is empty, this rule matches all sources. + // +optional + From []NetworkPolicyPeer `json:"from"` + // Rule is matched if traffic is intended for workloads selected by + // this field. If this field is empty or missing, this rule matches all + // destinations. + // +optional + To []NetworkPolicyPeer `json:"to"` +} + +// NetworkPolicyPeer describes the grouping selector of workloads. +type NetworkPolicyPeer struct { + // IPBlock describes the IPAddresses/IPBlocks that is matched in to/from. + // IPBlock cannot be set as part of the AppliedTo field. + // Cannot be set with any other selector. + // +optional + IPBlock *IPBlock `json:"ipBlock,omitempty"` + // Select Pods from NetworkPolicy's Namespace as workloads in + // AppliedTo/To/From fields. If set with NamespaceSelector, Pods are + // matched from Namespaces matched by the NamespaceSelector. + // Cannot be set with any other selector except NamespaceSelector. + // +optional + PodSelector *metav1.LabelSelector `json:"podSelector,omitempty"` + // Select all Pods from Namespaces matched by this selector, as + // workloads in To/From fields. If set with PodSelector, + // Pods are matched from Namespaces matched by the NamespaceSelector. + // Cannot be set with any other selector except PodSelector or + // ExternalEntitySelector. + // +optional + NamespaceSelector *metav1.LabelSelector `json:"namespaceSelector,omitempty"` + // Select ExternalEntities from NetworkPolicy's Namespace as workloads + // in AppliedTo/To/From fields. If set with NamespaceSelector, + // ExternalEntities are matched from Namespaces matched by the + // NamespaceSelector. + // Cannot be set with any other selector except NamespaceSelector. + ExternalEntitySelector *metav1.LabelSelector `json:"externalEntitySelector,omitempty"` +} + +// IPBlock describes a particular CIDR (Ex. "192.168.1.1/24") that is allowed +// or denied to/from the workloads matched by a Spec.AppliedTo. +type IPBlock struct { + // CIDR is a string representing the IP Block + // Valid examples are "192.168.1.1/24". + CIDR string `json:"cidr"` +} + +// NetworkPolicyPort describes the port and protocol to match in a rule. +type NetworkPolicyPort struct { + // The protocol (TCP, UDP, or SCTP) which traffic must match. + // If not specified, this field defaults to TCP. + // +optional + Protocol *v1.Protocol `json:"protocol"` + // The port on the given protocol. This can either be a numerical + // or named port on a Pod. If this field is not provided, this + // matches all port names and numbers. + // TODO: extend it to include Port Range. + // +optional + Port *intstr.IntOrString `json:"port"` +} + +// RuleAction describes the action to be applied on traffic matching a rule. +type RuleAction string + +const ( + // RuleActionAllow describes that rule matching traffic must be allowed. + RuleActionAllow RuleAction = "ALLOW" + // RuleActionDrop describes that rule matching traffic must be dropped. + RuleActionDrop RuleAction = "DROP" +) + +// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object + +type NetworkPolicyList struct { + metav1.TypeMeta `json:",inline"` + // +optional + metav1.ListMeta `json:"metadata,omitempty"` + + Items []NetworkPolicy `json:"items"` +} diff --git a/pkg/apis/security/v1alpha1/zz_generated.deepcopy.go b/pkg/apis/security/v1alpha1/zz_generated.deepcopy.go new file mode 100644 index 00000000000..37bc21bc08a --- /dev/null +++ b/pkg/apis/security/v1alpha1/zz_generated.deepcopy.go @@ -0,0 +1,243 @@ +// +build !ignore_autogenerated + +// Copyright 2020 Antrea 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 deepcopy-gen. DO NOT EDIT. + +package v1alpha1 + +import ( + corev1 "k8s.io/api/core/v1" + v1 "k8s.io/apimachinery/pkg/apis/meta/v1" + runtime "k8s.io/apimachinery/pkg/runtime" + intstr "k8s.io/apimachinery/pkg/util/intstr" +) + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *IPBlock) DeepCopyInto(out *IPBlock) { + *out = *in + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new IPBlock. +func (in *IPBlock) DeepCopy() *IPBlock { + if in == nil { + return nil + } + out := new(IPBlock) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *NetworkPolicy) DeepCopyInto(out *NetworkPolicy) { + *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 NetworkPolicy. +func (in *NetworkPolicy) DeepCopy() *NetworkPolicy { + if in == nil { + return nil + } + out := new(NetworkPolicy) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *NetworkPolicy) 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 *NetworkPolicyList) DeepCopyInto(out *NetworkPolicyList) { + *out = *in + out.TypeMeta = in.TypeMeta + in.ListMeta.DeepCopyInto(&out.ListMeta) + if in.Items != nil { + in, out := &in.Items, &out.Items + *out = make([]NetworkPolicy, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new NetworkPolicyList. +func (in *NetworkPolicyList) DeepCopy() *NetworkPolicyList { + if in == nil { + return nil + } + out := new(NetworkPolicyList) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *NetworkPolicyList) 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 *NetworkPolicyPeer) DeepCopyInto(out *NetworkPolicyPeer) { + *out = *in + if in.IPBlock != nil { + in, out := &in.IPBlock, &out.IPBlock + *out = new(IPBlock) + **out = **in + } + if in.PodSelector != nil { + in, out := &in.PodSelector, &out.PodSelector + *out = new(v1.LabelSelector) + (*in).DeepCopyInto(*out) + } + if in.NamespaceSelector != nil { + in, out := &in.NamespaceSelector, &out.NamespaceSelector + *out = new(v1.LabelSelector) + (*in).DeepCopyInto(*out) + } + if in.ExternalEntitySelector != nil { + in, out := &in.ExternalEntitySelector, &out.ExternalEntitySelector + *out = new(v1.LabelSelector) + (*in).DeepCopyInto(*out) + } + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new NetworkPolicyPeer. +func (in *NetworkPolicyPeer) DeepCopy() *NetworkPolicyPeer { + if in == nil { + return nil + } + out := new(NetworkPolicyPeer) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *NetworkPolicyPort) DeepCopyInto(out *NetworkPolicyPort) { + *out = *in + if in.Protocol != nil { + in, out := &in.Protocol, &out.Protocol + *out = new(corev1.Protocol) + **out = **in + } + if in.Port != nil { + in, out := &in.Port, &out.Port + *out = new(intstr.IntOrString) + **out = **in + } + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new NetworkPolicyPort. +func (in *NetworkPolicyPort) DeepCopy() *NetworkPolicyPort { + if in == nil { + return nil + } + out := new(NetworkPolicyPort) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *NetworkPolicySpec) DeepCopyInto(out *NetworkPolicySpec) { + *out = *in + if in.AppliedTo != nil { + in, out := &in.AppliedTo, &out.AppliedTo + *out = make([]NetworkPolicyPeer, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } + if in.Ingress != nil { + in, out := &in.Ingress, &out.Ingress + *out = make([]Rule, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } + if in.Egress != nil { + in, out := &in.Egress, &out.Egress + *out = make([]Rule, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new NetworkPolicySpec. +func (in *NetworkPolicySpec) DeepCopy() *NetworkPolicySpec { + if in == nil { + return nil + } + out := new(NetworkPolicySpec) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *Rule) DeepCopyInto(out *Rule) { + *out = *in + if in.Action != nil { + in, out := &in.Action, &out.Action + *out = new(RuleAction) + **out = **in + } + if in.Ports != nil { + in, out := &in.Ports, &out.Ports + *out = make([]NetworkPolicyPort, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } + if in.From != nil { + in, out := &in.From, &out.From + *out = make([]NetworkPolicyPeer, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } + if in.To != nil { + in, out := &in.To, &out.To + *out = make([]NetworkPolicyPeer, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Rule. +func (in *Rule) DeepCopy() *Rule { + if in == nil { + return nil + } + out := new(Rule) + in.DeepCopyInto(out) + return out +} diff --git a/pkg/client/clientset/versioned/clientset.go b/pkg/client/clientset/versioned/clientset.go index fc6a1def7c7..9e53426d0f1 100644 --- a/pkg/client/clientset/versioned/clientset.go +++ b/pkg/client/clientset/versioned/clientset.go @@ -20,7 +20,9 @@ import ( "fmt" clusterinformationv1beta1 "github.com/vmware-tanzu/antrea/pkg/client/clientset/versioned/typed/clusterinformation/v1beta1" + corev1alpha1 "github.com/vmware-tanzu/antrea/pkg/client/clientset/versioned/typed/core/v1alpha1" networkingv1beta1 "github.com/vmware-tanzu/antrea/pkg/client/clientset/versioned/typed/networking/v1beta1" + securityv1alpha1 "github.com/vmware-tanzu/antrea/pkg/client/clientset/versioned/typed/security/v1alpha1" systemv1beta1 "github.com/vmware-tanzu/antrea/pkg/client/clientset/versioned/typed/system/v1beta1" discovery "k8s.io/client-go/discovery" rest "k8s.io/client-go/rest" @@ -30,7 +32,9 @@ import ( type Interface interface { Discovery() discovery.DiscoveryInterface ClusterinformationV1beta1() clusterinformationv1beta1.ClusterinformationV1beta1Interface + CoreV1alpha1() corev1alpha1.CoreV1alpha1Interface NetworkingV1beta1() networkingv1beta1.NetworkingV1beta1Interface + SecurityV1alpha1() securityv1alpha1.SecurityV1alpha1Interface SystemV1beta1() systemv1beta1.SystemV1beta1Interface } @@ -39,7 +43,9 @@ type Interface interface { type Clientset struct { *discovery.DiscoveryClient clusterinformationV1beta1 *clusterinformationv1beta1.ClusterinformationV1beta1Client + coreV1alpha1 *corev1alpha1.CoreV1alpha1Client networkingV1beta1 *networkingv1beta1.NetworkingV1beta1Client + securityV1alpha1 *securityv1alpha1.SecurityV1alpha1Client systemV1beta1 *systemv1beta1.SystemV1beta1Client } @@ -48,11 +54,21 @@ func (c *Clientset) ClusterinformationV1beta1() clusterinformationv1beta1.Cluste return c.clusterinformationV1beta1 } +// CoreV1alpha1 retrieves the CoreV1alpha1Client +func (c *Clientset) CoreV1alpha1() corev1alpha1.CoreV1alpha1Interface { + return c.coreV1alpha1 +} + // NetworkingV1beta1 retrieves the NetworkingV1beta1Client func (c *Clientset) NetworkingV1beta1() networkingv1beta1.NetworkingV1beta1Interface { return c.networkingV1beta1 } +// SecurityV1alpha1 retrieves the SecurityV1alpha1Client +func (c *Clientset) SecurityV1alpha1() securityv1alpha1.SecurityV1alpha1Interface { + return c.securityV1alpha1 +} + // SystemV1beta1 retrieves the SystemV1beta1Client func (c *Clientset) SystemV1beta1() systemv1beta1.SystemV1beta1Interface { return c.systemV1beta1 @@ -83,10 +99,18 @@ func NewForConfig(c *rest.Config) (*Clientset, error) { if err != nil { return nil, err } + cs.coreV1alpha1, err = corev1alpha1.NewForConfig(&configShallowCopy) + if err != nil { + return nil, err + } cs.networkingV1beta1, err = networkingv1beta1.NewForConfig(&configShallowCopy) if err != nil { return nil, err } + cs.securityV1alpha1, err = securityv1alpha1.NewForConfig(&configShallowCopy) + if err != nil { + return nil, err + } cs.systemV1beta1, err = systemv1beta1.NewForConfig(&configShallowCopy) if err != nil { return nil, err @@ -104,7 +128,9 @@ func NewForConfig(c *rest.Config) (*Clientset, error) { func NewForConfigOrDie(c *rest.Config) *Clientset { var cs Clientset cs.clusterinformationV1beta1 = clusterinformationv1beta1.NewForConfigOrDie(c) + cs.coreV1alpha1 = corev1alpha1.NewForConfigOrDie(c) cs.networkingV1beta1 = networkingv1beta1.NewForConfigOrDie(c) + cs.securityV1alpha1 = securityv1alpha1.NewForConfigOrDie(c) cs.systemV1beta1 = systemv1beta1.NewForConfigOrDie(c) cs.DiscoveryClient = discovery.NewDiscoveryClientForConfigOrDie(c) @@ -115,7 +141,9 @@ func NewForConfigOrDie(c *rest.Config) *Clientset { func New(c rest.Interface) *Clientset { var cs Clientset cs.clusterinformationV1beta1 = clusterinformationv1beta1.New(c) + cs.coreV1alpha1 = corev1alpha1.New(c) cs.networkingV1beta1 = networkingv1beta1.New(c) + cs.securityV1alpha1 = securityv1alpha1.New(c) cs.systemV1beta1 = systemv1beta1.New(c) cs.DiscoveryClient = discovery.NewDiscoveryClient(c) diff --git a/pkg/client/clientset/versioned/fake/clientset_generated.go b/pkg/client/clientset/versioned/fake/clientset_generated.go index fc1d82d3f8c..7afff400fa0 100644 --- a/pkg/client/clientset/versioned/fake/clientset_generated.go +++ b/pkg/client/clientset/versioned/fake/clientset_generated.go @@ -20,8 +20,12 @@ import ( clientset "github.com/vmware-tanzu/antrea/pkg/client/clientset/versioned" clusterinformationv1beta1 "github.com/vmware-tanzu/antrea/pkg/client/clientset/versioned/typed/clusterinformation/v1beta1" fakeclusterinformationv1beta1 "github.com/vmware-tanzu/antrea/pkg/client/clientset/versioned/typed/clusterinformation/v1beta1/fake" + corev1alpha1 "github.com/vmware-tanzu/antrea/pkg/client/clientset/versioned/typed/core/v1alpha1" + fakecorev1alpha1 "github.com/vmware-tanzu/antrea/pkg/client/clientset/versioned/typed/core/v1alpha1/fake" networkingv1beta1 "github.com/vmware-tanzu/antrea/pkg/client/clientset/versioned/typed/networking/v1beta1" fakenetworkingv1beta1 "github.com/vmware-tanzu/antrea/pkg/client/clientset/versioned/typed/networking/v1beta1/fake" + securityv1alpha1 "github.com/vmware-tanzu/antrea/pkg/client/clientset/versioned/typed/security/v1alpha1" + fakesecurityv1alpha1 "github.com/vmware-tanzu/antrea/pkg/client/clientset/versioned/typed/security/v1alpha1/fake" systemv1beta1 "github.com/vmware-tanzu/antrea/pkg/client/clientset/versioned/typed/system/v1beta1" fakesystemv1beta1 "github.com/vmware-tanzu/antrea/pkg/client/clientset/versioned/typed/system/v1beta1/fake" "k8s.io/apimachinery/pkg/runtime" @@ -83,11 +87,21 @@ func (c *Clientset) ClusterinformationV1beta1() clusterinformationv1beta1.Cluste return &fakeclusterinformationv1beta1.FakeClusterinformationV1beta1{Fake: &c.Fake} } +// CoreV1alpha1 retrieves the CoreV1alpha1Client +func (c *Clientset) CoreV1alpha1() corev1alpha1.CoreV1alpha1Interface { + return &fakecorev1alpha1.FakeCoreV1alpha1{Fake: &c.Fake} +} + // NetworkingV1beta1 retrieves the NetworkingV1beta1Client func (c *Clientset) NetworkingV1beta1() networkingv1beta1.NetworkingV1beta1Interface { return &fakenetworkingv1beta1.FakeNetworkingV1beta1{Fake: &c.Fake} } +// SecurityV1alpha1 retrieves the SecurityV1alpha1Client +func (c *Clientset) SecurityV1alpha1() securityv1alpha1.SecurityV1alpha1Interface { + return &fakesecurityv1alpha1.FakeSecurityV1alpha1{Fake: &c.Fake} +} + // SystemV1beta1 retrieves the SystemV1beta1Client func (c *Clientset) SystemV1beta1() systemv1beta1.SystemV1beta1Interface { return &fakesystemv1beta1.FakeSystemV1beta1{Fake: &c.Fake} diff --git a/pkg/client/clientset/versioned/fake/register.go b/pkg/client/clientset/versioned/fake/register.go index 149de158c4b..e2668838524 100644 --- a/pkg/client/clientset/versioned/fake/register.go +++ b/pkg/client/clientset/versioned/fake/register.go @@ -18,7 +18,9 @@ package fake import ( clusterinformationv1beta1 "github.com/vmware-tanzu/antrea/pkg/apis/clusterinformation/v1beta1" + corev1alpha1 "github.com/vmware-tanzu/antrea/pkg/apis/core/v1alpha1" networkingv1beta1 "github.com/vmware-tanzu/antrea/pkg/apis/networking/v1beta1" + securityv1alpha1 "github.com/vmware-tanzu/antrea/pkg/apis/security/v1alpha1" systemv1beta1 "github.com/vmware-tanzu/antrea/pkg/apis/system/v1beta1" v1 "k8s.io/apimachinery/pkg/apis/meta/v1" runtime "k8s.io/apimachinery/pkg/runtime" @@ -32,7 +34,9 @@ var codecs = serializer.NewCodecFactory(scheme) var parameterCodec = runtime.NewParameterCodec(scheme) var localSchemeBuilder = runtime.SchemeBuilder{ clusterinformationv1beta1.AddToScheme, + corev1alpha1.AddToScheme, networkingv1beta1.AddToScheme, + securityv1alpha1.AddToScheme, systemv1beta1.AddToScheme, } diff --git a/pkg/client/clientset/versioned/scheme/register.go b/pkg/client/clientset/versioned/scheme/register.go index 5c46c0256b7..f7ba50bc77a 100644 --- a/pkg/client/clientset/versioned/scheme/register.go +++ b/pkg/client/clientset/versioned/scheme/register.go @@ -18,7 +18,9 @@ package scheme import ( clusterinformationv1beta1 "github.com/vmware-tanzu/antrea/pkg/apis/clusterinformation/v1beta1" + corev1alpha1 "github.com/vmware-tanzu/antrea/pkg/apis/core/v1alpha1" networkingv1beta1 "github.com/vmware-tanzu/antrea/pkg/apis/networking/v1beta1" + securityv1alpha1 "github.com/vmware-tanzu/antrea/pkg/apis/security/v1alpha1" systemv1beta1 "github.com/vmware-tanzu/antrea/pkg/apis/system/v1beta1" v1 "k8s.io/apimachinery/pkg/apis/meta/v1" runtime "k8s.io/apimachinery/pkg/runtime" @@ -32,7 +34,9 @@ var Codecs = serializer.NewCodecFactory(Scheme) var ParameterCodec = runtime.NewParameterCodec(Scheme) var localSchemeBuilder = runtime.SchemeBuilder{ clusterinformationv1beta1.AddToScheme, + corev1alpha1.AddToScheme, networkingv1beta1.AddToScheme, + securityv1alpha1.AddToScheme, systemv1beta1.AddToScheme, } diff --git a/pkg/client/clientset/versioned/typed/core/v1alpha1/core_client.go b/pkg/client/clientset/versioned/typed/core/v1alpha1/core_client.go new file mode 100644 index 00000000000..806ae116e79 --- /dev/null +++ b/pkg/client/clientset/versioned/typed/core/v1alpha1/core_client.go @@ -0,0 +1,87 @@ +// Copyright 2020 Antrea 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 v1alpha1 + +import ( + v1alpha1 "github.com/vmware-tanzu/antrea/pkg/apis/core/v1alpha1" + "github.com/vmware-tanzu/antrea/pkg/client/clientset/versioned/scheme" + rest "k8s.io/client-go/rest" +) + +type CoreV1alpha1Interface interface { + RESTClient() rest.Interface + ExternalEntitiesGetter +} + +// CoreV1alpha1Client is used to interact with features provided by the core.antrea.tanzu.vmware.com group. +type CoreV1alpha1Client struct { + restClient rest.Interface +} + +func (c *CoreV1alpha1Client) ExternalEntities(namespace string) ExternalEntityInterface { + return newExternalEntities(c, namespace) +} + +// NewForConfig creates a new CoreV1alpha1Client for the given config. +func NewForConfig(c *rest.Config) (*CoreV1alpha1Client, error) { + config := *c + if err := setConfigDefaults(&config); err != nil { + return nil, err + } + client, err := rest.RESTClientFor(&config) + if err != nil { + return nil, err + } + return &CoreV1alpha1Client{client}, nil +} + +// NewForConfigOrDie creates a new CoreV1alpha1Client for the given config and +// panics if there is an error in the config. +func NewForConfigOrDie(c *rest.Config) *CoreV1alpha1Client { + client, err := NewForConfig(c) + if err != nil { + panic(err) + } + return client +} + +// New creates a new CoreV1alpha1Client for the given RESTClient. +func New(c rest.Interface) *CoreV1alpha1Client { + return &CoreV1alpha1Client{c} +} + +func setConfigDefaults(config *rest.Config) error { + gv := v1alpha1.SchemeGroupVersion + config.GroupVersion = &gv + config.APIPath = "/apis" + config.NegotiatedSerializer = scheme.Codecs.WithoutConversion() + + if config.UserAgent == "" { + config.UserAgent = rest.DefaultKubernetesUserAgent() + } + + return nil +} + +// RESTClient returns a RESTClient that is used to communicate +// with API server by this client implementation. +func (c *CoreV1alpha1Client) RESTClient() rest.Interface { + if c == nil { + return nil + } + return c.restClient +} diff --git a/pkg/client/clientset/versioned/typed/core/v1alpha1/doc.go b/pkg/client/clientset/versioned/typed/core/v1alpha1/doc.go new file mode 100644 index 00000000000..16e4506b415 --- /dev/null +++ b/pkg/client/clientset/versioned/typed/core/v1alpha1/doc.go @@ -0,0 +1,18 @@ +// Copyright 2020 Antrea 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. + +// This package has the automatically generated typed clients. +package v1alpha1 diff --git a/pkg/client/clientset/versioned/typed/core/v1alpha1/externalentity.go b/pkg/client/clientset/versioned/typed/core/v1alpha1/externalentity.go new file mode 100644 index 00000000000..af382e4a979 --- /dev/null +++ b/pkg/client/clientset/versioned/typed/core/v1alpha1/externalentity.go @@ -0,0 +1,172 @@ +// Copyright 2020 Antrea 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 v1alpha1 + +import ( + "time" + + v1alpha1 "github.com/vmware-tanzu/antrea/pkg/apis/core/v1alpha1" + scheme "github.com/vmware-tanzu/antrea/pkg/client/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" +) + +// ExternalEntitiesGetter has a method to return a ExternalEntityInterface. +// A group's client should implement this interface. +type ExternalEntitiesGetter interface { + ExternalEntities(namespace string) ExternalEntityInterface +} + +// ExternalEntityInterface has methods to work with ExternalEntity resources. +type ExternalEntityInterface interface { + Create(*v1alpha1.ExternalEntity) (*v1alpha1.ExternalEntity, error) + Update(*v1alpha1.ExternalEntity) (*v1alpha1.ExternalEntity, error) + Delete(name string, options *v1.DeleteOptions) error + DeleteCollection(options *v1.DeleteOptions, listOptions v1.ListOptions) error + Get(name string, options v1.GetOptions) (*v1alpha1.ExternalEntity, error) + List(opts v1.ListOptions) (*v1alpha1.ExternalEntityList, error) + Watch(opts v1.ListOptions) (watch.Interface, error) + Patch(name string, pt types.PatchType, data []byte, subresources ...string) (result *v1alpha1.ExternalEntity, err error) + ExternalEntityExpansion +} + +// externalEntities implements ExternalEntityInterface +type externalEntities struct { + client rest.Interface + ns string +} + +// newExternalEntities returns a ExternalEntities +func newExternalEntities(c *CoreV1alpha1Client, namespace string) *externalEntities { + return &externalEntities{ + client: c.RESTClient(), + ns: namespace, + } +} + +// Get takes name of the externalEntity, and returns the corresponding externalEntity object, and an error if there is any. +func (c *externalEntities) Get(name string, options v1.GetOptions) (result *v1alpha1.ExternalEntity, err error) { + result = &v1alpha1.ExternalEntity{} + err = c.client.Get(). + Namespace(c.ns). + Resource("externalentities"). + Name(name). + VersionedParams(&options, scheme.ParameterCodec). + Do(). + Into(result) + return +} + +// List takes label and field selectors, and returns the list of ExternalEntities that match those selectors. +func (c *externalEntities) List(opts v1.ListOptions) (result *v1alpha1.ExternalEntityList, err error) { + var timeout time.Duration + if opts.TimeoutSeconds != nil { + timeout = time.Duration(*opts.TimeoutSeconds) * time.Second + } + result = &v1alpha1.ExternalEntityList{} + err = c.client.Get(). + Namespace(c.ns). + Resource("externalentities"). + VersionedParams(&opts, scheme.ParameterCodec). + Timeout(timeout). + Do(). + Into(result) + return +} + +// Watch returns a watch.Interface that watches the requested externalEntities. +func (c *externalEntities) Watch(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("externalentities"). + VersionedParams(&opts, scheme.ParameterCodec). + Timeout(timeout). + Watch() +} + +// Create takes the representation of a externalEntity and creates it. Returns the server's representation of the externalEntity, and an error, if there is any. +func (c *externalEntities) Create(externalEntity *v1alpha1.ExternalEntity) (result *v1alpha1.ExternalEntity, err error) { + result = &v1alpha1.ExternalEntity{} + err = c.client.Post(). + Namespace(c.ns). + Resource("externalentities"). + Body(externalEntity). + Do(). + Into(result) + return +} + +// Update takes the representation of a externalEntity and updates it. Returns the server's representation of the externalEntity, and an error, if there is any. +func (c *externalEntities) Update(externalEntity *v1alpha1.ExternalEntity) (result *v1alpha1.ExternalEntity, err error) { + result = &v1alpha1.ExternalEntity{} + err = c.client.Put(). + Namespace(c.ns). + Resource("externalentities"). + Name(externalEntity.Name). + Body(externalEntity). + Do(). + Into(result) + return +} + +// Delete takes name of the externalEntity and deletes it. Returns an error if one occurs. +func (c *externalEntities) Delete(name string, options *v1.DeleteOptions) error { + return c.client.Delete(). + Namespace(c.ns). + Resource("externalentities"). + Name(name). + Body(options). + Do(). + Error() +} + +// DeleteCollection deletes a collection of objects. +func (c *externalEntities) DeleteCollection(options *v1.DeleteOptions, listOptions v1.ListOptions) error { + var timeout time.Duration + if listOptions.TimeoutSeconds != nil { + timeout = time.Duration(*listOptions.TimeoutSeconds) * time.Second + } + return c.client.Delete(). + Namespace(c.ns). + Resource("externalentities"). + VersionedParams(&listOptions, scheme.ParameterCodec). + Timeout(timeout). + Body(options). + Do(). + Error() +} + +// Patch applies the patch and returns the patched externalEntity. +func (c *externalEntities) Patch(name string, pt types.PatchType, data []byte, subresources ...string) (result *v1alpha1.ExternalEntity, err error) { + result = &v1alpha1.ExternalEntity{} + err = c.client.Patch(pt). + Namespace(c.ns). + Resource("externalentities"). + SubResource(subresources...). + Name(name). + Body(data). + Do(). + Into(result) + return +} diff --git a/pkg/client/clientset/versioned/typed/core/v1alpha1/fake/doc.go b/pkg/client/clientset/versioned/typed/core/v1alpha1/fake/doc.go new file mode 100644 index 00000000000..ed1b262831b --- /dev/null +++ b/pkg/client/clientset/versioned/typed/core/v1alpha1/fake/doc.go @@ -0,0 +1,18 @@ +// Copyright 2020 Antrea 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 has the automatically generated clients. +package fake diff --git a/pkg/client/clientset/versioned/typed/core/v1alpha1/fake/fake_core_client.go b/pkg/client/clientset/versioned/typed/core/v1alpha1/fake/fake_core_client.go new file mode 100644 index 00000000000..8d34a399965 --- /dev/null +++ b/pkg/client/clientset/versioned/typed/core/v1alpha1/fake/fake_core_client.go @@ -0,0 +1,38 @@ +// Copyright 2020 Antrea 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 ( + v1alpha1 "github.com/vmware-tanzu/antrea/pkg/client/clientset/versioned/typed/core/v1alpha1" + rest "k8s.io/client-go/rest" + testing "k8s.io/client-go/testing" +) + +type FakeCoreV1alpha1 struct { + *testing.Fake +} + +func (c *FakeCoreV1alpha1) ExternalEntities(namespace string) v1alpha1.ExternalEntityInterface { + return &FakeExternalEntities{c, namespace} +} + +// RESTClient returns a RESTClient that is used to communicate +// with API server by this client implementation. +func (c *FakeCoreV1alpha1) RESTClient() rest.Interface { + var ret *rest.RESTClient + return ret +} diff --git a/pkg/client/clientset/versioned/typed/core/v1alpha1/fake/fake_externalentity.go b/pkg/client/clientset/versioned/typed/core/v1alpha1/fake/fake_externalentity.go new file mode 100644 index 00000000000..35e54e64e9d --- /dev/null +++ b/pkg/client/clientset/versioned/typed/core/v1alpha1/fake/fake_externalentity.go @@ -0,0 +1,126 @@ +// Copyright 2020 Antrea 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 ( + v1alpha1 "github.com/vmware-tanzu/antrea/pkg/apis/core/v1alpha1" + v1 "k8s.io/apimachinery/pkg/apis/meta/v1" + labels "k8s.io/apimachinery/pkg/labels" + schema "k8s.io/apimachinery/pkg/runtime/schema" + types "k8s.io/apimachinery/pkg/types" + watch "k8s.io/apimachinery/pkg/watch" + testing "k8s.io/client-go/testing" +) + +// FakeExternalEntities implements ExternalEntityInterface +type FakeExternalEntities struct { + Fake *FakeCoreV1alpha1 + ns string +} + +var externalentitiesResource = schema.GroupVersionResource{Group: "core.antrea.tanzu.vmware.com", Version: "v1alpha1", Resource: "externalentities"} + +var externalentitiesKind = schema.GroupVersionKind{Group: "core.antrea.tanzu.vmware.com", Version: "v1alpha1", Kind: "ExternalEntity"} + +// Get takes name of the externalEntity, and returns the corresponding externalEntity object, and an error if there is any. +func (c *FakeExternalEntities) Get(name string, options v1.GetOptions) (result *v1alpha1.ExternalEntity, err error) { + obj, err := c.Fake. + Invokes(testing.NewGetAction(externalentitiesResource, c.ns, name), &v1alpha1.ExternalEntity{}) + + if obj == nil { + return nil, err + } + return obj.(*v1alpha1.ExternalEntity), err +} + +// List takes label and field selectors, and returns the list of ExternalEntities that match those selectors. +func (c *FakeExternalEntities) List(opts v1.ListOptions) (result *v1alpha1.ExternalEntityList, err error) { + obj, err := c.Fake. + Invokes(testing.NewListAction(externalentitiesResource, externalentitiesKind, c.ns, opts), &v1alpha1.ExternalEntityList{}) + + if obj == nil { + return nil, err + } + + label, _, _ := testing.ExtractFromListOptions(opts) + if label == nil { + label = labels.Everything() + } + list := &v1alpha1.ExternalEntityList{ListMeta: obj.(*v1alpha1.ExternalEntityList).ListMeta} + for _, item := range obj.(*v1alpha1.ExternalEntityList).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 externalEntities. +func (c *FakeExternalEntities) Watch(opts v1.ListOptions) (watch.Interface, error) { + return c.Fake. + InvokesWatch(testing.NewWatchAction(externalentitiesResource, c.ns, opts)) + +} + +// Create takes the representation of a externalEntity and creates it. Returns the server's representation of the externalEntity, and an error, if there is any. +func (c *FakeExternalEntities) Create(externalEntity *v1alpha1.ExternalEntity) (result *v1alpha1.ExternalEntity, err error) { + obj, err := c.Fake. + Invokes(testing.NewCreateAction(externalentitiesResource, c.ns, externalEntity), &v1alpha1.ExternalEntity{}) + + if obj == nil { + return nil, err + } + return obj.(*v1alpha1.ExternalEntity), err +} + +// Update takes the representation of a externalEntity and updates it. Returns the server's representation of the externalEntity, and an error, if there is any. +func (c *FakeExternalEntities) Update(externalEntity *v1alpha1.ExternalEntity) (result *v1alpha1.ExternalEntity, err error) { + obj, err := c.Fake. + Invokes(testing.NewUpdateAction(externalentitiesResource, c.ns, externalEntity), &v1alpha1.ExternalEntity{}) + + if obj == nil { + return nil, err + } + return obj.(*v1alpha1.ExternalEntity), err +} + +// Delete takes name of the externalEntity and deletes it. Returns an error if one occurs. +func (c *FakeExternalEntities) Delete(name string, options *v1.DeleteOptions) error { + _, err := c.Fake. + Invokes(testing.NewDeleteAction(externalentitiesResource, c.ns, name), &v1alpha1.ExternalEntity{}) + + return err +} + +// DeleteCollection deletes a collection of objects. +func (c *FakeExternalEntities) DeleteCollection(options *v1.DeleteOptions, listOptions v1.ListOptions) error { + action := testing.NewDeleteCollectionAction(externalentitiesResource, c.ns, listOptions) + + _, err := c.Fake.Invokes(action, &v1alpha1.ExternalEntityList{}) + return err +} + +// Patch applies the patch and returns the patched externalEntity. +func (c *FakeExternalEntities) Patch(name string, pt types.PatchType, data []byte, subresources ...string) (result *v1alpha1.ExternalEntity, err error) { + obj, err := c.Fake. + Invokes(testing.NewPatchSubresourceAction(externalentitiesResource, c.ns, name, pt, data, subresources...), &v1alpha1.ExternalEntity{}) + + if obj == nil { + return nil, err + } + return obj.(*v1alpha1.ExternalEntity), err +} diff --git a/pkg/client/clientset/versioned/typed/core/v1alpha1/generated_expansion.go b/pkg/client/clientset/versioned/typed/core/v1alpha1/generated_expansion.go new file mode 100644 index 00000000000..4c7559e8c59 --- /dev/null +++ b/pkg/client/clientset/versioned/typed/core/v1alpha1/generated_expansion.go @@ -0,0 +1,19 @@ +// Copyright 2020 Antrea 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 v1alpha1 + +type ExternalEntityExpansion interface{} diff --git a/pkg/client/clientset/versioned/typed/security/v1alpha1/doc.go b/pkg/client/clientset/versioned/typed/security/v1alpha1/doc.go new file mode 100644 index 00000000000..16e4506b415 --- /dev/null +++ b/pkg/client/clientset/versioned/typed/security/v1alpha1/doc.go @@ -0,0 +1,18 @@ +// Copyright 2020 Antrea 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. + +// This package has the automatically generated typed clients. +package v1alpha1 diff --git a/pkg/client/clientset/versioned/typed/security/v1alpha1/fake/doc.go b/pkg/client/clientset/versioned/typed/security/v1alpha1/fake/doc.go new file mode 100644 index 00000000000..ed1b262831b --- /dev/null +++ b/pkg/client/clientset/versioned/typed/security/v1alpha1/fake/doc.go @@ -0,0 +1,18 @@ +// Copyright 2020 Antrea 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 has the automatically generated clients. +package fake diff --git a/pkg/client/clientset/versioned/typed/security/v1alpha1/fake/fake_networkpolicy.go b/pkg/client/clientset/versioned/typed/security/v1alpha1/fake/fake_networkpolicy.go new file mode 100644 index 00000000000..d9297d6d80f --- /dev/null +++ b/pkg/client/clientset/versioned/typed/security/v1alpha1/fake/fake_networkpolicy.go @@ -0,0 +1,126 @@ +// Copyright 2020 Antrea 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 ( + v1alpha1 "github.com/vmware-tanzu/antrea/pkg/apis/security/v1alpha1" + v1 "k8s.io/apimachinery/pkg/apis/meta/v1" + labels "k8s.io/apimachinery/pkg/labels" + schema "k8s.io/apimachinery/pkg/runtime/schema" + types "k8s.io/apimachinery/pkg/types" + watch "k8s.io/apimachinery/pkg/watch" + testing "k8s.io/client-go/testing" +) + +// FakeNetworkPolicies implements NetworkPolicyInterface +type FakeNetworkPolicies struct { + Fake *FakeSecurityV1alpha1 + ns string +} + +var networkpoliciesResource = schema.GroupVersionResource{Group: "security.antrea.tanzu.vmware.com", Version: "v1alpha1", Resource: "networkpolicies"} + +var networkpoliciesKind = schema.GroupVersionKind{Group: "security.antrea.tanzu.vmware.com", Version: "v1alpha1", Kind: "NetworkPolicy"} + +// Get takes name of the networkPolicy, and returns the corresponding networkPolicy object, and an error if there is any. +func (c *FakeNetworkPolicies) Get(name string, options v1.GetOptions) (result *v1alpha1.NetworkPolicy, err error) { + obj, err := c.Fake. + Invokes(testing.NewGetAction(networkpoliciesResource, c.ns, name), &v1alpha1.NetworkPolicy{}) + + if obj == nil { + return nil, err + } + return obj.(*v1alpha1.NetworkPolicy), err +} + +// List takes label and field selectors, and returns the list of NetworkPolicies that match those selectors. +func (c *FakeNetworkPolicies) List(opts v1.ListOptions) (result *v1alpha1.NetworkPolicyList, err error) { + obj, err := c.Fake. + Invokes(testing.NewListAction(networkpoliciesResource, networkpoliciesKind, c.ns, opts), &v1alpha1.NetworkPolicyList{}) + + if obj == nil { + return nil, err + } + + label, _, _ := testing.ExtractFromListOptions(opts) + if label == nil { + label = labels.Everything() + } + list := &v1alpha1.NetworkPolicyList{ListMeta: obj.(*v1alpha1.NetworkPolicyList).ListMeta} + for _, item := range obj.(*v1alpha1.NetworkPolicyList).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 networkPolicies. +func (c *FakeNetworkPolicies) Watch(opts v1.ListOptions) (watch.Interface, error) { + return c.Fake. + InvokesWatch(testing.NewWatchAction(networkpoliciesResource, c.ns, opts)) + +} + +// Create takes the representation of a networkPolicy and creates it. Returns the server's representation of the networkPolicy, and an error, if there is any. +func (c *FakeNetworkPolicies) Create(networkPolicy *v1alpha1.NetworkPolicy) (result *v1alpha1.NetworkPolicy, err error) { + obj, err := c.Fake. + Invokes(testing.NewCreateAction(networkpoliciesResource, c.ns, networkPolicy), &v1alpha1.NetworkPolicy{}) + + if obj == nil { + return nil, err + } + return obj.(*v1alpha1.NetworkPolicy), err +} + +// Update takes the representation of a networkPolicy and updates it. Returns the server's representation of the networkPolicy, and an error, if there is any. +func (c *FakeNetworkPolicies) Update(networkPolicy *v1alpha1.NetworkPolicy) (result *v1alpha1.NetworkPolicy, err error) { + obj, err := c.Fake. + Invokes(testing.NewUpdateAction(networkpoliciesResource, c.ns, networkPolicy), &v1alpha1.NetworkPolicy{}) + + if obj == nil { + return nil, err + } + return obj.(*v1alpha1.NetworkPolicy), err +} + +// Delete takes name of the networkPolicy and deletes it. Returns an error if one occurs. +func (c *FakeNetworkPolicies) Delete(name string, options *v1.DeleteOptions) error { + _, err := c.Fake. + Invokes(testing.NewDeleteAction(networkpoliciesResource, c.ns, name), &v1alpha1.NetworkPolicy{}) + + return err +} + +// DeleteCollection deletes a collection of objects. +func (c *FakeNetworkPolicies) DeleteCollection(options *v1.DeleteOptions, listOptions v1.ListOptions) error { + action := testing.NewDeleteCollectionAction(networkpoliciesResource, c.ns, listOptions) + + _, err := c.Fake.Invokes(action, &v1alpha1.NetworkPolicyList{}) + return err +} + +// Patch applies the patch and returns the patched networkPolicy. +func (c *FakeNetworkPolicies) Patch(name string, pt types.PatchType, data []byte, subresources ...string) (result *v1alpha1.NetworkPolicy, err error) { + obj, err := c.Fake. + Invokes(testing.NewPatchSubresourceAction(networkpoliciesResource, c.ns, name, pt, data, subresources...), &v1alpha1.NetworkPolicy{}) + + if obj == nil { + return nil, err + } + return obj.(*v1alpha1.NetworkPolicy), err +} diff --git a/pkg/client/clientset/versioned/typed/security/v1alpha1/fake/fake_security_client.go b/pkg/client/clientset/versioned/typed/security/v1alpha1/fake/fake_security_client.go new file mode 100644 index 00000000000..284362a7284 --- /dev/null +++ b/pkg/client/clientset/versioned/typed/security/v1alpha1/fake/fake_security_client.go @@ -0,0 +1,38 @@ +// Copyright 2020 Antrea 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 ( + v1alpha1 "github.com/vmware-tanzu/antrea/pkg/client/clientset/versioned/typed/security/v1alpha1" + rest "k8s.io/client-go/rest" + testing "k8s.io/client-go/testing" +) + +type FakeSecurityV1alpha1 struct { + *testing.Fake +} + +func (c *FakeSecurityV1alpha1) NetworkPolicies(namespace string) v1alpha1.NetworkPolicyInterface { + return &FakeNetworkPolicies{c, namespace} +} + +// RESTClient returns a RESTClient that is used to communicate +// with API server by this client implementation. +func (c *FakeSecurityV1alpha1) RESTClient() rest.Interface { + var ret *rest.RESTClient + return ret +} diff --git a/pkg/client/clientset/versioned/typed/security/v1alpha1/generated_expansion.go b/pkg/client/clientset/versioned/typed/security/v1alpha1/generated_expansion.go new file mode 100644 index 00000000000..521b253bbbb --- /dev/null +++ b/pkg/client/clientset/versioned/typed/security/v1alpha1/generated_expansion.go @@ -0,0 +1,19 @@ +// Copyright 2020 Antrea 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 v1alpha1 + +type NetworkPolicyExpansion interface{} diff --git a/pkg/client/clientset/versioned/typed/security/v1alpha1/networkpolicy.go b/pkg/client/clientset/versioned/typed/security/v1alpha1/networkpolicy.go new file mode 100644 index 00000000000..0ca35e82783 --- /dev/null +++ b/pkg/client/clientset/versioned/typed/security/v1alpha1/networkpolicy.go @@ -0,0 +1,172 @@ +// Copyright 2020 Antrea 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 v1alpha1 + +import ( + "time" + + v1alpha1 "github.com/vmware-tanzu/antrea/pkg/apis/security/v1alpha1" + scheme "github.com/vmware-tanzu/antrea/pkg/client/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" +) + +// NetworkPoliciesGetter has a method to return a NetworkPolicyInterface. +// A group's client should implement this interface. +type NetworkPoliciesGetter interface { + NetworkPolicies(namespace string) NetworkPolicyInterface +} + +// NetworkPolicyInterface has methods to work with NetworkPolicy resources. +type NetworkPolicyInterface interface { + Create(*v1alpha1.NetworkPolicy) (*v1alpha1.NetworkPolicy, error) + Update(*v1alpha1.NetworkPolicy) (*v1alpha1.NetworkPolicy, error) + Delete(name string, options *v1.DeleteOptions) error + DeleteCollection(options *v1.DeleteOptions, listOptions v1.ListOptions) error + Get(name string, options v1.GetOptions) (*v1alpha1.NetworkPolicy, error) + List(opts v1.ListOptions) (*v1alpha1.NetworkPolicyList, error) + Watch(opts v1.ListOptions) (watch.Interface, error) + Patch(name string, pt types.PatchType, data []byte, subresources ...string) (result *v1alpha1.NetworkPolicy, err error) + NetworkPolicyExpansion +} + +// networkPolicies implements NetworkPolicyInterface +type networkPolicies struct { + client rest.Interface + ns string +} + +// newNetworkPolicies returns a NetworkPolicies +func newNetworkPolicies(c *SecurityV1alpha1Client, namespace string) *networkPolicies { + return &networkPolicies{ + client: c.RESTClient(), + ns: namespace, + } +} + +// Get takes name of the networkPolicy, and returns the corresponding networkPolicy object, and an error if there is any. +func (c *networkPolicies) Get(name string, options v1.GetOptions) (result *v1alpha1.NetworkPolicy, err error) { + result = &v1alpha1.NetworkPolicy{} + err = c.client.Get(). + Namespace(c.ns). + Resource("networkpolicies"). + Name(name). + VersionedParams(&options, scheme.ParameterCodec). + Do(). + Into(result) + return +} + +// List takes label and field selectors, and returns the list of NetworkPolicies that match those selectors. +func (c *networkPolicies) List(opts v1.ListOptions) (result *v1alpha1.NetworkPolicyList, err error) { + var timeout time.Duration + if opts.TimeoutSeconds != nil { + timeout = time.Duration(*opts.TimeoutSeconds) * time.Second + } + result = &v1alpha1.NetworkPolicyList{} + err = c.client.Get(). + Namespace(c.ns). + Resource("networkpolicies"). + VersionedParams(&opts, scheme.ParameterCodec). + Timeout(timeout). + Do(). + Into(result) + return +} + +// Watch returns a watch.Interface that watches the requested networkPolicies. +func (c *networkPolicies) Watch(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("networkpolicies"). + VersionedParams(&opts, scheme.ParameterCodec). + Timeout(timeout). + Watch() +} + +// Create takes the representation of a networkPolicy and creates it. Returns the server's representation of the networkPolicy, and an error, if there is any. +func (c *networkPolicies) Create(networkPolicy *v1alpha1.NetworkPolicy) (result *v1alpha1.NetworkPolicy, err error) { + result = &v1alpha1.NetworkPolicy{} + err = c.client.Post(). + Namespace(c.ns). + Resource("networkpolicies"). + Body(networkPolicy). + Do(). + Into(result) + return +} + +// Update takes the representation of a networkPolicy and updates it. Returns the server's representation of the networkPolicy, and an error, if there is any. +func (c *networkPolicies) Update(networkPolicy *v1alpha1.NetworkPolicy) (result *v1alpha1.NetworkPolicy, err error) { + result = &v1alpha1.NetworkPolicy{} + err = c.client.Put(). + Namespace(c.ns). + Resource("networkpolicies"). + Name(networkPolicy.Name). + Body(networkPolicy). + Do(). + Into(result) + return +} + +// Delete takes name of the networkPolicy and deletes it. Returns an error if one occurs. +func (c *networkPolicies) Delete(name string, options *v1.DeleteOptions) error { + return c.client.Delete(). + Namespace(c.ns). + Resource("networkpolicies"). + Name(name). + Body(options). + Do(). + Error() +} + +// DeleteCollection deletes a collection of objects. +func (c *networkPolicies) DeleteCollection(options *v1.DeleteOptions, listOptions v1.ListOptions) error { + var timeout time.Duration + if listOptions.TimeoutSeconds != nil { + timeout = time.Duration(*listOptions.TimeoutSeconds) * time.Second + } + return c.client.Delete(). + Namespace(c.ns). + Resource("networkpolicies"). + VersionedParams(&listOptions, scheme.ParameterCodec). + Timeout(timeout). + Body(options). + Do(). + Error() +} + +// Patch applies the patch and returns the patched networkPolicy. +func (c *networkPolicies) Patch(name string, pt types.PatchType, data []byte, subresources ...string) (result *v1alpha1.NetworkPolicy, err error) { + result = &v1alpha1.NetworkPolicy{} + err = c.client.Patch(pt). + Namespace(c.ns). + Resource("networkpolicies"). + SubResource(subresources...). + Name(name). + Body(data). + Do(). + Into(result) + return +} diff --git a/pkg/client/clientset/versioned/typed/security/v1alpha1/security_client.go b/pkg/client/clientset/versioned/typed/security/v1alpha1/security_client.go new file mode 100644 index 00000000000..5c946a2574c --- /dev/null +++ b/pkg/client/clientset/versioned/typed/security/v1alpha1/security_client.go @@ -0,0 +1,87 @@ +// Copyright 2020 Antrea 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 v1alpha1 + +import ( + v1alpha1 "github.com/vmware-tanzu/antrea/pkg/apis/security/v1alpha1" + "github.com/vmware-tanzu/antrea/pkg/client/clientset/versioned/scheme" + rest "k8s.io/client-go/rest" +) + +type SecurityV1alpha1Interface interface { + RESTClient() rest.Interface + NetworkPoliciesGetter +} + +// SecurityV1alpha1Client is used to interact with features provided by the security.antrea.tanzu.vmware.com group. +type SecurityV1alpha1Client struct { + restClient rest.Interface +} + +func (c *SecurityV1alpha1Client) NetworkPolicies(namespace string) NetworkPolicyInterface { + return newNetworkPolicies(c, namespace) +} + +// NewForConfig creates a new SecurityV1alpha1Client for the given config. +func NewForConfig(c *rest.Config) (*SecurityV1alpha1Client, error) { + config := *c + if err := setConfigDefaults(&config); err != nil { + return nil, err + } + client, err := rest.RESTClientFor(&config) + if err != nil { + return nil, err + } + return &SecurityV1alpha1Client{client}, nil +} + +// NewForConfigOrDie creates a new SecurityV1alpha1Client for the given config and +// panics if there is an error in the config. +func NewForConfigOrDie(c *rest.Config) *SecurityV1alpha1Client { + client, err := NewForConfig(c) + if err != nil { + panic(err) + } + return client +} + +// New creates a new SecurityV1alpha1Client for the given RESTClient. +func New(c rest.Interface) *SecurityV1alpha1Client { + return &SecurityV1alpha1Client{c} +} + +func setConfigDefaults(config *rest.Config) error { + gv := v1alpha1.SchemeGroupVersion + config.GroupVersion = &gv + config.APIPath = "/apis" + config.NegotiatedSerializer = scheme.Codecs.WithoutConversion() + + if config.UserAgent == "" { + config.UserAgent = rest.DefaultKubernetesUserAgent() + } + + return nil +} + +// RESTClient returns a RESTClient that is used to communicate +// with API server by this client implementation. +func (c *SecurityV1alpha1Client) RESTClient() rest.Interface { + if c == nil { + return nil + } + return c.restClient +} diff --git a/pkg/client/informers/externalversions/core/interface.go b/pkg/client/informers/externalversions/core/interface.go new file mode 100644 index 00000000000..3e90d107a47 --- /dev/null +++ b/pkg/client/informers/externalversions/core/interface.go @@ -0,0 +1,44 @@ +// Copyright 2020 Antrea 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 core + +import ( + v1alpha1 "github.com/vmware-tanzu/antrea/pkg/client/informers/externalversions/core/v1alpha1" + internalinterfaces "github.com/vmware-tanzu/antrea/pkg/client/informers/externalversions/internalinterfaces" +) + +// Interface provides access to each of this group's versions. +type Interface interface { + // V1alpha1 provides access to shared informers for resources in V1alpha1. + V1alpha1() v1alpha1.Interface +} + +type group struct { + factory internalinterfaces.SharedInformerFactory + namespace string + tweakListOptions internalinterfaces.TweakListOptionsFunc +} + +// New returns a new Interface. +func New(f internalinterfaces.SharedInformerFactory, namespace string, tweakListOptions internalinterfaces.TweakListOptionsFunc) Interface { + return &group{factory: f, namespace: namespace, tweakListOptions: tweakListOptions} +} + +// V1alpha1 returns a new v1alpha1.Interface. +func (g *group) V1alpha1() v1alpha1.Interface { + return v1alpha1.New(g.factory, g.namespace, g.tweakListOptions) +} diff --git a/pkg/client/informers/externalversions/core/v1alpha1/externalentity.go b/pkg/client/informers/externalversions/core/v1alpha1/externalentity.go new file mode 100644 index 00000000000..2b6dc5fde16 --- /dev/null +++ b/pkg/client/informers/externalversions/core/v1alpha1/externalentity.go @@ -0,0 +1,87 @@ +// Copyright 2020 Antrea 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 v1alpha1 + +import ( + time "time" + + corev1alpha1 "github.com/vmware-tanzu/antrea/pkg/apis/core/v1alpha1" + versioned "github.com/vmware-tanzu/antrea/pkg/client/clientset/versioned" + internalinterfaces "github.com/vmware-tanzu/antrea/pkg/client/informers/externalversions/internalinterfaces" + v1alpha1 "github.com/vmware-tanzu/antrea/pkg/client/listers/core/v1alpha1" + 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" +) + +// ExternalEntityInformer provides access to a shared informer and lister for +// ExternalEntities. +type ExternalEntityInformer interface { + Informer() cache.SharedIndexInformer + Lister() v1alpha1.ExternalEntityLister +} + +type externalEntityInformer struct { + factory internalinterfaces.SharedInformerFactory + tweakListOptions internalinterfaces.TweakListOptionsFunc + namespace string +} + +// NewExternalEntityInformer constructs a new informer for ExternalEntity 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 NewExternalEntityInformer(client versioned.Interface, namespace string, resyncPeriod time.Duration, indexers cache.Indexers) cache.SharedIndexInformer { + return NewFilteredExternalEntityInformer(client, namespace, resyncPeriod, indexers, nil) +} + +// NewFilteredExternalEntityInformer constructs a new informer for ExternalEntity 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 NewFilteredExternalEntityInformer(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.CoreV1alpha1().ExternalEntities(namespace).List(options) + }, + WatchFunc: func(options v1.ListOptions) (watch.Interface, error) { + if tweakListOptions != nil { + tweakListOptions(&options) + } + return client.CoreV1alpha1().ExternalEntities(namespace).Watch(options) + }, + }, + &corev1alpha1.ExternalEntity{}, + resyncPeriod, + indexers, + ) +} + +func (f *externalEntityInformer) defaultInformer(client versioned.Interface, resyncPeriod time.Duration) cache.SharedIndexInformer { + return NewFilteredExternalEntityInformer(client, f.namespace, resyncPeriod, cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc}, f.tweakListOptions) +} + +func (f *externalEntityInformer) Informer() cache.SharedIndexInformer { + return f.factory.InformerFor(&corev1alpha1.ExternalEntity{}, f.defaultInformer) +} + +func (f *externalEntityInformer) Lister() v1alpha1.ExternalEntityLister { + return v1alpha1.NewExternalEntityLister(f.Informer().GetIndexer()) +} diff --git a/pkg/client/informers/externalversions/core/v1alpha1/interface.go b/pkg/client/informers/externalversions/core/v1alpha1/interface.go new file mode 100644 index 00000000000..d7876afaf34 --- /dev/null +++ b/pkg/client/informers/externalversions/core/v1alpha1/interface.go @@ -0,0 +1,43 @@ +// Copyright 2020 Antrea 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 v1alpha1 + +import ( + internalinterfaces "github.com/vmware-tanzu/antrea/pkg/client/informers/externalversions/internalinterfaces" +) + +// Interface provides access to all the informers in this group version. +type Interface interface { + // ExternalEntities returns a ExternalEntityInformer. + ExternalEntities() ExternalEntityInformer +} + +type version struct { + factory internalinterfaces.SharedInformerFactory + namespace string + tweakListOptions internalinterfaces.TweakListOptionsFunc +} + +// New returns a new Interface. +func New(f internalinterfaces.SharedInformerFactory, namespace string, tweakListOptions internalinterfaces.TweakListOptionsFunc) Interface { + return &version{factory: f, namespace: namespace, tweakListOptions: tweakListOptions} +} + +// ExternalEntities returns a ExternalEntityInformer. +func (v *version) ExternalEntities() ExternalEntityInformer { + return &externalEntityInformer{factory: v.factory, namespace: v.namespace, tweakListOptions: v.tweakListOptions} +} diff --git a/pkg/client/informers/externalversions/factory.go b/pkg/client/informers/externalversions/factory.go new file mode 100644 index 00000000000..cf95a585e4a --- /dev/null +++ b/pkg/client/informers/externalversions/factory.go @@ -0,0 +1,184 @@ +// Copyright 2020 Antrea 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 externalversions + +import ( + reflect "reflect" + sync "sync" + time "time" + + versioned "github.com/vmware-tanzu/antrea/pkg/client/clientset/versioned" + core "github.com/vmware-tanzu/antrea/pkg/client/informers/externalversions/core" + internalinterfaces "github.com/vmware-tanzu/antrea/pkg/client/informers/externalversions/internalinterfaces" + security "github.com/vmware-tanzu/antrea/pkg/client/informers/externalversions/security" + v1 "k8s.io/apimachinery/pkg/apis/meta/v1" + runtime "k8s.io/apimachinery/pkg/runtime" + schema "k8s.io/apimachinery/pkg/runtime/schema" + cache "k8s.io/client-go/tools/cache" +) + +// SharedInformerOption defines the functional option type for SharedInformerFactory. +type SharedInformerOption func(*sharedInformerFactory) *sharedInformerFactory + +type sharedInformerFactory struct { + client versioned.Interface + namespace string + tweakListOptions internalinterfaces.TweakListOptionsFunc + lock sync.Mutex + defaultResync time.Duration + customResync map[reflect.Type]time.Duration + + informers map[reflect.Type]cache.SharedIndexInformer + // startedInformers is used for tracking which informers have been started. + // This allows Start() to be called multiple times safely. + startedInformers map[reflect.Type]bool +} + +// WithCustomResyncConfig sets a custom resync period for the specified informer types. +func WithCustomResyncConfig(resyncConfig map[v1.Object]time.Duration) SharedInformerOption { + return func(factory *sharedInformerFactory) *sharedInformerFactory { + for k, v := range resyncConfig { + factory.customResync[reflect.TypeOf(k)] = v + } + return factory + } +} + +// WithTweakListOptions sets a custom filter on all listers of the configured SharedInformerFactory. +func WithTweakListOptions(tweakListOptions internalinterfaces.TweakListOptionsFunc) SharedInformerOption { + return func(factory *sharedInformerFactory) *sharedInformerFactory { + factory.tweakListOptions = tweakListOptions + return factory + } +} + +// WithNamespace limits the SharedInformerFactory to the specified namespace. +func WithNamespace(namespace string) SharedInformerOption { + return func(factory *sharedInformerFactory) *sharedInformerFactory { + factory.namespace = namespace + return factory + } +} + +// NewSharedInformerFactory constructs a new instance of sharedInformerFactory for all namespaces. +func NewSharedInformerFactory(client versioned.Interface, defaultResync time.Duration) SharedInformerFactory { + return NewSharedInformerFactoryWithOptions(client, defaultResync) +} + +// NewFilteredSharedInformerFactory constructs a new instance of sharedInformerFactory. +// Listers obtained via this SharedInformerFactory will be subject to the same filters +// as specified here. +// Deprecated: Please use NewSharedInformerFactoryWithOptions instead +func NewFilteredSharedInformerFactory(client versioned.Interface, defaultResync time.Duration, namespace string, tweakListOptions internalinterfaces.TweakListOptionsFunc) SharedInformerFactory { + return NewSharedInformerFactoryWithOptions(client, defaultResync, WithNamespace(namespace), WithTweakListOptions(tweakListOptions)) +} + +// NewSharedInformerFactoryWithOptions constructs a new instance of a SharedInformerFactory with additional options. +func NewSharedInformerFactoryWithOptions(client versioned.Interface, defaultResync time.Duration, options ...SharedInformerOption) SharedInformerFactory { + factory := &sharedInformerFactory{ + client: client, + namespace: v1.NamespaceAll, + defaultResync: defaultResync, + informers: make(map[reflect.Type]cache.SharedIndexInformer), + startedInformers: make(map[reflect.Type]bool), + customResync: make(map[reflect.Type]time.Duration), + } + + // Apply all options + for _, opt := range options { + factory = opt(factory) + } + + return factory +} + +// Start initializes all requested informers. +func (f *sharedInformerFactory) Start(stopCh <-chan struct{}) { + f.lock.Lock() + defer f.lock.Unlock() + + for informerType, informer := range f.informers { + if !f.startedInformers[informerType] { + go informer.Run(stopCh) + f.startedInformers[informerType] = true + } + } +} + +// WaitForCacheSync waits for all started informers' cache were synced. +func (f *sharedInformerFactory) WaitForCacheSync(stopCh <-chan struct{}) map[reflect.Type]bool { + informers := func() map[reflect.Type]cache.SharedIndexInformer { + f.lock.Lock() + defer f.lock.Unlock() + + informers := map[reflect.Type]cache.SharedIndexInformer{} + for informerType, informer := range f.informers { + if f.startedInformers[informerType] { + informers[informerType] = informer + } + } + return informers + }() + + res := map[reflect.Type]bool{} + for informType, informer := range informers { + res[informType] = cache.WaitForCacheSync(stopCh, informer.HasSynced) + } + return res +} + +// InternalInformerFor returns the SharedIndexInformer for obj using an internal +// client. +func (f *sharedInformerFactory) InformerFor(obj runtime.Object, newFunc internalinterfaces.NewInformerFunc) cache.SharedIndexInformer { + f.lock.Lock() + defer f.lock.Unlock() + + informerType := reflect.TypeOf(obj) + informer, exists := f.informers[informerType] + if exists { + return informer + } + + resyncPeriod, exists := f.customResync[informerType] + if !exists { + resyncPeriod = f.defaultResync + } + + informer = newFunc(f.client, resyncPeriod) + f.informers[informerType] = informer + + return informer +} + +// SharedInformerFactory provides shared informers for resources in all known +// API group versions. +type SharedInformerFactory interface { + internalinterfaces.SharedInformerFactory + ForResource(resource schema.GroupVersionResource) (GenericInformer, error) + WaitForCacheSync(stopCh <-chan struct{}) map[reflect.Type]bool + + Core() core.Interface + Security() security.Interface +} + +func (f *sharedInformerFactory) Core() core.Interface { + return core.New(f, f.namespace, f.tweakListOptions) +} + +func (f *sharedInformerFactory) Security() security.Interface { + return security.New(f, f.namespace, f.tweakListOptions) +} diff --git a/pkg/client/informers/externalversions/generic.go b/pkg/client/informers/externalversions/generic.go new file mode 100644 index 00000000000..da8106ef4ee --- /dev/null +++ b/pkg/client/informers/externalversions/generic.go @@ -0,0 +1,65 @@ +// Copyright 2020 Antrea 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 externalversions + +import ( + "fmt" + + v1alpha1 "github.com/vmware-tanzu/antrea/pkg/apis/core/v1alpha1" + securityv1alpha1 "github.com/vmware-tanzu/antrea/pkg/apis/security/v1alpha1" + schema "k8s.io/apimachinery/pkg/runtime/schema" + cache "k8s.io/client-go/tools/cache" +) + +// GenericInformer is type of SharedIndexInformer which will locate and delegate to other +// sharedInformers based on type +type GenericInformer interface { + Informer() cache.SharedIndexInformer + Lister() cache.GenericLister +} + +type genericInformer struct { + informer cache.SharedIndexInformer + resource schema.GroupResource +} + +// Informer returns the SharedIndexInformer. +func (f *genericInformer) Informer() cache.SharedIndexInformer { + return f.informer +} + +// Lister returns the GenericLister. +func (f *genericInformer) Lister() cache.GenericLister { + return cache.NewGenericLister(f.Informer().GetIndexer(), f.resource) +} + +// ForResource gives generic access to a shared informer of the matching type +// TODO extend this to unknown resources with a client pool +func (f *sharedInformerFactory) ForResource(resource schema.GroupVersionResource) (GenericInformer, error) { + switch resource { + // Group=core.antrea.tanzu.vmware.com, Version=v1alpha1 + case v1alpha1.SchemeGroupVersion.WithResource("externalentities"): + return &genericInformer{resource: resource.GroupResource(), informer: f.Core().V1alpha1().ExternalEntities().Informer()}, nil + + // Group=security.antrea.tanzu.vmware.com, Version=v1alpha1 + case securityv1alpha1.SchemeGroupVersion.WithResource("networkpolicies"): + return &genericInformer{resource: resource.GroupResource(), informer: f.Security().V1alpha1().NetworkPolicies().Informer()}, nil + + } + + return nil, fmt.Errorf("no informer found for %v", resource) +} diff --git a/pkg/client/informers/externalversions/internalinterfaces/factory_interfaces.go b/pkg/client/informers/externalversions/internalinterfaces/factory_interfaces.go new file mode 100644 index 00000000000..e0160fc66ca --- /dev/null +++ b/pkg/client/informers/externalversions/internalinterfaces/factory_interfaces.go @@ -0,0 +1,38 @@ +// Copyright 2020 Antrea 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 internalinterfaces + +import ( + time "time" + + versioned "github.com/vmware-tanzu/antrea/pkg/client/clientset/versioned" + v1 "k8s.io/apimachinery/pkg/apis/meta/v1" + runtime "k8s.io/apimachinery/pkg/runtime" + cache "k8s.io/client-go/tools/cache" +) + +// NewInformerFunc takes versioned.Interface and time.Duration to return a SharedIndexInformer. +type NewInformerFunc func(versioned.Interface, time.Duration) cache.SharedIndexInformer + +// SharedInformerFactory a small interface to allow for adding an informer without an import cycle +type SharedInformerFactory interface { + Start(stopCh <-chan struct{}) + InformerFor(obj runtime.Object, newFunc NewInformerFunc) cache.SharedIndexInformer +} + +// TweakListOptionsFunc is a function that transforms a v1.ListOptions. +type TweakListOptionsFunc func(*v1.ListOptions) diff --git a/pkg/client/informers/externalversions/security/interface.go b/pkg/client/informers/externalversions/security/interface.go new file mode 100644 index 00000000000..cd967e582fe --- /dev/null +++ b/pkg/client/informers/externalversions/security/interface.go @@ -0,0 +1,44 @@ +// Copyright 2020 Antrea 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 security + +import ( + internalinterfaces "github.com/vmware-tanzu/antrea/pkg/client/informers/externalversions/internalinterfaces" + v1alpha1 "github.com/vmware-tanzu/antrea/pkg/client/informers/externalversions/security/v1alpha1" +) + +// Interface provides access to each of this group's versions. +type Interface interface { + // V1alpha1 provides access to shared informers for resources in V1alpha1. + V1alpha1() v1alpha1.Interface +} + +type group struct { + factory internalinterfaces.SharedInformerFactory + namespace string + tweakListOptions internalinterfaces.TweakListOptionsFunc +} + +// New returns a new Interface. +func New(f internalinterfaces.SharedInformerFactory, namespace string, tweakListOptions internalinterfaces.TweakListOptionsFunc) Interface { + return &group{factory: f, namespace: namespace, tweakListOptions: tweakListOptions} +} + +// V1alpha1 returns a new v1alpha1.Interface. +func (g *group) V1alpha1() v1alpha1.Interface { + return v1alpha1.New(g.factory, g.namespace, g.tweakListOptions) +} diff --git a/pkg/client/informers/externalversions/security/v1alpha1/interface.go b/pkg/client/informers/externalversions/security/v1alpha1/interface.go new file mode 100644 index 00000000000..f63e8a254c0 --- /dev/null +++ b/pkg/client/informers/externalversions/security/v1alpha1/interface.go @@ -0,0 +1,43 @@ +// Copyright 2020 Antrea 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 v1alpha1 + +import ( + internalinterfaces "github.com/vmware-tanzu/antrea/pkg/client/informers/externalversions/internalinterfaces" +) + +// Interface provides access to all the informers in this group version. +type Interface interface { + // NetworkPolicies returns a NetworkPolicyInformer. + NetworkPolicies() NetworkPolicyInformer +} + +type version struct { + factory internalinterfaces.SharedInformerFactory + namespace string + tweakListOptions internalinterfaces.TweakListOptionsFunc +} + +// New returns a new Interface. +func New(f internalinterfaces.SharedInformerFactory, namespace string, tweakListOptions internalinterfaces.TweakListOptionsFunc) Interface { + return &version{factory: f, namespace: namespace, tweakListOptions: tweakListOptions} +} + +// NetworkPolicies returns a NetworkPolicyInformer. +func (v *version) NetworkPolicies() NetworkPolicyInformer { + return &networkPolicyInformer{factory: v.factory, namespace: v.namespace, tweakListOptions: v.tweakListOptions} +} diff --git a/pkg/client/informers/externalversions/security/v1alpha1/networkpolicy.go b/pkg/client/informers/externalversions/security/v1alpha1/networkpolicy.go new file mode 100644 index 00000000000..fe266b39193 --- /dev/null +++ b/pkg/client/informers/externalversions/security/v1alpha1/networkpolicy.go @@ -0,0 +1,87 @@ +// Copyright 2020 Antrea 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 v1alpha1 + +import ( + time "time" + + securityv1alpha1 "github.com/vmware-tanzu/antrea/pkg/apis/security/v1alpha1" + versioned "github.com/vmware-tanzu/antrea/pkg/client/clientset/versioned" + internalinterfaces "github.com/vmware-tanzu/antrea/pkg/client/informers/externalversions/internalinterfaces" + v1alpha1 "github.com/vmware-tanzu/antrea/pkg/client/listers/security/v1alpha1" + 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" +) + +// NetworkPolicyInformer provides access to a shared informer and lister for +// NetworkPolicies. +type NetworkPolicyInformer interface { + Informer() cache.SharedIndexInformer + Lister() v1alpha1.NetworkPolicyLister +} + +type networkPolicyInformer struct { + factory internalinterfaces.SharedInformerFactory + tweakListOptions internalinterfaces.TweakListOptionsFunc + namespace string +} + +// NewNetworkPolicyInformer constructs a new informer for NetworkPolicy 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 NewNetworkPolicyInformer(client versioned.Interface, namespace string, resyncPeriod time.Duration, indexers cache.Indexers) cache.SharedIndexInformer { + return NewFilteredNetworkPolicyInformer(client, namespace, resyncPeriod, indexers, nil) +} + +// NewFilteredNetworkPolicyInformer constructs a new informer for NetworkPolicy 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 NewFilteredNetworkPolicyInformer(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.SecurityV1alpha1().NetworkPolicies(namespace).List(options) + }, + WatchFunc: func(options v1.ListOptions) (watch.Interface, error) { + if tweakListOptions != nil { + tweakListOptions(&options) + } + return client.SecurityV1alpha1().NetworkPolicies(namespace).Watch(options) + }, + }, + &securityv1alpha1.NetworkPolicy{}, + resyncPeriod, + indexers, + ) +} + +func (f *networkPolicyInformer) defaultInformer(client versioned.Interface, resyncPeriod time.Duration) cache.SharedIndexInformer { + return NewFilteredNetworkPolicyInformer(client, f.namespace, resyncPeriod, cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc}, f.tweakListOptions) +} + +func (f *networkPolicyInformer) Informer() cache.SharedIndexInformer { + return f.factory.InformerFor(&securityv1alpha1.NetworkPolicy{}, f.defaultInformer) +} + +func (f *networkPolicyInformer) Lister() v1alpha1.NetworkPolicyLister { + return v1alpha1.NewNetworkPolicyLister(f.Informer().GetIndexer()) +} diff --git a/pkg/client/listers/core/v1alpha1/expansion_generated.go b/pkg/client/listers/core/v1alpha1/expansion_generated.go new file mode 100644 index 00000000000..d4b5052f659 --- /dev/null +++ b/pkg/client/listers/core/v1alpha1/expansion_generated.go @@ -0,0 +1,25 @@ +// Copyright 2020 Antrea 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 v1alpha1 + +// ExternalEntityListerExpansion allows custom methods to be added to +// ExternalEntityLister. +type ExternalEntityListerExpansion interface{} + +// ExternalEntityNamespaceListerExpansion allows custom methods to be added to +// ExternalEntityNamespaceLister. +type ExternalEntityNamespaceListerExpansion interface{} diff --git a/pkg/client/listers/core/v1alpha1/externalentity.go b/pkg/client/listers/core/v1alpha1/externalentity.go new file mode 100644 index 00000000000..c58b4ade822 --- /dev/null +++ b/pkg/client/listers/core/v1alpha1/externalentity.go @@ -0,0 +1,92 @@ +// Copyright 2020 Antrea 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 v1alpha1 + +import ( + v1alpha1 "github.com/vmware-tanzu/antrea/pkg/apis/core/v1alpha1" + "k8s.io/apimachinery/pkg/api/errors" + "k8s.io/apimachinery/pkg/labels" + "k8s.io/client-go/tools/cache" +) + +// ExternalEntityLister helps list ExternalEntities. +type ExternalEntityLister interface { + // List lists all ExternalEntities in the indexer. + List(selector labels.Selector) (ret []*v1alpha1.ExternalEntity, err error) + // ExternalEntities returns an object that can list and get ExternalEntities. + ExternalEntities(namespace string) ExternalEntityNamespaceLister + ExternalEntityListerExpansion +} + +// externalEntityLister implements the ExternalEntityLister interface. +type externalEntityLister struct { + indexer cache.Indexer +} + +// NewExternalEntityLister returns a new ExternalEntityLister. +func NewExternalEntityLister(indexer cache.Indexer) ExternalEntityLister { + return &externalEntityLister{indexer: indexer} +} + +// List lists all ExternalEntities in the indexer. +func (s *externalEntityLister) List(selector labels.Selector) (ret []*v1alpha1.ExternalEntity, err error) { + err = cache.ListAll(s.indexer, selector, func(m interface{}) { + ret = append(ret, m.(*v1alpha1.ExternalEntity)) + }) + return ret, err +} + +// ExternalEntities returns an object that can list and get ExternalEntities. +func (s *externalEntityLister) ExternalEntities(namespace string) ExternalEntityNamespaceLister { + return externalEntityNamespaceLister{indexer: s.indexer, namespace: namespace} +} + +// ExternalEntityNamespaceLister helps list and get ExternalEntities. +type ExternalEntityNamespaceLister interface { + // List lists all ExternalEntities in the indexer for a given namespace. + List(selector labels.Selector) (ret []*v1alpha1.ExternalEntity, err error) + // Get retrieves the ExternalEntity from the indexer for a given namespace and name. + Get(name string) (*v1alpha1.ExternalEntity, error) + ExternalEntityNamespaceListerExpansion +} + +// externalEntityNamespaceLister implements the ExternalEntityNamespaceLister +// interface. +type externalEntityNamespaceLister struct { + indexer cache.Indexer + namespace string +} + +// List lists all ExternalEntities in the indexer for a given namespace. +func (s externalEntityNamespaceLister) List(selector labels.Selector) (ret []*v1alpha1.ExternalEntity, err error) { + err = cache.ListAllByNamespace(s.indexer, s.namespace, selector, func(m interface{}) { + ret = append(ret, m.(*v1alpha1.ExternalEntity)) + }) + return ret, err +} + +// Get retrieves the ExternalEntity from the indexer for a given namespace and name. +func (s externalEntityNamespaceLister) Get(name string) (*v1alpha1.ExternalEntity, error) { + obj, exists, err := s.indexer.GetByKey(s.namespace + "/" + name) + if err != nil { + return nil, err + } + if !exists { + return nil, errors.NewNotFound(v1alpha1.Resource("externalentity"), name) + } + return obj.(*v1alpha1.ExternalEntity), nil +} diff --git a/pkg/client/listers/security/v1alpha1/expansion_generated.go b/pkg/client/listers/security/v1alpha1/expansion_generated.go new file mode 100644 index 00000000000..27439876fb4 --- /dev/null +++ b/pkg/client/listers/security/v1alpha1/expansion_generated.go @@ -0,0 +1,25 @@ +// Copyright 2020 Antrea 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 v1alpha1 + +// NetworkPolicyListerExpansion allows custom methods to be added to +// NetworkPolicyLister. +type NetworkPolicyListerExpansion interface{} + +// NetworkPolicyNamespaceListerExpansion allows custom methods to be added to +// NetworkPolicyNamespaceLister. +type NetworkPolicyNamespaceListerExpansion interface{} diff --git a/pkg/client/listers/security/v1alpha1/networkpolicy.go b/pkg/client/listers/security/v1alpha1/networkpolicy.go new file mode 100644 index 00000000000..5c12a3f294b --- /dev/null +++ b/pkg/client/listers/security/v1alpha1/networkpolicy.go @@ -0,0 +1,92 @@ +// Copyright 2020 Antrea 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 v1alpha1 + +import ( + v1alpha1 "github.com/vmware-tanzu/antrea/pkg/apis/security/v1alpha1" + "k8s.io/apimachinery/pkg/api/errors" + "k8s.io/apimachinery/pkg/labels" + "k8s.io/client-go/tools/cache" +) + +// NetworkPolicyLister helps list NetworkPolicies. +type NetworkPolicyLister interface { + // List lists all NetworkPolicies in the indexer. + List(selector labels.Selector) (ret []*v1alpha1.NetworkPolicy, err error) + // NetworkPolicies returns an object that can list and get NetworkPolicies. + NetworkPolicies(namespace string) NetworkPolicyNamespaceLister + NetworkPolicyListerExpansion +} + +// networkPolicyLister implements the NetworkPolicyLister interface. +type networkPolicyLister struct { + indexer cache.Indexer +} + +// NewNetworkPolicyLister returns a new NetworkPolicyLister. +func NewNetworkPolicyLister(indexer cache.Indexer) NetworkPolicyLister { + return &networkPolicyLister{indexer: indexer} +} + +// List lists all NetworkPolicies in the indexer. +func (s *networkPolicyLister) List(selector labels.Selector) (ret []*v1alpha1.NetworkPolicy, err error) { + err = cache.ListAll(s.indexer, selector, func(m interface{}) { + ret = append(ret, m.(*v1alpha1.NetworkPolicy)) + }) + return ret, err +} + +// NetworkPolicies returns an object that can list and get NetworkPolicies. +func (s *networkPolicyLister) NetworkPolicies(namespace string) NetworkPolicyNamespaceLister { + return networkPolicyNamespaceLister{indexer: s.indexer, namespace: namespace} +} + +// NetworkPolicyNamespaceLister helps list and get NetworkPolicies. +type NetworkPolicyNamespaceLister interface { + // List lists all NetworkPolicies in the indexer for a given namespace. + List(selector labels.Selector) (ret []*v1alpha1.NetworkPolicy, err error) + // Get retrieves the NetworkPolicy from the indexer for a given namespace and name. + Get(name string) (*v1alpha1.NetworkPolicy, error) + NetworkPolicyNamespaceListerExpansion +} + +// networkPolicyNamespaceLister implements the NetworkPolicyNamespaceLister +// interface. +type networkPolicyNamespaceLister struct { + indexer cache.Indexer + namespace string +} + +// List lists all NetworkPolicies in the indexer for a given namespace. +func (s networkPolicyNamespaceLister) List(selector labels.Selector) (ret []*v1alpha1.NetworkPolicy, err error) { + err = cache.ListAllByNamespace(s.indexer, s.namespace, selector, func(m interface{}) { + ret = append(ret, m.(*v1alpha1.NetworkPolicy)) + }) + return ret, err +} + +// Get retrieves the NetworkPolicy from the indexer for a given namespace and name. +func (s networkPolicyNamespaceLister) Get(name string) (*v1alpha1.NetworkPolicy, error) { + obj, exists, err := s.indexer.GetByKey(s.namespace + "/" + name) + if err != nil { + return nil, err + } + if !exists { + return nil, errors.NewNotFound(v1alpha1.Resource("networkpolicy"), name) + } + return obj.(*v1alpha1.NetworkPolicy), nil +}