add namespace import
Gitea Actions Demo / Explore-Gitea-Actions (push) Successful in 3s

This commit is contained in:
2026-06-19 15:58:38 +01:00
parent e74b659b45
commit aa0939be6d
7 changed files with 105 additions and 18 deletions
@@ -14,6 +14,7 @@ import ruamel.yaml
import yaml
import urllib.request
def hello(request):
return HttpResponse('<h1>Hello k8s!</h1>')
@@ -43,15 +44,6 @@ def scale_down(request,namespace_name,deploy_name):
return render(request, 'dashboard/shutdown.html',
{'namespace': namespace_name, 'deployment': deploy_name, 'url': 'https://namespace.com'})
def Import_Deployments():
config.load_kube_config(config_file='/kubeconfig/config')
deployment = api.list_namespaced_deployment('servarr')
len(deployment.items) #list all deployment inside the namespace
test.items[0].spec.template.spec.containers[0].name # name the first deploy within the namespace
test.items[2].spec.template.spec.containers[0].name # name the third deploy within the namespace
return 0
def nodes(request):
config.load_kube_config(config_file='/code/kubeconfig')
v1 = client.CoreV1Api()
@@ -1,7 +1,9 @@
from kubernetes import client, config
def scale_up(namespace_name,deploy_name,replicas=1):
config.load_kube_config(config_file='/kubeconfig/config')
api = client.AppsV1Api()
deployment = api.read_namespaced_deployment(name=deploy_name, namespace=namespace_name)
deployment.spec.replicas = replicas
@@ -16,4 +18,26 @@ def scale_down(namespace_name,deploy_name):
deployment.spec.replicas = 0
resp = api.patch_namespaced_deployment(
name=deploy_name, namespace=namespace_name, body=deployment);
return 0
return 0
def import_Deployments():
config.load_kube_config(config_file='/kubeconfig/config')
api = client.AppsV1Api()
deployment = api.list_deployment_for_all_namespaces()
for i in range(1,len(deployment.items)):
print(deployment.items[i].spec.template.spec.containers[0].name)
len(deployment.items) #list all deployment inside the namespace
test.items[0].spec.template.spec.containers[0].name # name the first deploy within the namespace
test.items[2].spec.template.spec.containers[0].name # name the third deploy within the namespace
return 0
def get_namespace():
config.load_kube_config(config_file='/kubeconfig/config')
core = client.CoreV1Api()
namespace = core.list_namespace()
namespace_list = []
for i in range(1,len(namespace.items)):
print(namespace.items[i].metadata.name)
namespace_list.append(namespace.items[i].metadata.name)
return namespace_list