Skip to content

Commit aa90250

Browse files
committed
first commit with changes
1 parent 1647159 commit aa90250

File tree

5 files changed

+334
-3
lines changed

5 files changed

+334
-3
lines changed

hack/update-codegen.sh

+3-3
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,15 @@ set -o nounset
1919
set -o pipefail
2020

2121
SCRIPT_ROOT=$(dirname "${BASH_SOURCE[0]}")/..
22-
CODEGEN_PKG=${CODEGEN_PKG:-$(cd "${SCRIPT_ROOT}"; ls -d -1 ./vendor/k8s.io/code-generator 2>/dev/null || echo ../code-generator)}
23-
22+
#CODEGEN_PKG=${CODEGEN_PKG:-$(cd "${SCRIPT_ROOT}"; ls -d -1 ./vendor/k8s.io/code-generator 2>/dev/null || echo ../code-generator)}
23+
CODEGEN_PKG=$GOPATH/src/k8s.io/code-generator
2424
# generate the code with:
2525
# --output-base because this script should also be able to run inside the vendor dir of
2626
# k8s.io/kubernetes. The output-base is needed for the generators to output into the vendor dir
2727
# instead of the $GOPATH directly. For normal projects this can be dropped.
2828
"${CODEGEN_PKG}"/generate-groups.sh "deepcopy,client,informer,lister" \
2929
k8s.io/sample-controller/pkg/generated k8s.io/sample-controller/pkg/apis \
30-
samplecontroller:v1alpha1 \
30+
polycubenetworkpolicy:v1abeta1 \
3131
--output-base "$(dirname "${BASH_SOURCE[0]}")/../../.." \
3232
--go-header-file "${SCRIPT_ROOT}"/hack/boilerplate.go.txt
3333

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
/*
2+
Copyright 2017 The Kubernetes Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package polycubenetworkpolicy
18+
19+
// GroupName is the group name used in this package
20+
const (
21+
GroupName = "polycubenetwork.com"
22+
)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
/*
2+
Copyright 2017 The Kubernetes Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
// +k8s:deepcopy-gen=package
18+
// +groupName=polycubenetwork.com
19+
20+
// Package v1beta1 is the v1beta1 version of the API.
21+
package v1beta1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/*
2+
Copyright 2017 The Kubernetes Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package v1beta1
18+
19+
import (
20+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
21+
"k8s.io/apimachinery/pkg/runtime"
22+
"k8s.io/apimachinery/pkg/runtime/schema"
23+
24+
polycubenetworkpolicy "github.com/SunSince90/sample-controller"
25+
)
26+
27+
// SchemeGroupVersion is group version used to register these objects
28+
var SchemeGroupVersion = schema.GroupVersion{Group: polycubenetworkpolicy.GroupName, Version: "v1beta1"}
29+
30+
// Kind takes an unqualified kind and returns back a Group qualified GroupKind
31+
func Kind(kind string) schema.GroupKind {
32+
return SchemeGroupVersion.WithKind(kind).GroupKind()
33+
}
34+
35+
// Resource takes an unqualified resource and returns a Group qualified GroupResource
36+
func Resource(resource string) schema.GroupResource {
37+
return SchemeGroupVersion.WithResource(resource).GroupResource()
38+
}
39+
40+
var (
41+
// SchemeBuilder initializes a scheme builder
42+
SchemeBuilder = runtime.NewSchemeBuilder(addKnownTypes)
43+
// AddToScheme is a global function that registers this API group & version to a scheme
44+
AddToScheme = SchemeBuilder.AddToScheme
45+
)
46+
47+
// Adds the list of known types to Scheme.
48+
func addKnownTypes(scheme *runtime.Scheme) error {
49+
scheme.AddKnownTypes(SchemeGroupVersion,
50+
&PolycubeNetworkPolicy{},
51+
&PolycubeNetworkPolicyList{},
52+
)
53+
metav1.AddToGroupVersion(scheme, SchemeGroupVersion)
54+
return nil
55+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,233 @@
1+
package v1beta1
2+
3+
import metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
4+
5+
// +genclient
6+
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
7+
8+
// PolycubeNetworkPolicy is a network policy handled by polycube
9+
type PolycubeNetworkPolicy struct {
10+
metav1.TypeMeta `json:",inline"`
11+
// +optional
12+
metav1.ObjectMeta `json:"metadata,omitempty"`
13+
// ApplyTo defines who this policy is intended for
14+
ApplyTo PolycubeNetworkPolicyTarget `json:"applyTo,omitempty"`
15+
// Spec of this policy
16+
Spec PolycubeNetworkPolicySpec `json:"spec,omitempty"`
17+
}
18+
19+
// PolycubeNetworkPolicyTarget is the target of this policy
20+
type PolycubeNetworkPolicyTarget struct {
21+
// Target is the object that should enforce this policy
22+
Target PolycubeNetworkPolicyTargetObject `json:"target,omitempty"`
23+
// +optional
24+
// If name and labels are irrelevant
25+
Any *bool `json:"any,omitempty"`
26+
// +optional
27+
// WithName specifies the name of the object. Valid only for Service
28+
WithName string `json:"withName,omitempty"`
29+
// +optional
30+
// WithLabels specifies the labels of the target. Valid only for Pod
31+
WithLabels map[string]string `json:"withLabels,omitempty"`
32+
}
33+
34+
// PolycubeNetworkPolicyTargetObject is the target object
35+
type PolycubeNetworkPolicyTargetObject string
36+
37+
const (
38+
// PodTarget represents a Pod
39+
PodTarget PolycubeNetworkPolicyTargetObject = "pod"
40+
// ServiceTarget represents a Service
41+
ServiceTarget PolycubeNetworkPolicyTargetObject = "service"
42+
)
43+
44+
// PolycubeNetworkPolicySpec contains the specifications of this Network Policy
45+
type PolycubeNetworkPolicySpec struct {
46+
// +optional
47+
// Description is the description of the policy
48+
Description string `json:"description,omitempty"`
49+
// +optional
50+
// IngressRules contains the ingress rules
51+
IngressRules PolycubeNetworkPolicyIngressRuleContainer `json:"ingressRules,omitempty"`
52+
// +optional
53+
// EgressRules contains the egress rules
54+
EngressRules PolycubeNetworkPolicyEgressRuleContainer `json:"egressRules,omitempty"`
55+
}
56+
57+
// PolycubeNetworkPolicyIngressRuleContainer is a container of ingress rules
58+
type PolycubeNetworkPolicyIngressRuleContainer struct {
59+
// +optional
60+
// DropAll specifies to drop everything in ingress
61+
DropAll *bool `json:"dropAll,omitempty"`
62+
// +optional
63+
// AllowAll specifies to allow anyone in ingress
64+
AllowAll *bool `json:"allowAll,omitempty"`
65+
// +optional
66+
// Rules is a list of ingress rules
67+
Rules []PolycubeNetworkPolicyIngressRule `json:"rules,omitempty"`
68+
}
69+
70+
// PolycubeNetworkPolicyEgressRuleContainer is a container of egress rules
71+
type PolycubeNetworkPolicyEgressRuleContainer struct {
72+
// +optional
73+
// DropAll specifies to drop everything in egress
74+
DropAll *bool `json:"dropAll,omitempty"`
75+
// +optional
76+
// AllowAll specifies to allow anyone in egress
77+
AllowAll *bool `json:"allowAll,omitempty"`
78+
// +optional
79+
// Rules is a list of egress rules
80+
Rules []PolycubeNetworkPolicyEgressRule `json:"rules,omitempty"`
81+
}
82+
83+
// PolycubeNetworkPolicyIngressRule is an ingress rule
84+
type PolycubeNetworkPolicyIngressRule struct {
85+
// From is the peer
86+
From PolycubeNetworkPolicyPeer `json:"from,omitempty"`
87+
// Protocols is the level 4 protocol list
88+
Protocols []PolycubeNetworkPolicyProtocolContainer `json:"protocols,omitempty"`
89+
// TCPFlags is a list of TCP flags
90+
TCPFlags []PolycubeNetworkPolicyTCPFlag `json:"tcpflags,omitempty"`
91+
// Action is the action to be taken
92+
Action PolycubeNetworkPolicyRuleAction `json:"action,omitempty"`
93+
// Description is the description of the rule
94+
Description string `json:"description,omitempty"`
95+
}
96+
97+
// PolycubeNetworkPolicyProtocolContainer contains the protocol details
98+
type PolycubeNetworkPolicyProtocolContainer struct {
99+
// Ports is the container of the ports
100+
Ports PolycubeNetworkPolicyPorts `json:"ports,omitempty"`
101+
// Protocol is the l4 protocol
102+
Protocol PolycubeNetworkPolicyProtocol
103+
}
104+
105+
// PolycubeNetworkPolicyEgressRule the rule for egress
106+
type PolycubeNetworkPolicyEgressRule struct {
107+
// To is the peer
108+
To PolycubeNetworkPolicyPeer `json:"to,omitempty"`
109+
// Protocols is the protocols list
110+
Protocols []PolycubeNetworkPolicyProtocolContainer `json:"protocols,omitempty"`
111+
// TCPFlags is a list of TCP flags
112+
TCPFlags []PolycubeNetworkPolicyTCPFlag `json:"tcpflags,omitempty"`
113+
// Action is the action to be taken
114+
Action PolycubeNetworkPolicyRuleAction `json:"action,omitempty"`
115+
// Description is the description of the rule
116+
Description string `json:"description,omitempty"`
117+
}
118+
119+
// PolycubeNetworkPolicyPeer contains data of the peer
120+
type PolycubeNetworkPolicyPeer struct {
121+
// Peer is the peer type
122+
Peer PolycubeNetworkPolicyPeerObject `json:"peer,omitempty"`
123+
// +optional
124+
// Any tells if name and labels don't matter
125+
Any *bool `json:"any,omitempty"`
126+
// +optional
127+
// WithName specifies the name of the object. Only for Service
128+
//WithName string `json:"withName,omitempty"`
129+
// +optional
130+
// WithLabels specifies the labels of the object. Only for Pod
131+
WithLabels map[string]string `json:"withLabels,omitempty"`
132+
// +optional
133+
// WithIP specifies the ip. Only for World
134+
WithIP PolycubeNetworkPolicyWithIP `json:"withIP,omitempty"`
135+
// +optional
136+
// OnNamespace specifies the namespaces of the peer. Only for Pod
137+
OnNamespace *PolycubeNetworkPolicyNamespaceSelector `json:"onNamespace,omitempty"`
138+
}
139+
140+
// PolycubeNetworkPolicyWithIP is the IP container
141+
type PolycubeNetworkPolicyWithIP struct {
142+
// List is a list of IPs in CIDR notation
143+
List []string `json:"list,omitempty"`
144+
}
145+
146+
// PolycubeNetworkPolicyPeerObject is the object peer
147+
type PolycubeNetworkPolicyPeerObject string
148+
149+
const (
150+
// ServicePeer is the Service
151+
ServicePeer PolycubeNetworkPolicyPeerObject = "service"
152+
// PodPeer is the Pod
153+
PodPeer PolycubeNetworkPolicyPeerObject = "pod"
154+
// WorldPeer is the World
155+
WorldPeer PolycubeNetworkPolicyPeerObject = "world"
156+
)
157+
158+
// PolycubeNetworkPolicyNamespaceSelector is a selector for namespaces
159+
type PolycubeNetworkPolicyNamespaceSelector struct {
160+
// +optional
161+
// WithName is a list of the names of the namespace
162+
WithNames []string `json:"withNames,omitempty"`
163+
// +optional
164+
// WithLabels is the namespace's labels
165+
WithLabels map[string]string `json:"withLabels,omitempty"`
166+
// +optional
167+
// Any specifies any namespace
168+
Any *bool `json:"any,omitempty"`
169+
}
170+
171+
// PolycubeNetworkPolicyProtocol is the level 4 protocol
172+
type PolycubeNetworkPolicyProtocol string
173+
174+
const (
175+
// TCP is TCP
176+
TCP PolycubeNetworkPolicyProtocol = "tcp"
177+
// UDP is UDP
178+
UDP PolycubeNetworkPolicyProtocol = "udp"
179+
// ICMP is ICMPv4
180+
ICMP PolycubeNetworkPolicyProtocol = "icmp"
181+
)
182+
183+
// PolycubeNetworkPolicyPorts contains the ports
184+
type PolycubeNetworkPolicyPorts struct {
185+
// +optional
186+
// Source is the source port
187+
Source int32 `json:"source,omitempty"`
188+
// Destination is the destination port
189+
Destination int32 `json:"destination,omitempty"`
190+
}
191+
192+
// PolycubeNetworkPolicyTCPFlag is the TCP flag
193+
type PolycubeNetworkPolicyTCPFlag string
194+
195+
const (
196+
// SYNFlag is SYN
197+
SYNFlag PolycubeNetworkPolicyTCPFlag = "SYN"
198+
// FINFlag is FIN
199+
FINFlag PolycubeNetworkPolicyTCPFlag = "FIN"
200+
// ACKFlag is ACK
201+
ACKFlag PolycubeNetworkPolicyTCPFlag = "ACK"
202+
// RSTFlag is RST
203+
RSTFlag PolycubeNetworkPolicyTCPFlag = "RST"
204+
// PSHFlag is PSH
205+
PSHFlag PolycubeNetworkPolicyTCPFlag = "PSH"
206+
// URGFlag is URG
207+
URGFlag PolycubeNetworkPolicyTCPFlag = "URG"
208+
// CWRFlag is CWR
209+
CWRFlag PolycubeNetworkPolicyTCPFlag = "CWR"
210+
// ECEFlag is ECE
211+
ECEFlag PolycubeNetworkPolicyTCPFlag = "ECE"
212+
)
213+
214+
// PolycubeNetworkPolicyRuleAction is the action
215+
type PolycubeNetworkPolicyRuleAction string
216+
217+
const (
218+
// DropAction is DROP
219+
DropAction PolycubeNetworkPolicyRuleAction = "drop"
220+
// AllowAction is Forward
221+
AllowAction PolycubeNetworkPolicyRuleAction = "forward"
222+
)
223+
224+
// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object
225+
226+
// PolycubeNetworkPolicyList contains a list of Network Policies.
227+
type PolycubeNetworkPolicyList struct {
228+
metav1.TypeMeta `json:",inline"`
229+
// +optional
230+
metav1.ListMeta `son:"metadata,omitempty"`
231+
// Items contains the network policies
232+
Items []PolycubeNetworkPolicy `json:"items"`
233+
}

0 commit comments

Comments
 (0)