A fake kube-apiserver that serves static data from files

Overview

Static KAS

A fake kube-apiserver that serves static data from an Openshift must-gather. Dynamically discovers resources and supports logs. Requires golang >= 1.17. While there is no explicit documentation for the directory layout, a sample is included for testing in ./pkg/handler/testdata.

Usage:

  1. Start the static-kas in a distinct terminal: go run ./cmd/ --base-dir ../must-gather/quay-io-openshift-release-dev-ocp-v4-0-art-dev-sha256-ec058cf120ee79c97fa385205ae5b4ab7745e4064716cadd1e319652f5999ffd/
  2. Create a Kubeconfig:
cat <<EOF >/tmp/kk
apiVersion: v1
clusters:
- cluster:
    server: http://localhost:8080
  name: static-kas
contexts:
- context:
    cluster: static-kas
    user: ""
    namespace: default
  name: static-kas
current-context: static-kas
kind: Config
EOF
  1. Use kubectl or any other standard client to interact with the static kas: kubectl --kubeconfig=/tmp/kk get pod
Comments
  • Automatically determine default container name when not given

    Automatically determine default container name when not given

    Background

    Older versions of kubectl/oc, when ran as kubectl logs -n <namespace> <name>, first try to GET the pod resource requested, if they see there's only one container in it, they will then try to GET:

    http://<api>/api/v1/namespaces/<namespace>/pods/<name>/log

    Without any container=... query param (newer versions of kubectl/oc always specify this query parameter regardless). The behavior of the regular kubernetes API server in this scenario is that when the pod has only a single container, the logs for that only container are returned. If the pod has more than one pod, an error response is returned, listing the names of the containers in the pod.

    Issue

    static-kas works fine when the container name is given in the query param (which is the case for newer oc/kubectl clients), but breaks down when the container parameter is omitted.

    Solution

    static-kas will now better imitate the behavior of the regular kubernetes API server

    opened by omertuc 9
  • Similar project

    Similar project

    Hey, I've been working on a similar project https://github.com/omertuc/o-must-external-reader

    I've written it in Python rather than Go.

    It's far from perfect and very buggy. My main goal was getting k9s to work somewhat ok, and i've come pretty far. You can view pods, containers, container logs (truncated due to k9s weirdness I've yet to figure out), yaml files.

    I can't seem to get k9s to work at all with your fake API server, it wouldn't even connect. I wonder why. I also couldn't do oc get pods -A .

    Looking forward to seeing how you improve this, hopefully I could use your server with k9s some day. Or if you want, we can join efforts and work on my project (or the other way around) - but I'm not sure how much overlap there is in what we've done so far and what things mine can do and yours can't and vice versa.

    Anyway just thought I should mention this

    opened by omertuc 3
  • Too many openfiles issues is not documented

    Too many openfiles issues is not documented

    When running static-kas on a large must-gather with the user limit of 1024 openfiles, you run into the error:

    {"error":"failed to read file namespaces/xxxx/operators.coreos.com/clusterserviceversions/jaeger-operator.v1.30.0.yaml: open namespaces/xxxxx/operators.coreos.com/clusterserviceversions/jaeger-operator.v1.30.0.yaml: too many open files"}],"stacktrace":"main.main\n\t/home/manu/Projects/git/static-kas/cmd/main.go:57\nruntime.main\n\t/usr/local/go/src/runtime/proc.go:255"
    

    This happens with 15000 files in a must-gather

    it is easy to resolve the error by using the user hardlimit of openfiles, following https://www.baeldung.com/linux/error-too-many-open-files or https://access.redhat.com/solutions/2469

    however this is maybe not trivial for an end user.

    If we agree to open a Wiki for the project, maybe linked from the Readme, we could add a line along the way of:

    When the must-gather you process with static-kas has a large number of files, you may reach into an error "too many open files". In that case you will need to [increase the maximum number of open file descriptors] for the user running static-kas(https://www.baeldung.com/linux/error-too-many-open-files). A limit of 4096 has been found to process correctly large must-gathers.

    opened by EmmanuelKasper 2
  • fix: set default kind and groupVersion

    fix: set default kind and groupVersion

    I have encountered this issue with resources coming from Cilium sysdumps. Is that an OK change for you @alvaroaleman ?

    Signed-off-by: Raphaël Pinson [email protected]

    opened by raphink 1
  • k9s container logs are truncated

    k9s container logs are truncated

    1. type :pods
    2. select an arbitrary pod
    3. press ↵ Return
    4. select an arbitrary container
    5. press L

    Logs are shown, but they're truncated. Pressing 0 does not help

    opened by omertuc 1
  • k9s

    k9s "edit" button doesn't work

    1. Type :pods
    2. Move the cursor to some arbitrary pod
    3. press y - works, shows you the YAML
    4. press esc to go back
    5. press e, should open in editor, but it doesn't

    I don't want editing to literally work, obviously, the gather should be immutable, but it's really nice having the yaml open in your $EDITOR of your choice

    Note that this is an API issue - it works OK with regular API servers

    opened by omertuc 1
  • feat: add optional version.json file to return version information

    feat: add optional version.json file to return version information

    Note: the Cilium Sysdump tool dumps the Kubernetes server version as Go code, e.g.:

    version.Info{Major:"1", Minor:"21+", GitVersion:"v1.21.5-eks-bc4871b", GitCommit:"5236faf39f1b7a7dabea8df12726f25608131aa9", GitTreeState:"clean", BuildDate:"2021-10-29T23:32:16Z", GoVersion:"go1.16.8", Compiler:"gc", Platform:"linux/amd64"}
    

    I think it's probably better to provide a JSON file as a standard (I actually don't see an easy way to parse the go version file in go).

    Signed-off-by: Raphaël Pinson [email protected]

    opened by raphink 0
Owner
Alvaro Aleman
Alvaro Aleman
Endpoints-operator - Kubernetes endpoints balance for outsite apiserver

endpoints-operator 对于集群内访问集群外部服务场景使用固定的endpoint维护增加探活功能 背景 在实际使用中,两个K8s集群内的服务经常有

sealyun 61 Dec 9, 2022
Command kube-tmux prints Kubernetes context and namespace to tmux status line.

kube-tmux Command kube-tmux prints Kubernetes context and namespace to tmux status line.

null 7 Sep 10, 2021
A general purpose cloud provider for Kube-Vip

kube-vip-cloud-provider The Kube-Vip cloud provider is a general purpose cloud-provider for on-prem bare-metal or virtualised environments. It's desig

kube-vip 63 Jan 8, 2023
Reworking kube-proxy's architecture

Kubernetes Proxy NG The Kubernetes Proxy NG a new design of kube-proxy aimed at allowing Kubernetes business logic to evolve with minimal to no impact

Kubernetes SIGs 185 Jan 3, 2023
A controller managing namespaces deployments, statefulsets and cronjobs objects. Inspired by kube-downscaler.

kube-ns-suspender Kubernetes controller managing namespaces life cycle. kube-ns-suspender Goal Usage Internals The watcher The suspender Flags Resourc

Virtuo 62 Dec 27, 2022
scenario system to check the behavior of kube-scheduler

kube-scheduler-simulator-cli: Kubernetes Scheduler simulator on CLI and scenario system. Hello world. This repository is scenario system for kube-sche

Kensei Nakada 2 Jan 25, 2022
Kube - A simple Kubernetes client, based on client-go

kube A simple Kubernetes client, based on client-go.

PengQi Shi 2 Aug 9, 2022
Container image sweeper kube

container-image-sweeper-kube container-image-sweeper-kube は、不要になった Docker イメージを自

Latona, Inc. 0 Jan 24, 2022
Kube-step-podautoscaler - Controller to scale workloads based on steps

Refer controller/*controller.go for implementation details and explanation for a better understanding.

Danish Prakash 5 Sep 5, 2022
Serves images taken on a FLIR Lepton connected to a Raspberry Pi SPI port to over HTTP.

go-lepton Streams images taken on a FLIR Lepton connected to a Raspberry Pi SPI port to over via WebSockets via embedded HTTP server. It sends the raw

M-A 24 Oct 29, 2022
Fake AWS S3 server for local development

FakeS3 server for local development Download latest binaries here Creating new release go get github.com/johannesboyne/gofakes3/cmd/[email protected]

Railsware 4 Aug 16, 2022
Vulnerability Static Analysis for Containers

Clair Note: The main branch may be in an unstable or even broken state during development. Please use releases instead of the main branch in order to

QUAY 9.3k Jan 4, 2023
Chronos - A static race detector for the go language

Chronos Chronos is a static race detector for the Go language written in Go. Quick Start: Download the package go get -v github.com/amit-davidson/Chro

Amit Davidson 383 Dec 12, 2022
Static analysis for CloudFormation templates to identify common misconfigurations

cfsec What is it? cfsec scans your yaml or json CloudFormation configuration files for common security misconfigurations. Installation Home Brew - Mac

Aqua Security 56 Nov 7, 2022
debiman generates a static manpage HTML repository out of a Debian archive

debiman Goals debiman makes (Debian) manpages accessible in a web browser. Its goals are, in order: completeness: all manpages in Debian should be ava

The Universal OS 145 Jan 4, 2023
Extract files from DATA.BIN

psptk5 学习研究对象:PSP 太阁立志传 5(TAIKOU RISSHIDEN V) ULJM-05525|303A88BDAC0128BC|0001|G 学习目的:从 DATA.BIN 文件中提取所有的文件 使用方法 psptk5 extract [path of DATA.BIN] [pa

Alexsel 2 Feb 21, 2022
HBase Exporter,fetch data from jmx for region-level data.

HBase Exporter Prometheus exporter for HBase which fetch data from hbase jmx, written in Go. You can even see region-level metrics. Installation and U

David 13 Nov 4, 2022
Kstone is an etcd management platform, providing cluster management, monitoring, backup, inspection, data migration, visual viewing of etcd data, and intelligent diagnosis.

Kstone 中文 Kstone is an etcd management platform, providing cluster management, monitoring, backup, inspection, data migration, visual viewing of etcd

TKEStack 596 Dec 27, 2022
Conduit - Data Integration for Production Data Stores

Conduit Data Integration for Production Data Stores. ?? Overview Conduit is a da

Conduit 244 Jan 3, 2023