Przeglądaj źródła

refactor: change schema backwards compatibility - only load schemas if explicitly declared

xcad 3 miesięcy temu
rodzic
commit
3cd8c9955d

+ 27 - 6
cli/core/template/template.py

@@ -356,9 +356,15 @@ class Template:
             # Validate 'kind' field (always needed)
             self._validate_kind(self._template_data)
 
-            # Extract schema version (default to 1.0 for backward compatibility)
-            self.schema_version = str(self._template_data.get("schema", "1.0"))
-            logger.debug(f"Template schema version: {self.schema_version}")
+            # Extract schema version (only if explicitly declared in template.yaml)
+            # If schema property is missing, template is self-contained (no schema inheritance)
+            if "schema" in self._template_data:
+                self.schema_version = str(self._template_data["schema"])
+                logger.debug(f"Template uses schema version: {self.schema_version}")
+            else:
+                # No schema property = template is self-contained
+                self.schema_version = None
+                logger.debug(f"Template is self-contained (no schema property)")
 
             # Note: Schema version validation is done by the module when loading templates
 
@@ -637,6 +643,8 @@ class Template:
     def _validate_schema_version(self, module_schema: str, module_name: str) -> None:
         """Validate that template schema version is supported by the module.
 
+        Self-contained templates (with schema=None) don't require validation.
+        
         Args:
             module_schema: Schema version supported by the module
             module_name: Name of the module (for error messages)
@@ -646,6 +654,11 @@ class Template:
         """
         template_schema = self.schema_version
 
+        # Self-contained templates (no schema property) don't need validation
+        if template_schema is None:
+            logger.debug(f"Template '{self.id}' is self-contained (no schema inheritance)")
+            return
+
         # Compare schema versions
         if not is_compatible(module_schema, template_schema):
             logger.error(
@@ -932,10 +945,18 @@ class Template:
 
     @property
     def module_specs(self) -> dict:
-        """Get the spec from the module definition for this template's schema version."""
+        """Get the spec from the module definition for this template's schema version.
+        
+        Returns empty dict if template doesn't declare a schema (self-contained).
+        """
         if self.__module_specs is None:
-            kind = self._template_data.get("kind")
-            self.__module_specs = self._load_module_specs_for_schema(kind, self.schema_version)
+            # Only load module specs if template explicitly declares a schema version
+            # Templates without a schema property are self-contained
+            if self.schema_version is not None:
+                kind = self._template_data.get("kind")
+                self.__module_specs = self._load_module_specs_for_schema(kind, self.schema_version)
+            else:
+                self.__module_specs = {}
         return self.__module_specs
 
     @property

+ 1 - 1
library/compose/alloy/config/config.alloy.j2

@@ -174,7 +174,7 @@ prometheus.exporter.unix "metrics" {
   filesystem {
     fs_types_exclude     = "^(autofs|binfmt_misc|bpf|cgroup2?|configfs|debugfs|devpts|devtmpfs|tmpfs|fusectl|hugetlbfs|iso9660|mqueue|nsfs|overlay|proc|procfs|pstore|rpc_pipefs|securityfs|selinuxfs|squashfs|sysfs|tracefs)$"
     mount_points_exclude = "^/(dev|proc|run/credentials/.+|sys|var/lib/docker/.+)($|/)"
-    mount_timeout        = "5s"
+    mount_out        = "5s"
   }
   netclass {
     ignored_devices = "^(veth.*|cali.*|[a-f0-9]{15})$"

+ 19 - 1
library/compose/alloy/template.yaml

@@ -20,7 +20,6 @@ metadata:
     provider: selfh
     id: grafana
   next_steps:
-schema: 1.2
 spec:
   general:
     vars:
@@ -29,6 +28,9 @@ spec:
       container_hostname:
         description: Container internal hostname
         type: str
+      container_timezone:
+        description: Container timezone (e.g., Europe/Berlin)
+        type: str
       restart_policy:
         description: Container restart policy
         type: enum
@@ -39,6 +41,17 @@ spec:
           - 'no'
         default: unless-stopped
         required: true
+  network:
+    title: Network
+    vars:
+      network_mode:
+        description: Docker network mode
+        type: enum
+        options:
+          - bridge
+          - host
+          - macvlan
+        default: bridge
   logs:
     title: Log Collection
     toggle: logs_enabled
@@ -82,12 +95,15 @@ spec:
         type: bool
         default: true
   ports:
+    title: Ports
     vars:
       ports_webui:
         description: Port for Alloy web UI
         type: int
         default: 12345
   traefik:
+    title: Traefik
+    toggle: traefik_enabled
     vars:
       traefik_enabled:
         description: Enable Traefik reverse proxy integration
@@ -106,6 +122,8 @@ spec:
         default: home.arpa
         required: true
   traefik_tls:
+    title: Traefik TLS/SSL
+    toggle: traefik_tls_enabled
     vars:
       traefik_tls_enabled:
         description: Enable HTTPS/TLS

+ 3 - 1
library/compose/whoami/template.yaml

@@ -22,12 +22,14 @@ metadata:
   tags:
     - traefik
     - swarm
-schema: "1.2"
 spec:
   general:
     vars:
       service_name:
         default: whoami
+      container_timezone:
+        description: Container timezone (e.g., Europe/Berlin)
+        type: str
       restart_policy:
         description: Container restart policy
         type: enum