This library provides a simplified interface on top of the official kubernetes client libraries.
The design focus of this module is usability, not performance or type-safety. We wanted to create a module that is closer to the use of kubectl based scripts.
We use this library for tools that interact with the Kubernetes API,
especially when the inspected objects are of varying types.
There's also support for building simple admission webhooks using the
Gin framework. This provides an
alternative solutions to writing admission controllers that is more
lightweight than the official SDK.
This repository is in active development but is not our main focus.
PRs are welcome, but will take some time to be reviewed.
All files in the repository are subject to the Apache 2.0 License
All commits to the main branch need to use conventional commits.
Releases will be generated automatically from these commits using Release Please.
All required tools can be installed locally via nix
and are loaded on demand via direnv.
On MacOS you can install nix via the installer from determinate systems.
curl --proto '=https' --tlsv1.2 -sSf -L https://install.determinate.systems/nix | sh -s -- installWe provided a justfile to generate the required .envrc file.
Run just init-nix to get started, or run the script directly.
After you have set up your environment, run unittests via just test or
go test ./...We use pre-commit hooks to ensure code quality.
These hooks are run on PR creation.
If you encounter issues reported during PR creation, please run the tests
locally until the issues are resolved.
You can use just lint to run the pre-commit hooks.
Please note that this command requires [RequiredTools] to be installed
We provide example code in the cmd directory.
This code is not part of the official library.
func ListAllNamespaces() {
// Get the kubeconfig file path
kubeConfigPath := os.Getenv("KUBECONFIG")
if kubeConfigPath == "" {
kubeConfigPath = os.ExpandEnv("$HOME/.kube/config")
}
// Create a new client
client, err := kubernetes.NewClient(kubeConfigPath)
if err != nil {
log.Fatal(err)
}
// List all objects of type "namespace"
namespaces, err := client.ListAllObjects(kubernetes.ResourceNamespace, "", "")
if err != nil {
log.Fatal(err)
}
// Print the names
for _, namespace := range namespaces {
fmt.Println(namespace.GetName())
}
}