Skip to content

Commit

Permalink
Merge pull request #20 from port-labs/PORT-5363-ui-create-default-res…
Browse files Browse the repository at this point in the history
…ources

Port 5363 UI create default resources
  • Loading branch information
yairsimantov20 authored Dec 27, 2023
2 parents b6c2412 + 7e18cab commit 2ad080c
Show file tree
Hide file tree
Showing 27 changed files with 1,290 additions and 141 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -23,3 +23,5 @@ __debug_bin
config.yaml

deployments/k8s

.env
106 changes: 106 additions & 0 deletions assets/defaults/appConfig.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
createMissingRelatedEntities: true
resources:
- kind: v1/namespaces
port:
entity:
mappings:
- blueprint: '"namespace"'
identifier: .metadata.name + "-" + env.CLUSTER_NAME
properties:
creationTimestamp: .metadata.creationTimestamp
labels: .metadata.labels
relations:
Cluster: env.CLUSTER_NAME
title: .metadata.name
selector:
query: .metadata.name | startswith("kube") | not
- kind: v1/namespaces
port:
entity:
mappings:
- blueprint: '"cluster"'
identifier: env.CLUSTER_NAME
title: env.CLUSTER_NAME
selector:
query: .metadata.name | contains("kube-system")
- kind: apps/v1/deployments
port:
entity:
mappings:
- blueprint: '"workload"'
icon: '"Deployment"'
identifier: .metadata.name + "-Deployment-" + .metadata.namespace + "-" + env.CLUSTER_NAME
properties:
images: '(.spec.template.spec.containers | map({name, image, resources})) | map("\(.name): \(.image)")'
availableReplicas: .status.availableReplicas
containers: (.spec.template.spec.containers | map({name, image, resources}))
creationTimestamp: .metadata.creationTimestamp
hasLatest: .spec.template.spec.containers[].image | contains(":latest")
hasLimits: .spec.template.spec.containers | all(has("resources") and (.resources.limits.memory
and .resources.limits.cpu))
hasPrivileged: .spec.template.spec.containers | [.[].securityContext.privileged]
| any
isHealthy: if .spec.replicas == .status.availableReplicas then "Healthy"
else "Unhealthy" end
kind: '"Deployment"'
labels: .metadata.labels
replicas: .spec.replicas
strategy: .spec.strategy.type
strategyConfig: .spec.strategy // {}
relations:
Namespace: .metadata.namespace + "-" + env.CLUSTER_NAME
title: .metadata.name
selector:
query: .metadata.namespace | startswith("kube") | not
- kind: apps/v1/daemonsets
port:
entity:
mappings:
- blueprint: '"workload"'
identifier: .metadata.name + "-DaemonSet-" + .metadata.namespace + "-" + env.CLUSTER_NAME
properties:
availableReplicas: .status.availableReplicas
containers: (.spec.template.spec.containers | map({name, image, resources}))
creationTimestamp: .metadata.creationTimestamp
hasLatest: .spec.template.spec.containers[].image | contains(":latest")
hasLimits: .spec.template.spec.containers | all(has("resources") and (.resources.limits.memory
and .resources.limits.cpu))
hasPrivileged: .spec.template.spec.containers | [.[].securityContext.privileged]
| any
isHealthy: if .spec.replicas == .status.availableReplicas then "Healthy"
else "Unhealthy" end
kind: '"DaemonSet"'
labels: .metadata.labels
replicas: .spec.replicas
strategyConfig: .spec.strategy // {}
relations:
Namespace: .metadata.namespace + "-" + env.CLUSTER_NAME
title: .metadata.name
selector:
query: .metadata.namespace | startswith("kube") | not
- kind: apps/v1/statefulsets
port:
entity:
mappings:
- blueprint: '"workload"'
identifier: .metadata.name + "-StatefulSet-" + .metadata.namespace + "-" + env.CLUSTER_NAME
properties:
availableReplicas: .status.availableReplicas
containers: (.spec.template.spec.containers | map({name, image, resources}))
creationTimestamp: .metadata.creationTimestamp
hasLatest: .spec.template.spec.containers[].image | contains(":latest")
hasLimits: .spec.template.spec.containers | all(has("resources") and (.resources.limits.memory
and .resources.limits.cpu))
hasPrivileged: .spec.template.spec.containers | [.[].securityContext.privileged]
| any
isHealthy: if .spec.replicas == .status.availableReplicas then "Healthy"
else "Unhealthy" end
kind: '"StatefulSet"'
labels: .metadata.labels
replicas: .spec.replicas
strategyConfig: .spec.strategy // {}
relations:
Namespace: .metadata.namespace + "-" + env.CLUSTER_NAME
title: .metadata.name
selector:
query: .metadata.namespace | startswith("kube") | not
151 changes: 151 additions & 0 deletions assets/defaults/blueprints.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
[
{
"identifier": "cluster",
"description": "This blueprint represents a Kubernetes Cluster",
"title": "Cluster",
"icon": "Cluster",
"schema": {
"properties": {},
"required": []
},
"mirrorProperties": {},
"calculationProperties": {},
"relations": {}
},
{
"identifier": "namespace",
"description": "This blueprint represents a k8s Namespace",
"title": "Namespace",
"icon": "Environment",
"schema": {
"properties": {
"creationTimestamp": {
"type": "string",
"title": "Created",
"format": "date-time",
"description": "When the Namespace was created"
},
"labels": {
"type": "object",
"title": "Labels",
"description": "Labels of the Namespace"
}
},
"required": []
},
"mirrorProperties": {},
"calculationProperties": {},
"relations": {
"Cluster": {
"title": "Cluster",
"description": "The namespace's Kubernetes cluster",
"target": "cluster",
"required": false,
"many": false
}
}
},
{
"identifier": "workload",
"description": "This blueprint represents a k8s Workload. This includes all k8s objects which can create pods (deployments[replicasets], daemonsets, statefulsets...)",
"title": "Workload",
"icon": "Deployment",
"schema": {
"properties": {
"availableReplicas": {
"type": "number",
"title": "Running Replicas",
"description": "Current running replica count"
},
"containers": {
"type": "array",
"title": "Containers",
"default": [],
"description": "The containers for each pod instance of the Workload"
},
"creationTimestamp": {
"type": "string",
"title": "Created",
"format": "date-time",
"description": "When the Workload was created"
},
"labels": {
"type": "object",
"title": "Labels",
"description": "Labels of the Workload"
},
"replicas": {
"type": "number",
"title": "Wanted Replicas",
"description": "Wanted replica count"
},
"strategy": {
"type": "string",
"title": "Strategy",
"description": "Rollout Strategy"
},
"hasPrivileged": {
"type": "boolean",
"title": "Has Privileged Container"
},
"hasLatest": {
"type": "boolean",
"title": "Has 'latest' tag",
"description": "Has Container with 'latest' as image tag"
},
"hasLimits": {
"type": "boolean",
"title": "All containers have limits"
},
"isHealthy": {
"type": "string",
"enum": [
"Healthy",
"Unhealthy"
],
"enumColors": {
"Healthy": "green",
"Unhealthy": "red"
},
"title": "Workload Health"
},
"kind": {
"title": "Workload Kind",
"description": "The kind of Workload",
"type": "string",
"enum": [
"StatefulSet",
"DaemonSet",
"Deployment",
"Rollout"
]
},
"strategyConfig": {
"type": "object",
"title": "Strategy Config",
"description": "The workloads rollout strategy"
}
},
"required": []
},
"mirrorProperties": {
"Cluster": {
"title": "Cluster",
"path": "Namespace.Cluster.$title"
},
"namespace": {
"title": "Namespace",
"path": "Namespace.$title"
}
},
"calculationProperties": {},
"relations": {
"Namespace": {
"title": "Namespace",
"target": "namespace",
"required": false,
"many": false
}
}
}
]
Loading

0 comments on commit 2ad080c

Please sign in to comment.