fix: Fixes various issues.

This commit is contained in:
greysoh 2024-07-15 18:59:33 -04:00
parent aa040035cd
commit 8abe8541df
Signed by: imterah
GPG key ID: 8FA7DD57BA6CEA37
5 changed files with 43 additions and 18 deletions

View file

@ -0,0 +1,12 @@
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: admin-user
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: cluster-admin
subjects:
- kind: ServiceAccount
name: admin-user
namespace: kubernetes-dashboard

View file

@ -1,12 +1,5 @@
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
apiVersion: v1
kind: ServiceAccount
metadata:
name: admin
roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: cluster-admin
subjects:
- kind: ServiceAccount
name: admin-user
namespace: kubernetes-dashboard

View file

@ -23,12 +23,21 @@ repo = kubernetes-dashboard/kubernetes-dashboard
namespace = kubernetes-dashboard
create_namespace = true
### Users
[k3s_dash_admin_user]
description = Kubernetes Dashboard Admin Account
### User Related Tasks
[k3s_dash_admin_bind]
description = Kubernetes Dashboard Admin Binding
mode = k3s
depends_on = k3s_dash
[#k3s_dash_admin_bind/k3s]
mode = install
yml_path = ./adminbind.yml
[k3s_dash_admin_user]
description = Kubernetes Dashboard Admin User
mode = k3s
depends_on = k3s_dash_admin_bind
[#k3s_dash_admin_user/k3s]
mode = install
yml_path = ./adminuser.yml

View file

@ -314,7 +314,7 @@ def generate_change_set(projects: list[Project]) -> dict[str, list[str]]:
changeset_path = f"{base_changeset_path}/gen_{len(dir_contents) + 1}/"
try:
shutil.copytree(f"{base_changeset_path}/gen_{len(dir_contents) - 1}/", changeset_path)
shutil.copytree(f"{base_changeset_path}/gen_{len(dir_contents)}/", changeset_path)
except FileNotFoundError:
os.mkdir(changeset_path)
os.mkdir(f"{changeset_path}/k3hashes")
@ -350,12 +350,12 @@ def generate_change_set(projects: list[Project]) -> dict[str, list[str]]:
Path(f"{changeset_path}/helmhashes/{meta_id}").touch()
changeset_values[project.name] = [
f"helm repo update {project.helm_settings.repo}",
f"helm repo update {project.helm_settings.repo[:project.helm_settings.repo.index("/")]}",
f"helm upgrade --install {project.helm_settings.name} {project.helm_settings.repo} {"--create-namespace" if project.helm_settings.create_namespace else ""} --namespace {project.helm_settings.namespace_name}"
]
elif project.helm_settings.mode == "upgrade" or mode == "update":
changeset_values[project.name] = [
f"helm repo update {project.helm_settings.repo}",
f"helm repo update {project.helm_settings.repo[:project.helm_settings.repo.index("/")]}",
f"helm upgrade {project.helm_settings.name} {project.helm_settings.repo} {"--create-namespace" if project.helm_settings.create_namespace else ""} --namespace {project.helm_settings.namespace_name}"
]
case "k3s":
@ -378,10 +378,13 @@ def generate_change_set(projects: list[Project]) -> dict[str, list[str]]:
data = kube_file.read()
file_hash = hashlib.md5(data).hexdigest()
with open(f"{changeset_path}/k3hashes/{meta_id}", "rw") as kube_metaid_file:
if kube_metaid_file.read() == file_hash:
with open(f"{changeset_path}/k3hashes/{meta_id}", "r+") as kube_metaid_file:
read_hash = kube_metaid_file.read()
if read_hash == file_hash:
continue
else:
kube_metaid_file.seek(0)
kube_metaid_file.write(file_hash)
changeset_values[project.name] = [
@ -425,6 +428,10 @@ if not projects:
print("Generating changesets...")
change_set = generate_change_set(projects)
if not change_set:
print("No changes detected.")
exit(0)
if args.dryrun_only:
sigint_handler(None, None)
@ -441,4 +448,4 @@ else:
print(f"Applying changeset for '{project_name}'...")
for command in change_set[project_name]:
os.system(command)
os.system(command)

4
kubernetes/open-dash.sh Executable file
View file

@ -0,0 +1,4 @@
#!/usr/bin/env bash
kubectl -n kubernetes-dashboard create token admin-user
echo
kubectl -n kubernetes-dashboard port-forward svc/kubernetes-dashboard-kong-proxy 8443:443