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
Create a filter implementation for K8s runtime.Object
s
#2631
Conversation
The latest updates on your projects. Learn more about Vercel for Git ↗︎
|
One very explicit thing you will need is to register the fields in the opencost/core/pkg/filter/ops/ops.go Lines 28 to 33 in 8a4002a
(this is likely the best choice -- just replace the // typeutil.TypeOf[containerstats.ContainerStatsField](): containerstats.DefaultFieldByName, line - heheheh)
If the fields are added outside of the opencost repo, you can use this in an init: opencost/core/pkg/filter/ops/ops.go Line 36 in 8a4002a
|
TIL! Done, that point about stuff outside of the Opencost repo is neat as heck |
a40123b
to
e7ce935
Compare
FieldNamespace K8sObjectField = K8sObjectField(fieldstrings.FieldNamespace) | ||
FieldControllerKind K8sObjectField = K8sObjectField(fieldstrings.FieldControllerKind) | ||
FieldControllerName K8sObjectField = K8sObjectField(fieldstrings.FieldControllerName) | ||
FieldPod K8sObjectField = K8sObjectField(fieldstrings.FieldPod) | ||
FieldLabel K8sObjectField = K8sObjectField(fieldstrings.FieldLabel) | ||
FieldAnnotation K8sObjectField = K8sObjectField(fieldstrings.FieldAnnotation) |
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.
Did go force you to add the type cast when you referred to the fieldstrings
constants?
ie:
const FieldNamespace K8sObjectField = "namespace"
is fine, but
const FieldNamespace K8sObjectField = fieldstrings.FieldNamespace
barks at you that they're not the same type?
Bah
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.
Yeah, it barks; I'm glad it does, otherwise these enum-like things would be pretty useless.
// valid left-hand comparators | ||
var k8sObjectFilterFields []*ast.Field = []*ast.Field{ | ||
ast.NewField(FieldNamespace), | ||
ast.NewField(FieldControllerName, ast.FieldAttributeNilable), |
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.
Just wanted to point out (if you haven't noted field attributes yet) that ast.FieldAttributeNilable
(or any attribute that might be needed) on a field is simply metadata that can be accessed in the compiler or code generator to help alleviate any special cases that may exist.
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.
Attributes are just bitflags (sorry, I think I'm showing my age), so they're not super expansive, but likely more space than we'll ever need. I think Nilable starts at the 5th bit, and we're using an int
, so it's expandable to another 27 custom attributes 🤷
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.
Oh very neat, I just copied whatever Allocation was using for consistency; I think it also makes sense here.
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
Signed-off-by: Michael Dresser <michaelmdresser@gmail.com>
Signed-off-by: Michael Dresser <michaelmdresser@gmail.com>
Signed-off-by: Michael Dresser <michaelmdresser@gmail.com>
Signed-off-by: Michael Dresser <michaelmdresser@gmail.com>
Signed-off-by: Michael Dresser <michaelmdresser@gmail.com>
Signed-off-by: Michael Dresser <michaelmdresser@gmail.com>
e7ce935
to
ee0c997
Compare
Quality Gate passedIssues Measures |
What does this PR change?
runtime.Object
type in the K8s libraryDoes this PR relate to any other PRs?
How will this PR impact users?
Does this PR address any GitHub or Zendesk issues?
How was this PR tested?
Does this PR require changes to documentation?