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

Index arbitrary labels #317

Draft
wants to merge 28 commits into
base: main
Choose a base branch
from

Conversation

ericpromislow
Copy link
Contributor

Related to #46333

Works with lasso PR rancher/lasso#117

Marked as draft because go.mod has a replace lasso ... ../lasso directive.

return obj, nil
}

func addLabelFields(raw *unstructured.Unstructured) error {
labels := raw.GetLabels()

Choose a reason for hiding this comment

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

This code never returns an error?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

True, good catch.

@@ -74,6 +100,15 @@ func addIDField(raw *unstructured.Unstructured) *unstructured.Unstructured {
return raw
}

// updateTypeField replaces the _type field with the contents of the field named "type", if it exists
func fixTypeField(raw *unstructured.Unstructured) *unstructured.Unstructured {

Choose a reason for hiding this comment

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

It's not clear why this returns the resource, it's modified in place?

addLabelFields also modifies in place, but doesn't return anything?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@@ -74,6 +100,15 @@ func addIDField(raw *unstructured.Unstructured) *unstructured.Unstructured {
return raw
}

// updateTypeField replaces the _type field with the contents of the field named "type", if it exists
func fixTypeField(raw *unstructured.Unstructured) *unstructured.Unstructured {
currentTypeValue, ok := raw.Object["type"]

Choose a reason for hiding this comment

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

This could dispense with the comma, ok approach and just get the value, and if it's not nil, store it?

Presumably an empty string (or other value) shouldn't be used as the _type ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Turns out this function was replaced by TransformEventObject, which returns a nil error because it's part of that same object-transform loop.

return obj, nil
}

// TransformLabels caches the labels

Choose a reason for hiding this comment

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

This comment sounds wrong?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, and I see the code was calling TransformLabels twice. The second call has no effect, but is confusing.

@@ -266,6 +266,36 @@ func TestParseQuery(t *testing.T) {
return nil
},
})
tests = append(tests, testCase{
description: "ParseQuery() with a labels filter param " +

Choose a reason for hiding this comment

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

I don't think you need to break this over two strings?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

ok. I'm still a slave to the 80-character guideline.

@@ -0,0 +1,143 @@
package queryparser

Choose a reason for hiding this comment

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

Should this not retain its original license header?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

good point. I made a few changes but let me look into it

The UI team wasn't sure whether the event fields should go in the empty-string group or in 'events.k8s.io',
so let's go with both until/unless specified otherwise.
- Remove the erroneously added management.cattle.io.nodes fields
- Use the builtin Event class, not events.k8s.io (by looking at the dashboard client code)
Following clause 4.3 of the Apache license:
"You must cause any modified files to carry prominent notices stating that You changed the files..."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants