You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@openserverless.apache.org by ms...@apache.org on 2026/08/21 11:30:21 UTC

(openserverless-operator) branch 0.9.1 updated: fix: kube type detection (#114)

This is an automated email from the ASF dual-hosted git repository.

sciabarracom pushed a commit to branch 0.9.1
in repository https://gitbox.apache.org/repos/asf/openserverless-operator.git


The following commit(s) were added to refs/heads/0.9.1 by this push:
     new 9314caf  fix: kube type detection (#114)
9314caf is described below

commit 9314caf9942fd284725cb074e901aad956670b9c
Author: Bruno Salzano <d4...@gmail.com>
AuthorDate: Fri Aug 21 13:30:15 2026 +0200

    fix: kube type detection (#114)
---
 .gitignore                   |  1 +
 Taskfile.yml                 |  4 +++-
 TaskfileBuild.yml            |  5 +++++
 nuvolaris/kube.py            | 50 +++++++++++++++++++++++++++++++++++++-------
 nuvolaris/registry_deploy.py |  5 +++--
 5 files changed, 55 insertions(+), 10 deletions(-)

diff --git a/.gitignore b/.gitignore
index ab4a642..566f6b0 100644
--- a/.gitignore
+++ b/.gitignore
@@ -57,3 +57,4 @@ actions/github/webhook/common
 .direnv/
 .idea/**
 .vscode/**
+misc
\ No newline at end of file
diff --git a/Taskfile.yml b/Taskfile.yml
index 51341e5..69a4e6b 100644
--- a/Taskfile.yml
+++ b/Taskfile.yml
@@ -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"
diff --git a/TaskfileBuild.yml b/TaskfileBuild.yml
index b6f24b4..81e018b 100644
--- a/TaskfileBuild.yml
+++ b/TaskfileBuild.yml
@@ -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 
diff --git a/nuvolaris/kube.py b/nuvolaris/kube.py
index a921173..8772744 100644
--- a/nuvolaris/kube.py
+++ b/nuvolaris/kube.py
@@ -21,6 +21,7 @@ import nuvolaris.template as tpl
 import subprocess
 import json
 import logging
+import re
 import yaml
 
 
@@ -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
\ No newline at end of file
+        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"
\ No newline at end of file
diff --git a/nuvolaris/registry_deploy.py b/nuvolaris/registry_deploy.py
index e9c13fe..5a2f445 100644
--- a/nuvolaris/registry_deploy.py
+++ b/nuvolaris/registry_deploy.py
@@ -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"