Skip to content
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

Unstructured support in different functions #112

Merged
merged 6 commits into from
Aug 10, 2020

Conversation

somtochiama
Copy link
Member

No description provided.

@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery. labels Jul 22, 2020
@k8s-ci-robot
Copy link
Contributor

Hi @somtochiama. Thanks for your PR.

I'm waiting for a kubernetes-sigs member to verify that this patch is reasonable to test. If it is, they should reply with /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work. Regular contributors should join the org to skip this step.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@k8s-ci-robot k8s-ci-robot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Jul 22, 2020
}
version = v

healthy, _, err = unstructured.NestedBool(unstruct.Object, "spec", "healthy")
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this should be "status" "healthy". We probably also should check the error (as you do with version)

return fmt.Errorf("provided object (%T) does not implement Patchable type", object)
}

var p addonsv1alpha1.Patchable
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: Do you need to declare this here? Looks like you could declare it in on line 54 with else if p, ok := object.... ?

if ok {
patch, _, err := unstructured.NestedSlice(unstruct.Object, "spec", "patches")
if err != nil {
return fmt.Errorf("unable to get patches from unstruct: %v", err)
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: unstructured, not unstruct, as we expect this will eventually bubble-up to the user.

@@ -46,50 +47,90 @@ type aggregator struct {
func (a *aggregator) Reconciled(ctx context.Context, src declarative.DeclarativeObject, objs *manifest.Objects) error {
log := log.Log

instance, ok := src.(addonv1alpha1.CommonObject)
if !ok {
unstruct, ok := src.(*unstructured.Unstructured)
Copy link
Contributor

Choose a reason for hiding this comment

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

It might be clearer if you constructed the healthy state first, and then applied it to the object. i.e. move the type-checking on src to around line 89

return fmt.Errorf("unable to get status from unstructured: %v", err)
}
if !reflect.DeepEqual(status, s) {
err = unstructured.SetNestedField(unstruct.Object, statusHealthy, "status", "healthy")
Copy link
Contributor

Choose a reason for hiding this comment

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

Missed error-check here


log.WithValues("name", unstruct.GetName()).WithValues("status", status).Info("updating status")

err = a.client.Update(ctx, unstruct)
Copy link
Contributor

Choose a reason for hiding this comment

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

If you make this a.client.Update(ctx, src), can you eliminate the duplication between the two if branches?

Copy link
Member Author

Choose a reason for hiding this comment

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

I don't know if this would work as the status wasn't changed on src. Unlike the SetNestedField in unstruct and SetCommonStatus in instance that changes the status

Copy link
Contributor

Choose a reason for hiding this comment

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

Do we know where we don't change src? src and unstruct are just a pointer-cast, so they should be the same object.

(Also, if we're changing status we might have to use client.Status().Update(...)

Copy link
Member Author

Choose a reason for hiding this comment

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

It seems every time we run the update function, src has changed. I will change to client.Status().Update(...) in another PR

@justinsb
Copy link
Contributor

/ok-to-test

A few nits, but it's exciting to see this.

@k8s-ci-robot k8s-ci-robot added ok-to-test Indicates a non-member PR verified by an org member that is safe to test. and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Jul 27, 2020
var healthy bool
var addonObject addonsv1alpha1.CommonObject

if unstruct, ok := instance.(*unstructured.Unstructured); ok {
Copy link
Contributor

Choose a reason for hiding this comment

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

Looking at the other PRs, we might want to create helper functions here. e.g. GetVersion and GetHealthy (or maybe GetCommonSpec and GetCommonStatus)

Copy link
Member Author

Choose a reason for hiding this comment

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

I could definitely work on this. I think it is a good idea


log.WithValues("name", unstruct.GetName()).WithValues("status", status).Info("updating status")

err = a.client.Update(ctx, unstruct)
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we know where we don't change src? src and unstruct are just a pointer-cast, so they should be the same object.

(Also, if we're changing status we might have to use client.Status().Update(...)

@justinsb
Copy link
Contributor

One query about unstruct != src (and one suggestion for future PRs to refactor out some helper methods) but this lgtm.

Looks like we need a goimports fix though

/approve
/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Aug 10, 2020
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: justinsb, SomtochiAma

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Aug 10, 2020
@k8s-ci-robot k8s-ci-robot merged commit 1d1fd97 into kubernetes-sigs:master Aug 10, 2020
@somtochiama
Copy link
Member Author

Do we know where we don't change src? src and unstruct are just a pointer-cast, so they should be the same object.

I will check on that. When we update src/unstruct, do we update the main instance?

@somtochiama somtochiama deleted the unstructured-support branch August 20, 2020 07:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. ok-to-test Indicates a non-member PR verified by an org member that is safe to test. sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants