Uploaded image for project: 'OpenShift Windows Containers'
  1. OpenShift Windows Containers
  2. WINC-1537

Consolidate WINC test templates using Go text/template to reduce file count and improve maintainability

XMLWordPrintable

    • None
    • None
    • None

      Problem Statement

      The WINC test suite currently uses 35+ static YAML template files in test/extended/testdata/winc/. Many of these files are near-duplicates with minor variations:

      Windows Web Server variants (7 files):

      • windows_web_server.yaml
      • windows_web_server_no_taint.yaml
      • windows_web_server_pvc.yaml
      • windows_web_server_scaler.yaml
      • windows_webserver_secondary_os.yaml
      • windows_webserver_projected_volume.yaml
      • windows_web_server_disconnected.yaml

      Machineset templates (10 files):

      • 5 platform-specific Windows machinesets (AWS, Azure, GCP, vSphere, Nutanix)
      • 5 BYOH machinesets (being removed in WINC-1508)

      Note: windows_web_server_byoh.yaml and the 5 BYOH machineset templates will be removed by WINC-1508 and are excluded from this consolidation effort.

      This creates significant maintenance overhead:

      • Changes to common structure must be duplicated across multiple files
      • Easy to introduce inconsistencies between variants
      • Difficult to understand what differentiates each template
      • Hard to create new test variants
      • Increases file count and repository size

      Proposed Solution

      Implement a Go template-based system using Go's text/template package to consolidate test templates. This will reduce file count by ~70% while maintaining full backward compatibility.

      Scope: Focus on Windows web server templates (Phase 1) with optional expansion to machinesets (Phase 3), coordinating with WINC-1508 for BYOH removal.

      Objectives

      1. Reduce Windows web server template file count from 7 to 1 consolidated template
      2. Improve maintainability through centralized template definitions
      3. Add type safety to template configuration
      4. Enable easier creation of new test variants
      5. Support both file-based and stdin-based (oc apply -f -) deployment
      6. Maintain backward compatibility with existing tests
      7. Coordinate with WINC-1508 to avoid conflicts with BYOH template removal

      Proposed Approach

      Phase 1: Infrastructure Setup (Windows Web Server Templates)

      1. Create Consolidated Template

      • Create windows_web_server_template.yaml using Go text/template syntax
      • Support 7 existing Windows web server variants through configuration (excluding BYOH)
      • Use conditional blocks ({{ {\{if\}}

        ..{{

        {\{end\}}

        }}) for optional sections

      • Support dynamic values through template variables

      2. Add Type-Safe Configuration

      • Create WindowsWebServerConfig struct in test/extended/winc/utils.go
      • Add fields for all configuration options:
        • Service inclusion
        • Tolerations
        • Security context
        • Replica count
        • PVC mounting
        • Resource limits
        • Node selectors
        • Image pull secrets
        • PowerShell version
        • OS label styles
      • Add NewDefaultWindowsWebServerConfig() helper function
      • Import text/template package

      3. Implement Template Functions

      • Create createWorkloadFromTemplate() function for file-based deployment
      • Create createWorkloadFromTemplateWithStdin() function for stdin-based deployment
      • Handle template parsing, execution, and error checking
      • Support waiting for workload readiness

      4. Documentation

      • Create migration guide with before/after examples
      • Document all configuration options
      • Provide usage examples for each template variant
      • Include troubleshooting guide

      Phase 2: Migration (Optional - Future Ticket)

      • Update test/extended/winc/winc.go to use new template system
      • Update test/extended/winc/storage.go to use new template system
      • Update other test files using Windows web server templates
      • Verify all tests pass in CI
      • Remove old static YAML files (coordinate with WINC-1508)

      Phase 3: Expansion to Machinesets (Future Ticket)

      • Wait for WINC-1508 BYOH removal to complete
      • Apply same pattern to remaining machineset templates (5 platforms, Windows only)
      • Create per-platform consolidated templates
      • Further reduce file count

      Technical Design

      Template System Architecture

      Test Code (*.go)
          ↓
      WindowsWebServerConfig (typed configuration)
          ↓
      createWorkloadFromTemplate[WithStdin]()
          ↓
      text/template.Execute()
          ↓
      windows_web_server_template.yaml
          ↓
      Generated YAML
          ↓
      oc apply -f <file> OR oc apply -f -
      

      Configuration Example

      Current approach (map of strings):

      createWorkload(oc, namespace, "windows_web_server_pvc.yaml",
          map[string]string{
              "<id>": pvc,
              "<pvc-name>": pvc,
              "<windows_container_image>": image,
              "<node-selector>": nodeSelector,
          },
          false, windowsWorkloads+"-"+pvc)
      

      Proposed approach (type-safe struct):

      config := NewDefaultWindowsWebServerConfig()
      config.ImageName = image
      config.NameSuffix = pvc
      config.PVCName = pvc
      config.Replicas = 3
      config.AdditionalNodeSelector = nodeSelector
      
      createWorkloadFromTemplateWithStdin(oc, namespace,
          "windows_web_server_template.yaml", config, false, windowsWorkloads+"-"+pvc)
      

      Template Consolidation Mapping

      Current Template File Configuration in New System Status
      windows_web_server.yaml Default configuration Active
      windows_web_server_no_taint.yaml IncludeTolerations=false, IncludeService=false Active
      windows_web_server_pvc.yaml PVCName, Replicas=3, NameSuffix Active
      windows_web_server_scaler.yaml ResourceLimits="1" Active
      windows_webserver_secondary_os.yaml UseNewOSLabels=true, KernelID Active
      windows_webserver_projected_volume.yaml ProjectedVolume=true Active
      windows_web_server_disconnected.yaml ImagePullSecrets, MultilineCommand=true Active
      windows_web_server_byoh.yaml N/A - Being removed in WINC-1508 Excluded

      Expected Benefits

      1. Reduced Maintenance: Common changes only need to be made once in the template
      2. Type Safety: Configuration validated at compile time, preventing typos in placeholder strings
      3. Improved Clarity: Explicit configuration shows what makes each test variant different
      4. Easier Testing: Create new test variants without creating new files
      5. Better Efficiency: Stdin mode eliminates temp file I/O overhead
      6. Supports OTE Migration: Cleaner codebase makes framework migration easier (WINC-1536)
      7. No Conflicts with BYOH Removal: Work is coordinated with WINC-1508

      Implementation Tasks

      Required Work (Phase 1)

      1. Create windows_web_server_template.yaml with Go template syntax
      2. Add WindowsWebServerConfig struct to utils.go
      3. Add text/template import to utils.go
      4. Implement createWorkloadFromTemplate() function
      5. Implement createWorkloadFromTemplateWithStdin() function
      6. Add NewDefaultWindowsWebServerConfig() helper function
      7. Create comprehensive migration guide
      8. Create usage examples for all 7 template variants (excluding BYOH)
      9. Add testing utilities
      10. Validate template syntax and rendering

      Coordination Required

      1. Verify WINC-1508 status and timeline for BYOH removal
      2. Ensure no conflicts with BYOH template removal work
      3. Document that BYOH templates are excluded from this effort

      Optional Follow-up Work (Future Tickets)

      1. Migrate existing test code to use new template system
      2. Remove old static YAML files (after WINC-1508 completes)
      3. Create machineset templates for each cloud provider (5 platforms)
      4. Consolidate other resource templates

      Acceptance Criteria

      Phase 1: Infrastructure (Core Deliverable)

      • [ ] windows_web_server_template.yaml created with Go template syntax supporting 7 variants
      • [ ] WindowsWebServerConfig struct implemented with all required fields
      • [ ] createWorkloadFromTemplate() function implemented and tested
      • [ ] createWorkloadFromTemplateWithStdin() function implemented and tested
      • [ ] NewDefaultWindowsWebServerConfig() helper function created
      • [ ] Template syntax validated (no parsing errors)
      • [ ] Documentation created:
        • Migration guide with before/after examples
        • Usage examples for all template variants
        • Configuration reference
        • Troubleshooting guide
      • [ ] Can generate YAML equivalent to all 7 original template files (excluding BYOH)
      • [ ] No breaking changes to existing tests
      • [ ] No conflicts with WINC-1508 BYOH removal work

      Phase 2: Migration (Optional - Future Ticket)

      • [ ] All test files migrated to use new template system
      • [ ] All tests pass in CI
      • [ ] Old static YAML files removed (coordinate timing with WINC-1508)
      • [ ] Code review completed

      Phase 3: Expansion (Future Ticket - After WINC-1508)

      • [ ] WINC-1508 BYOH removal completed
      • [ ] Machineset templates created for 5 platforms (Windows only)
      • [ ] Additional resource templates consolidated
      • [ ] Template best practices documented

      Success Metrics

      • Windows web server file count reduction: 7 files → 1 template (86% reduction)
      • Potential overall reduction after Phase 3: ~29 files → ~8-10 templates (65-70% reduction)
      • Zero test failures introduced by migration
      • Improved code review velocity (less duplication to review)
      • Easier for team members to create new test variants
      • Clean coordination with WINC-1508 (no merge conflicts)

      Dependencies and Related Work

      Dependencies

      • None - this work is independent and can proceed immediately
      • However, Phase 3 (machineset consolidation) should wait for WINC-1508 to complete

      Related Issues

      • WINC-1536 (Epic): Stabilize and Migrate WINC Tests to OpenShift Tests Extension (OTE)
        • This work supports test stabilization and cleaner codebase for OTE migration
      • WINC-1508: Remove BYOH template support
        • Affects 6 files: windows_web_server_byoh.yaml + 5 BYOH machineset templates
        • This consolidation effort excludes BYOH templates to avoid conflicts
        • Phase 3 machineset consolidation should wait for WINC-1508 completion

      Coordination Plan

      1. Phase 1 (this ticket): Focus only on Windows web server templates (excludes BYOH)
      2. WINC-1508: Removes BYOH templates independently
      3. Phase 2 (future): Migrate code to use new templates (after both efforts stabilize)
      4. Phase 3 (future): Consolidate remaining machineset templates (after WINC-1508 completes)

      Risks and Mitigations

      Risk: Conflicts with WINC-1508 BYOH removal
      Mitigation: Explicitly exclude BYOH templates from consolidation scope

      Risk: Breaking existing tests during migration
      Mitigation: Keep old templates until migration is complete and verified in CI

      Risk: Template syntax errors
      Mitigation: Validate templates before use, add unit tests for template rendering

      Risk: Team unfamiliarity with Go templates
      Mitigation: Provide comprehensive documentation and examples

      Timeline Estimate

      • Phase 1 (Infrastructure): 3-5 days
      • Phase 2 (Migration): 3-5 days (future ticket, coordinate with WINC-1508)
      • Phase 3 (Expansion): 5-8 days (future ticket, after WINC-1508)

      Story Points

      Recommended: 5 Story Points (Phase 1 only)

      • Medium complexity
      • Clear requirements
      • Well-defined scope
      • Excludes migration and expansion work

      Resources

              Unassigned Unassigned
              rrasouli Aharon Rasouli
              None
              None
              None
              None
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

                Created:
                Updated: