Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
67 changes: 66 additions & 1 deletion cmd/api/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@
"k8s.io/client-go/kubernetes"
"k8s.io/client-go/rest"

kubearchive "github.com/tektoncd/results/pkg/kubearchive"

Check failure on line 47 in cmd/api/main.go

View workflow job for this annotation

GitHub Actions / lint

File is not properly formatted (gofmt)
"github.com/tektoncd/results/pkg/kubearchive/adapter"
kaRouters "github.com/kubearchive/kubearchive/cmd/api/routers"
"github.com/kubearchive/kubearchive/pkg/cache"

"go.uber.org/zap"
"go.uber.org/zap/zapcore"

Expand Down Expand Up @@ -233,6 +238,7 @@

// Create the authorization authCheck
var authCheck auth.Checker
var k8s kubernetes.Interface // Declare k8s client for use in Kubearchive integration
serverMuxOptions := []runtime.ServeMuxOption{runtime.WithMarshalerOption(runtime.MIMEWildcard, &runtime.JSONPb{
MarshalOptions: protojson.MarshalOptions{
UseProtoNames: true,
Expand All @@ -244,6 +250,16 @@
if serverConfig.AUTH_DISABLE {
log.Warn("Kubernetes RBAC authorization check disabled - all requests will be allowed by the API server")
authCheck = &auth.AllowAll{}
// Still need k8s client for Kubearchive kubectl-compatible API
k8sConfig, err := rest.InClusterConfig()
if err != nil {
log.Warn("Warning: Could not get kubernetes client config (kubectl API will not work):", err)
} else {
k8s, err = kubernetes.NewForConfig(k8sConfig)
if err != nil {
log.Warn("Warning: Could not create kubernetes client (kubectl API will not work):", err)
}
}
} else {
log.Info("Kubernetes RBAC authorization check enabled")
// Create k8s client
Expand All @@ -260,7 +276,7 @@
if burst > 0 {
k8sConfig.Burst = burst
}
k8s, err := kubernetes.NewForConfig(k8sConfig)
k8s, err = kubernetes.NewForConfig(k8sConfig)
if err != nil {
log.Fatal("Error creating kubernetes clientset:", err)
}
Expand Down Expand Up @@ -407,8 +423,57 @@

httpMux = v1alpha2.Handler(httpMux, v1a2.LogPluginServer)

// Create Kubearchive adapter for kubectl-compatible API (if k8s client is available)
if k8s != nil {
dbAdapter := adapter.NewTektonResultsAdapter(db)
kubearchiveCache := cache.New()
kubearchiveCacheConfig := &kaRouters.CacheExpirations{
Authorized: 10 * time.Minute,
Unauthorized: 1 * time.Minute,
}

// Create Kubearchive router (returns http.Handler)
// For proof of concept, accepts any API group
kubearchiveHandler := kubearchive.NewRouter(
k8s, // Existing K8s client
dbAdapter,
kubearchiveCache,
kubearchiveCacheConfig,
)

// Save the original httpMux before reassigning to avoid circular reference
originalHttpMux := httpMux

Check failure on line 445 in cmd/api/main.go

View workflow job for this annotation

GitHub Actions / lint

var-naming: var originalHttpMux should be originalHTTPMux (revive)

// Create a custom handler that routes between Kubearchive and Tekton Results
// Route to Kubearchive for any /apis/<group>/ EXCEPT results.tekton.dev
combinedHandler := http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
// Check if request is for Tekton Results API (results.tekton.dev)
if strings.HasPrefix(r.URL.Path, "/apis/results.tekton.dev/") {
originalHttpMux.ServeHTTP(w, r)
return
}

// Check if request is for any other API group (starts with /apis/<something>/)
if strings.HasPrefix(r.URL.Path, "/apis/") && len(r.URL.Path) > 6 {
// Route to Kubearchive kubectl-compatible API
kubearchiveHandler.ServeHTTP(w, r)
return
}

// Otherwise, use existing Tekton Results handler
originalHttpMux.ServeHTTP(w, r)
})

// Use combined handler for server initialization
httpMux = combinedHandler
log.Info("Kubearchive kubectl-compatible API enabled for /apis/<group>/ (except results.tekton.dev)")
} else {
log.Warn("Kubearchive kubectl-compatible API disabled (Kubernetes client not available)")
}

// Start server with gRPC and REST handler
log.Infof("gRPC and REST server listening on: %s", serverConfig.SERVER_PORT)

if tlsError != nil {
log.Fatal(http.ListenAndServe(":"+serverConfig.SERVER_PORT, grpcHandler(gs, httpMux)))
}
Expand Down
72 changes: 54 additions & 18 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ require (
github.com/aws/aws-sdk-go-v2/credentials v1.19.12
github.com/aws/aws-sdk-go-v2/service/s3 v1.97.1
github.com/fatih/color v1.18.0
github.com/gin-gonic/gin v1.12.0
github.com/golang-jwt/jwt/v4 v4.5.2
github.com/golang/protobuf v1.5.4
github.com/google/cel-go v0.27.0
Expand All @@ -27,6 +28,7 @@ require (
github.com/jackc/pgx/v5 v5.8.0
github.com/jonboulle/clockwork v0.5.0
github.com/json-iterator/go v1.1.12
github.com/kubearchive/kubearchive v1.20.0
github.com/mattn/go-sqlite3 v1.14.34
github.com/prometheus/client_golang v1.23.2
github.com/robfig/cron/v3 v3.0.1
Expand Down Expand Up @@ -54,9 +56,9 @@ require (
k8s.io/api v0.34.5
k8s.io/apimachinery v0.34.5
k8s.io/apiserver v0.32.13
k8s.io/cli-runtime v0.29.15
k8s.io/cli-runtime v0.32.13
k8s.io/client-go v0.34.5
k8s.io/utils v0.0.0-20250820121507-0af2bda4dd1d
k8s.io/utils v0.0.0-20260210185600-b8788abfbbc2
knative.dev/pkg v0.0.0-20250415155312-ed3e2158b883
sigs.k8s.io/yaml v1.6.0
)
Expand Down Expand Up @@ -110,12 +112,17 @@ require (
github.com/beorn7/perks v1.0.1 // indirect
github.com/blang/semver/v4 v4.0.0 // indirect
github.com/blendle/zapdriver v1.3.1 // indirect
github.com/bytedance/gopkg v0.1.3 // indirect
github.com/bytedance/sonic v1.15.0 // indirect
github.com/bytedance/sonic/loader v0.5.0 // indirect
github.com/cenkalti/backoff/v5 v5.0.3 // indirect
github.com/census-instrumentation/opencensus-proto v0.4.1 // indirect
github.com/cespare/xxhash/v2 v2.3.0 // indirect
github.com/chrismellard/docker-credential-acr-env v0.0.0-20230304212654-82a0ddb27589 // indirect
github.com/clipperhouse/stringish v0.1.1 // indirect
github.com/clipperhouse/uax29/v2 v2.3.0 // indirect
github.com/cloudevents/sdk-go/v2 v2.16.2 // indirect
github.com/cloudwego/base64x v0.1.6 // indirect
github.com/cncf/xds/go v0.0.0-20251210132809-ee656c7534f5 // indirect
github.com/containerd/stargz-snapshotter/estargz v0.18.2 // indirect
github.com/cpuguy83/go-md2man/v2 v2.0.7 // indirect
Expand All @@ -124,22 +131,25 @@ require (
github.com/docker/cli v29.2.1+incompatible // indirect
github.com/docker/distribution v2.8.3+incompatible // indirect
github.com/docker/docker-credential-helpers v0.9.3 // indirect
github.com/ebitengine/purego v0.10.0 // indirect
github.com/emicklei/go-restful/v3 v3.12.2 // indirect
github.com/envoyproxy/go-control-plane/envoy v1.36.0 // indirect
github.com/envoyproxy/protoc-gen-validate v1.3.0 // indirect
github.com/evanphx/json-patch v5.9.0+incompatible // indirect
github.com/evanphx/json-patch/v5 v5.9.11 // indirect
github.com/felixge/httpsnoop v1.0.4 // indirect
github.com/fsnotify/fsnotify v1.9.0 // indirect
github.com/fxamacker/cbor/v2 v2.9.0 // indirect
github.com/gabriel-vasile/mimetype v1.4.13 // indirect
github.com/gdamore/encoding v1.0.1 // indirect
github.com/gdamore/tcell/v2 v2.9.0 // indirect
github.com/gin-contrib/sse v1.1.0 // indirect
github.com/go-errors/errors v1.4.2 // indirect
github.com/go-jose/go-jose/v4 v4.1.3 // indirect
github.com/go-kit/log v0.2.1 // indirect
github.com/go-logfmt/logfmt v0.6.0 // indirect
github.com/go-logr/logr v1.4.3 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/go-ole/go-ole v1.3.0 // indirect
github.com/go-openapi/jsonpointer v0.22.4 // indirect
github.com/go-openapi/jsonreference v0.21.4 // indirect
github.com/go-openapi/swag v0.25.4 // indirect
Expand All @@ -154,8 +164,13 @@ require (
github.com/go-openapi/swag/stringutils v0.25.4 // indirect
github.com/go-openapi/swag/typeutils v0.25.4 // indirect
github.com/go-openapi/swag/yamlutils v0.25.4 // indirect
github.com/go-playground/locales v0.14.1 // indirect
github.com/go-playground/universal-translator v0.18.1 // indirect
github.com/go-playground/validator/v10 v10.30.1 // indirect
github.com/go-sql-driver/mysql v1.9.3 // indirect
github.com/go-viper/mapstructure/v2 v2.4.0 // indirect
github.com/goccy/go-json v0.10.5 // indirect
github.com/goccy/go-yaml v1.19.2 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang/groupcache v0.0.0-20241129210726-2c02b8208cf8 // indirect
github.com/google/btree v1.1.3 // indirect
Expand All @@ -164,14 +179,12 @@ require (
github.com/google/go-containerregistry/pkg/authn/k8schain v0.0.0-20240108195214-a0658aa1d0cc // indirect
github.com/google/go-containerregistry/pkg/authn/kubernetes v0.0.0-20240108195214-a0658aa1d0cc // indirect
github.com/google/s2a-go v0.1.9 // indirect
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 // indirect
github.com/google/wire v0.7.0 // indirect
github.com/googleapis/enterprise-certificate-proxy v0.3.14 // indirect
github.com/googleapis/gax-go/v2 v2.17.0 // indirect
github.com/gorilla/websocket v1.5.4-0.20250319132907-e064f32e3674 // indirect
github.com/gregjones/httpcache v0.0.0-20190611155906-901d90724c79 // indirect
github.com/hashicorp/golang-lru v1.0.2 // indirect
github.com/imdario/mergo v0.3.16 // indirect
github.com/inconshreveable/mousetrap v1.1.0 // indirect
github.com/jackc/chunkreader/v2 v2.0.1 // indirect
github.com/jackc/pgio v1.0.0 // indirect
Expand All @@ -184,10 +197,13 @@ require (
github.com/kballard/go-shellquote v0.0.0-20180428030007-95032a82bc51 // indirect
github.com/kelseyhightower/envconfig v1.4.0 // indirect
github.com/klauspost/compress v1.18.4 // indirect
github.com/klauspost/cpuid/v2 v2.3.0 // indirect
github.com/ktr0731/go-ansisgr v0.1.0 // indirect
github.com/ktr0731/go-fuzzyfinder v0.9.0 // indirect
github.com/leodido/go-urn v1.4.0 // indirect
github.com/liggitt/tabwriter v0.0.0-20181228230101-89fcab3d43de // indirect
github.com/lucasb-eyer/go-colorful v1.3.0 // indirect
github.com/lufia/plan9stats v0.0.0-20260216142805-b3301c5f2a88 // indirect
github.com/mattn/go-colorable v0.1.14 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/mattn/go-runewidth v0.0.19 // indirect
Expand All @@ -209,13 +225,17 @@ require (
github.com/pkg/errors v0.9.1 // indirect
github.com/planetscale/vtprotobuf v0.6.1-0.20240319094008-0393e58bdf10 // indirect
github.com/pmezard/go-difflib v1.0.1-0.20181226105442-5d4384ee4fb2 // indirect
github.com/power-devops/perfstat v0.0.0-20240221224432-82ca36839d55 // indirect
github.com/prometheus/client_model v0.6.2 // indirect
github.com/prometheus/common v0.67.5 // indirect
github.com/prometheus/procfs v0.17.0 // indirect
github.com/prometheus/statsd_exporter v0.22.7 // indirect
github.com/quic-go/qpack v0.6.0 // indirect
github.com/quic-go/quic-go v0.59.0 // indirect
github.com/russross/blackfriday/v2 v2.1.0 // indirect
github.com/sagikazarmark/locafero v0.11.0 // indirect
github.com/secure-systems-lab/go-securesystemslib v0.10.0 // indirect
github.com/shirou/gopsutil/v4 v4.26.2 // indirect
github.com/sigstore/protobuf-specs v0.5.0 // indirect
github.com/sigstore/sigstore v1.10.4 // indirect
github.com/sirupsen/logrus v1.9.4 // indirect
Expand All @@ -227,23 +247,39 @@ require (
github.com/subosito/gotenv v1.6.0 // indirect
github.com/tektoncd/triggers v0.35.0 // indirect
github.com/tidwall/match v1.1.1 // indirect
github.com/tidwall/pretty v1.2.0 // indirect
github.com/tidwall/pretty v1.2.1 // indirect
github.com/tklauser/go-sysconf v0.3.16 // indirect
github.com/tklauser/numcpus v0.11.0 // indirect
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
github.com/ugorji/go/codec v1.3.1 // indirect
github.com/vbatts/tar-split v0.12.2 // indirect
github.com/x448/float16 v0.8.4 // indirect
github.com/xlab/treeprint v1.2.0 // indirect
github.com/yusufpapurcu/wmi v1.2.4 // indirect
go.mongodb.org/mongo-driver/v2 v2.5.0 // indirect
go.opentelemetry.io/auto/sdk v1.2.1 // indirect
go.opentelemetry.io/contrib/bridges/otelslog v0.17.0 // indirect
go.opentelemetry.io/contrib/detectors/gcp v1.39.0 // indirect
go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.63.0 // indirect
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.63.0 // indirect
go.opentelemetry.io/otel v1.40.0 // indirect
go.opentelemetry.io/otel/metric v1.40.0 // indirect
go.opentelemetry.io/otel/sdk v1.40.0 // indirect
go.opentelemetry.io/otel/sdk/metric v1.40.0 // indirect
go.opentelemetry.io/otel/trace v1.40.0 // indirect
go.starlark.net v0.0.0-20230525235612-a134d8f9ddca // indirect
go.opentelemetry.io/contrib/instrumentation/host v0.67.0 // indirect
go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.67.0 // indirect
go.opentelemetry.io/contrib/instrumentation/runtime v0.67.0 // indirect
go.opentelemetry.io/otel v1.42.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlplog/otlploghttp v0.18.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlpmetric/otlpmetrichttp v1.42.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlptrace v1.42.0 // indirect
go.opentelemetry.io/otel/exporters/otlp/otlptrace/otlptracehttp v1.42.0 // indirect
go.opentelemetry.io/otel/log v0.18.0 // indirect
go.opentelemetry.io/otel/metric v1.42.0 // indirect
go.opentelemetry.io/otel/sdk v1.42.0 // indirect
go.opentelemetry.io/otel/sdk/log v0.18.0 // indirect
go.opentelemetry.io/otel/sdk/metric v1.42.0 // indirect
go.opentelemetry.io/otel/trace v1.42.0 // indirect
go.opentelemetry.io/proto/otlp v1.9.0 // indirect
go.uber.org/multierr v1.11.0 // indirect
go.yaml.in/yaml/v2 v2.4.3 // indirect
go.yaml.in/yaml/v3 v3.0.4 // indirect
golang.org/x/arch v0.22.0 // indirect
golang.org/x/crypto v0.49.0 // indirect
golang.org/x/exp v0.0.0-20250620022241-b7579e27df2b // indirect
golang.org/x/sync v0.20.0 // indirect
Expand All @@ -257,12 +293,12 @@ require (
google.golang.org/genproto/googleapis/rpc v0.0.0-20260226221140-a57be14db171 // indirect
gopkg.in/evanphx/json-patch.v4 v4.12.0 // indirect
gopkg.in/inf.v0 v0.9.1 // indirect
k8s.io/apiextensions-apiserver v0.32.11 // indirect
k8s.io/klog/v2 v2.130.1 // indirect
k8s.io/apiextensions-apiserver v0.32.12 // indirect
k8s.io/klog/v2 v2.140.0 // indirect
k8s.io/kube-openapi v0.0.0-20250710124328-f3f2b991d03b // indirect
sigs.k8s.io/json v0.0.0-20241014173422-cfa47c3a1cc8 // indirect
sigs.k8s.io/kustomize/api v0.13.5-0.20230601165947-6ce0bf390ce3 // indirect
sigs.k8s.io/kustomize/kyaml v0.14.3-0.20230601165947-6ce0bf390ce3 // indirect
sigs.k8s.io/json v0.0.0-20250730193827-2d320260d730 // indirect
sigs.k8s.io/kustomize/api v0.20.1 // indirect
sigs.k8s.io/kustomize/kyaml v0.20.1 // indirect
sigs.k8s.io/randfill v1.0.0 // indirect
sigs.k8s.io/structured-merge-diff/v6 v6.3.0 // indirect
)
Loading
Loading