Skip to content

Commit 11cc35f

Browse files
committed
feat: Embed NetworkPolicy to extensions
1 parent 4d63bf1 commit 11cc35f

File tree

8 files changed

+764
-41
lines changed

8 files changed

+764
-41
lines changed

extensions/api/v1alpha1/sandboxtemplate_types.go

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,65 @@ import (
3838
// NOTE: json tags are required. Any new fields you add must have json tags for the fields to be serialized.
3939
// Important: Run "make" to regenerate code after modifying this file
4040

41+
// NetworkPolicySpec defines the desired state of the NetworkPolicy.
42+
type NetworkPolicySpec struct {
43+
Enabled bool `json:"enabled,omitempty"`
44+
IngressControllerSelectors *IngressSelector `json:"ingressControllerSelectors,omitempty"`
45+
IngressFromIPBlocks []IPBlock `json:"ingressFromIPBlocks,omitempty"`
46+
AdditionalIngressRules []IngressRule `json:"additionalIngressRules,omitempty"`
47+
AdditionalEgressRules []EgressRule `json:"additionalEgressRules,omitempty"`
48+
}
49+
50+
// IngressSelector defines selectors for an in-cluster ingress controller.
51+
type IngressSelector struct {
52+
NamespaceSelector map[string]string `json:"namespaceSelector,omitempty"`
53+
PodSelector map[string]string `json:"podSelector,omitempty"`
54+
}
55+
56+
// IPBlock defines a CIDR block for ingress or egress rules.
57+
type IPBlock struct {
58+
CIDR string `json:"cidr,omitempty"`
59+
}
60+
61+
// EgressRule defines a single egress rule.
62+
type EgressRule struct {
63+
Description string `json:"description,omitempty"`
64+
ToIPBlock *IPBlockWithExcept `json:"toIPBlock,omitempty"`
65+
ToPodSelector map[string]string `json:"toPodSelector,omitempty"`
66+
InNamespaceSelector map[string]string `json:"inNamespaceSelector,omitempty"`
67+
Ports []NetworkPort `json:"ports,omitempty"`
68+
}
69+
70+
// IngressRule defines a single ingress rule from another pod.
71+
type IngressRule struct {
72+
Description string `json:"description,omitempty"`
73+
FromPodSelector map[string]string `json:"fromPodSelector,omitempty"`
74+
InNamespaceSelector map[string]string `json:"inNamespaceSelector,omitempty"`
75+
}
76+
77+
// IPBlockWithExcept is for egress rules that need an "except" clause.
78+
type IPBlockWithExcept struct {
79+
CIDR string `json:"cidr,omitempty"`
80+
Except []string `json:"except,omitempty"`
81+
}
82+
83+
// NetworkPort defines a port for a network policy rule.
84+
type NetworkPort struct {
85+
Protocol *corev1.Protocol `json:"protocol,omitempty"`
86+
Port *int32 `json:"port,omitempty"`
87+
}
88+
4189
// SandboxTemplateSpec defines the desired state of Sandbox
4290
type SandboxTemplateSpec struct {
4391
// template is the object that describes the pod spec that will be used to create
4492
// an agent sandbox.
4593
// +kubebuilder:validation:Required
4694
PodTemplate corev1.PodTemplateSpec `json:"podTemplate" protobuf:"bytes,3,opt,name=podTemplate"`
95+
96+
// NetworkPolicy defines the network policy to be applied to the sandboxes
97+
// created from this template.
98+
// +optional
99+
NetworkPolicy *NetworkPolicySpec `json:"networkPolicy,omitempty"`
47100
}
48101

49102
// SandboxTemplateStatus defines the observed state of Sandbox.

extensions/api/v1alpha1/zz_generated.deepcopy.go

Lines changed: 204 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)