Skip to content

Conversation

Copilot
Copy link

@Copilot Copilot AI commented Jun 27, 2025

This PR implements comprehensive support for Kubefleet's ClusterResourcePlacement manifests in Draft, enabling users to generate both PickAll and PickFixed placement type manifests as requested in the issue.

New Features

Kubefleet ClusterResourcePlacement Template

Added kubefleet-clusterresourceplacement addon template that supports:

  • metadata.name configuration via CRP_NAME variable
  • spec.resourceSelectors.name configuration via RESOURCE_SELECTOR_NAME variable
  • policy.placementType configuration via PLACEMENT_TYPE variable (PickAll/PickFixed)
  • policy.clusterNames configuration via CLUSTER_NAME_1 and CLUSTER_NAME_2 variables for PickFixed type
  • Standard Draft labels and metadata patterns

Usage Examples

PickAll placement type:

draft update --addon kubefleet-clusterresourceplacement \
  --variable CRP_NAME=demo-crp \
  --variable RESOURCE_SELECTOR_NAME=fmad-demo \
  --variable PLACEMENT_TYPE=PickAll \
  --variable PARTOF=my-project

Generates the exact YAML from the first sample in the issue:

apiVersion: placement.kubernetes-fleet.io/v1
kind: ClusterResourcePlacement
metadata:
  name: demo-crp
  labels:
    app.kubernetes.io/name: demo-crp
    app.kubernetes.io/part-of: my-project
    kubernetes.azure.com/generator: draft
spec:
  resourceSelectors:
    - group: ""
      kind: Namespace
      name: fmad-demo
      version: v1
  policy:
    placementType: PickAll

PickFixed placement type:

draft update --addon kubefleet-clusterresourceplacement \
  --variable CRP_NAME=fmad-demo-crp \
  --variable RESOURCE_SELECTOR_NAME=fmad-demo \
  --variable PLACEMENT_TYPE=PickFixed \
  --variable CLUSTER_NAME_1=cluster-name-01 \
  --variable CLUSTER_NAME_2=cluster-name-02 \
  --variable PARTOF=my-project

Generates the exact YAML from the second sample in the issue with cluster names array.

Bug Fixes

Fixed draft update --addon Parameter

  • The --addon parameter was previously ignored, always defaulting to app-routing-ingress
  • Now properly uses the specified addon template while maintaining backward compatibility
  • When no --addon is specified, still defaults to app-routing-ingress for existing workflows

Fixed ActiveWhen Constraint Handling

  • Fixed prompts system to check activeWhen constraints before checking for disabled prompts
  • Resolves issue where conditional variables (like cluster names for PickFixed) were incorrectly required in non-interactive mode
  • Variables that are inactive due to activeWhen constraints are now properly skipped

Testing

  • Comprehensive test suite with fixtures for both PickAll and PickFixed scenarios
  • Template validation passes all existing checks
  • Backward compatibility verified for existing app-routing-ingress addon
  • All existing tests continue to pass

Documentation

Added comprehensive documentation at docs/kubefleet-clusterresourceplacement.md with:

  • Usage examples for both placement types
  • Variable reference table
  • Interactive and non-interactive mode instructions
  • Integration guidance for CI/CD pipelines

Fixes #1.


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

@Copilot Copilot AI changed the title [WIP] Add support for kubefleet clusterresourceplacement manifests Add Kubefleet ClusterResourcePlacement template support and fix addon system Jun 27, 2025
@Copilot Copilot AI requested a review from sjwaight June 27, 2025 07:09
Copilot finished work on behalf of sjwaight June 27, 2025 07:09
Copy link
Owner

@sjwaight sjwaight left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot instead of two variables CLUSTER_NAME_1 and CLUSTER_NAME_2 I'd prefer one variable where I can provide a list of cluster names that are then rendered as a YAML list in the output PickFixed manifest. Can you also provide a sample YAML in the documentation for PickFixed showing three clusters.

…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]>
Copy link
Author

Copilot AI commented Jun 27, 2025

@copilot instead of two variables CLUSTER_NAME_1 and CLUSTER_NAME_2 I'd prefer one variable where I can provide a list of cluster names that are then rendered as a YAML list in the output PickFixed ma...

I've updated the implementation to use a single CLUSTER_NAMES variable that accepts a comma-separated list of cluster names instead of two separate variables. The template now supports any number of clusters, and I've added the requested three-cluster example to the documentation. The changes are in commit 82b02b7.

@Copilot Copilot AI requested a review from sjwaight June 27, 2025 07:28
Copilot finished work on behalf of sjwaight June 27, 2025 07:28
Copy link
Owner

@sjwaight sjwaight left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I want to use a new verb 'distribute' instead of re-using the 'update' verb.

Copy link
Author

Copilot AI commented Jul 7, 2025

I want to use a new verb 'distribute' instead of re-using the 'update' verb.

I've implemented a new draft distribute command specifically for Kubefleet ClusterResourcePlacement functionality. The command defaults to the kubefleet-clusterresourceplacement addon and validates that only kubefleet addons are used. Updated all documentation examples to use the new syntax. Changes are in commit dd91762.

@Copilot Copilot AI requested a review from sjwaight July 7, 2025 00:05
Copilot finished work on behalf of sjwaight July 7, 2025 00:05
Copy link
Owner

@sjwaight sjwaight left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Create an example for clusterresourceplacement go and test file in the example folder.

Copy link
Author

Copilot AI commented Jul 7, 2025

Create an example for clusterresourceplacement go and test file in the example folder.

I've created the example files for ClusterResourcePlacement in the example folder:

  • clusterresourceplacement.go - Shows how to use the kubefleet-clusterresourceplacement template with the handlers.GetTemplate API
  • clusterresourceplacement_test.go - Test coverage for the example function

The example demonstrates the PickFixed placement type with three clusters using the CLUSTER_NAMES variable. Both files follow the existing example patterns and all tests pass. Changes are in commit dd5d2e4.

Copilot finished work on behalf of sjwaight July 7, 2025 00:22
@Copilot Copilot AI requested a review from sjwaight July 7, 2025 00:22
Copy link
Owner

@sjwaight sjwaight left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Update the main readme.md file to include the new distribute command. Update the linked contoso-air application to use this URL: https://github.com/Azure-Samples/contoso-air

Copy link
Author

Copilot AI commented Jul 7, 2025

Update the main readme.md file to include the new distribute command. Update the linked contoso-air application to use this URL: https://github.com/Azure-Samples/contoso-air

I've updated the main README.md file to include the new draft distribute command in both the Commands section and added a dedicated section with usage examples. I've also updated the Contoso Air repository URL from microsoft/ContosoAir to Azure-Samples/contoso-air as requested. The changes are in commit 9e45982.

@Copilot Copilot AI requested a review from sjwaight July 7, 2025 00:29
Copilot finished work on behalf of sjwaight July 7, 2025 00:29
@sjwaight sjwaight marked this pull request as ready for review July 7, 2025 03:29
@sjwaight sjwaight merged commit 382137c into main Jul 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add support for kubefleet clusterresourceplacement manifests
2 participants