New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implementing Apply, Delete and DeleteByName in Kube HTTP Client #610
Conversation
…nto 546-kube-apply
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tough to review this one. This level of complexity is why I didn't implement the .Apply()
method in the first place I guess.
I would feel better if there were some test coverage for these changes in the kubehttp_test.go
file.
if err != nil { | ||
return nil, fmt.Errorf("failed to initialize discovery client: %s", err) | ||
} | ||
mapper := restmapper.NewDeferredDiscoveryRESTMapper(memory.NewMemCacheClient(dc)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there a memcached
instance running somewhere? Or is this only an in-memory cache?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That in-memory cache only I believe
indeed, that ":8080" I reported happened while implementing those tests. |
Might help, it has a teardown func: weave-gitops/pkg/testutils/testutils.go Line 18 in 6b91a81
|
pkg/kube/kubehttp.go
Outdated
|
||
func (c *KubeHTTP) getResourceInterface(manifest []byte) (dynamic.ResourceInterface, string, []byte, error) { | ||
obj := &unstructured.Unstructured{} | ||
_, gvk, err := decUnstructured.Decode([]byte(manifest), nil, obj) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Major: It's already a []byte
. Why create a new one?
pkg/kube/kubehttp_test.go
Outdated
Expect(kustObj.Name).To(Equal(name)) | ||
}) | ||
|
||
It("Delete", func() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Major: I'll make this comment here and at the top of the PR. I would really like to see more thorough testing on apply
, delete
, delete by name
. This is a super crucial object and I think it should be locked down tight.
Some other tests I would like to see are:
- Better error handling (i.e. test the error path and confirm those areas are covered)
- Test namespace scoped objects and non-namespace scoped objects. The current tests just test namespace resources.
- Malformed manifests being passed into the functions
An example, is what happens to Apply
when a different namespace is passed in as the parameter and the manifest
parameter has a different namespace.
I know as a team we haven't come together yet on what are expectations for unit testing. Happy to discuss this further face-to-face or pair program to get some extra tests down for these functions.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. Thanks for addressing so many comments.
default: | ||
return kube.GVRKustomization | ||
return schema.GroupVersionResource{}, fmt.Errorf("no matching schema.GroupVersionResource to the ResourceKind: %s", string(rk)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FYI: I think it's good that you are passing the resourceKind that caused the error. Another approach could have been a custom error:
type ConversionError struct {
kind string
}
func (e *ConversionError) Error() string {
return fmt.Sprintf("no matching schema.GroupVersionResource to the ResourceKind: %s", string(e.kind))
}
The effect of this is a more clear way to check for the error consistently with errors.As(err, &e)
and not having to worry about the ResourceKind changing on you. However, this is excessive considering you aren't explicitly checking this error and handling it in a special way.
Thanks for addressing my main concern of odd side effects.
What changed?
Apply
,Delete
andDeleteByName
in kubehttp #546Why?
kubectl
binaryHow did you test it?
Release notes
Documentation Changes