Add support for multi-cluster distribution by generation of kubefleet clusterresourceplacement manifests#583
Add support for multi-cluster distribution by generation of kubefleet clusterresourceplacement manifests#583sjwaight wants to merge 12 commits intoAzure:mainfrom
Conversation
Co-authored-by: sjwaight <4828246+sjwaight@users.noreply.github.com>
…stem Co-authored-by: sjwaight <4828246+sjwaight@users.noreply.github.com>
Co-authored-by: sjwaight <4828246+sjwaight@users.noreply.github.com>
…ariable - Replaced two separate cluster name variables with a single comma-separated list variable - Added custom template functions (split and trim) to parse comma-separated values - Updated template logic to handle dynamic list of cluster names - Updated documentation with three-cluster example as requested - All tests updated and passing Co-authored-by: sjwaight <4828246+sjwaight@users.noreply.github.com>
Co-authored-by: sjwaight <4828246+sjwaight@users.noreply.github.com>
Co-authored-by: sjwaight <4828246+sjwaight@users.noreply.github.com>
Co-authored-by: sjwaight <4828246+sjwaight@users.noreply.github.com>
Add Kubefleet ClusterResourcePlacement template support and fix addon system
Resolve test failure due to add-on template name not matching expected value for webapp_routing add-on.
There was a problem hiding this comment.
Pull Request Overview
This PR adds support for multi-cluster distribution by introducing a new distribute command that generates KubeFleet ClusterResourcePlacement (CRP) manifests. The implementation follows an add-on pattern similar to existing webapp routing functionality and includes comprehensive testing and documentation.
- Introduces a new
distributecommand specifically for KubeFleet multi-cluster resource placement - Adds template functions and variable validation improvements to support conditional prompting
- Provides comprehensive test coverage and documentation for the new functionality
Reviewed Changes
Copilot reviewed 14 out of 14 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
template/addons/kubefleet/clusterresourceplacement/draft.yaml |
Defines template configuration for KubeFleet CRP with variables and validation |
template/addons/kubefleet/clusterresourceplacement/clusterresourceplacement.yaml |
Template manifest for generating CRP resources with conditional cluster selection |
pkg/prompts/prompts.go |
Moves ActiveWhen constraint checking to occur before prompt disable checks |
pkg/handlers/template.go |
Adds custom template functions for string manipulation (split and trim) |
cmd/distribute.go |
New command implementation for KubeFleet distribution functionality |
cmd/update.go |
Refactors to support configurable addon templates instead of hardcoded ingress |
docs/kubefleet-clusterresourceplacement.md |
Comprehensive documentation with usage examples and variable descriptions |
| - name: "PARTOF" | ||
| type: "string" | ||
| kind: "label" | ||
| description: "the label to identify which project the resource belong to" |
There was a problem hiding this comment.
Grammatical error: 'belong' should be 'belongs' to match singular subject 'resource'.
| description: "the label to identify which project the resource belong to" | |
| description: "the label to identify which project the resource belongs to" |
| func TestWriteClusterResourcePlacementFilesExample(t *testing.T) { | ||
| err := WriteClusterResourcePlacementFilesExample() | ||
| if err != nil { | ||
| t.Errorf("WriteClusterResourcePlacementFilesExample failed: %e", err) |
There was a problem hiding this comment.
Incorrect error formatting verb: '%e' is not a valid verb for error formatting. Use '%v' or '%s' instead.
| t.Errorf("WriteClusterResourcePlacementFilesExample failed: %e", err) | |
| t.Errorf("WriteClusterResourcePlacementFilesExample failed: %v", err) |
| // Get the kubefleet template | ||
| template, err := handlers.GetTemplate(templateType, "", outputPath, &w) | ||
| if err != nil { | ||
| return fmt.Errorf("failed to get template: %e", err) |
There was a problem hiding this comment.
Incorrect error formatting verb: '%e' is not a valid verb for error formatting. Use '%v' or '%s' instead.
| return fmt.Errorf("failed to get template: %e", err) | |
| return fmt.Errorf("failed to get template: %v", err) |
| // Generate the ClusterResourcePlacement files | ||
| err = template.Generate() | ||
| if err != nil { | ||
| return fmt.Errorf("failed to generate manifest: %e", err) |
There was a problem hiding this comment.
Incorrect error formatting verb: '%e' is not a valid verb for error formatting. Use '%v' or '%s' instead.
| return fmt.Errorf("failed to generate manifest: %e", err) | |
| return fmt.Errorf("failed to generate manifest: %v", err) |
| placementType: {{ .Config.GetVariableValue "PLACEMENT_TYPE" }}{{- if eq (.Config.GetVariableValue "PLACEMENT_TYPE") "PickFixed" }}{{- $clusterNames := .Config.GetVariableValue "CLUSTER_NAMES" }}{{- if ne $clusterNames "" }} | ||
| clusterNames:{{- range (split "," $clusterNames) }}{{- $cluster := . | trim }}{{- if ne $cluster "" }} | ||
| - {{ $cluster }}{{- end }}{{- end }}{{- end }}{{- end }} No newline at end of file |
There was a problem hiding this comment.
[nitpick] The complex template logic on lines 16-18 uses nested conditionals and string operations that could be difficult to debug. Consider breaking this into smaller, more readable template sections or adding comments to explain the logic flow.
| placementType: {{ .Config.GetVariableValue "PLACEMENT_TYPE" }}{{- if eq (.Config.GetVariableValue "PLACEMENT_TYPE") "PickFixed" }}{{- $clusterNames := .Config.GetVariableValue "CLUSTER_NAMES" }}{{- if ne $clusterNames "" }} | |
| clusterNames:{{- range (split "," $clusterNames) }}{{- $cluster := . | trim }}{{- if ne $cluster "" }} | |
| - {{ $cluster }}{{- end }}{{- end }}{{- end }}{{- end }} | |
| placementType: {{ .Config.GetVariableValue "PLACEMENT_TYPE" }} | |
| {{- /* Check if placementType is "PickFixed" and process clusterNames */ -}} | |
| {{- if eq (.Config.GetVariableValue "PLACEMENT_TYPE") "PickFixed" }} | |
| {{- $clusterNames := .Config.GetVariableValue "CLUSTER_NAMES" }} | |
| {{- if ne $clusterNames "" }} | |
| clusterNames: | |
| {{- /* Split clusterNames by comma and trim each name */ -}} | |
| {{- range (split "," $clusterNames) }} | |
| {{- $cluster := . | trim }} | |
| {{- if ne $cluster "" }} | |
| - {{ $cluster }} | |
| {{- end }} | |
| {{- end }} | |
| {{- end }} | |
| {{- end }} |
Description
The KubeFleet multi-cluster management solution requires support in Draft in order to generate ClusterResourcePlacement (CRP) definitions to place namespaces on multiple clusters. This PR adds support for generating CRP manifests in Draft.
Documentation has been updated to include the new
distributecommand which is based on theupdatecommand.The feature has been delivered as an add-on.
Note: implemented through use of GitHub Copilot, with resulting implementation refined across three sessions.
Type of change
How Has This Been Tested?
Provide instructions so we can reproduce, and list any relevant details for your test configuration. Please mention if this is a breaking change which will impact consuming tool(s).
Checklist: