Skip to content

Commit

Permalink
Add SNATPolicy CRD
Browse files Browse the repository at this point in the history
  • Loading branch information
jianjuns committed Oct 25, 2020
1 parent 251c408 commit 9c0f7ed
Show file tree
Hide file tree
Showing 25 changed files with 1,200 additions and 6 deletions.
14 changes: 8 additions & 6 deletions hack/update-codegen-dockerized.sh
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,10 @@ $GOPATH/bin/client-gen \
--input "clusterinformation/v1beta1" \
--input "controlplane/v1beta1" \
--input "system/v1beta1" \
--input "security/v1alpha1" \
--input "core/v1alpha1" \
--input "networking/v1alpha1" \
--input "ops/v1alpha1" \
--input "security/v1alpha1" \
--input "stats/v1alpha1" \
--output-package "${ANTREA_PKG}/pkg/client/clientset" \
--plural-exceptions "NetworkPolicyStats:NetworkPolicyStats" \
Expand All @@ -44,15 +45,15 @@ $GOPATH/bin/client-gen \

# Generate listers with K8s codegen tools.
$GOPATH/bin/lister-gen \
--input-dirs "${ANTREA_PKG}/pkg/apis/security/v1alpha1,${ANTREA_PKG}/pkg/apis/core/v1alpha1" \
--input-dirs "${ANTREA_PKG}/pkg/apis/ops/v1alpha1" \
--input-dirs "${ANTREA_PKG}/pkg/apis/core/v1alpha1,${ANTREA_PKG}/pkg/apis/networking/v1alpha1" \
--input-dirs "${ANTREA_PKG}/pkg/apis/ops/v1alpha1,${ANTREA_PKG}/pkg/apis/security/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" \
--input-dirs "${ANTREA_PKG}/pkg/apis/ops/v1alpha1" \
--input-dirs "${ANTREA_PKG}/pkg/apis/core/v1alpha1,${ANTREA_PKG}/pkg/apis/networking/v1alpha1" \
--input-dirs "${ANTREA_PKG}/pkg/apis/ops/v1alpha1,${ANTREA_PKG}/pkg/apis/security/v1alpha1" \
--versioned-clientset-package "${ANTREA_PKG}/pkg/client/clientset/versioned" \
--listers-package "${ANTREA_PKG}/pkg/client/listers" \
--output-package "${ANTREA_PKG}/pkg/client/informers" \
Expand All @@ -63,9 +64,10 @@ $GOPATH/bin/deepcopy-gen \
--input-dirs "${ANTREA_PKG}/pkg/apis/controlplane" \
--input-dirs "${ANTREA_PKG}/pkg/apis/controlplane/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" \
--input-dirs "${ANTREA_PKG}/pkg/apis/networking/v1alpha1" \
--input-dirs "${ANTREA_PKG}/pkg/apis/ops/v1alpha1" \
--input-dirs "${ANTREA_PKG}/pkg/apis/security/v1alpha1" \
--input-dirs "${ANTREA_PKG}/pkg/apis/stats" \
--input-dirs "${ANTREA_PKG}/pkg/apis/stats/v1alpha1" \
-O zz_generated.deepcopy \
Expand Down
14 changes: 14 additions & 0 deletions pkg/apis/core/v1alpha1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,17 @@ type ExternalEntityList struct {

Items []ExternalEntity `json:"items,omitempty"`
}

// AppliedTo defines the workloads to which a policy is applied.
type AppliedTo struct {
// Select Pods matched by this selector. If set with NamespaceSelector,
// Pods are matched from Namespaces matched by the NamespaceSelector;
// otherwise, Pods are matched from all Namespaces.
// +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.
// +optional
NamespaceSelector *metav1.LabelSelector `json:"namespaceSelector,omitempty"`
}
27 changes: 27 additions & 0 deletions pkg/apis/core/v1alpha1/zz_generated.deepcopy.go

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

19 changes: 19 additions & 0 deletions pkg/apis/networking/v1alpha1/doc.go
Original file line number Diff line number Diff line change
@@ -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=networking.antrea.tanzu.vmware.com

package v1alpha1 // import "github.com/vmware-tanzu/antrea/pkg/apis/networking/v1alpha1"
53 changes: 53 additions & 0 deletions pkg/apis/networking/v1alpha1/register.go
Original file line number Diff line number Diff line change
@@ -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 = "networking.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,
&SNATPolicy{},
&SNATPolicyList{},
)

metav1.AddToGroupVersion(scheme, SchemeGroupVersion)
return nil
}
75 changes: 75 additions & 0 deletions pkg/apis/networking/v1alpha1/types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
// 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"

antreacore "github.com/vmware-tanzu/antrea/pkg/apis/core/v1alpha1"
)

// +genclient
// +genclient:noStatus
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object

type SNATPolicy struct {
metav1.TypeMeta `json:",inline"`
// Standard metadata of the object.
metav1.ObjectMeta `json:"metadata,omitempty"`

// Specification of the desired behavior of SNATPolicy.
Spec SNATPolicySpec `json:"spec"`
}

// SNATPolicySpec defines the desired state for SNATPolicy.
type SNATPolicySpec struct {
// AppliedTo selects workloads to which the SNATPolicy will be applied.
AppliedTo antreacore.AppliedTo `json:"appliedTo"`
// SNATIP specifies the SNAT IP address for the selected workloads.
SNATIP string
}

// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object

type SNATPolicyList struct {
metav1.TypeMeta `json:",inline"`
// +optional
metav1.ListMeta `json:"metadata,omitempty"`

Items []SNATPolicy `json:"items"`
}

// +genclient
// +genclient:noStatus
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object

type NodeIPAddressBinding struct {
metav1.TypeMeta `json:",inline"`
// Standard metadata of the object.
metav1.ObjectMeta `json:"metadata,omitempty"`

// IP addresses of the Node.
IPAddresses []string `json:"ipAddresses"`
}

// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object

type NodeIPAddressBindingList struct {
metav1.TypeMeta `json:",inline"`
// +optional
metav1.ListMeta `json:"metadata,omitempty"`

Items []NodeIPAddressBinding `json:"items"`
}
Loading

0 comments on commit 9c0f7ed

Please sign in to comment.