@@ -31,19 +31,73 @@ limitations under the License.
3131package v1alpha1
3232
3333import (
34+ corev1 "k8s.io/api/core/v1"
3435 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
3536 sandboxv1alpha1 "sigs.k8s.io/agent-sandbox/api/v1alpha1"
3637)
3738
3839// NOTE: json tags are required. Any new fields you add must have json tags for the fields to be serialized.
3940// Important: Run "make" to regenerate code after modifying this file
4041
42+ // NetworkPolicySpec defines the desired state of the NetworkPolicy.
43+ type NetworkPolicySpec struct {
44+ Enabled bool `json:"enabled,omitempty"`
45+ IngressControllerSelectors * IngressSelector `json:"ingressControllerSelectors,omitempty"`
46+ IngressFromIPBlocks []IPBlock `json:"ingressFromIPBlocks,omitempty"`
47+ AdditionalIngressRules []IngressRule `json:"additionalIngressRules,omitempty"`
48+ AdditionalEgressRules []EgressRule `json:"additionalEgressRules,omitempty"`
49+ }
50+
51+ // IngressSelector defines selectors for an in-cluster ingress controller.
52+ type IngressSelector struct {
53+ NamespaceSelector map [string ]string `json:"namespaceSelector,omitempty"`
54+ PodSelector map [string ]string `json:"podSelector,omitempty"`
55+ }
56+
57+ // IPBlock defines a CIDR block for ingress or egress rules.
58+ type IPBlock struct {
59+ CIDR string `json:"cidr,omitempty"`
60+ }
61+
62+ // EgressRule defines a single egress rule.
63+ type EgressRule struct {
64+ Description string `json:"description,omitempty"`
65+ ToIPBlock * IPBlockWithExcept `json:"toIPBlock,omitempty"`
66+ ToPodSelector map [string ]string `json:"toPodSelector,omitempty"`
67+ InNamespaceSelector map [string ]string `json:"inNamespaceSelector,omitempty"`
68+ Ports []NetworkPort `json:"ports,omitempty"`
69+ }
70+
71+ // IngressRule defines a single ingress rule from another pod.
72+ type IngressRule struct {
73+ Description string `json:"description,omitempty"`
74+ FromPodSelector map [string ]string `json:"fromPodSelector,omitempty"`
75+ InNamespaceSelector map [string ]string `json:"inNamespaceSelector,omitempty"`
76+ }
77+
78+ // IPBlockWithExcept is for egress rules that need an "except" clause.
79+ type IPBlockWithExcept struct {
80+ CIDR string `json:"cidr,omitempty"`
81+ Except []string `json:"except,omitempty"`
82+ }
83+
84+ // NetworkPort defines a port for a network policy rule.
85+ type NetworkPort struct {
86+ Protocol * corev1.Protocol `json:"protocol,omitempty"`
87+ Port * int32 `json:"port,omitempty"`
88+ }
89+
4190// SandboxTemplateSpec defines the desired state of Sandbox
4291type SandboxTemplateSpec struct {
4392 // template is the object that describes the pod spec that will be used to create
4493 // an agent sandbox.
4594 // +kubebuilder:validation:Required
4695 PodTemplate sandboxv1alpha1.PodTemplate `json:"podTemplate" protobuf:"bytes,3,opt,name=podTemplate"`
96+
97+ // NetworkPolicy defines the network policy to be applied to the sandboxes
98+ // created from this template.
99+ // +optional
100+ NetworkPolicy * NetworkPolicySpec `json:"networkPolicy,omitempty"`
47101}
48102
49103// SandboxTemplateStatus defines the observed state of Sandbox.
0 commit comments