get pipeline and pipeline run for deployment - #3014
Conversation
andrewballantyne
left a comment
There was a problem hiding this comment.
Thanks a bunch for doing this - this will be the base for both our work.
However, a couple points need addressing below.
There was a problem hiding this comment.
This is the concern I have with blindly using _.get. It looks great on paper... but essentially you have just created a chance for a NPE. _.get allows you to blindly walk into an object without care, but you make no attempt to validate the response before using it.
Since this appears to be the structure of this utility class, I recommend just using the 3rd param here and setting it to an empty array so the .filter a couple lines down doesn't blow up if it fails to get something back (which likely will be undefined)
There was a problem hiding this comment.
@sahil143 I think we have had this conversation a couple times now... I'd like you to focus on your usage of _.get more closely. I worry we are going to slip and drop NPEs into our code with this kind of approach to _.get.
Either make liberal use of the 3rd param (making it the empty value of the type of what you're looking for) or avoid it at all costs, forcing the question of "what if the properties along the way are not there?".
There was a problem hiding this comment.
My bad, destructuring of object can be used here instead of _.get.
fixed in 3acef67
There was a problem hiding this comment.
Is it possible for pipelineRuns not to be part of the this.resources object?
There was a problem hiding this comment.
Boy, not a lot of types going around this utility, huh?
Do we need to update the PodRingResources interface-type?
export interface PodRingResources {
pods: Resource;
replicaSets: Resource;
replicationControllers: Resource;
deployments?: Resource;
deploymentConfigs?: Resource;
}
There was a problem hiding this comment.
No, we don't need to update the PodRingResource types here because that only deals with getting the data for pods.
Is it possible for pipelineRuns not to be part of the this.resources object?
No, We added pipeline and Pipeline Run here https://github.com/openshift/console/pull/3014/files#diff-0dffb9abd12f8591b1d227efedf17dcbR113 in the resource object.
There was a problem hiding this comment.
Right you are ... my IDE had a reference issue where it didn't track it to this import lol. @console references seem to be an issue for my IDE to track.
There was a problem hiding this comment.
as these are crd based resources, will adding optional: true make sense?
There was a problem hiding this comment.
Shouldn't we be plugging into this in the same manner we've done with knative?
The console-shared package should not depend on any other packages.
There was a problem hiding this comment.
This is a bad dependency.
console-shared cannot depend on dev-console.
Look at how knative plugs into the overview.
There was a problem hiding this comment.
that can be achieved from plugin.tsx in dev-console as an extension, but going forward will it be a good idea to have tekton as a separate plugin like kn.
There was a problem hiding this comment.
Yup I agree. I told the same thing to @sahil143. But for now pipelines being in dev-console is fine until we get time to refactor it out.
657b838 to
8cd0909
Compare
ca46425 to
5c85f26
Compare
|
@andrewballantyne @invincibleJai @christianvogt PR is ready for review. |
There was a problem hiding this comment.
Array to single is not ideal. Typically the consumer will have an issue understanding if it's an array or not. Where is this used that you needed to change it?
There was a problem hiding this comment.
This single instead of an array is back because pipeline in getPipelineAndPipelineRunsForResource method is an object instead of array.
There was a problem hiding this comment.
Yeah... I see that. I am wondering if we should just just return an array for the purity of the common utility.
There was a problem hiding this comment.
Easier to deal with a single variant. Leave it an array for now.
There was a problem hiding this comment.
{ [key: string]: ResourceItem } expands out to be:
{
[key: string]: {
[key: string]: K8sResourceKind[] | K8sResourceKind;
};
};
I doubt you were referring to a map of a map of K8sResourceKinds, where you? Because if so, we should definitely look into that.
There was a problem hiding this comment.
Couple things here... typically you don't return undefined unless you're trying to trigger default values - which isn't what I am seeing here. You're making a call on line 56 and your type specifies it's not optional.
And the other thing is, I am pretty sure there is a logic flaw here:
| if (props && !props.pipelineRuns) return undefined; | |
| if (!props || !props.pipelineRuns) return undefined; |
Otherwise on line 33 you're going to have an issue if props is not an object. If props cannot be null (or another falsey value) then you don't need to check against it in this if-condition.
There was a problem hiding this comment.
Thanks for noticing this. I was also a bit skeptical about the condition fixed in 61c377e
There was a problem hiding this comment.
Same issues here with returning undefined and the conditional issue.
|
@karthikjeeyar @abhinandan13jan Please take a look at this PR. |
There was a problem hiding this comment.
Not that it'll help clean this up, but any reason why we are returning an object with only 1 key? Why not just the value (type in this case)?
There was a problem hiding this comment.
This method will execute here element https://github.com/openshift/console/pull/3014/files#diff-0dffb9abd12f8591b1d227efedf17dcbR608 and it uses the spread operator. Returning a value like this will add pipelines prop to overviewItem.
There was a problem hiding this comment.
Something about changing this type to solve our problem feels like a mis-use of this code. All the other utilities are able to send back a map to K8sResourceKind[], I know we have two types here... perhaps we need to produce two keys... pipelines and pipelineRuns. Instead of wrapping them up in their own (PipelineOverviewItem)
There was a problem hiding this comment.
Agreed! After creating this utility and using through a plugin, Even I'm in favor of creating two separate keys instead of wrapping them up in their own.
0f582ea to
1d50f66
Compare
There was a problem hiding this comment.
Any reason for the sort?
There was a problem hiding this comment.
Yes, to have the latest run at start of the list because we want to show 3 latest runs on the side panel.
There was a problem hiding this comment.
I wonder if this is not more suited for your usage of the code, rather than at the top level.
There was a problem hiding this comment.
Consider the view point of possible usages:
- Would we want PipelineRuns for a table view - where the user can sort?
- Would we want PipelineRuns for a filterable view?
It's not always beneficial to apply mutations like sort on a low-level set of data.
There was a problem hiding this comment.
A default sort can't hurt though.
There was a problem hiding this comment.
Perhaps. If you're not bothered by it, I'll let it go.
c341647 to
ccf6ac8
Compare
There was a problem hiding this comment.
If we are keeping sort, you should type this function. left and right are not variable names that showcase type. Ideally when reading a function, there should be limited need to trace origins to understand the nature of the function.
There was a problem hiding this comment.
Can we avoid having these listed here?
I see the knative snuck in some values here. We'd need to clean those up as well.
Knative and pipelines shouldn't bleed into the console-shared.
Where are these being used?
There was a problem hiding this comment.
@christianvogt @sahil143
So now that these are out of the types here - it's confusing reading the code.
const createTopologyNodeData = (dc: OverviewItem, cheURL?: string): TopologyDataObject => {
I read this, and go "okay, dc is of type OverviewItem, let's see what comes out of that type" - and don't find pipeline or pipelineRuns. However, if I now start up the code and throw a debugger/log in, oh look, there it is.
I get the purity of the package, but we need to consider how to address this kind of stuff across packages. TypeScript is here to help us, we definitely should be showcasing all relevant properties of an object, especially when it's typed.
There was a problem hiding this comment.
Gorkem had a suggestion. Perhaps we simply find the pipeline run with the same instance label as the deployment?
There was a problem hiding this comment.
I doubt you mean pipeline run here. Do you mean we add the instance label to the pipeline instead of adding pipeline-ref to deployment?
There was a problem hiding this comment.
I think he means for the other function - you're fetching all pipeline runs and tossing out everything that is not related to our pipeline that has the label.
RE: https://github.com/openshift/console/pull/3014/files#diff-bbb2e3628eb7d5b19c6b638c0968dc9dR47
There was a problem hiding this comment.
I meant pipeline (corrected).
Yes instead of adding a ref on the deployment.
If a deployment and a pipeline have the same instance label, we can assume that they are related.
See https://github.com/gorkem/app-labels/blob/master/labels-annotation-for-openshift.adoc
There was a problem hiding this comment.
@christianvogt If a deployment doesn't have an instance label, do we fallback to metadata.name or just return null?
There was a problem hiding this comment.
After discussion decided to return null. fixed in 347fce3
There was a problem hiding this comment.
Easier to deal with a single variant. Leave it an array for now.
There was a problem hiding this comment.
Although this is sample, lets not use serviceAccount field anymore
There was a problem hiding this comment.
you can use _.has notation instead
|
/retest |
|
/retest |
change the logic to return only one pipeline with each resource use destructuring instead of _.get() lodash change the order for PipelineRef check fix unit-tests commit Create a plugin to get pipeline and pipeline run for a resource add K8sResourceKind type update snapshot add unit tests for pipeline-plugin-utils add proper types and return null instead of undefined sort pipeline runs by creationTimestamp return props remove plural Update frontend/packages/dev-console/src/utils/pipeline-plugin-utils.ts Co-Authored-By: Andrew Ballantyne <8126518+andrewballantyne@users.noreply.github.com> Update frontend/packages/console-shared/src/types/resource.ts cleanup add types to sort function and remove pipeline and pipelinerun from overviewITem use instance label instead of pipeline-ref
347fce3 to
762998c
Compare
|
/retest |
|
/approve |
|
/lgtm |
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: andrewballantyne, christianvogt, sahil143 The full list of commands accepted by this bot can be found here. The pull request process is described here DetailsNeeds approval from an approver in each of these files:
Approvers can indicate their approval by writing |
|
/retest |
ODC Task: https://jira.coreos.com/browse/ODC-2061
This PR adds utilities in
resource-utilsto fetch the pipeline and pipelineRuns considering that there is a labelapp.openshift.io/pipeline-refon the resource(Deployment/Deployment Config).Fetched data can be used in topology view and Sidebar panel