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

Refactors code to set and get status from object #118

Merged
merged 1 commit into from
Oct 8, 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. sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery. labels Aug 19, 2020
@k8s-ci-robot k8s-ci-robot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Aug 19, 2020
@somtochiama
Copy link
Member Author

/assign @justinsb

Errors []string `json:"errors,omitempty"`
Phase string `json:"phase,omitempty"`
VersionCheckErrors []string
StatusErrors []string
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this intended? Should we add these two fields in a separate PR?

@@ -9,48 +9,71 @@ import (
addonsv1alpha1 "sigs.k8s.io/kubebuilder-declarative-pattern/pkg/patterns/addon/pkg/apis/v1alpha1"
)

func GetCommonVersion(instance runtime.Object) (string, error) {
func genError(v runtime.Object) error {
return fmt.Errorf("instance %T is not addonsv1alpha1.CommonObject or unstructured", v)
Copy link
Contributor

Choose a reason for hiding this comment

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

I probably would have just inlined this function each time, but I guess it's nice that it is consistent! 👍

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks. I could change it if that would be more concise.

log.Error(err, "failed to get status")
}
compiledStatus := utils.CompileErrors(status)
fmt.Println("compiling errors")
Copy link
Contributor

Choose a reason for hiding this comment

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

Should be log, rather than using fmt which will go to stdout.

Copy link
Member Author

@somtochiama somtochiama Sep 23, 2020

Choose a reason for hiding this comment

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

Sure. I will change it

func CompileErrors(status addonsv1alpha1.CommonStatus) addonsv1alpha1.CommonStatus {
fmt.Println(status.StatusErrors)
status.Errors = []string{}
status.Errors = append(status.Errors, status.VersionCheckErrors...)
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm a little uneasy about introducing this in this refactor PR

@justinsb
Copy link
Contributor

Is it possible to split the version errors into a different PR and keep this just as a refactor? (I can show you how I would do it in git if you'd like...)

There's also some ongoing discussions about more structured error handling: kubernetes/community#4521 so I think we should be careful when introducing new status!

@@ -47,9 +47,11 @@ type CommonSpec struct {

// CommonSpec is a set of status attributes that must be exposed on all addons.
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: replace CommonSpec with CommonStatus

@somtochiama
Copy link
Member Author

Is it possible to split the version errors into a different PR and keep this just as a refactor? (I can show you how I would do it in git if you'd like...)

There's also some ongoing discussions about more structured error handling: kubernetes/community#4521 so I think we should be careful when introducing new status!

Sure. I will separate it into different PR and then we can discuss the change there

log.WithValues("name", src.GetName()).WithValues("phase", aggregatedPhase).Info("updating status")
err := k.client.Status().Update(ctx, src)
err = k.client.Status().Update(ctx, src)
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit - if you're not going to need error out side the block, it's probably better to do either err := ... or if err := foo(); err != nil

@justinsb
Copy link
Contributor

justinsb commented Oct 8, 2020

Thanks @somtochiama - looks great :-)

/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 Oct 8, 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 Oct 8, 2020
@k8s-ci-robot k8s-ci-robot merged commit 045672b into kubernetes-sigs:master Oct 8, 2020
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. 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

4 participants