keiailab-commons

module
v0.13.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 30, 2026 License: MIT

README

keiailab

keiailab-commons

Shared Go helpers for Kubernetes operator scaffolding — finalizers, recommended labels, status conditions, supported-version allowlists, restricted PodSecurity contexts, NetworkPolicies, ServiceMonitor builders, and a Helm library chart.

English | 한국어 | 日本語 | 中文

Go Go Reference

Design assets

Asset Path Usage
Centered service symbol docs/branding/symbol.png GitHub README, Artifact Hub icon/screenshot
Keiailab base symbol docs/branding/base-symbol.png Source reference for the outer rotating-arrow mark
Branding guide docs/BRANDING.md Public visual usage rules

Operator authors repeatedly re-implement the same scaffolding: restricted PodSecurity contexts, supported-version matrices, default-deny NetworkPolicies, ServiceMonitor builders, finalizer helpers, status condition catalogs. Each independent copy drifts apart over time and grows silent inconsistencies. keiailab-commons is one place to get the canonical implementation, behind a small API surface that follows a clear stability promise.

Installation

go get github.com/keiailab/keiailab-commons@latest

Requires Go 1.26+. The library depends only on k8s.io/api, k8s.io/apimachinery, and sigs.k8s.io/controller-runtime; most packages use no controller-runtime at all (see the table below).

Usage

Build a restricted-profile container SecurityContext and a supported-version allowlist:

import (
	"github.com/keiailab/keiailab-commons/pkg/security"
	"github.com/keiailab/keiailab-commons/pkg/version"
	corev1 "k8s.io/api/core/v1"
)

var supported = version.MustList("1.0", "1.1", "1.2")

func containerSecurityContext() *corev1.SecurityContext {
	return security.RestrictedContainer(
		security.WithRunAsUser(999),
		security.WithRunAsGroup(999),
	)
}

func isAllowed(v string) bool { return supported.IsSupported(v) }

Apply recommended Kubernetes labels and report status conditions on a CR:

import (
	"github.com/keiailab/keiailab-commons/pkg/labels"
	"github.com/keiailab/keiailab-commons/pkg/status"
	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

// app.kubernetes.io/* recommended labels.
ls := labels.New("my-db", "my-db-prod", "database", "1.2.0", "my-operator")
deployment.Labels = ls.All()                 // full label set
deployment.Spec.Selector.MatchLabels = ls.Selector() // stable subset (no version)

// Standard Ready/Available conditions.
status.SetReady(&cr.Status.Conditions, "Reconciled", "all components ready", cr.Generation)
if status.IsReady(cr.Status.Conditions) {
	// ...
}

Each package ships runnable examples in its doc.go — browse them with go doc github.com/keiailab/keiailab-commons/pkg/<name> or on pkg.go.dev.

Packages

Package Tier Purpose
pkg/finalizer Stable Finalizer helpers — Add / Remove / Has / EnsureOrder (stdlib slices only, no controller-runtime).
pkg/labels Stable Recommended app.kubernetes.io/* labels — New, Set.All(), Set.Selector(), plus a v2 mapping (AllV2).
pkg/status Stable Standard Condition types + Reason catalog — SetReady, SetAvailable, SetProgressing, SetDegraded, IsReady, FindCondition, plus UpdateWithRetry (retry-on-conflict status persistence).
pkg/storageclass Stable DNS-1123 storageClass validation + Normalize / MustNormalize (empty → cluster-default pointer).
pkg/version Beta Supported-version allowlist — MustList, IsSupported, Strings, Default + generic Matrix[E MatrixEntry].
pkg/monitoring Beta Prometheus Operator ServiceMonitor / PrometheusRule builders (unstructured — no CRD dependency).
pkg/networkpolicy Beta Deny-by-default NetworkPolicy builder + functional options (WithSelfIngress, WithIngressFromPeers, WithDenyEgress, WithEgressToPeers).
pkg/security Beta PodSecurity restricted SecurityContext builder — container / pod split + seccomp profile helpers.
pkg/events Beta Minimal Recorder interface + Emit / EmitWarning / WrappedError (nil-safe).
pkg/pvc Beta PVC expansion helpers — comparison + safe in-place update (uses controller-runtime).
pkg/topology Beta TopologySpreadConstraints HA defaults + zone-aware affinity.
pkg/apply Beta Idempotent apply helpers — ConfigMap / Service / StatefulSet / Deployment / NetworkPolicy / PDB / HPA, preserving immutable fields + server defaults (uses controller-runtime).
pkg/certmanager Beta cert-manager Certificate / self-signed Issuer builders — CertParams, BuildCertificate, BuildSelfSignedIssuer, ServiceSANs (unstructured — no CRD dependency).
pkg/reconcile Beta Reconcile-loop helpers — Statusable, ApplyErrorCondition, HandleFinalizerCleanup, SecretIfNotExists (uses controller-runtime).
pkg/reconcilemetrics Beta Prometheus reconcile metrics — New(subsystem) (preserves existing series names), IncTotal / ObserveReconcile / IncError, ResultFor (uses prometheus/client_golang).
pkg/probes Experimental corev1.Probe fluent builder — HTTP / HTTPS / TCP / Exec with kubelet defaults.
pkg/webhook Experimental Admission validation helpers — ValidateAllowedVersion, ValidateWithPredicate, conversion registry.
pkg/bundle Experimental OLM v1 bundle metadata helpers — annotations, FBC schema types, directory validation.

A Helm library chart (charts/keiailab-commons, type: library) provides matching partials for downstream consumer charts.

See docs/STABILITY.md for the tier promise, docs/ARCHITECTURE.md for the package surface and design invariants, and docs/ROADMAP.md for tier-promotion criteria and the v1.0 graduation checklist.

Versioning

  • v0.x: API breaking changes are allowed. Each v0.N.M tag bumps a package's public API or a meaningful behavioural change — pin a specific version in go.mod.
  • v1.0 onwards: Semantic Versioning. Breaking changes require an ADR.

Contributing

Bug reports and feature requests go to Issues. See CONTRIBUTING.md for the development workflow and SECURITY.md for the private disclosure process.

License

MIT © keiailab.

Directories

Path Synopsis
pkg
apply
Package apply 는 K8s 리소스의 idempotent apply 헬퍼를 제공한다 — controllerutil.CreateOrUpdate 를 도메인 타입별로 감싸 immutable 필드의 create-only 가드와 server-default 보존 (nil-guard) 을 일관 적용한다.
Package apply 는 K8s 리소스의 idempotent apply 헬퍼를 제공한다 — controllerutil.CreateOrUpdate 를 도메인 타입별로 감싸 immutable 필드의 create-only 가드와 server-default 보존 (nil-guard) 을 일관 적용한다.
batchjob
Package batchjob 은 downstream operator 공통의 batch/v1 Job 엔벨로프 빌더를 제공한다.
Package batchjob 은 downstream operator 공통의 batch/v1 Job 엔벨로프 빌더를 제공한다.
bundle
Stability: Experimental.
Stability: Experimental.
certmanager
Package certmanager 는 cert-manager (cert-manager.io/v1) 의 Certificate / Issuer CR 을 unstructured 로 생성하는 공통 builder 를 제공한다.
Package certmanager 는 cert-manager (cert-manager.io/v1) 의 Certificate / Issuer CR 을 unstructured 로 생성하는 공통 builder 를 제공한다.
events
Stability: Beta.
Stability: Beta.
finalizer
Stability: Stable.
Stability: Stable.
hpa
Package hpa 는 downstream operator 공통의 HorizontalPodAutoscaler 빌더와 표준 metric 헬퍼를 제공한다.
Package hpa 는 downstream operator 공통의 HorizontalPodAutoscaler 빌더와 표준 metric 헬퍼를 제공한다.
labels
Stability: Stable.
Stability: Stable.
monitoring
Stability: Beta.
Stability: Beta.
networkpolicy
Stability: Stable.
Stability: Stable.
pdb
Package pdb 는 downstream operator 공통의 PodDisruptionBudget 빌더를 제공한다.
Package pdb 는 downstream operator 공통의 PodDisruptionBudget 빌더를 제공한다.
probes
Package probes provides a fluent builder for corev1.Probe.
Package probes provides a fluent builder for corev1.Probe.
pvc
Package pvc 는 downstream operator 의 공통 PVC 처리 헬퍼를 제공한다.
Package pvc 는 downstream operator 의 공통 PVC 처리 헬퍼를 제공한다.
reconcile
Package reconcile 는 downstream operator controller 의 공통 reconcile orchestration 헬퍼를 제공한다 — status 추상화 interface (Statusable), 에러 condition 표준 적용 (ApplyErrorCondition), finalizer cleanup 흐름 (HandleFinalizerCleanup), Secret 멱등 생성 (SecretIfNotExists).
Package reconcile 는 downstream operator controller 의 공통 reconcile orchestration 헬퍼를 제공한다 — status 추상화 interface (Statusable), 에러 condition 표준 적용 (ApplyErrorCondition), finalizer cleanup 흐름 (HandleFinalizerCleanup), Secret 멱등 생성 (SecretIfNotExists).
reconcilemetrics
Package reconcilemetrics 는 downstream operator 의 공통 reconcile SLO Prometheus metrics trio (reconcile_total / reconcile_duration_seconds / reconcile_errors_total) 와 CR 삭제 시 cardinality 정리 (DeleteFor) 를 제공한다.
Package reconcilemetrics 는 downstream operator 의 공통 reconcile SLO Prometheus metrics trio (reconcile_total / reconcile_duration_seconds / reconcile_errors_total) 와 CR 삭제 시 cardinality 정리 (DeleteFor) 를 제공한다.
secrethash
Package secrethash 는 Secret data 의 *결정적* digest 를 계산하는 헬퍼를 제공한다.
Package secrethash 는 Secret data 의 *결정적* digest 를 계산하는 헬퍼를 제공한다.
security
Stability: Stable.
Stability: Stable.
service
Package service 는 downstream operator 공통의 Kubernetes Service 조립 빌더를 제공한다.
Package service 는 downstream operator 공통의 Kubernetes Service 조립 빌더를 제공한다.
status
Package status 는 downstream consumer keiailab operator 공통 Condition Type / Reason 카탈로그 + apimeta.SetStatusCondition 헬퍼를 제공한다.
Package status 는 downstream consumer keiailab operator 공통 Condition Type / Reason 카탈로그 + apimeta.SetStatusCondition 헬퍼를 제공한다.
storageclass
Stability: Stable.
Stability: Stable.
topology
Package topology 는 keiailab downstream operator 의 공통 TopologySpreadConstraints 헬퍼를 제공한다.
Package topology 는 keiailab downstream operator 의 공통 TopologySpreadConstraints 헬퍼를 제공한다.
version
Stability: Beta.
Stability: Beta.
volume
Package volume 은 downstream operator 공통의 Pod Volume / VolumeMount 빌더를 제공한다.
Package volume 은 downstream operator 공통의 Pod Volume / VolumeMount 빌더를 제공한다.
webhook
Stability: Experimental.
Stability: Experimental.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL