mirror of
https://github.com/kubernetes/client-go.git
synced 2025-07-20 01:50:06 +00:00
Merge pull request #110425 from LY-today/fake-evict-list-err
fix: list pod err after an pod evicted Kubernetes-commit: 1d811065345bfe9f3be7f6757a9938c1760180c7
This commit is contained in:
commit
899bcd7409
58
kubernetes/fake/clientset_generated_test.go
Normal file
58
kubernetes/fake/clientset_generated_test.go
Normal file
@ -0,0 +1,58 @@
|
||||
/*
|
||||
Copyright 2022 The Kubernetes Authors.
|
||||
|
||||
Licensed under the Apache License, Version 2.0 (the "License");
|
||||
you may not use this file except in compliance with the License.
|
||||
You may obtain a copy of the License at
|
||||
|
||||
http://www.apache.org/licenses/LICENSE-2.0
|
||||
|
||||
Unless required by applicable law or agreed to in writing, software
|
||||
distributed under the License is distributed on an "AS IS" BASIS,
|
||||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
See the License for the specific language governing permissions and
|
||||
limitations under the License.
|
||||
*/
|
||||
|
||||
package fake
|
||||
|
||||
import (
|
||||
"context"
|
||||
v1 "k8s.io/api/core/v1"
|
||||
policy "k8s.io/api/policy/v1"
|
||||
meta_v1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestNewSimpleClientset(t *testing.T) {
|
||||
client := NewSimpleClientset()
|
||||
client.CoreV1().Pods("default").Create(context.Background(), &v1.Pod{
|
||||
ObjectMeta: meta_v1.ObjectMeta{
|
||||
Name: "pod-1",
|
||||
Namespace: "default",
|
||||
},
|
||||
}, meta_v1.CreateOptions{})
|
||||
client.CoreV1().Pods("default").Create(context.Background(), &v1.Pod{
|
||||
ObjectMeta: meta_v1.ObjectMeta{
|
||||
Name: "pod-2",
|
||||
Namespace: "default",
|
||||
},
|
||||
}, meta_v1.CreateOptions{})
|
||||
err := client.CoreV1().Pods("default").EvictV1(context.Background(), &policy.Eviction{
|
||||
ObjectMeta: meta_v1.ObjectMeta{
|
||||
Name: "pod-2",
|
||||
},
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
t.Errorf("TestNewSimpleClientset() res = %v", err.Error())
|
||||
}
|
||||
|
||||
pods, err := client.CoreV1().Pods("default").List(context.Background(), meta_v1.ListOptions{})
|
||||
// err: item[0]: can't assign or convert v1beta1.Eviction into v1.Pod
|
||||
if err != nil {
|
||||
t.Errorf("TestNewSimpleClientset() res = %v", err.Error())
|
||||
} else {
|
||||
t.Logf("TestNewSimpleClientset() res = %v", pods)
|
||||
}
|
||||
}
|
@ -102,10 +102,20 @@ func ObjectReaction(tracker ObjectTracker) ReactionFunc {
|
||||
if action.GetSubresource() == "" {
|
||||
err = tracker.Create(gvr, action.GetObject(), ns)
|
||||
} else {
|
||||
oldObj, getOldObjErr := tracker.Get(gvr, ns, objMeta.GetName())
|
||||
if getOldObjErr != nil {
|
||||
return true, nil, getOldObjErr
|
||||
}
|
||||
// Check whether the existing historical object type is the same as the current operation object type that needs to be updated, and if it is the same, perform the update operation.
|
||||
if reflect.TypeOf(oldObj) == reflect.TypeOf(action.GetObject()) {
|
||||
// TODO: Currently we're handling subresource creation as an update
|
||||
// on the enclosing resource. This works for some subresources but
|
||||
// might not be generic enough.
|
||||
err = tracker.Update(gvr, action.GetObject(), ns)
|
||||
} else {
|
||||
// If the historical object type is different from the current object type, need to make sure we return the object submitted,don't persist the submitted object in the tracker.
|
||||
return true, action.GetObject(), nil
|
||||
}
|
||||
}
|
||||
if err != nil {
|
||||
return true, nil, err
|
||||
|
Loading…
Reference in New Issue
Block a user