Skip to content

Commit 20c8fec

Browse files
committed
improve documentation structure
1 parent 55a4cfe commit 20c8fec

File tree

16 files changed

+448
-428
lines changed

16 files changed

+448
-428
lines changed

README.md

Lines changed: 2 additions & 427 deletions
Large diffs are not rendered by default.

Taskfile.yaml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,5 @@ includes:
55
taskfile: hack/common/Taskfile_library.yaml
66
flatten: true
77
vars:
8-
CODE_DIRS: '{{.ROOT_DIR}}/pkg/...'
8+
CODE_DIRS: '{{.ROOT_DIR}}/pkg/...'
9+
GENERATE_DOCS_INDEX: "true"

docs/README.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<!-- Do not edit this file, as it is auto-generated!-->
2+
# Documentation Index
3+
4+
## Libraries
5+
6+
- [Connecting to Kubernetes Clusters](libs/clusters.md)
7+
- [Collections](libs/collections.md)
8+
- [Controller Utility Functions](libs/controller.md)
9+
- [Custom Resource Definitions](libs/crds.md)
10+
- [Error Handling](libs/errors.md)
11+
- [Logging](libs/logging.md)
12+
- [Readiness Checks](libs/readiness.md)
13+
- [Kubernetes Resource Management](libs/resource.md)
14+
- [Kubernetes Resource Status Updating](libs/status.md)
15+
- [Testing](libs/testing.md)
16+
- [Thread Management](libs/threads.md)
17+
- [Webhooks](libs/webhooks.md)
18+

docs/libs/.docnames

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"header": "Libraries"
3+
}

docs/libs/clusters.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Connecting to Kubernetes Clusters
2+
3+
Both, the `pkg/clientconfig` and the `pkg/clusters` package, provide library functions that help with constructing clients for interacting with kubernetes clusters. The former one is more low-level, while the latter one tries to hide most of the boilerplate coding related to client creation.
4+
5+
## clientconfig
6+
7+
The `pkg/clientconfig` package provides helper functions for creating Kubernetes clients using multiple connection methods. It defines a `Config` struct that encapsulates a Kubernetes API target and supports various authentication methods like kubeconfig file and a Service Account.
8+
9+
### Noteworthy Functions
10+
11+
- `GetRESTConfig` generates a `*rest.Config` for interacting with the Kubernetes API. It supports using a kubeconfig string, a kubeconfig file path, a secret reference that contains a kubeconfig file or a Service Account.
12+
- `GetClient` creates a client.Client for managing Kubernetes resources.
13+
14+
## clusters
15+
16+
The `pkg/clusters` package helps with loading kubeconfigs and creating clients for multiple clusters.
17+
```go
18+
foo := clusters.New("foo") // initializes a new cluster with id 'foo'
19+
foo.RegisterConfigPathFlag(cmd.Flags()) // adds a '--foo-cluster' flag to the flag set for passing in a kubeconfig path
20+
foo.InitializeRESTConfig() // loads the kubeconfig using the 'LoadKubeconfig' function from the 'controller' package
21+
foo.InitializeClient(myScheme) // initializes the 'Client' and 'Cluster' interfaces from the controller-runtime
22+
```
23+
You can then use the different getter methods for working with the cluster.

docs/libs/collections.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Collections
2+
3+
The `pkg/collections` package contains multiple interfaces for collections, modelled after the Java Collections Framework. The only actual implementation currently contained is a `LinkedList`, which fulfills the `List` and `Queue` interfaces.
4+
5+
The package also contains further packages that contain some auxiliary functions for working with slices and maps in golang, e.g. for filtering.

docs/libs/controller.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Controller Utility Functions
2+
3+
The `pkg/controller` package contains useful functions for setting up and running k8s controllers.
4+
5+
### Noteworthy Functions
6+
7+
- `LoadKubeconfig` creates a REST config for accessing a k8s cluster. It can be used with a path to a kubeconfig file, or a directory containing files for a trust relationship. When called with an empty path, it returns the in-cluster configuration.
8+
- See also the [`clusters`](#clusters) package, which uses this function internally, but provides some further tooling around it.
9+
- There are some functions useful for working with annotations and labels, e.g. `HasAnnotationWithValue` or `EnsureLabel`.
10+
- There are multiple predefined predicates to help with filtering reconciliation triggers in controllers, e.g. `HasAnnotationPredicate` or `DeletionTimestampChangedPredicate`.
11+
- The `K8sNameHash` function can be used to create a hash that can be used as a name for k8s resources.

docs/libs/crds.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Custom Resource Definitions
2+
3+
The `pkg/init/crds` package allows user to deploy CRDs from yaml files to a target cluster. It uses `embed.FS` to provide the files for deployment.

docs/libs/errors.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# Error Handling
2+
3+
The `pkg/errors` package contains the `ReasonableError` type, which combines a normal `error` with a reason string. This is useful for errors that happen during reconciliation for updating the resource's status with a reason for the error later on.
4+
5+
### Noteworthy Functions:
6+
7+
- `WithReason(...)` can be used to wrap a standard error together with a reason into a `ReasonableError`.
8+
- `Errorf(...)` can be used to wrap an existing `ReasonableError` together with a new error, similarly to how `fmt.Errorf(...)` does it for standard errors.
9+
- `NewReasonableErrorList(...)` or `Join(...)` can be used to work with lists of errors. `Aggregate()` turns them into a single error again.
10+

docs/libs/logging.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# Logging
2+
3+
This package contains the logging library from the [Landscaper controller-utils module](https://github.com/gardener/landscaper/tree/master/controller-utils/pkg/logging).
4+
5+
The library provides a wrapper around `logr.Logger`, exposing additional helper functions. The original `logr.Logger` can be retrieved by using the `Logr()` method. Also, it notices when multiple values are added to the logger with the same key - instead of simply overwriting the previous ones (like `logr.Logger` does it), it appends the key with a `_conflict(x)` suffix, where `x` is the number of times this conflict has occurred.
6+
7+
### Noteworthy Functions
8+
9+
- `GetLogger()` is a singleton-style getter function for a logger.
10+
- There are several `FromContext...` functions for retrieving a logger from a `context.Context` object.
11+
- `InitFlags(...)` can be used to add the configuration flags for this logger to a cobra `FlagSet`.

0 commit comments

Comments
 (0)