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

Add fully qualified resource reference type #351

Conversation

killianmuldoon
Copy link

This PR adds a new type - ResourceReference - and a function to use it which allows logging a fully qualified resource reference that allows logging Name, Namespace, Kind, Version and Group for an object.

Fixes #350

New type - `ResourceReference` which allows logging a fully qualified resource reference that allows logging Name, Namespace, Kind, Version and Group for an object.

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Sep 15, 2022
@k8s-ci-robot
Copy link

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by: killianmuldoon
Once this PR has been reviewed and has the lgtm label, please assign dims for approval by writing /assign @dims in a comment. For more information see:The Kubernetes Code Review Process.

The full list of commands accepted by this bot can be found 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 size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Sep 15, 2022
Copy link
Author

@killianmuldoon killianmuldoon left a comment

Choose a reason for hiding this comment

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

@sbueringer I'd appreciate your review on the API here. I wonder if we could also have KResourceObj that takes an interface that's able to get the GVK as well as the Name and Namespace which might make this easier to consume in some cases.

k8s_references.go Outdated Show resolved Hide resolved
k8s_references.go Outdated Show resolved Hide resolved
@sbueringer
Copy link
Member

sbueringer commented Sep 15, 2022

@sbueringer I'd appreciate your review on the API here. I wonder if we could also have KResourceObj that takes an interface that's able to get the GVK as well as the Name and Namespace which might make this easier to consume in some cases.

Could be nice, the problem is probably to get gvk out of an object without having to handle/return an error (for apiVersion parsing)

@k8s-ci-robot k8s-ci-robot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Sep 15, 2022
klog_test.go Outdated Show resolved Hide resolved
klog_test.go Show resolved Hide resolved
@@ -156,3 +157,29 @@ func (ks kobjSlice) process() ([]interface{}, error) {
}
return objectRefs, nil
}

// ResourceRef is a full Kubernetes resource reference composed of Group, Version, Kind, Namespace and Name.
type ResourceRef struct {

Choose a reason for hiding this comment

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

Can you please check if this can be named as KResourceRef now that there is no func KResourceRef(....) ?

Copy link
Author

Choose a reason for hiding this comment

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

It feels slightly strange that KObj and KRef are functions while this would be a struct, but I'm happy to go either way on this if there's consensus.

Choose a reason for hiding this comment

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

Good point. @pohly which one do you think would be more natural to the framework ?

Copy link

@pohly pohly Sep 27, 2022

Choose a reason for hiding this comment

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

For the sake of clarity and usability, I prefer just the struct (see comment above) But for the sake of consistency we would have to use a function.

@serathius: what do you think?

Choose a reason for hiding this comment

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

I agree with @pohly that struct should be preferred.

k8s_references.go Outdated Show resolved Hide resolved
@k8s-ci-robot k8s-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Sep 27, 2022
@serathius
Copy link

serathius commented Sep 27, 2022

I'm not sure about the design the the API change:

  • Name ResourceRef implies this is a reference to a resource. This doesn't follow K8s naming convention as Resources and Objects are two separate things.
  • ResourceRef struct just stores reference to K8s object, similarly to ObjectRef with addition of GVK. Should we consider extending ObjectRef to include GVK?
  • It's good that Cluster API has defined it's own standard for fully qualified object reference, however we need broader discussion to define a standard for whole community. I think we should include api machinery people.

@serathius
Copy link

serathius commented Sep 27, 2022

Linking in the discussion about fully qualified object references in original structured logging kep kubernetes/enhancements#1367 (comment)

@deads2k @derekwaynecarr @thockin @deads2k Was there any progress made with defining a grammar for K8s object references?

@k8s-triage-robot
Copy link

The Kubernetes project currently lacks enough contributors to adequately respond to all issues and PRs.

This bot triages issues and PRs according to the following rules:

  • After 90d of inactivity, lifecycle/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was applied, the issue is closed

You can:

  • Mark this issue or PR as fresh with /remove-lifecycle stale
  • Mark this issue or PR as rotten with /lifecycle rotten
  • Close this issue or PR with /close
  • Offer to help out with Issue Triage

Please send feedback to sig-contributor-experience at kubernetes/community.

/lifecycle stale

@k8s-ci-robot k8s-ci-robot added the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label Dec 27, 2022
@k8s-triage-robot
Copy link

The Kubernetes project currently lacks enough active contributors to adequately respond to all issues and PRs.

This bot triages issues and PRs according to the following rules:

  • After 90d of inactivity, lifecycle/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was applied, the issue is closed

You can:

  • Mark this issue or PR as fresh with /remove-lifecycle rotten
  • Close this issue or PR with /close
  • Offer to help out with Issue Triage

Please send feedback to sig-contributor-experience at kubernetes/community.

/lifecycle rotten

@k8s-ci-robot k8s-ci-robot added lifecycle/rotten Denotes an issue or PR that has aged beyond stale and will be auto-closed. and removed lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. labels Jan 26, 2023
@pohly
Copy link

pohly commented Feb 13, 2023

It might be necessary to join a meeting (presumably SIG apimachinery?) and discuss the grammar question there.

@pohly
Copy link

pohly commented Feb 13, 2023

/remove-lifecycle rotten

@k8s-ci-robot k8s-ci-robot removed the lifecycle/rotten Denotes an issue or PR that has aged beyond stale and will be auto-closed. label Feb 13, 2023
@thockin
Copy link
Member

thockin commented Feb 13, 2023

Was there any progress made with defining a grammar for K8s object references

To the best of my knowledge, nobody has tackled this definition. I don't have bandwidth in the near future but here's where I would start:

  1. Think, grep, ask, look for all the places we use compound strings. Off the top of my head:
    a) apiVersion: $group/$version => "apps/v1"
    b) kubectl get name: $resource(ish).$group/$name => "deployment.apps/mydeploy"
    c) namespacedName: $namespace/$name => "myapp-prod/mysvc"
    d) DNS: $name.$namespace => "kubernetes.default"
    e) there must be more...

  2. Formalize them (e.g. what is "deployment" in 1b? It's not a kind ("Deployment") nor a resource ("deployments")

  3. Think about where those overlap (e.g. 1b vs 1c) and whether it matters

  4. Think about what a unified format (or formats) could look like, emphasizing compat

  5. Think about how migration could happen (or if it can't)

  6. Make a proposal (ranging from "document the mess" to "a grand unified format")

@killianmuldoon
Copy link
Author

@pohly - I see you're assigned to this in the issue at #350 - are you planning to work on this?

@pohly
Copy link

pohly commented Mar 10, 2023

No, I was assigned today and haven't had the time to unassign myself.

@k8s-triage-robot
Copy link

The Kubernetes project currently lacks enough contributors to adequately respond to all PRs.

This bot triages PRs according to the following rules:

  • After 90d of inactivity, lifecycle/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was applied, the PR is closed

You can:

  • Mark this PR as fresh with /remove-lifecycle stale
  • Close this PR with /close
  • Offer to help out with Issue Triage

Please send feedback to sig-contributor-experience at kubernetes/community.

/lifecycle stale

@k8s-ci-robot k8s-ci-robot added the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label Jun 8, 2023
@pohly
Copy link

pohly commented Jun 12, 2023

/remove-lifecycle stale

Still seems relevant, but needs someone to drive it.

@k8s-ci-robot k8s-ci-robot removed the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label Jun 12, 2023
@killianmuldoon
Copy link
Author

going to close this PR as a cleanup - but the issue is still open if someone has time to drive the change.

@killianmuldoon
Copy link
Author

/close

@k8s-ci-robot
Copy link

@killianmuldoon: Closed this PR.

In response to this:

/close

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. 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.

Add logging reference format with Group, Version, Kind, Namespace and Name
8 participants