generated from knative-extensions/sample-controller
    
        
        - 
                Notifications
    
You must be signed in to change notification settings  - Fork 102
 
Open
Description
I am planning to start moving parts of the codebase to use Jsonnet for resource generation, beginning with serverlessservice.go.
Before opening a PR, I’d like to check if anyone has strong opinions against this approach.
Here’s a snippet of the current Go-based implementation:
vs := resources.MakeVirtualService(sks)
if _, err := istioaccessor.ReconcileVirtualService(ctx, sks, vs, r); err != nil {
	return fmt.Errorf("failed to reconcile VirtualService: %w", err)
}
dr := resources.MakeDestinationRule(sks)
if _, err := istioaccessor.ReconcileDestinationRule(ctx, sks, dr, r); err != nil {
	return fmt.Errorf("failed to reconcile DestinationRule: %w", err)
}
Advantages of a Jsonnet Approach
Declarative vs. Imperative
- Go: Imperative code builds resources step-by-step, with conditional logic scattered throughout.
 - Jsonnet: Declarative templates describe the desired end state, making the resource structure immediately visible.
 
Separation of Concerns
- Go: Business logic (when to create resources) is mixed with resource structure (how resources look).
 - Jsonnet: Go handles the “when,” Jsonnet defines the “what.”
 
Template Reusability & Consistency
- Go: Resource generation logic is often duplicated across controllers.
 - Jsonnet: Shared templates/libraries (e.g., 
istio.libsonnet) ensure consistency across resource generation. 
Easier Maintenance & Customization
- Go: Modifying structures requires diving into complex nested conditionals.
 - Jsonnet: Resource modifications are straightforward template changes, easier to review and test.
 
Better Resource Completeness
- Previous Jsonnet implementations generated more complete and spec-compliant Istio resources compared to Go.
 
Configuration Flexibility
- Go: Hard-coded resource structures with limited parameterization.
 - Jsonnet: Highly parameterizable templates adapt to different configurations without code changes.
 
Next Steps
- Start by migrating 
serverlessservice.goresource generation to Jsonnet as a pilot PR. - Gather feedback from maintainers and contributors on readability, reviewability, and maintainability.
 - If successful, progressively migrate other controllers/resources to Jsonnet.
 - Document the Jsonnet workflow to help contributors adopt the new approach smoothly.
 
Metadata
Metadata
Assignees
Labels
No labels