Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 0 additions & 22 deletions pkg/client/applyconfigurations.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,28 +39,6 @@ func ApplyConfigurationFromUnstructured(u *unstructured.Unstructured) runtime.Ap
return &unstructuredApplyConfiguration{Unstructured: u}
}

type applyconfigurationRuntimeObject struct {
runtime.ApplyConfiguration
}

func (a *applyconfigurationRuntimeObject) GetObjectKind() schema.ObjectKind {
return a
}

func (a *applyconfigurationRuntimeObject) GroupVersionKind() schema.GroupVersionKind {
return schema.GroupVersionKind{}
}

func (a *applyconfigurationRuntimeObject) SetGroupVersionKind(gvk schema.GroupVersionKind) {}

func (a *applyconfigurationRuntimeObject) DeepCopyObject() runtime.Object {
panic("applyconfigurationRuntimeObject does not support DeepCopyObject")
}

func runtimeObjectFromApplyConfiguration(ac runtime.ApplyConfiguration) runtime.Object {
return &applyconfigurationRuntimeObject{ApplyConfiguration: ac}
}

func gvkFromApplyConfiguration(ac applyConfiguration) (schema.GroupVersionKind, error) {
var gvk schema.GroupVersionKind
gv, err := schema.ParseGroupVersion(ptr.Deref(ac.GetAPIVersion(), ""))
Expand Down
2 changes: 2 additions & 0 deletions pkg/client/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -943,6 +943,7 @@ U5wwSivyi7vmegHKmblOzNVKA5qPO8zWzqBC

err = cl.Apply(ctx, client.ApplyConfigurationFromUnstructured(obj), &client.ApplyOptions{FieldManager: "test-manager"})
Expect(err).NotTo(HaveOccurred())
Expect(obj.GetResourceVersion()).NotTo(BeEmpty())

cm, err := clientset.CoreV1().ConfigMaps(obj.GetNamespace()).Get(ctx, obj.GetName(), metav1.GetOptions{})
Expect(err).NotTo(HaveOccurred())
Expand Down Expand Up @@ -1015,6 +1016,7 @@ U5wwSivyi7vmegHKmblOzNVKA5qPO8zWzqBC

err = cl.Apply(ctx, obj, &client.ApplyOptions{FieldManager: "test-manager"})
Expect(err).NotTo(HaveOccurred())
Expect(obj.ResourceVersion).NotTo(BeNil())
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we add something similar for subresource Apply?


cm, err := clientset.CoreV1().ConfigMaps(ptr.Deref(obj.GetNamespace(), "")).Get(ctx, ptr.Deref(obj.GetName(), ""), metav1.GetOptions{})
Expect(err).NotTo(HaveOccurred())
Expand Down
27 changes: 15 additions & 12 deletions pkg/client/typed_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package client

import (
"context"
"encoding/json"
"fmt"

"k8s.io/apimachinery/pkg/runtime"
Expand Down Expand Up @@ -146,17 +147,18 @@ func (c *typedClient) Apply(ctx context.Context, obj runtime.ApplyConfiguration,
applyOpts := &ApplyOptions{}
applyOpts.ApplyOptions(opts)

return req.
body, err := req.
NamespaceIfScoped(o.namespace, o.isNamespaced()).
Resource(o.resource()).
Name(o.name).
VersionedParams(applyOpts.AsPatchOptions(), c.paramCodec).
Do(ctx).
// This is hacky, it is required because `Into` takes a `runtime.Object` and
// that is not implemented by the ApplyConfigurations. The generated clients
// don't have this problem because they deserialize into the api type, not the
// apply configuration: https://github.com/kubernetes/kubernetes/blob/22f5e01a37c0bc6a5f494dec14dd4e3688ee1d55/staging/src/k8s.io/client-go/gentype/type.go#L296-L317
Into(runtimeObjectFromApplyConfiguration(obj))
Raw()
if err != nil {
return err
}

return json.Unmarshal(body, obj)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we have to do some sort of zeroing on the obj?

}

// Get implements client.Client.
Expand Down Expand Up @@ -324,16 +326,17 @@ func (c *typedClient) ApplySubResource(ctx context.Context, obj runtime.ApplyCon
return fmt.Errorf("failed to create apply request: %w", err)
}

return req.
respBody, err := req.
NamespaceIfScoped(o.namespace, o.isNamespaced()).
Resource(o.resource()).
Name(o.name).
SubResource(subResource).
VersionedParams(applyOpts.AsPatchOptions(), c.paramCodec).
Do(ctx).
// This is hacky, it is required because `Into` takes a `runtime.Object` and
// that is not implemented by the ApplyConfigurations. The generated clients
// don't have this problem because they deserialize into the api type, not the
// apply configuration: https://github.com/kubernetes/kubernetes/blob/22f5e01a37c0bc6a5f494dec14dd4e3688ee1d55/staging/src/k8s.io/client-go/gentype/type.go#L296-L317
Into(runtimeObjectFromApplyConfiguration(obj))
Raw()
if err != nil {
return err
}

return json.Unmarshal(respBody, obj)
}