Merge pull request #99214 from jpbetz/apply-client-go-builders2-typedclient

Add Apply to client-go's typed client
This commit is contained in:
Kubernetes Prow Robot
2021-03-06 22:17:41 -08:00
committed by GitHub
209 changed files with 8366 additions and 269 deletions

View File

@@ -36,6 +36,7 @@ import (
"k8s.io/apimachinery/pkg/types"
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
"k8s.io/apimachinery/pkg/watch"
appsv1apply "k8s.io/client-go/applyconfigurations/apps/v1"
coreinformers "k8s.io/client-go/informers/core/v1"
clientset "k8s.io/client-go/kubernetes"
appsv1client "k8s.io/client-go/kubernetes/typed/apps/v1"
@@ -247,6 +248,14 @@ func (c conversionClient) Patch(ctx context.Context, name string, pt types.Patch
return nil, errors.New("Patch() is not implemented for conversionClient")
}
func (c conversionClient) Apply(ctx context.Context, rs *appsv1apply.ReplicaSetApplyConfiguration, opts metav1.ApplyOptions) (*apps.ReplicaSet, error) {
return nil, errors.New("Apply() is not implemented for conversionClient")
}
func (c conversionClient) ApplyStatus(ctx context.Context, rs *appsv1apply.ReplicaSetApplyConfiguration, opts metav1.ApplyOptions) (*apps.ReplicaSet, error) {
return nil, errors.New("ApplyStatus() is not implemented for conversionClient")
}
func (c conversionClient) GetScale(ctx context.Context, name string, options metav1.GetOptions) (result *autoscalingv1.Scale, err error) {
// This is not used by RSC.
return nil, errors.New("GetScale() is not implemented for conversionClient")

View File

@@ -36,6 +36,7 @@ import (
"k8s.io/apimachinery/pkg/util/sets"
"k8s.io/apimachinery/pkg/util/strategicpatch"
"k8s.io/apimachinery/pkg/watch"
v1apply "k8s.io/client-go/applyconfigurations/core/v1"
"k8s.io/client-go/kubernetes/fake"
v1core "k8s.io/client-go/kubernetes/typed/core/v1"
"k8s.io/client-go/tools/cache"
@@ -349,6 +350,36 @@ func (m *FakeNodeHandler) Patch(_ context.Context, name string, pt types.PatchTy
return &updatedNode, nil
}
// Apply applies a NodeApplyConfiguration to a Node in the fake store.
func (m *FakeNodeHandler) Apply(ctx context.Context, node *v1apply.NodeApplyConfiguration, opts metav1.ApplyOptions) (*v1.Node, error) {
patchOpts := opts.ToPatchOptions()
data, err := json.Marshal(node)
if err != nil {
return nil, err
}
name := node.Name
if name == nil {
return nil, fmt.Errorf("deployment.Name must be provided to Apply")
}
return m.Patch(ctx, *name, types.ApplyPatchType, data, patchOpts)
}
// ApplyStatus applies a status of a Node in the fake store.
func (m *FakeNodeHandler) ApplyStatus(ctx context.Context, node *v1apply.NodeApplyConfiguration, opts metav1.ApplyOptions) (*v1.Node, error) {
patchOpts := opts.ToPatchOptions()
data, err := json.Marshal(node)
if err != nil {
return nil, err
}
name := node.Name
if name == nil {
return nil, fmt.Errorf("deployment.Name must be provided to Apply")
}
return m.Patch(ctx, *name, types.ApplyPatchType, data, patchOpts, "status")
}
// FakeRecorder is used as a fake during testing.
type FakeRecorder struct {
sync.Mutex