|
| 1 | +/* |
| 2 | +Copyright Amazon.com Inc. or its affiliates. All Rights Reserved. |
| 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 v1alpha1 |
| 18 | + |
| 19 | +import ( |
| 20 | + metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" |
| 21 | +) |
| 22 | + |
| 23 | +// Tier defines the tier of the admin policy |
| 24 | +// +kubebuilder:validation:Enum={"Admin", "Baseline"} |
| 25 | +type Tier string |
| 26 | + |
| 27 | +const ( |
| 28 | + // AdminTier |
| 29 | + AdminTier Tier = "Admin" |
| 30 | + // BaselineTier |
| 31 | + BaselineTier Tier = "Baseline" |
| 32 | +) |
| 33 | + |
| 34 | +// ClusterPolicyAction defines the action to be applied by the admin policy |
| 35 | +// +kubebuilder:validation:Enum={"Accept", "Deny", "Pass"} |
| 36 | + |
| 37 | +type ClusterNetworkPolicyRuleAction string |
| 38 | + |
| 39 | +const ( |
| 40 | + ClusterNetworkPolicyRuleActionAccept ClusterNetworkPolicyRuleAction = "Accept" |
| 41 | + ClusterNetworkPolicyRuleActionDeny ClusterNetworkPolicyRuleAction = "Deny" |
| 42 | + ClusterNetworkPolicyRuleActionPass ClusterNetworkPolicyRuleAction = "Pass" |
| 43 | +) |
| 44 | + |
| 45 | +// ClusterPolicyReference is the reference to the admin network policy resource |
| 46 | +type ClusterPolicyReference struct { |
| 47 | + // Name is the name of the ClusterNetworkPolicy |
| 48 | + Name string `json:"name"` |
| 49 | +} |
| 50 | + |
| 51 | +// EndpointInfo defines the network endpoint information for the policy ingress/egress |
| 52 | +type ClusterEndpointInfo struct { |
| 53 | + |
| 54 | + // CIDR is the network address(s) of the endpoint |
| 55 | + CIDR NetworkAddress `json:"cidr,omitempty"` |
| 56 | + |
| 57 | + // Ports is the list of ports |
| 58 | + Ports []Port `json:"ports,omitempty"` |
| 59 | + |
| 60 | + // DomainName is the FQDN for the endpoint (egress-only) |
| 61 | + DomainName DomainName `json:"domainName,omitempty"` |
| 62 | + |
| 63 | + // Action from the CNP rule |
| 64 | + Action ClusterNetworkPolicyRuleAction `json:"action"` |
| 65 | +} |
| 66 | + |
| 67 | +// ClusterPolicyEndpointSpec defines the desired state of ClusterPolicyEndpoint |
| 68 | +type ClusterPolicyEndpointSpec struct { |
| 69 | + |
| 70 | + // PolicyRef is a reference to the Kubernetes AdminNetworkPolicy resource. |
| 71 | + PolicyRef ClusterPolicyReference `json:"policyRef"` |
| 72 | + |
| 73 | + // Tier defines the type of admin policy |
| 74 | + Tier Tier `json:"tier"` |
| 75 | + |
| 76 | + // Priority is the priority of the admin policy endpoint |
| 77 | + Priority int32 `json:"priority"` |
| 78 | + |
| 79 | + // PodSelectorEndpoints contains information about the pods |
| 80 | + // matching the podSelector |
| 81 | + PodSelectorEndpoints []PodEndpoint `json:"podSelectorEndpoints,omitempty"` |
| 82 | + |
| 83 | + // Ingress is the list of ingress rules containing resolved network addresses |
| 84 | + Ingress []ClusterEndpointInfo `json:"ingress,omitempty"` |
| 85 | + |
| 86 | + // Egress is the list of egress rules containing resolved network addresses |
| 87 | + Egress []ClusterEndpointInfo `json:"egress,omitempty"` |
| 88 | +} |
| 89 | + |
| 90 | +// ClusterPolicyEndpointStatus defines the observed state of ClusterPolicyEndpoint |
| 91 | +type ClusterPolicyEndpointStatus struct { |
| 92 | + // INSERT ADDITIONAL STATUS FIELD - define observed state of cluster |
| 93 | + // Important: Run "make" to regenerate code after modifying this file |
| 94 | +} |
| 95 | + |
| 96 | +//+kubebuilder:object:root=true |
| 97 | +//+kubebuilder:subresource:status |
| 98 | +//+kubebuilder:resource:scope=Cluster |
| 99 | + |
| 100 | +// ClusterPolicyEndpoint is the Schema for the ClusterPolicyendpoints API |
| 101 | +type ClusterPolicyEndpoint struct { |
| 102 | + metav1.TypeMeta `json:",inline"` |
| 103 | + metav1.ObjectMeta `json:"metadata,omitempty"` |
| 104 | + |
| 105 | + Spec ClusterPolicyEndpointSpec `json:"spec,omitempty"` |
| 106 | + Status ClusterPolicyEndpointStatus `json:"status,omitempty"` |
| 107 | +} |
| 108 | + |
| 109 | +//+kubebuilder:object:root=true |
| 110 | + |
| 111 | +// ClusterPolicyEndpointList contains a list of ClusterPolicyEndpoint |
| 112 | +type ClusterPolicyEndpointList struct { |
| 113 | + metav1.TypeMeta `json:",inline"` |
| 114 | + metav1.ListMeta `json:"metadata,omitempty"` |
| 115 | + Items []ClusterPolicyEndpoint `json:"items"` |
| 116 | +} |
| 117 | + |
| 118 | +func init() { |
| 119 | + SchemeBuilder.Register(&ClusterPolicyEndpoint{}, &ClusterPolicyEndpointList{}) |
| 120 | +} |
0 commit comments