Skip to content

Latest commit

 

History

History
83 lines (62 loc) · 2.38 KB

development.md

File metadata and controls

83 lines (62 loc) · 2.38 KB

Local development

How to run the CLI against a locally running KubeRocketCI Portal.

Prerequisites

  1. A KubeRocketCI portal backend on port 3001
  2. The portal's .env configured with a valid OIDC_ISSUER_URL (e.g. a Keycloak realm)
  3. Go 1.27+

Start the portal

cd krci-portal
cp .env.example .env   # fill in OIDC_ISSUER_URL, OIDC_CLIENT_ID, OIDC_CLIENT_SECRET
pnpm dev

The backend listens on http://localhost:3001. The Vite dev server (port 5173) only proxies /api, but the CLI talks to /rest/v1/ endpoints — point it directly at port 3001.

Build the CLI

make build        # → dist/krci
make test         # race detector + coverage
make lint         # golangci-lint v2
make lint-fix     # auto-fix formatting
make ci           # lint → test → build

Login against the local portal

The local portal runs over HTTP. The CLI accepts an http portal URL only for localhost and loopback IPs, and discovers the OIDC issuer and cluster metadata from it like from a remote portal:

./dist/krci auth login --portal-url http://localhost:3001

To skip discovery, supply the values via environment variables:

KRCI_ISSUER_URL=https://idp.example.com/realms/my-realm \
KRCI_CLUSTER_NAME=my-cluster \
KRCI_NAMESPACE=my-namespace \
  ./dist/krci auth login --portal-url http://localhost:3001

A browser window opens for authentication. On success:

Logged in as user@example.com (User Name)

All values are persisted to ~/.config/krci/config.yaml, so subsequent commands need no flags or env vars:

./dist/krci project list
./dist/krci deployment list
./dist/krci pipelinerun list --project keycloak-operator --reason

Architecture notes

  • Portal-only — the CLI talks exclusively to the portal tRPC API (Bearer idToken). No direct Kubernetes access.
  • Factory gate — internal/cmdutil/Factory validates PortalURL, ClusterName, and Namespace before creating PortalClient; commands never see invalid state.
  • Config precedence — flags > env vars > config.yaml > defaults (Viper-based, internal/config/).
  • Public OIDC issuer — the issuer URL comes from the portal's unauthenticated config.get endpoint (public metadata per OIDC Discovery).

Command layout

Each command lives in pkg/cmd/<group>/<verb>/ and exports NewCmd<Verb>(f, runF). Follow the existing commands as examples.