Merge pull request #88906 from liggitt/dynamic-delete

Dynamic client: plumb context

Kubernetes-commit: cf4d797b5dddef1b1e06a50ebda8a0738e04b66c
This commit is contained in:
Kubernetes Publisher 2020-03-06 13:17:54 -08:00
commit 27fa797464
8 changed files with 22 additions and 20 deletions

4
Godeps/Godeps.json generated
View File

@ -576,11 +576,11 @@
},
{
"ImportPath": "k8s.io/cli-runtime",
"Rev": "f26b0857ea34"
"Rev": "058578b5f081"
},
{
"ImportPath": "k8s.io/client-go",
"Rev": "7b31ec144ad8"
"Rev": "b173caf5988c"
},
{
"ImportPath": "k8s.io/code-generator",

8
go.mod
View File

@ -39,8 +39,8 @@ require (
gotest.tools v2.2.0+incompatible // indirect
k8s.io/api v0.0.0-20200306151724-0a52b7486422
k8s.io/apimachinery v0.0.0-20200306202157-ac276fc34867
k8s.io/cli-runtime v0.0.0-20200304164305-f26b0857ea34
k8s.io/client-go v0.0.0-20200307002525-7b31ec144ad8
k8s.io/cli-runtime v0.0.0-20200307004336-058578b5f081
k8s.io/client-go v0.0.0-20200307002526-b173caf5988c
k8s.io/component-base v0.0.0-20200305122702-2cff9454e9d1
k8s.io/klog v1.0.0
k8s.io/kube-openapi v0.0.0-20200121204235-bf4fb3bd569c
@ -56,8 +56,8 @@ replace (
golang.org/x/tools => golang.org/x/tools v0.0.0-20190821162956-65e3620a7ae7 // pinned to release-branch.go1.13
k8s.io/api => k8s.io/api v0.0.0-20200306151724-0a52b7486422
k8s.io/apimachinery => k8s.io/apimachinery v0.0.0-20200306202157-ac276fc34867
k8s.io/cli-runtime => k8s.io/cli-runtime v0.0.0-20200304164305-f26b0857ea34
k8s.io/client-go => k8s.io/client-go v0.0.0-20200307002525-7b31ec144ad8
k8s.io/cli-runtime => k8s.io/cli-runtime v0.0.0-20200307004336-058578b5f081
k8s.io/client-go => k8s.io/client-go v0.0.0-20200307002526-b173caf5988c
k8s.io/code-generator => k8s.io/code-generator v0.0.0-20200306081859-6a048a382944
k8s.io/component-base => k8s.io/component-base v0.0.0-20200305122702-2cff9454e9d1
k8s.io/metrics => k8s.io/metrics v0.0.0-20200304084343-4cf3f455bf52

4
go.sum
View File

@ -308,8 +308,8 @@ honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWh
honnef.co/go/tools v0.0.0-20190106161140-3f1c8253044a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
k8s.io/api v0.0.0-20200306151724-0a52b7486422/go.mod h1:4bHpvwcObcdIFmIlnwDdJznMrytQbQCBpJvQgh+FnrA=
k8s.io/apimachinery v0.0.0-20200306202157-ac276fc34867/go.mod h1:5X8oEhnd931nEg6/Nkumo00nT6ZsCLp2h7Xwd7Ym6P4=
k8s.io/cli-runtime v0.0.0-20200304164305-f26b0857ea34/go.mod h1:1K5QYF8MW308AOVMg+33nPuGTXZadAOYUrG0HCZQoHM=
k8s.io/client-go v0.0.0-20200307002525-7b31ec144ad8/go.mod h1:9W6NBDAP22mJEhrKYXmPsL6dTQqczIp6+4GZcpWDlKs=
k8s.io/cli-runtime v0.0.0-20200307004336-058578b5f081/go.mod h1:IGv1kvgynL+0m4h0lIHl0H4+x9mvhAl0W9rGCuKu2ic=
k8s.io/client-go v0.0.0-20200307002526-b173caf5988c/go.mod h1:9W6NBDAP22mJEhrKYXmPsL6dTQqczIp6+4GZcpWDlKs=
k8s.io/code-generator v0.0.0-20200306081859-6a048a382944/go.mod h1:+UHX5rSbxmR8kzS+FAv7um6dtYrZokQvjHpDSYRVkTc=
k8s.io/component-base v0.0.0-20200305122702-2cff9454e9d1/go.mod h1:3RwNWXDYjUOPPeNNQE+7cPPoWAnnL/938q4q+jnBTNk=
k8s.io/gengo v0.0.0-20190128074634-0689ccc1d7d6/go.mod h1:ezvh/TsK7cY6rbqRK0oQQ8IAqLxYwwyPxAX1Pzy0ii0=

View File

@ -17,6 +17,7 @@ limitations under the License.
package apply
import (
"context"
"fmt"
"io"
"strings"
@ -97,7 +98,7 @@ func (p *pruner) pruneAll(o *ApplyOptions) error {
func (p *pruner) prune(namespace string, mapping *meta.RESTMapping) error {
objList, err := p.dynamicClient.Resource(mapping.Resource).
Namespace(namespace).
List(metav1.ListOptions{
List(context.TODO(), metav1.ListOptions{
LabelSelector: p.labelSelector,
FieldSelector: p.fieldSelector,
})
@ -145,9 +146,9 @@ func (p *pruner) delete(namespace, name string, mapping *meta.RESTMapping) error
}
func runDelete(namespace, name string, mapping *meta.RESTMapping, c dynamic.Interface, cascade bool, gracePeriod int, serverDryRun bool) error {
options := &metav1.DeleteOptions{}
options := metav1.DeleteOptions{}
if gracePeriod >= 0 {
options = metav1.NewDeleteOptions(int64(gracePeriod))
options = *metav1.NewDeleteOptions(int64(gracePeriod))
}
if serverDryRun {
options.DryRun = []string{metav1.DryRunAll}
@ -157,7 +158,7 @@ func runDelete(namespace, name string, mapping *meta.RESTMapping, c dynamic.Inte
policy = metav1.DeletePropagationOrphan
}
options.PropagationPolicy = &policy
return c.Resource(mapping.Resource).Namespace(namespace).Delete(name, options)
return c.Resource(mapping.Resource).Namespace(namespace).Delete(context.TODO(), name, options)
}
type pruneResource struct {

View File

@ -17,6 +17,7 @@ limitations under the License.
package create
import (
"context"
"fmt"
"io"
"net/url"
@ -451,7 +452,7 @@ func (o *CreateSubcommandOptions) Run() error {
}
createOptions.DryRun = []string{metav1.DryRunAll}
}
actualObject, err := o.DynamicClient.Resource(mapping.Resource).Namespace(o.Namespace).Create(asUnstructured, createOptions)
actualObject, err := o.DynamicClient.Resource(mapping.Resource).Namespace(o.Namespace).Create(context.TODO(), asUnstructured, createOptions)
if err != nil {
return err
}

View File

@ -192,11 +192,11 @@ func (o *RolloutStatusOptions) Run() error {
lw := &cache.ListWatch{
ListFunc: func(options metav1.ListOptions) (runtime.Object, error) {
options.FieldSelector = fieldSelector
return o.DynamicClient.Resource(info.Mapping.Resource).Namespace(info.Namespace).List(options)
return o.DynamicClient.Resource(info.Mapping.Resource).Namespace(info.Namespace).List(context.TODO(), options)
},
WatchFunc: func(options metav1.ListOptions) (watch.Interface, error) {
options.FieldSelector = fieldSelector
return o.DynamicClient.Resource(info.Mapping.Resource).Namespace(info.Namespace).Watch(options)
return o.DynamicClient.Resource(info.Mapping.Resource).Namespace(info.Namespace).Watch(context.TODO(), options)
},
}

View File

@ -263,7 +263,7 @@ func IsDeleted(info *resource.Info, o *WaitOptions) (runtime.Object, bool, error
nameSelector := fields.OneTermEqualSelector("metadata.name", info.Name).String()
// List with a name field selector to get the current resourceVersion to watch from (not the object's resourceVersion)
gottenObjList, err := o.DynamicClient.Resource(info.Mapping.Resource).Namespace(info.Namespace).List(metav1.ListOptions{FieldSelector: nameSelector})
gottenObjList, err := o.DynamicClient.Resource(info.Mapping.Resource).Namespace(info.Namespace).List(context.TODO(), metav1.ListOptions{FieldSelector: nameSelector})
if apierrors.IsNotFound(err) {
return info.Object, true, nil
}
@ -289,7 +289,7 @@ func IsDeleted(info *resource.Info, o *WaitOptions) (runtime.Object, bool, error
watchOptions := metav1.ListOptions{}
watchOptions.FieldSelector = nameSelector
watchOptions.ResourceVersion = gottenObjList.GetResourceVersion()
objWatch, err := o.DynamicClient.Resource(info.Mapping.Resource).Namespace(info.Namespace).Watch(watchOptions)
objWatch, err := o.DynamicClient.Resource(info.Mapping.Resource).Namespace(info.Namespace).Watch(context.TODO(), watchOptions)
if err != nil {
return gottenObj, false, err
}
@ -361,7 +361,7 @@ func (w ConditionalWait) IsConditionMet(info *resource.Info, o *WaitOptions) (ru
var gottenObj *unstructured.Unstructured
// List with a name field selector to get the current resourceVersion to watch from (not the object's resourceVersion)
gottenObjList, err := o.DynamicClient.Resource(info.Mapping.Resource).Namespace(info.Namespace).List(metav1.ListOptions{FieldSelector: nameSelector})
gottenObjList, err := o.DynamicClient.Resource(info.Mapping.Resource).Namespace(info.Namespace).List(context.TODO(), metav1.ListOptions{FieldSelector: nameSelector})
resourceVersion := ""
switch {
@ -384,7 +384,7 @@ func (w ConditionalWait) IsConditionMet(info *resource.Info, o *WaitOptions) (ru
watchOptions := metav1.ListOptions{}
watchOptions.FieldSelector = nameSelector
watchOptions.ResourceVersion = resourceVersion
objWatch, err := o.DynamicClient.Resource(info.Mapping.Resource).Namespace(info.Namespace).Watch(watchOptions)
objWatch, err := o.DynamicClient.Resource(info.Mapping.Resource).Namespace(info.Namespace).Watch(context.TODO(), watchOptions)
if err != nil {
return gottenObj, false, err
}

View File

@ -247,7 +247,7 @@ type genericDescriber struct {
}
func (g *genericDescriber) Describe(namespace, name string, describerSettings DescriberSettings) (output string, err error) {
obj, err := g.dynamic.Resource(g.mapping.Resource).Namespace(namespace).Get(name, metav1.GetOptions{})
obj, err := g.dynamic.Resource(g.mapping.Resource).Namespace(namespace).Get(context.TODO(), name, metav1.GetOptions{})
if err != nil {
return "", err
}