Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line numberDiff line numberDiff line change
Expand Up@@ -57,3 +57,4 @@ actions/github/webhook/common
.direnv/
.idea/**
.vscode/**
misc
4 changes: 3 additions & 1 deletion Taskfile.yml
Original file line numberDiff line numberDiff line change
Expand Up@@ -22,7 +22,9 @@ vars:
N: ""
T: ""
P: ""
BASETAG: 0.1.0-incubating
BASETAG:
# fixed to 0.1.0-incubating - overridable with MY_BASETAG env var
sh: echo "${MY_BASETAG:-0.1.0-incubating}"
KUBE:
sh: ./detect.sh
NS: "nuvolaris"
Expand Down
5 changes: 5 additions & 0 deletions TaskfileBuild.yml
Original file line numberDiff line numberDiff line change
Expand Up@@ -53,6 +53,11 @@ tasks:
${MY_OPERATOR_IMAGE:-{{.OPERATOR_IMAGE}}}:{{.OPERATOR_TAG}}
--name=nuvolaris

k3s:build-and-load:
- task: build
- >
docker save ${MY_OPERATOR_IMAGE:-{{.OPERATOR_IMAGE}}}:{{.OPERATOR_TAG}} | sudo k3s ctr images import -

buildx-and-push:
- >
docker buildx build
Expand Down
50 changes: 43 additions & 7 deletions nuvolaris/kube.py
Original file line numberDiff line numberDiff line change
Expand Up@@ -21,6 +21,7 @@
import subprocess
import json
import logging
import re
import yaml


Expand DownExpand Up@@ -172,11 +173,46 @@ def rollout(name, namespace="nuvolaris"):
except:
return None

def detect_kind():
def detect() -> str | None:
"""
>>> import nuvolaris.kube as kube
>>> kube.mocker.config("get nodes", [{"nuvolaris.io/kube": "kind"}])
>>> kube.detect()
'kind'
>>> kube.mocker.config("get nodes", [{"eksctl.io/cluster-name": "prod"}])
>>> kube.detect()
'eks'
>>> kube.mocker.config("get nodes", [{"kubernetes.io/os": "linux"}])
>>> kube.detect()
'generic'
>>> kube.mocker.reset()
"""
try:
is_kind = kubectl("get","node/nuvolaris-control-plane",
namespace=None,
jsonpath='{.metadata.labels.nuvolaris\\.io/kube}')
return is_kind and "kind" in is_kind
except:
return False
nodes_labels = kubectl("get", "nodes", namespace=None,
jsonpath='{.items[].metadata.labels}')
except Exception:
return None

if not nodes_labels or not isinstance(nodes_labels, (list, dict)):
return None

if isinstance(nodes_labels, dict):
nodes_labels = [nodes_labels]

text = json.dumps(nodes_labels)

if "eksctl.io" in text:
return "eks"
elif "microk8s.io" in text:
return "microk8s"
elif "lke.linode.com" in text:
return "lks"
elif "openshift.io" in text:
return "openshift"
elif re.search(r"instance-type.*k3s", text):
return "k3s"
elif any(isinstance(labels, dict) and "kind" in labels.get("nuvolaris.io/kube", "")
for labels in nodes_labels):
return "kind"
else:
return "generic"
5 changes: 3 additions & 2 deletions nuvolaris/registry_deploy.py
Original file line numberDiff line numberDiff line change
Expand Up@@ -70,8 +70,9 @@ def create_internal_registry(data, owner=None):

#path the registry pull secret
repoInternalHost = data['repoHostname']
if kube.detect_kind():
# when repo is kind, the registry pull secret will point
kube_kind = kube.detect()
if kube_kind == 'kind' or kube_kind == 'k3s':
# when kubernetes is installed on kind or k3s, the registry pull secret will point
# to the node port exposed on the node
repoInternalHost = "127.0.0.1:32000"

Expand Down