Skip to content

Commit

Permalink
Generify fake clientsets
Browse files Browse the repository at this point in the history
This adds a generic implementation of a fake clientset, and uses it to
replace the template code in generated fake clientsets for the default
methods. The templates are preserved as-is (or as close as they can
be) for use in extensions, whether for resources or subresources.

Fake clientsets with no extensions are reduced to their main getter,
their specific struct, and their constructor. All method
implementations are provided by the generic implementation. The
dedicated struct is preserved to allow extensions and expansions to be
defined where necessary.

Instead of handling the variants (with/without list, apply) with a
complex sequence of if statements, build up an index into an array
containing the various declarations.

Similarly, instead of calling different action constructors for
namespaced and non-namespaced clientsets, assume the current behaviour
of non-namespaced action creation (equivalent to creating a namespaced
action with an empty namespace) and document that assumption in the
action implementation.

Signed-off-by: Stephen Kitt <[email protected]>

Kubernetes-commit: b0ce65df9b74d4dc72050840d5ad067596d7b822
  • Loading branch information
skitt authored and k8s-publishing-bot committed Jul 30, 2024
1 parent 2466f75 commit 35e9b33
Show file tree
Hide file tree
Showing 2 changed files with 96 additions and 18 deletions.
22 changes: 16 additions & 6 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ require (
github.com/gogo/protobuf v1.3.2
github.com/stretchr/testify v1.9.0
google.golang.org/grpc v1.65.0
k8s.io/api v0.0.0-20241108114310-4772861d607e
k8s.io/apimachinery v0.0.0-20241106231735-d941d9fb4c83
k8s.io/apiserver v0.0.0-20241108130127-67b987f568cf
k8s.io/client-go v0.0.0-20241107030607-c57dbd8decb0
k8s.io/component-base v0.0.0-20241107031631-88ede593c6c4
k8s.io/cri-api v0.0.0-20241107034520-f9fb3fa09445
k8s.io/api v0.0.0
k8s.io/apimachinery v0.0.0
k8s.io/apiserver v0.0.0
k8s.io/client-go v0.0.0
k8s.io/component-base v0.0.0
k8s.io/cri-api v0.0.0
k8s.io/klog/v2 v2.130.1
k8s.io/utils v0.0.0-20241104100929-3ea5e8cea738
)
Expand Down Expand Up @@ -63,3 +63,13 @@ require (
sigs.k8s.io/structured-merge-diff/v4 v4.4.2 // indirect
sigs.k8s.io/yaml v1.4.0 // indirect
)

replace (
k8s.io/api => ../api
k8s.io/apimachinery => ../apimachinery
k8s.io/apiserver => ../apiserver
k8s.io/client-go => ../client-go
k8s.io/component-base => ../component-base
k8s.io/cri-api => ../cri-api
k8s.io/kms => ../kms
)
Loading

0 comments on commit 35e9b33

Please sign in to comment.