You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
feat(sync): zero-flag usage via kubeconfig context and connection header - #89
Namespace auto-detection: --greenhouse-cluster-namespace is no longer required. Resolution order: explicit flag → ~/.cloudctl.yaml → namespace of the active kubeconfig context (org name == namespace set by bootstrap). Running cloudctl sync with no flags just works after bootstrap.
Write-target fallback: When neither --remote-cluster-kubeconfig nor KUBECONFIG is set, the write target falls back to ~/.kube/config, mirroring kubectl behaviour.
Connection info header: Every sync now prints a one-line summary (kubeconfig:, context:, namespace:, and optionally writing: when the write target differs) before the cluster list, making it immediately clear which Greenhouse org was synced and where the result was written.
Crash fix for --include-not-ready: mergeKubeconfig previously returned a hard error when a ClusterKubeconfig had contexts but no matching authinfos in its spec (e.g. not-ready clusters). These are now skipped with a debug log instead of failing the whole sync.
Internal cleanups
resolveDisplayPath delegates to resolveWriteTarget (single path-resolution logic, no duplication).
resolveDisplayContext + namespaceFromKubeconfig merged into loadKubeconfigContext (one kubeconfig load instead of two).
conn is built after the file-existence check so error messages always show the real context name.
Test plan
make test passes (ok cmd, ok cmd/output)
cloudctl sync (no flags) works when the active context has a namespace set
cloudctl sync --include-not-ready no longer crashes on orgs with not-ready clusters
Connection header appears at top of sync output with correct kubeconfig path and context name
writing: line appears only when the write target differs from the kubeconfig source
When --include-not-ready is set, some ClusterKubeconfigs have contexts
in their spec but no corresponding authinfo (e.g. the secret is absent
so only partial spec data is present). mergeKubeconfig was returning a
fatal error for these, failing the entire sync.
Skip such contexts with a debug-level log instead. The authinfo check
is applied to both the mergeIdenticalUsers=true and =false paths.
Signed-off-by: onuryilmaz <onur.yilmaz@sap.com>
Closes#79.
--greenhouse-cluster-namespace no longer required as a flag. Resolution
order: explicit flag → ~/.cloudctl.yaml → namespace of the active
Greenhouse context (org name == namespace set by bootstrap).
When no context is specified, the current-context from the kubeconfig is
used, mirroring kubectl behaviour. Write target defaults to ~/.kube/config
when neither --remote-cluster-kubeconfig nor KUBECONFIG is set, so a plain
`cloudctl sync` works out of the box after bootstrap.
Every sync now prints a one-line connection summary (kubeconfig path,
context, namespace) before the cluster list, making it immediately clear
which Greenhouse org was synced and where the result was written.
Internal cleanups:
- resolveDisplayPath delegates to resolveWriteTarget (single path-resolution logic)
- resolveDisplayContext + namespaceFromKubeconfig merged into loadKubeconfigContext
(single kubeconfig load instead of two)
- conn built after file-existence check so error messages always show
the real context name instead of "(unknown)"
Signed-off-by: onuryilmaz <onur.yilmaz@sap.com>
The reason will be displayed to describe this comment to others. Learn more.
🟡 Changes recommended
With deduplication enabled, sync can delete existing managed credentials and contexts when incoming authinfo is missing, then persist those deletions and report success.
This PR simplifies cloudctl’s Greenhouse kubeconfig sync workflow, supporting zero-flag usage through persisted defaults and namespace inference from the selected context.
Changes:
Adds namespace auto-detection, setup guidance, and a default write target of ~/.kube/config.
Adds connection details to sync output and clearer configuration errors.
Changes missing-authinfo handling to skip affected contexts and adds tests for fallback behavior.
File
Description
cmd/sync.go
Adds connection resolution, output metadata, write fallback, and missing-authinfo handling.
cmd/sync_test.go
Tests default write-target selection and context/namespace lookup; adds namespace-error assertions.
cmd/root.go
Includes configuration file paths in read errors.
cmd/output/types.go
Adds connection and write-target fields to sync results.
cmd/output/plain_printer.go
Renders connection details in plain-text sync output.
cmd/output/interactive_printer.go
Renders styled connection details in interactive sync output.
resolveDisplayPath reported only the first file from a multi-file
KUBECONFIG, so the header could point to the wrong source when the
Greenhouse context lived in a later file.
Replace with resolveDisplaySources, which returns the full
colon-separated KUBECONFIG list verbatim. The write target (first
entry, kubectl convention) is resolved separately and shown on the
"writing:" line only when it is not already represented in the source
list (checked via isWriteTargetInSources).
Signed-off-by: onuryilmaz <onur.yilmaz@sap.com>
When a ClusterKubeconfig had contexts but no matching authinfo (e.g.
a partially-ready cluster under --include-not-ready), the context was
already skipped in the merge loop. However the cleanup pass then saw
the context's authinfo as unmapped and deleted the existing local
managed context, leaving the kubeconfig in a worse state than before.
Track skipped server-side contexts in skippedServerContexts and check
this set in the cleanup pass before deleting a context as "unmapped
authinfo", preserving the existing local entry instead.
Also expand leading "~/" in kubeconfig paths read from ~/.cloudctl.yaml
(shell tilde-expansion does not apply inside config files). Add
expandTilde helper in root.go; update the help example to note that
tilde is supported.
Signed-off-by: onuryilmaz <onur.yilmaz@sap.com>
The reason will be displayed to describe this comment to others. Learn more.
🟡 Changes recommended
Skipped contexts can lose working access when cleanup deletes their credentials or clusters, and dry-run output still omits the selected context and namespace.
The connection details are attached only to SyncResult, but sync --dry-run returns a separate SyncDryRunResult before reaching the final result construction. Neither dry-run printer renders this header, so previewing a zero-flag sync still gives no indication of the selected context or namespace. Carry the connection metadata into the dry-run result and render it in both text printers as well.
The previous fix preserved the local managed context when its incoming
authinfo was missing, but the authinfo and cluster referenced by that
context were still deleted by the cleanup passes.
Introduce preservedAuthInfos and preservedClusters sets alongside
skippedServerContexts. When a context is skipped, read its current
local managed authinfo and cluster names and add them to the respective
sets. The cluster and authinfo cleanup loops skip any entry present in
these sets, keeping the full kubeconfig entry intact across syncs.
Signed-off-by: onuryilmaz <onur.yilmaz@sap.com>
The reason will be displayed to describe this comment to others. Learn more.
🔵 Needs a closer look
With --merge-identical-users=false, the final reference check can still delete an existing context whose incoming replacement was skipped because of a missing user.
No open issues 🎉
1 previously missed issue
In code that hasn't changed since last review
Preserve skipped contexts when merging is disabled
cmd/sync.go:962
The preservation check still runs only when mergeIdenticalUsers is true. With --merge-identical-users=false, if an existing context references cloudctl:old-user and the incomplete incoming context references a missing new-user, insertion is skipped and its dependencies are preserved, but the final mismatched-reference check (lines 978–980) deletes the context anyway. Check skippedServerContexts before either mode's reference validation so skipped contexts survive in both modes.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #79.
Summary
--greenhouse-cluster-namespaceis no longer required. Resolution order: explicit flag →~/.cloudctl.yaml→ namespace of the active kubeconfig context (org name == namespace set by bootstrap). Runningcloudctl syncwith no flags just works after bootstrap.--remote-cluster-kubeconfignorKUBECONFIGis set, the write target falls back to~/.kube/config, mirroringkubectlbehaviour.kubeconfig:,context:,namespace:, and optionallywriting:when the write target differs) before the cluster list, making it immediately clear which Greenhouse org was synced and where the result was written.--include-not-ready:mergeKubeconfigpreviously returned a hard error when aClusterKubeconfighad contexts but no matching authinfos in its spec (e.g. not-ready clusters). These are now skipped with a debug log instead of failing the whole sync.Internal cleanups
resolveDisplayPathdelegates toresolveWriteTarget(single path-resolution logic, no duplication).resolveDisplayContext+namespaceFromKubeconfigmerged intoloadKubeconfigContext(one kubeconfig load instead of two).connis built after the file-existence check so error messages always show the real context name.Test plan
make testpasses (ok cmd,ok cmd/output)cloudctl sync(no flags) works when the active context has a namespace setcloudctl sync --include-not-readyno longer crashes on orgs with not-ready clusterswriting:line appears only when the write target differs from the kubeconfig source