TenantManager_impl_k8s_anywhere #47
							
								
								
									
										15
									
								
								Cargo.lock
									
									
									
										generated
									
									
									
								
							
							
						
						
									
										15
									
								
								Cargo.lock
									
									
									
										generated
									
									
									
								
							@ -1070,6 +1070,21 @@ dependencies = [
 | 
				
			|||||||
 "url",
 | 
					 "url",
 | 
				
			||||||
]
 | 
					]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					[[package]]
 | 
				
			||||||
 | 
					name = "example-tenant"
 | 
				
			||||||
 | 
					version = "0.1.0"
 | 
				
			||||||
 | 
					dependencies = [
 | 
				
			||||||
 | 
					 "cidr",
 | 
				
			||||||
 | 
					 "env_logger",
 | 
				
			||||||
 | 
					 "harmony",
 | 
				
			||||||
 | 
					 "harmony_cli",
 | 
				
			||||||
 | 
					 "harmony_macros",
 | 
				
			||||||
 | 
					 "harmony_types",
 | 
				
			||||||
 | 
					 "log",
 | 
				
			||||||
 | 
					 "tokio",
 | 
				
			||||||
 | 
					 "url",
 | 
				
			||||||
 | 
					]
 | 
				
			||||||
 | 
					
 | 
				
			||||||
[[package]]
 | 
					[[package]]
 | 
				
			||||||
name = "example-tui"
 | 
					name = "example-tui"
 | 
				
			||||||
version = "0.1.0"
 | 
					version = "0.1.0"
 | 
				
			||||||
 | 
				
			|||||||
							
								
								
									
										41
									
								
								adr/tenant/NetworkPolicy.yaml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										41
									
								
								adr/tenant/NetworkPolicy.yaml
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,41 @@
 | 
				
			|||||||
 | 
					apiVersion: networking.k8s.io/v1
 | 
				
			||||||
 | 
					kind: NetworkPolicy
 | 
				
			||||||
 | 
					metadata:
 | 
				
			||||||
 | 
					  name: tenant-isolation-policy
 | 
				
			||||||
 | 
					  namespace: testtenant
 | 
				
			||||||
 | 
					spec:
 | 
				
			||||||
 | 
					  podSelector: {}  # Selects all pods in the namespace
 | 
				
			||||||
 | 
					  policyTypes:
 | 
				
			||||||
 | 
					  - Ingress
 | 
				
			||||||
 | 
					  - Egress
 | 
				
			||||||
 | 
					  ingress:
 | 
				
			||||||
 | 
					  - from:
 | 
				
			||||||
 | 
					    - podSelector: {}  # Allow from all pods in the same namespace
 | 
				
			||||||
 | 
					  egress:
 | 
				
			||||||
 | 
					  - to:
 | 
				
			||||||
 | 
					    - podSelector: {}  # Allow to all pods in the same namespace
 | 
				
			||||||
 | 
					  - to:
 | 
				
			||||||
 | 
					    - podSelector: {}
 | 
				
			||||||
 | 
					      namespaceSelector: 
 | 
				
			||||||
 | 
					        matchLabels:
 | 
				
			||||||
 | 
					          kubernetes.io/metadata.name: openshift-dns # Target the openshift-dns namespace
 | 
				
			||||||
 | 
					    # Note, only opening port 53 is not enough, will have to dig deeper into this one eventually
 | 
				
			||||||
 | 
					    # ports:
 | 
				
			||||||
 | 
					    # - protocol: UDP
 | 
				
			||||||
 | 
					    #   port: 53
 | 
				
			||||||
 | 
					    # - protocol: TCP
 | 
				
			||||||
 | 
					    #   port: 53
 | 
				
			||||||
 | 
					  # Allow egress to public internet only
 | 
				
			||||||
 | 
					  - to:
 | 
				
			||||||
 | 
					    - ipBlock:
 | 
				
			||||||
 | 
					        cidr: 0.0.0.0/0
 | 
				
			||||||
 | 
					        except:
 | 
				
			||||||
 | 
					        - 10.0.0.0/8      # RFC1918
 | 
				
			||||||
 | 
					        - 172.16.0.0/12   # RFC1918
 | 
				
			||||||
 | 
					        - 192.168.0.0/16  # RFC1918
 | 
				
			||||||
 | 
					        - 169.254.0.0/16  # Link-local
 | 
				
			||||||
 | 
					        - 127.0.0.0/8     # Loopback
 | 
				
			||||||
 | 
					        - 224.0.0.0/4     # Multicast
 | 
				
			||||||
 | 
					        - 240.0.0.0/4     # Reserved
 | 
				
			||||||
 | 
					        - 100.64.0.0/10   # Carrier-grade NAT
 | 
				
			||||||
 | 
					        - 0.0.0.0/8       # Reserved
 | 
				
			||||||
							
								
								
									
										95
									
								
								adr/tenant/TestDeployment.yaml
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										95
									
								
								adr/tenant/TestDeployment.yaml
									
									
									
									
									
										Normal file
									
								
							@ -0,0 +1,95 @@
 | 
				
			|||||||
 | 
					apiVersion: v1
 | 
				
			||||||
 | 
					kind: Namespace
 | 
				
			||||||
 | 
					metadata:
 | 
				
			||||||
 | 
					  name: testtenant
 | 
				
			||||||
 | 
					---
 | 
				
			||||||
 | 
					apiVersion: v1
 | 
				
			||||||
 | 
					kind: Namespace
 | 
				
			||||||
 | 
					metadata:
 | 
				
			||||||
 | 
					  name: testtenant2
 | 
				
			||||||
 | 
					---
 | 
				
			||||||
 | 
					apiVersion: apps/v1
 | 
				
			||||||
 | 
					kind: Deployment
 | 
				
			||||||
 | 
					metadata:
 | 
				
			||||||
 | 
					  name: test-web
 | 
				
			||||||
 | 
					  namespace: testtenant
 | 
				
			||||||
 | 
					spec:
 | 
				
			||||||
 | 
					  replicas: 1
 | 
				
			||||||
 | 
					  selector:
 | 
				
			||||||
 | 
					    matchLabels:
 | 
				
			||||||
 | 
					      app: test-web
 | 
				
			||||||
 | 
					  template:
 | 
				
			||||||
 | 
					    metadata:
 | 
				
			||||||
 | 
					      labels:
 | 
				
			||||||
 | 
					        app: test-web
 | 
				
			||||||
 | 
					    spec:
 | 
				
			||||||
 | 
					      containers:
 | 
				
			||||||
 | 
					      - name: nginx
 | 
				
			||||||
 | 
					        image: nginxinc/nginx-unprivileged
 | 
				
			||||||
 | 
					        ports:
 | 
				
			||||||
 | 
					        - containerPort: 80
 | 
				
			||||||
 | 
					---
 | 
				
			||||||
 | 
					apiVersion: v1
 | 
				
			||||||
 | 
					kind: Service
 | 
				
			||||||
 | 
					metadata:
 | 
				
			||||||
 | 
					  name: test-web
 | 
				
			||||||
 | 
					  namespace: testtenant
 | 
				
			||||||
 | 
					spec:
 | 
				
			||||||
 | 
					  selector:
 | 
				
			||||||
 | 
					    app: test-web
 | 
				
			||||||
 | 
					  ports:
 | 
				
			||||||
 | 
					  - port: 80
 | 
				
			||||||
 | 
					    targetPort: 8080
 | 
				
			||||||
 | 
					---
 | 
				
			||||||
 | 
					apiVersion: apps/v1
 | 
				
			||||||
 | 
					kind: Deployment
 | 
				
			||||||
 | 
					metadata:
 | 
				
			||||||
 | 
					  name: test-client
 | 
				
			||||||
 | 
					  namespace: testtenant
 | 
				
			||||||
 | 
					spec:
 | 
				
			||||||
 | 
					  replicas: 1
 | 
				
			||||||
 | 
					  selector:
 | 
				
			||||||
 | 
					    matchLabels:
 | 
				
			||||||
 | 
					      app: test-client
 | 
				
			||||||
 | 
					  template:
 | 
				
			||||||
 | 
					    metadata:
 | 
				
			||||||
 | 
					      labels:
 | 
				
			||||||
 | 
					        app: test-client
 | 
				
			||||||
 | 
					    spec:
 | 
				
			||||||
 | 
					      containers:
 | 
				
			||||||
 | 
					      - name: curl
 | 
				
			||||||
 | 
					        image: curlimages/curl:latest
 | 
				
			||||||
 | 
					        command: ["/bin/sh", "-c", "sleep 3600"]
 | 
				
			||||||
 | 
					---
 | 
				
			||||||
 | 
					apiVersion: apps/v1
 | 
				
			||||||
 | 
					kind: Deployment
 | 
				
			||||||
 | 
					metadata:
 | 
				
			||||||
 | 
					  name: test-web
 | 
				
			||||||
 | 
					  namespace: testtenant2
 | 
				
			||||||
 | 
					spec:
 | 
				
			||||||
 | 
					  replicas: 1
 | 
				
			||||||
 | 
					  selector:
 | 
				
			||||||
 | 
					    matchLabels:
 | 
				
			||||||
 | 
					      app: test-web
 | 
				
			||||||
 | 
					  template:
 | 
				
			||||||
 | 
					    metadata:
 | 
				
			||||||
 | 
					      labels:
 | 
				
			||||||
 | 
					        app: test-web
 | 
				
			||||||
 | 
					    spec:
 | 
				
			||||||
 | 
					      containers:
 | 
				
			||||||
 | 
					      - name: nginx
 | 
				
			||||||
 | 
					        image: nginxinc/nginx-unprivileged
 | 
				
			||||||
 | 
					        ports:
 | 
				
			||||||
 | 
					        - containerPort: 80
 | 
				
			||||||
 | 
					---
 | 
				
			||||||
 | 
					apiVersion: v1
 | 
				
			||||||
 | 
					kind: Service
 | 
				
			||||||
 | 
					metadata:
 | 
				
			||||||
 | 
					  name: test-web
 | 
				
			||||||
 | 
					  namespace: testtenant2
 | 
				
			||||||
 | 
					spec:
 | 
				
			||||||
 | 
					  selector:
 | 
				
			||||||
 | 
					    app: test-web
 | 
				
			||||||
 | 
					  ports:
 | 
				
			||||||
 | 
					  - port: 80
 | 
				
			||||||
 | 
					    targetPort: 8080
 | 
				
			||||||
@ -16,3 +16,9 @@ impl std::fmt::Display for Id {
 | 
				
			|||||||
        f.write_str(&self.value)
 | 
					        f.write_str(&self.value)
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					impl Default for Id {
 | 
				
			||||||
 | 
					    fn default() -> Self {
 | 
				
			||||||
 | 
					        todo!()
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
				
			|||||||
@ -27,6 +27,28 @@ pub struct TenantConfig {
 | 
				
			|||||||
    pub labels_or_tags: HashMap<String, String>,
 | 
					    pub labels_or_tags: HashMap<String, String>,
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					impl Default for TenantConfig {
 | 
				
			||||||
 | 
					    fn default() -> Self {
 | 
				
			||||||
 | 
					        let id = Id::default();
 | 
				
			||||||
 | 
					        Self {
 | 
				
			||||||
 | 
					            name: format!("tenant_{id}"),
 | 
				
			||||||
 | 
					            id,
 | 
				
			||||||
 | 
					            resource_limits: ResourceLimits {
 | 
				
			||||||
 | 
					                cpu_request_cores: 4.0,
 | 
				
			||||||
 | 
					                cpu_limit_cores: 4.0,
 | 
				
			||||||
 | 
					                memory_request_gb: 4.0,
 | 
				
			||||||
 | 
					                memory_limit_gb: 4.0,
 | 
				
			||||||
 | 
					                storage_total_gb: 20.0,
 | 
				
			||||||
 | 
					            },
 | 
				
			||||||
 | 
					            network_policy: TenantNetworkPolicy {
 | 
				
			||||||
 | 
					                default_inter_tenant_ingress: InterTenantIngressPolicy::DenyAll,
 | 
				
			||||||
 | 
					                default_internet_egress: InternetEgressPolicy::AllowAll,
 | 
				
			||||||
 | 
					            },
 | 
				
			||||||
 | 
					            labels_or_tags: HashMap::new(),
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, Default)]
 | 
					#[derive(Debug, Clone, PartialEq, Serialize, Deserialize, Default)]
 | 
				
			||||||
pub struct ResourceLimits {
 | 
					pub struct ResourceLimits {
 | 
				
			||||||
    /// Requested/guaranteed CPU cores (e.g., 2.0).
 | 
					    /// Requested/guaranteed CPU cores (e.g., 2.0).
 | 
				
			||||||
 | 
				
			|||||||
@ -14,7 +14,7 @@ use crate::{
 | 
				
			|||||||
 | 
					
 | 
				
			||||||
#[derive(Debug, Serialize, Clone)]
 | 
					#[derive(Debug, Serialize, Clone)]
 | 
				
			||||||
pub struct TenantScore {
 | 
					pub struct TenantScore {
 | 
				
			||||||
    config: TenantConfig,
 | 
					    pub config: TenantConfig,
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
impl<T: Topology + TenantManager> Score<T> for TenantScore {
 | 
					impl<T: Topology + TenantManager> Score<T> for TenantScore {
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
		Reference in New Issue
	
	Block a user