Commit Graph

55 Commits

Author SHA1 Message Date
Michal Wozniak
a191e58772 SSA to add pod failure conditions - ready for review
Kubernetes-commit: fea883687feafc597591e15773f8c6f491b35d08
2022-10-24 14:55:16 +02:00
LY-today
9ac8bfecbb fix: list pod err after an pod evicted
Signed-off-by: LY-today <724102053@qq.com>

Kubernetes-commit: f299494e7977a935511208eb91001508b4b629ce
2022-06-22 23:30:40 +08:00
Daniel Smith
14e253c7f8 remove unneeded references
Kubernetes-commit: 2831f9a343ec405efce60d09da482a654971018e
2022-03-17 18:35:00 +00:00
Wojciech Tyczyński
a806c6e4fd Remove selflink references in different testing-related files
Kubernetes-commit: 551790729f1d26d75c1d3fa1411e341eb367f9f3
2022-01-13 11:33:26 +01:00
Chun Chen
d478a5752d Pass DeleteOptions down to the Reactor
Co-authored-by: Mo Khan <theenjeru@gmail.com>

Kubernetes-commit: 621970476f8f06419716325d573580be7b3378d9
2021-06-17 18:06:47 +08:00
novahe
b7e5fce706 client-go: copying object to fix data race (#103148)
Kubernetes-commit: ce257266aa7f3f104e656b722310be32e95a9cb5
2021-07-05 21:55:55 +08:00
Shiming Zhang
87154808e1 Support subresource match
Signed-off-by: Shiming Zhang <wzshiming@foxmail.com>

Kubernetes-commit: 58833d652d59229d49f001256f6ade4a46ae53ca
2021-04-09 12:55:57 +08:00
Shiming Zhang
ce9fcb2fe0 Add test
Signed-off-by: Shiming Zhang <wzshiming@foxmail.com>

Kubernetes-commit: 2c9f02c3290ce7e8bcdc94bea7d96edf92834cd7
2021-04-09 13:07:46 +08:00
Mengjiao Liu
8cb6ac7646 Prevent data race condition in csi unit tests
Kubernetes-commit: 92d0f8e6cc3b3d40194759afa4c7f2880dd5ada4
2021-05-18 18:00:03 +08:00
Markus Thömmes
3579fb3012 Implement a FakeClient interface
Kubernetes-commit: cf26825e3d9b89526e13bb53f74354593477205c
2021-03-15 14:47:24 +01:00
Stephen Solka
166114c4a0 prefer NoError/Error over Nil/NotNil
Kubernetes-commit: 203679cc6105ea490e75af1efa83497b771d7d36
2020-07-18 20:23:35 -04:00
Quan Tian
faf5681d1c Improve fake clientset performance
The fake clientset used a slice to store each kind of objects, it's
quite slow to init the clientset with massive objects because it checked
existence of an object by traversing all objects before adding it, which
leads to O(n^2) time complexity. Also, the Create, Update, Get, Delete
methods needs to traverse all objects, which affects the time statistic
of code that calls them.

This patch changed to use a map to store each kind of objects, reduced
the time complexity of initializing clientset to O(n) and the Create,
Update, Get, Delete to O(1).

For example:
Before this patch, it took ~29s to init a clientset with 30000 Pods,
and 2~4ms to create and get an Pod.
After this patch, it took ~50ms to init a clientset with 30000 Pods,
and tens of µs to create and get an Pod.

Kubernetes-commit: 7e15e31e11e48a6db855e30ca9b07dbce3047577
2020-03-27 18:39:20 +08:00
Markus Thömmes
1133cbffc1 Allow Action's Matches function to specify a subresource.
In other parts of the system (notably in RBAC rules), the "resource/subresource" notation is common to specify an explicit subresource. This makes this notation available to tests that use the `Matches` function on client actions as well.

Backwards compatibility is kept by ignoring the `Subresource` field if no specific subresource is defined in the resource string itself.

Kubernetes-commit: 47277f281eb0e7d484555e4d210b0ddb42974793
2020-01-30 12:04:23 +01:00
Jan Chaloupka
f8b3113764 Require exact match when calling Get method within fake clientset
`Get` method within the fake clientset returns an object that would not be normally returned when using the real clientset. Reproducer:

```go
package main

import (
	v1 "k8s.io/api/core/v1"
	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
	"k8s.io/client-go/kubernetes/fake"
)

func main () {
	cm := &v1.ConfigMap{
		ObjectMeta: metav1.ObjectMeta{Namespace: metav1.NamespaceSystem, Name: "cm"},
		}

	client := fake.NewSimpleClientset(cm)
	obj, err := client.CoreV1().ConfigMaps("").Get("", metav1.GetOptions{})
	if err != nil {
		panic(err)
	}
	fmt.Printf("obj: %#v\n", obj)
}
```

stored under `test.go` of `github.com/kubernetes/kubernetes` (master HEAD) root directory and ran:

```sh
$ go run test.go
obj: &v1.ConfigMap{TypeMeta:v1.TypeMeta{Kind:"", APIVersion:""}, ObjectMeta:v1.ObjectMeta{Name:"cm", GenerateName:"", Namespace:"kube-system", SelfLink:"", UID:"", ResourceVersion:"", Generation:0, CreationTimestamp:v1.Time{Time:time.Time{wall:0x0, ext:0, loc:(*time.Location)(nil)}}, DeletionTimestamp:(*v1.Time)(nil), DeletionGracePeriodSeconds:(*int64)(nil), Labels:map[string]string(nil), Annotations:map[string]string(nil), OwnerReferences:[]v1.OwnerReference(nil), Finalizers:[]string(nil), ClusterName:"", ManagedFields:[]v1.ManagedFieldsEntry(nil)}, Data:map[string]string(nil), BinaryData:map[string][]uint8(nil)}
```

As you can see fake clientset with a "test" configmap is created. When getting the object through the clientset back, I intentionally set the object name to an empty string. I would expect to get an error saying config map "" was not found. However, I get "test" configmap instead.

Reason for that is inside implementation of `filterByNamespaceAndName` private function:
```go
func filterByNamespaceAndName(objs []runtime.Object, ns, name string) ([]runtime.Object, error) {
	var res []runtime.Object

	for _, obj := range objs {
		acc, err := meta.Accessor(obj)
		if err != nil {
			return nil, err
		}
		if ns != "" && acc.GetNamespace() != ns {
			continue
		}
		if name != "" && acc.GetName() != name {
			continue
		}
		res = append(res, obj)
	}

	return res, nil
}
```

When `name` is empty, `name != "" && acc.GetName() != name` condition is false and thus `obj` is consider as a fit.

[1] https://github.com/kubernetes/client-go/blob/master/testing/fixture.go#L481-L493

Kubernetes-commit: d32c76fc03381784516c47cb1bf62ef932189afa
2019-09-17 17:52:28 +02:00
RainbowMango
532b6f676e Cleanup staticcheck issues for package in client-go.
Kubernetes-commit: c8c055b3163dd2661b3f9dd1b0ffb718a61aba24
2019-08-26 20:55:32 +08:00
Clayton Coleman
b83dc9a7d9 Fake ObjectReaction should handle PartialObjectMetadata special
When a client requests a PartialObjectMetadata returned from the
ObjectReaction type, if the object has a GVK set use that instead
of what the schema returns, since the majority of clients getting
partial object metadata will be doing so using the metadata client
or server side conversion.

Kubernetes-commit: baf091e9dbad00db39e246815f9d7a21d148044f
2019-04-03 12:12:11 -04:00
Clayton Coleman
58c2617e28 Calling PatchAction on typed objects should work correctly
Only Unstructured objects worked (because unstructured implicitly
clears the .Object map when Unmarshal is called). We must reset
obj before we attempt to unmarshal into it.

Kubernetes-commit: 3b599b383d32d80188fdc73adae1613cc167cbdd
2019-06-05 14:27:59 -04:00
Steve Kriss
f0c6576981 client-fake object tracker: support merge patch
Signed-off-by: Steve Kriss <krisss@vmware.com>

Kubernetes-commit: d425fe29bd808db54c59e3e0ecdedbe735b8f68b
2019-02-21 13:47:16 -07:00
James Munnelly
711082b69f Use a single deep copied object between all reactors in fake client
Kubernetes-commit: 41ebb22011cb79aed2241417249e824cdfcda5fc
2019-01-31 17:42:04 +00:00
Bouke van der Bijl
213a1e8b13 client-go/testing: properly handle Patch actions for missing Objects
Currently the fake client will return a default empty Object when a
Patch action is submitted on a missing Object. The correct behavior is to
instead propagate the NotFound error.

Kubernetes-commit: 96d0588440a96c5eba8b3ba0810563ad1e1a08b6
2018-11-09 19:25:02 +00:00
João Taveira Araújo
93c815ca99 Fix duped watch in client-go/testing.
This commit fixes a bug in the client-go/testing fixture whereby a
watcher would fire twice for objects with no namespace.

Kubernetes-commit: bd268c9971efd4db46074a80e52ce765583e0787
2018-11-19 09:50:17 -08:00
Ville Aikas
41406bf985 Add support for JSON patch in fake client
Kubernetes-commit: a363b153851326ece7f81f4c1ae0a1ab8700a209
2018-10-02 13:30:52 +00:00
Minhan Xia
6f353b5328 add Patch support in fake kubeClient
Kubernetes-commit: 8b3b4e4deabe4cf922eee752df2fad189b2c1471
2018-04-11 11:37:30 -07:00
David Eads
77541e5cb7 add subresource support for the dynamic client
Kubernetes-commit: 82e32d2a3260807237a69bc40fb371db640d26fc
2018-05-09 12:52:12 -04:00
Josh Horwitz
64101cbe6a Fixes fake client generation for non-namespaced subresources
Kubernetes-commit: 0f62a8cddac0a48506fc1b93f37da32530fd2358
2018-02-26 14:03:11 -05:00
hangaoshuai
e39ef65572 catch err when Watch testResource failed in func TestWatchCallNonNamespace
Kubernetes-commit: c63e22eea56c2ba3c24a284505fbe869b7678e14
2018-03-20 16:35:41 +08:00
David Eads
f8d192aa24 deep copy fake client actions to avoid accidental mutation
Kubernetes-commit: 9ef99d189f2e454a293b8c343fee173c876ed21f
2018-03-02 09:19:52 -05:00
Grant Rodgers
949db79a1d Use RaceFreeFakeWatcher in ObjectTracker
The FakeWatcher allows sends on the result channel after it's closed,
for example calling Stop() then Add() will panic. RaceFreeFakeWatcher
checks whether the watcher is stopped before attempting to send. It also
panics instead of blocking when the result channel is full.

Kubernetes-commit: b84ad8828b6ffe0dd289f69e395968eabb9fbeaa
2018-03-14 11:38:19 -07:00
yue9944882
d89f1e4c08 remove redundant fake discovery code
Kubernetes-commit: 38243460fa272a5503b7c1b43655d09caa65dd1c
2018-02-27 17:34:08 +08:00
Kubernetes Publisher
fff8c3d73e sync: initially remove files BUILD */BUILD BUILD.bazel */BUILD.bazel 2018-03-15 09:19:38 +00:00
Jeff Grafton
fca8bb2928 Autogenerated: hack/update-bazel.sh
Kubernetes-commit: ef56a8d6bb3800ab7803713eafc4191e8202ad6e
2018-02-16 13:43:01 -08:00
yue9944882
af8ed43b01 fix(fakeclient): write event to watch channel on add/update/delete
fix races with watch call

add test for non-namespace resource watch

add matching for all-namespace-watch

fix delete namespace watch & restrict test

fix multiple invocation on same resource & namespace

add descriptive doc for tracker.watchers

Kubernetes-commit: f57cc0b22d282bc8fe68faf91529e7175bc3918a
2017-12-21 16:50:16 +08:00
Jeff Grafton
c92755ea3b update BUILD files
Kubernetes-commit: aee5f457dbfd70c2d15c33e392dce6a3ca710116
2017-10-12 13:52:10 -07:00
Dr. Stefan Schimanski
0cfc379ff8 apimachinery: mechanical removal of ObjectCopier plumbing
Kubernetes-commit: 509df603b18d356777176953e5d160b6f3d0bba9
2017-10-06 13:30:12 +02:00
Dr. Stefan Schimanski
7cdaec7d07 client-go: simplify deepcopy calls
Kubernetes-commit: ed423054ba0089a6d58fb0e048fe1acfd966f0d7
2017-08-15 14:15:58 +02:00
Michal Fojtik
bf85a9d89b add missing sub-resources test actions
Kubernetes-commit: c026b62d19d83d4f68235d1bd039a469e87d215d
2017-09-04 13:49:16 +00:00
Lucas Käldström
1bc6d1247e kubeadm: Adds dry-run support for kubeadm using the '--dry-run' option
Kubernetes-commit: 0bf84aa182449ab51cbb5f819da3fbcad19690a2
2017-08-29 12:52:28 +00:00
Jeff Grafton
5da217e5c4 Use buildozer to delete licenses() rules except under third_party/
Kubernetes-commit: a7f49c906df816123e7d4ccbd4cebab411519465
2017-08-29 12:51:55 +00:00
Jeff Grafton
fa2ceb7462 Use buildozer to remove deprecated automanaged tags
Kubernetes-commit: 33276f06be5e872bf53ca62a095fcf0a6b6c11a8
2017-08-29 12:51:55 +00:00
Jeff Grafton
f921a73942 Run hack/update-bazel.sh to generate BUILD files
Kubernetes-commit: 3579017b865ddbc5449d6bba87346f086e4b93ff
2017-08-29 12:50:17 +00:00
Chao Xu
6db1a83402 generated clientset changes
propagate to client-go
update-bazel.sh

Kubernetes-commit: 5f5a70f65f7dbcfc9215caee27cfd9a4be23f348
2017-05-04 20:28:29 +00:00
Chao Xu
85c50f4ccb remove registry from testing/fixture.go; update client-gen to not use
registry in the generated clients

Kubernetes-commit: bbb94e42c108840c540c5667f8da97c33b81d84a
2017-05-04 20:28:29 +00:00
Mike Danese
9a45999fa0 autogenerated
Kubernetes-commit: a05c3c0efdc5822049e34b1a5a1ee259c5fb1906
2017-04-15 20:28:18 +00:00
Kubernetes Publisher
fb6075f2e0 published by bot
(https://github.com/kubernetes/contrib/tree/master/mungegithub)

copied from https://github.com/kubernetes/kubernetes.git, branch master,
last commit is abed7461722c195f8c77b4c502743e012d19d095
2017-01-27 15:19:42 +00:00
Kubernetes Publisher
687fd42903 published by bot
(https://github.com/kubernetes/contrib/tree/master/mungegithub)

copied from https://github.com/kubernetes/kubernetes.git, branch master,
last commit is 68f123dfa036bef57495f014a78144a9a1b517ca
2017-01-24 15:19:42 +00:00
Kubernetes Publisher
0eb5431cb7 published by bot
(https://github.com/kubernetes/contrib/tree/master/mungegithub)

copied from https://github.com/kubernetes/kubernetes.git, branch master,
last commit is 8d5227bb2e05e01031ace81fa6611a13f598278e
2017-01-21 15:19:42 +00:00
Kubernetes Publisher
14ee64eb52 published by bot
(https://github.com/kubernetes/contrib/tree/master/mungegithub)

copied from https://github.com/kubernetes/kubernetes.git, branch master,
last commit is ac857a5adefb894a8049ebf5295cabb719c9648d
2017-01-19 15:19:43 +00:00
Kubernetes Publisher
8fa0506b26 published by bot
(https://github.com/kubernetes/contrib/tree/master/mungegithub)

copied from https://github.com/kubernetes/kubernetes.git, branch master,
last commit is d9467519245c3858ac58c5fa91ec9e5b16c1f507
2017-01-18 15:19:42 +00:00
Kubernetes Publisher
204f12b1f3 published by bot
(https://github.com/kubernetes/contrib/tree/master/mungegithub)

copied from https://github.com/kubernetes/kubernetes.git, branch master,
last commit is 616038db1b0d1e852b4a3d10c8c512a052f91fba
2017-01-14 15:19:47 +00:00
Kubernetes Publisher
5fe6fc56cb published by bot
(https://github.com/kubernetes/contrib/tree/master/mungegithub)

copied from https://github.com/kubernetes/kubernetes.git, branch master,
last commit is 5b2823adb9a8777f7819884fa79a6e1daa26b9c2
2016-12-17 15:19:41 +00:00