Quellcode durchsuchen

feat: refine deprecation warnings and migrate alloy template

- Refine warning to only show variables USED but not defined
- Reduces noise - only warns about actual problems
- Migrate alloy template to be self-contained
- Add missing variable definitions (7 variables)
- Template now works without schema inheritance
- Proof of concept for template migration

Co-authored-by: ChristianLempa <28359525+ChristianLempa@users.noreply.github.com>
copilot-swe-agent[bot] vor 2 Monaten
Ursprung
Commit
2f2c46dd29
2 geänderte Dateien mit 56 neuen und 11 gelöschten Zeilen
  1. 18 11
      cli/core/template/template.py
  2. 38 0
      library/compose/alloy/template.yaml

+ 18 - 11
cli/core/template/template.py

@@ -472,8 +472,8 @@ class Template:
         """Warn about variables inherited from module schemas (deprecation warning).
 
         DEPRECATION (v0.1.3): Templates should define all variables explicitly in template.yaml.
-        This method detects variables that come from module schemas and warns users to add them
-        to the template spec.
+        This method detects variables that are used in template files but come from module schemas,
+        and warns users to add them to the template spec.
 
         Args:
             module_specs: Variables defined in module schema
@@ -495,22 +495,29 @@ class Template:
             if isinstance(section_data, dict) and "vars" in section_data:
                 template_vars.update(section_data["vars"].keys())
 
-        # Find variables inherited from module (not overridden in template)
-        inherited_vars = module_vars - template_vars
+        # Get variables actually used in template files
+        used_vars = self.used_variables
 
-        if inherited_vars:
+        # Find variables that are:
+        # 1. Used in template files
+        # 2. Defined in module schema
+        # 3. NOT explicitly defined in template.yaml
+        # These are the problematic ones - the template relies on schema
+        missing_definitions = (used_vars & module_vars) - template_vars
+
+        if missing_definitions:
             # Only warn once per template (use a flag to avoid repeated warnings)
             if not hasattr(self, "_schema_deprecation_warned"):
                 self._schema_deprecation_warned = True
                 logger.warning(
-                    f"DEPRECATION WARNING: Template '{self.id}' inherits {len(inherited_vars)} variables "
-                    f"from module schema (kind='{self._template_data.get('kind')}', schema={self.schema_version}). "
-                    f"In future versions, templates must define all variables in template.yaml. "
-                    f"Inherited variables: {', '.join(sorted(list(inherited_vars)[:10]))}{'...' if len(inherited_vars) > 10 else ''}"
+                    f"DEPRECATION WARNING: Template '{self.id}' uses {len(missing_definitions)} "
+                    f"variable(s) from module schema without defining them in template.yaml. "
+                    f"In future versions, all used variables must be defined in template.yaml. "
+                    f"Missing definitions: {', '.join(sorted(list(missing_definitions)[:10]))}{'...' if len(missing_definitions) > 10 else ''}"
                 )
                 logger.debug(
-                    f"Template '{self.id}' should add these variables to template.yaml spec: "
-                    f"{sorted(inherited_vars)}"
+                    f"Template '{self.id}' should add these variable definitions to template.yaml spec: "
+                    f"{sorted(missing_definitions)}"
                 )
 
     def _collect_template_files(self) -> None:

+ 38 - 0
library/compose/alloy/template.yaml

@@ -26,6 +26,19 @@ spec:
     vars:
       service_name:
         default: alloy
+      container_hostname:
+        description: Container internal hostname
+        type: str
+      restart_policy:
+        description: Container restart policy
+        type: enum
+        options:
+          - unless-stopped
+          - always
+          - on-failure
+          - 'no'
+        default: unless-stopped
+        required: true
   logs:
     title: Log Collection
     toggle: logs_enabled
@@ -76,5 +89,30 @@ spec:
         default: 12345
   traefik:
     vars:
+      traefik_enabled:
+        description: Enable Traefik reverse proxy integration
+        type: bool
+        default: false
+      traefik_network:
+        description: Traefik network name
+        type: str
+        default: traefik
+        required: true
       traefik_host:
         default: alloy
+      traefik_domain:
+        description: Base domain (e.g., example.com)
+        type: str
+        default: home.arpa
+        required: true
+  traefik_tls:
+    vars:
+      traefik_tls_enabled:
+        description: Enable HTTPS/TLS
+        type: bool
+        default: true
+      traefik_tls_certresolver:
+        description: Traefik certificate resolver name
+        type: str
+        default: cloudflare
+        required: true