-
Notifications
You must be signed in to change notification settings - Fork 262
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
feature(#580): adds traffic and tags information to revision list #581
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,6 +18,7 @@ import ( | |
"fmt" | ||
"sort" | ||
"strconv" | ||
"strings" | ||
|
||
"knative.dev/serving/pkg/apis/serving" | ||
|
||
|
@@ -85,6 +86,23 @@ func NewRevisionListCommand(p *commands.KnParams) *cobra.Command { | |
} | ||
} | ||
|
||
// Add revision/service info as annotations: traffic and tags | ||
var service *v1alpha1.Service | ||
var serviceName string | ||
for _, revision := range revisionList.Items { | ||
if serviceName == "" || revision.Labels[serving.ServiceLabelKey] != serviceName { | ||
serviceName = revision.Labels[serving.ServiceLabelKey] | ||
service, err = client.GetService(serviceName) | ||
if err != nil { | ||
return err | ||
} | ||
} | ||
|
||
traffic, tags := trafficForRevision(revision.Name, service) | ||
revision.Annotations[RevisionTrafficAnnotation] = fmt.Sprintf("%d%%", traffic) | ||
revision.Annotations[RevisionTagsAnnotation] = strings.Join(tags, ",") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we avoid modifying the revision here by e.g. using a map keyed by revision name ? Imagine if someone later would introduce such annotations for real (so that you would override it here). Also 'misusing' an object by writing to it in a pure read-only use case is not architectural sound. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thought of that, however, the revision is not modified permanently. Only temporarily to hold values that frankly belongs to it. These modified revision objects are in memory and are never seen by 'anyone' else other than the user that invoked the command. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
+1 We can use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Read my comment @navidshaikh it does not modify the revision except in memory which makes the rest of the code super clean There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sure! I think this information doesn't belong to Revision and we shouldn't piggyback this data onto Revision. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
It does at least when using the revision list. See why I opened this issue in the first place. It comes from the need to see this information and not having to have to show the details of the service and parsing the out to find the data. This is my feedback from real usage. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
That's where I disagree, i.e. that annotations are used for volatile information which never gets persisted ;-). But maybe we could at least agree that listing revisions is a read-only operation and could be implemented with immutable objects that don't allow mutating operations? Why should we break that without a need ?
That's not really the point, whether this feature exists or not as its just an illustrative example. When you say one can easily add a filter, that is a bad smell, too, to use another hack to fix the previous hack. Not sure whether I could convince you that keeping certain architectural constraints even when they are not enforced today is a good thing. So let's merge them at let me make an alternative suggestion in the next PR. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
That's not the part that I disagree with.
Yup, that's the conundrum. It's the use of annotations. For me, I feel that this is a good use since the attributes I am adding
OK cool. Look forward to it. Hopefully it's not a significant change since that was where I was headed until this approach. But maybe I am missing some easy trick... Happy to learn. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
I have to apologize a bit :) Ideally I would use classical "view object" used for printing. But the printer framework we are using insist on However, my point is illustrated quite nicely what happens at the moment, when you are doing a So, there is no easy trick. Life is complicated ;-) |
||
} | ||
|
||
// sort revisionList by configuration generation key | ||
sort.SliceStable(revisionList.Items, func(i, j int) bool { | ||
a := revisionList.Items[i] | ||
|
@@ -110,6 +128,7 @@ func NewRevisionListCommand(p *commands.KnParams) *cobra.Command { | |
if err != nil { | ||
return err | ||
} | ||
|
||
err = printer.PrintObj(revisionList, cmd.OutOrStdout()) | ||
if err != nil { | ||
return err | ||
|
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 working on an followup PR, but wanna leave some extra comments): It is by no means guaranteed that revisions from the list are sorted according to service. Better store in a map for latter referral.
Please don't fix I'm on it.