-
Notifications
You must be signed in to change notification settings - Fork 70
Add support for multi-cluster distribution by generation of kubefleet clusterresourceplacement manifests #583
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
Co-authored-by: sjwaight <[email protected]>
…stem Co-authored-by: sjwaight <[email protected]>
Co-authored-by: sjwaight <[email protected]>
…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 <[email protected]>
Co-authored-by: sjwaight <[email protected]>
Co-authored-by: sjwaight <[email protected]>
Co-authored-by: sjwaight <[email protected]>
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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
distribute
command 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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" |
Copilot uses AI. Check for mistakes.
func TestWriteClusterResourcePlacementFilesExample(t *testing.T) { | ||
err := WriteClusterResourcePlacementFilesExample() | ||
if err != nil { | ||
t.Errorf("WriteClusterResourcePlacementFilesExample failed: %e", err) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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) |
Copilot uses AI. Check for mistakes.
// 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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) |
Copilot uses AI. Check for mistakes.
// 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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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) |
Copilot uses AI. Check for mistakes.
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.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[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 }} |
Copilot uses AI. Check for mistakes.
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
distribute
command which is based on theupdate
command.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: