Skip to content

Add --only-new flag to optimize kubeconfig updates#1024

Draft
Copilot wants to merge 4 commits intomasterfrom
copilot/optimize-kubeconfig-update
Draft

Add --only-new flag to optimize kubeconfig updates#1024
Copilot wants to merge 4 commits intomasterfrom
copilot/optimize-kubeconfig-update

Conversation

Copy link

Copilot AI commented Oct 14, 2025

Fixes the issue where the update command would always export all EKS clusters to kubeconfig, even if they were already present. This resulted in unnecessary updates and potential kubeconfig bloat.

Changes

This PR adds a new --only-new flag to the aws update command that enables selective cluster export. When enabled, the command will:

  • Check each discovered cluster against the existing kubeconfig using the existing IsExported() method
  • Skip clusters that are already exported (same endpoint already exists in a context)
  • Only add truly new clusters to the kubeconfig
  • Provide informative output showing the count of new vs skipped clusters

Usage

# Default behavior (unchanged) - exports all clusters
kdiscover aws update

# New optimized behavior - only exports new clusters
kdiscover aws update --only-new

When using --only-new, the output will show:

Found 4 clusters remote
Added 2 new clusters, skipped 2 already exported clusters

Implementation Details

The implementation leverages the existing kubeconfig.IsExported() method which checks if a cluster with the same endpoint already exists in a context. This maintains consistency with the existing "exported locally" logic used in the list command.

The change is backward compatible - the default behavior remains unchanged, and the new flag is opt-in.

Testing

  • Added comprehensive test Test_onlyNewFlagLogic that validates the filtering behavior
  • All existing tests continue to pass
  • Manual verification of CLI help and flag functionality

Closes #[issue_number]

Original prompt

This section details on the original issue you should resolve

<issue_title>Optimize kubeconfig update</issue_title>
<issue_description>Currently, we update the configuration for each cluster found, Even if there is already a cluster with the same identity. Provide a flag to allow exporting only the currently unexported clusters. </issue_description>

Comments on the Issue (you are @copilot in this section)

Fixes #43


💡 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.

@lintrule-review
Copy link

You're out of free credits.

You can fix that by putting in a card here.

Copilot AI and others added 3 commits October 14, 2025 11:49
Co-authored-by: mateimicu <4560298+mateimicu@users.noreply.github.com>
Co-authored-by: mateimicu <4560298+mateimicu@users.noreply.github.com>
Co-authored-by: mateimicu <4560298+mateimicu@users.noreply.github.com>
Copilot AI changed the title [WIP] Add flag to optimize kubeconfig update process Add --only-new flag to optimize kubeconfig updates Oct 14, 2025
Copilot AI requested a review from mateimicu October 14, 2025 11:57
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.

Optimize kubeconfig update

2 participants