This document provides essential context and technical guidelines for AI agents and developers working on the cloudctl project.
cloudctl is a Go-based CLI tool (Go 1.25) designed to manage Kubernetes cluster access via the Greenhouse platform. Its primary purpose is to aggregate and sync kubeconfigs from a central Greenhouse management cluster to a user's local configuration.
- Language: Go 1.25+
- CLI Framework: Cobra
- Kubernetes Client:
k8s.io/client-goandsigs.k8s.io/controller-runtime/pkg/client - Testing: Standard Go tests + Gomega for E2E assertions.
- Build binary:
make build(outputs tobin/cloudctl) - Run without build:
make run ARGS="version" - Install to GOBIN:
make install
- Unit Tests:
make test - E2E Tests:
make e2e- Note: E2E tests require
k3d. TheMakefilemanages cluster lifecycle. - E2E tests are located in
/e2eand use thee2ebuild tag.
- Note: E2E tests require
Always use modern Go features:
- Looping:
for i := range ninstead offor i := 0; i < n; i++. - Slices/Maps: Use
slicesandmapspackages (e.g.,slices.Contains,maps.Clone). - Standard Library: Use
max(),min(), andclear(). - Iterators: Use
maps.Keys(m)ormaps.Values(m)withslices.Collect. - Error Handling: Use
errors.Isanderrors.As. - JSON tags: Use
omitzeroinstead ofomitemptyfortime.Time,time.Duration, structs, slices, and maps.
/cmd: CLI command implementations (using Cobra)./e2e: End-to-end tests andk3dlifecycle scripts./hack: Utility scripts and internal tools.
root.go: Defines the root command and global helpers likeconfigWithContext.sync.go: Contains the core logic for merging kubeconfigs.- It fetches
v1alpha1.ClusterKubeconfigresources from Greenhouse. - It merges clusters, contexts, and auth infos while preserving user modifications to unmanaged entries.
- It handles
oidc-login(kubelogin) configuration.
- It fetches
cluster-version.go: Implements Kubernetes version detection (unauthenticated fallback to authenticated).
When modifying sync.go, ensure:
- Deduplication: AuthInfos (users) are merged if they represent the same credentials (checked via
authInfoEqual). - Context Prefixing: Remote clusters and contexts are typically prefixed to avoid collisions.
- Immutability: Do not overwrite manual/unmanaged entries in the user's kubeconfig unless they overlap with managed entries.
- DCO: Ensure all commits have signed-off (
git commit -s). - Style: Use
type(scope): short descriptionstyle (e.g.,feat(controller): add dry-run support). - Note: Do NOT add
Co-authored-bytrailers unless explicitly requested.
- Code style? Followed Modern Go idioms and ran
make fmt. - Testing? Added/updated unit tests and verified with
make test. - E2E? Verified with
make e2eif affectingsyncorcluster-version. - Commits? All commits are signed-off (
-s).