mirror of
https://github.com/kubernetes/client-go.git
synced 2026-07-01 06:25:55 +00:00
Compare commits
11 Commits
kubernetes
...
kubernetes
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
456981240e | ||
|
|
f5b6af4563 | ||
|
|
1b23c1577a | ||
|
|
8dfe88aeff | ||
|
|
899bcd7409 | ||
|
|
0647d43372 | ||
|
|
9ac8bfecbb | ||
|
|
cb4a10df41 | ||
|
|
64585cf823 | ||
|
|
acab036eff | ||
|
|
5ce7078061 |
10
go.mod
10
go.mod
@@ -24,9 +24,9 @@ require (
|
||||
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211
|
||||
golang.org/x/time v0.0.0-20220210224613-90d013bbcef8
|
||||
google.golang.org/protobuf v1.27.1
|
||||
k8s.io/api v0.0.0-20220614194928-60387f6ceb7c
|
||||
k8s.io/apimachinery v0.0.0-20220614194717-c5be38573c73
|
||||
k8s.io/klog/v2 v2.60.1
|
||||
k8s.io/api v0.25.0-alpha.2
|
||||
k8s.io/apimachinery v0.25.0-alpha.2
|
||||
k8s.io/klog/v2 v2.70.0
|
||||
k8s.io/kube-openapi v0.0.0-20220603121420-31174f50af60
|
||||
k8s.io/utils v0.0.0-20220210201930-3a6ce19ff2f9
|
||||
sigs.k8s.io/structured-merge-diff/v4 v4.2.1
|
||||
@@ -63,6 +63,6 @@ require (
|
||||
)
|
||||
|
||||
replace (
|
||||
k8s.io/api => k8s.io/api v0.0.0-20220614194928-60387f6ceb7c
|
||||
k8s.io/apimachinery => k8s.io/apimachinery v0.0.0-20220614194717-c5be38573c73
|
||||
k8s.io/api => k8s.io/api v0.25.0-alpha.2
|
||||
k8s.io/apimachinery => k8s.io/apimachinery v0.25.0-alpha.2
|
||||
)
|
||||
|
||||
12
go.sum
12
go.sum
@@ -513,15 +513,15 @@ honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWh
|
||||
honnef.co/go/tools v0.0.1-2019.2.3/go.mod h1:a3bituU0lyd329TUQxRnasdCoJDkEUEAqEt0JzvZhAg=
|
||||
honnef.co/go/tools v0.0.1-2020.1.3/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9vFzvIQ3k=
|
||||
honnef.co/go/tools v0.0.1-2020.1.4/go.mod h1:X/FiERA/W4tHapMX5mGpAtMSVEeEUOyHaw9vFzvIQ3k=
|
||||
k8s.io/api v0.0.0-20220614194928-60387f6ceb7c h1:DC+Zvr6/68fhuaIy5pTL0W4bAhbrnZi4jxozgPQ6vp0=
|
||||
k8s.io/api v0.0.0-20220614194928-60387f6ceb7c/go.mod h1:GLhFhgtyTRwgH456jroUFHnl0QFlRJ7RFJ41U7TgOZc=
|
||||
k8s.io/apimachinery v0.0.0-20220614194717-c5be38573c73 h1:EBei3PXKAoJZbqTqFYcQVh/wJcgXA/X1w7m8tBDyi3s=
|
||||
k8s.io/apimachinery v0.0.0-20220614194717-c5be38573c73/go.mod h1:iknpugsBdD8jeaGNZyi85Q334Mj3GFqi1SEHEEB/KQM=
|
||||
k8s.io/api v0.25.0-alpha.2 h1:azwXduCht76Ecuv80QzZkCDzcFcLotKPXiE9/+jx5Qk=
|
||||
k8s.io/api v0.25.0-alpha.2/go.mod h1:wOntqHYj8WveLW2sh6q4tkE2vMZTtxe0MrFyVwO8JCM=
|
||||
k8s.io/apimachinery v0.25.0-alpha.2 h1:y6uTWaiqsPTPRewnXJ15IFyGmBo2qPt6enm4zszG8Z0=
|
||||
k8s.io/apimachinery v0.25.0-alpha.2/go.mod h1:h34FtK3eCxige6ZIACdBSYExtDaKAUxoc7hVe2LOxzw=
|
||||
k8s.io/gengo v0.0.0-20210813121822-485abfe95c7c/go.mod h1:FiNAH4ZV3gBg2Kwh89tzAEV2be7d5xI0vBa/VySYy3E=
|
||||
k8s.io/klog/v2 v2.0.0/go.mod h1:PBfzABfn139FHAV07az/IF9Wp1bkk3vpT2XSJ76fSDE=
|
||||
k8s.io/klog/v2 v2.2.0/go.mod h1:Od+F08eJP+W3HUb4pSrPpgp9DGU4GzlpG/TmITuYh/Y=
|
||||
k8s.io/klog/v2 v2.60.1 h1:VW25q3bZx9uE3vvdL6M8ezOX79vA2Aq1nEWLqNQclHc=
|
||||
k8s.io/klog/v2 v2.60.1/go.mod h1:y1WjHnz7Dj687irZUWR/WLkLc5N1YHtjLdmgWjndZn0=
|
||||
k8s.io/klog/v2 v2.70.0 h1:GMmmjoFOrNepPN0ZeGCzvD2Gh5IKRwdFx8W5PBxVTQU=
|
||||
k8s.io/klog/v2 v2.70.0/go.mod h1:y1WjHnz7Dj687irZUWR/WLkLc5N1YHtjLdmgWjndZn0=
|
||||
k8s.io/kube-openapi v0.0.0-20220603121420-31174f50af60 h1:cE/M8rmDQgibspuSm+X1iW16ByTImtEaapgaHoVSLX4=
|
||||
k8s.io/kube-openapi v0.0.0-20220603121420-31174f50af60/go.mod h1:ouUzE1U2mEv//HRoBwYLFE5pdqjIebvtX361vtEIlBI=
|
||||
k8s.io/utils v0.0.0-20210802155522-efc7438f0176/go.mod h1:jPW/WVKK9YHAvNhRxK0md/EJ228hCsBRufyofKtW8HA=
|
||||
|
||||
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 {
|
||||
// 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)
|
||||
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
|
||||
|
||||
6
third_party/forked/golang/template/exec.go
vendored
6
third_party/forked/golang/template/exec.go
vendored
@@ -17,7 +17,7 @@ var (
|
||||
// We indirect through pointers and empty interfaces (only) because
|
||||
// non-empty interfaces have methods we might need.
|
||||
func Indirect(v reflect.Value) (rv reflect.Value, isNil bool) {
|
||||
for ; v.Kind() == reflect.Ptr || v.Kind() == reflect.Interface; v = v.Elem() {
|
||||
for ; v.Kind() == reflect.Pointer || v.Kind() == reflect.Interface; v = v.Elem() {
|
||||
if v.IsNil() {
|
||||
return v, true
|
||||
}
|
||||
@@ -31,7 +31,7 @@ func Indirect(v reflect.Value) (rv reflect.Value, isNil bool) {
|
||||
// PrintableValue returns the, possibly indirected, interface value inside v that
|
||||
// is best for a call to formatted printer.
|
||||
func PrintableValue(v reflect.Value) (interface{}, bool) {
|
||||
if v.Kind() == reflect.Ptr {
|
||||
if v.Kind() == reflect.Pointer {
|
||||
v, _ = Indirect(v) // fmt.Fprint handles nil.
|
||||
}
|
||||
if !v.IsValid() {
|
||||
@@ -39,7 +39,7 @@ func PrintableValue(v reflect.Value) (interface{}, bool) {
|
||||
}
|
||||
|
||||
if !v.Type().Implements(errorType) && !v.Type().Implements(fmtStringerType) {
|
||||
if v.CanAddr() && (reflect.PtrTo(v.Type()).Implements(errorType) || reflect.PtrTo(v.Type()).Implements(fmtStringerType)) {
|
||||
if v.CanAddr() && (reflect.PointerTo(v.Type()).Implements(errorType) || reflect.PointerTo(v.Type()).Implements(fmtStringerType)) {
|
||||
v = v.Addr()
|
||||
} else {
|
||||
switch v.Kind() {
|
||||
|
||||
2
tools/cache/index.go
vendored
2
tools/cache/index.go
vendored
@@ -47,7 +47,7 @@ type Indexer interface {
|
||||
// ByIndex returns the stored objects whose set of indexed values
|
||||
// for the named index includes the given indexed value
|
||||
ByIndex(indexName, indexedValue string) ([]interface{}, error)
|
||||
// GetIndexer return the indexers
|
||||
// GetIndexers return the indexers
|
||||
GetIndexers() Indexers
|
||||
|
||||
// AddIndexers adds more indexers to this store. If you call this after you already have data
|
||||
|
||||
13
tools/cache/store.go
vendored
13
tools/cache/store.go
vendored
@@ -199,8 +199,11 @@ func (c *cache) Index(indexName string, obj interface{}) ([]interface{}, error)
|
||||
return c.cacheStorage.Index(indexName, obj)
|
||||
}
|
||||
|
||||
func (c *cache) IndexKeys(indexName, indexKey string) ([]string, error) {
|
||||
return c.cacheStorage.IndexKeys(indexName, indexKey)
|
||||
// IndexKeys returns the storage keys of the stored objects whose set of
|
||||
// indexed values for the named index includes the given indexed value.
|
||||
// The returned keys are suitable to pass to GetByKey().
|
||||
func (c *cache) IndexKeys(indexName, indexedValue string) ([]string, error) {
|
||||
return c.cacheStorage.IndexKeys(indexName, indexedValue)
|
||||
}
|
||||
|
||||
// ListIndexFuncValues returns the list of generated values of an Index func
|
||||
@@ -208,8 +211,10 @@ func (c *cache) ListIndexFuncValues(indexName string) []string {
|
||||
return c.cacheStorage.ListIndexFuncValues(indexName)
|
||||
}
|
||||
|
||||
func (c *cache) ByIndex(indexName, indexKey string) ([]interface{}, error) {
|
||||
return c.cacheStorage.ByIndex(indexName, indexKey)
|
||||
// ByIndex returns the stored objects whose set of indexed values
|
||||
// for the named index includes the given indexed value.
|
||||
func (c *cache) ByIndex(indexName, indexedValue string) ([]interface{}, error) {
|
||||
return c.cacheStorage.ByIndex(indexName, indexedValue)
|
||||
}
|
||||
|
||||
func (c *cache) AddIndexers(newIndexers Indexers) error {
|
||||
|
||||
4
tools/cache/thread_safe_store.go
vendored
4
tools/cache/thread_safe_store.go
vendored
@@ -47,9 +47,9 @@ type ThreadSafeStore interface {
|
||||
ListKeys() []string
|
||||
Replace(map[string]interface{}, string)
|
||||
Index(indexName string, obj interface{}) ([]interface{}, error)
|
||||
IndexKeys(indexName, indexKey string) ([]string, error)
|
||||
IndexKeys(indexName, indexedValue string) ([]string, error)
|
||||
ListIndexFuncValues(name string) []string
|
||||
ByIndex(indexName, indexKey string) ([]interface{}, error)
|
||||
ByIndex(indexName, indexedValue string) ([]interface{}, error)
|
||||
GetIndexers() Indexers
|
||||
|
||||
// AddIndexers adds more indexers to this store. If you call this after you already have data
|
||||
|
||||
@@ -204,8 +204,19 @@ func ConfirmUsable(config clientcmdapi.Config, passedContextName string) error {
|
||||
|
||||
if exists {
|
||||
validationErrors = append(validationErrors, validateContext(contextName, *context, config)...)
|
||||
validationErrors = append(validationErrors, validateAuthInfo(context.AuthInfo, *config.AuthInfos[context.AuthInfo])...)
|
||||
validationErrors = append(validationErrors, validateClusterInfo(context.Cluster, *config.Clusters[context.Cluster])...)
|
||||
|
||||
// Default to empty users and clusters and let the validation function report an error.
|
||||
authInfo := config.AuthInfos[context.AuthInfo]
|
||||
if authInfo == nil {
|
||||
authInfo = &clientcmdapi.AuthInfo{}
|
||||
}
|
||||
validationErrors = append(validationErrors, validateAuthInfo(context.AuthInfo, *authInfo)...)
|
||||
|
||||
cluster := config.Clusters[context.Cluster]
|
||||
if cluster == nil {
|
||||
cluster = &clientcmdapi.Cluster{}
|
||||
}
|
||||
validationErrors = append(validationErrors, validateClusterInfo(context.Cluster, *cluster)...)
|
||||
}
|
||||
|
||||
return newErrConfigurationInvalid(validationErrors)
|
||||
|
||||
@@ -65,6 +65,42 @@ func TestConfirmUsableBadInfoButOkConfig(t *testing.T) {
|
||||
badValidation.testConfig(t)
|
||||
}
|
||||
|
||||
func TestConfirmUsableMissingObjects(t *testing.T) {
|
||||
config := clientcmdapi.NewConfig()
|
||||
config.Clusters["kind-cluster"] = &clientcmdapi.Cluster{
|
||||
Server: "anything",
|
||||
}
|
||||
config.AuthInfos["kind-user"] = &clientcmdapi.AuthInfo{
|
||||
Token: "any-value",
|
||||
}
|
||||
config.Contexts["missing-user"] = &clientcmdapi.Context{
|
||||
Cluster: "kind-cluster",
|
||||
AuthInfo: "garbage",
|
||||
}
|
||||
config.Contexts["missing-cluster"] = &clientcmdapi.Context{
|
||||
Cluster: "garbage",
|
||||
AuthInfo: "kind-user",
|
||||
}
|
||||
|
||||
missingUser := configValidationTest{
|
||||
config: config,
|
||||
expectedErrorSubstring: []string{
|
||||
`user "garbage" was not found for context "missing-user"`,
|
||||
},
|
||||
}
|
||||
missingUser.testConfirmUsable("missing-user", t)
|
||||
missingUser.testConfig(t)
|
||||
|
||||
missingCluster := configValidationTest{
|
||||
config: config,
|
||||
expectedErrorSubstring: []string{
|
||||
`cluster "garbage" was not found for context "missing-cluster"`,
|
||||
},
|
||||
}
|
||||
missingCluster.testConfirmUsable("missing-cluster", t)
|
||||
missingCluster.testConfig(t)
|
||||
}
|
||||
|
||||
func TestConfirmUsableBadInfoConfig(t *testing.T) {
|
||||
config := clientcmdapi.NewConfig()
|
||||
config.Clusters["missing ca"] = &clientcmdapi.Cluster{
|
||||
|
||||
Reference in New Issue
Block a user