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

Consolidate Windows workload templates using Go templates and code generators in OTP for validation

XMLWordPrintable

    • None
    • None
    • None

      Overview

      As part of the OTE migration (WINC-1536), consolidate 23 template files into 4 Go templates using aggressive consolidation with code generators in openshift-tests-private. Validate the approach before future migration to origin.

      Background

      Current State:

      • 23 static YAML files in openshift-tests-private/test/extended/testdata/winc/
      • 9 Windows workload variations (windows_web_server.yaml, windows_web_server_byoh.yaml, etc.)
      • 14 supporting templates (namespace, PVC, configmap, storage, OLM resources, etc.)
      • Massive duplication and maintenance overhead

      Problem:

      • Nearly-identical files with minor variations
      • Simple resources using template files unnecessarily
      • String-based <placeholder> syntax is error-prone
      • Difficult to maintain consistency across 23 files

      Target State (OTP)

      4 Go Template Files in test/extended/testdata/winc/:

      1. windows_web_server_template.yaml - Parameterized Windows workload (replaces 9 files)
      2. linux_web_server_template.yaml - Linux comparison workload
      3. hpa_template.yaml - Horizontal Pod Autoscaler configuration
      4. olm_bundle_template.yaml - OLM resources (replaces 3 files)

      Code Generators in test/extended/util/winc/generators.go:

      • GenerateNamespace() - replaces namespace.yaml
      • GeneratePVC() - replaces pvc.yaml
      • GenerateConfigMap() - replaces config-map.yaml
      • GenerateDNSConfigMap() - replaces config-map-ip-dns.yaml
      • GenerateProxyEnvVars() - replaces proxy_vars.yaml
      • GenerateStorageClass() - replaces azure_storageclass.yaml + vsphere_storageclass.yaml
      • GenerateWICDConfigMap() - replaces wicd_configmap.yaml
      • GenerateImageDigestMirrorSet() - replaces stage-repo.yaml

      Result: 23 files → 4 files (83% reduction)

      Scope

      This story includes:

      • Create 4 Go templates in OTP testdata/winc/
      • Implement 8 resource code generators in util/winc/
      • Create WindowsWebServerConfig, HPAConfig, OLMBundleConfig structs
      • Create template renderer functions (RenderWindowsWebServerTemplate(), RenderHPA(), RenderOLMBundle())
      • Update all WINC tests to use new templates and code generators
      • Validate with full test suite
      • Remove 19 old static YAML files after validation
      • Update README.md documentation

      Out of Scope:

      • MachineSet templates (separate story, blocked by WINC-1508)
      • Migration to origin repository (future story, part of final OTE steps)

      Implementation Approach

      Phase 1: Create Templates and Generators

      • Enhance existing windows_web_server_template.yaml
      • Create linux_web_server_template.yaml, hpa_template.yaml, olm_bundle_template.yaml
      • Implement generators.go with 8 resource generators
      • Create windows_template.go with config structs and renderers

      Phase 2: Update Tests

      • Replace static YAML file references with template renderers
      • Replace template file usage with code generators
      • Update imports to github.com/openshift/openshift-tests-private/test/extended/util/winc

      Phase 3: Validate and Clean Up

      • Run full WINC test suite (go test ./test/extended/winc/...)
      • Fix any test failures
      • Remove 19 old static YAML files
      • Update documentation

      Why Code Generators > Template Files

      For simple resources (namespace, PVC, configmap):

      Old approach (template file):

      # namespace.yaml
      apiVersion: v1
      kind: Namespace
      metadata:
        name: <namespace_name>
      

      Requires: File I/O, placeholder replacement, error handling

      New approach (code generator):

      func GenerateNamespace(name string) string {
          return fmt.Sprintf(`apiVersion: v1
      kind: Namespace
      metadata:
        name: %s`, name)
      }
      

      Benefits:

      • No template file to maintain
      • Type-safe parameters
      • IDE validation and autocomplete
      • No file I/O overhead
      • Compile-time validation

      Location

      All work in: openshift-tests-private repository

      • Templates: test/extended/testdata/winc/
      • Code: test/extended/util/winc/
      • Tests: test/extended/winc/

      Future Work

      Migration to origin will happen later as one of the final steps of the OTE migration epic, after:

      • All templates validated in OTP
      • All tests passing with new approach
      • WINC team comfortable with the consolidation
      • Other OTE prerequisites completed

          1. Acceptance Criteria

      Templates and Code

      • [ ] Exactly 4 YAML template files in test/extended/testdata/winc/
      • [ ] generators.go created in test/extended/util/winc/ with 8+ resource generator functions
      • [ ] windows_template.go created in test/extended/util/winc/ with config structs and renderers
      • [ ] WindowsWebServerConfig struct created with all configuration options
      • [ ] HPAConfig struct created
      • [ ] OLMBundleConfig struct created
      • [ ] NewDefaultWindowsWebServerConfig() function created
      • [ ] RenderWindowsWebServerTemplate() function created
      • [ ] RenderHPA() function created
      • [ ] RenderOLMBundle() function created
      • [ ] All 8 resource generators implemented (namespace, PVC, configmap, DNS configmap, proxy vars, storage class, WICD configmap, ImageDigestMirrorSet)

      Testing and Validation

      • [ ] All WINC tests updated to use new templates and code generators
      • [ ] All WINC tests pass with new approach (go test ./test/extended/winc/...)
      • [ ] Go templates verified to support all 9 Windows workload scenarios
      • [ ] Code generators verified to replace 10 simple templates
      • [ ] OLM bundle verified to replace 3 OLM templates
      • [ ] All Go code compiles successfully

      File Management

      • [ ] 23 → 4 files (83% reduction achieved in OTP)
      • [ ] Old static YAML files removed after validation
      • [ ] MachineSet templates NOT touched (separate story)

      Documentation

      • [ ] README.md updated documenting new usage patterns
      • [ ] Documentation includes migration path to origin for future story
      • [ ] Code examples provided for common scenarios

      Delivery

      • [ ] PR submitted to openshift-tests-private repository
      • [ ] PR reviewed and merged
      • [ ] Unit tests added for generators (optional but recommended)

      Risks and Mitigations

      Risks

      • Aggressive refactoring (23 → 4 files) may introduce issues
      • New code generator approach needs validation
      • Test updates across ~15-20 test cases
      • Need to verify all scenarios still covered

      Mitigations

      • Templates already tested in OTP (proven working)
      • Code generators are simple and testable
      • Incremental test updates (one file at a time)
      • Run full test suite after each update
      • Keep old files until all tests pass
      • Document all configuration options clearly
      • Get review from WINC team before merging

      Verification steps

      1. Verify Files Created

      cd openshift-tests-private/test/extended/testdata/winc/
      ls -la *.yaml | grep -v machineset | wc -l
      # Should show exactly 4 YAML files
      

      2. Verify Go Code Exists

      cd openshift-tests-private/test/extended/util/winc/
      ls -la *.go
      # Should show: generators.go, windows_template.go
      

      3. Verify Code Compiles

      cd openshift-tests-private
      go build ./test/extended/util/winc/...
      # Should compile without errors
      

      4. Run Full Test Suite

      cd openshift-tests-private
      go test -v ./test/extended/winc/... -timeout 2h
      # All tests should pass
      

      5. Verify File Reduction

      # Before: 23 template files
      # After: 4 template files
      # Reduction: 83% (19 files eliminated)
      

       

      Example Usage 

      Using Go Template

      import "github.com/openshift/openshift-tests-private/test/extended/util/winc"
      
      config := winc.NewDefaultWindowsWebServerConfig()
      config.ImageName = "mcr.microsoft.com/windows/servercore:ltsc2022"
      config.Replicas = 3
      config.PVCName = "my-pvc"
      
      manifest, err := winc.RenderWindowsWebServerTemplate(config)
      // Apply manifest...
      

      Using Code Generators

      import "github.com/openshift/openshift-tests-private/test/extended/util/winc"
      
      // Generate namespace (no template file needed!)
      ns := winc.GenerateNamespace("winc-test")
      
      // Generate PVC (no template file needed!)
      pvc := winc.GeneratePVC("windows-data", "10Gi", "windows-sc")
      
      // Generate StorageClass (no template file needed!)
      sc := winc.GenerateStorageClass("windows-sc", winc.StorageClassAzure, nil)
      
      // Apply manifests...
      

      Notes

      1. OTP-first approach - Validate consolidation in OTP before origin migration
      2. Aggressive consolidation - 83% file reduction (23 → 4)
      3. Code generation over templates - Simple resources generated in Go code (no file I/O)
      4. Type safety - Struct-based configuration instead of string maps
      5. No BYOH templates - BYOH is just a node selector configuration
      6. Platform consolidation - Azure/vSphere StorageClass merged into one generator
      7. OLM bundle - 3 OLM resources consolidated into one template
      8. Test migration included - This story includes updating tests (not a separate story)
      9. Origin migration later - Migration to origin happens as part of final OTE steps
      10. Self-contained - All work happens in OTP, proves the approach works

      Estimate Breakdown

      • Create 4 Go templates: 2 points
      • Implement 8 resource generators: 2 points
      • Create config structs and renderers: 2 points
      • Update all tests to use new approach: 4 points
      • Run test suite and fix issues: 2 points
      • Documentation and PR: 1 point

      Total: 13 story points

      Note

      Story points increased from 8 to 13 because this story now includes test migration (was previously planned as a separate story)

      Definition of Done

      • All acceptance criteria met
      • All WINC tests passing in CI
      • Code reviewed and approved by WINC team
      • PR merged to main branch
      • Documentation updated
      • 83% file reduction achieved and validated

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

                Created:
                Updated: