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:
- 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/
- 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
- Use
kubectl
or any other standard client to interact with the static kas:kubectl --kubeconfig=/tmp/kk get pod
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
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
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:
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.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]
k9s container logs are truncated
:pods
Logs are shown, but they're truncated. Pressing 0 does not help
k9s "edit" button doesn't work
:pods
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 choiceNote that this is an API issue - it works OK with regular API servers
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.:
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]