Skip to content

get pipeline and pipeline run for deployment - #3014

Merged
openshift-merge-robot merged 1 commit into
openshift:masterfrom
sahil143:pipeline-res-list
Oct 24, 2019
Merged

get pipeline and pipeline run for deployment#3014
openshift-merge-robot merged 1 commit into
openshift:masterfrom
sahil143:pipeline-res-list

Conversation

@sahil143

Copy link
Copy Markdown
Contributor

ODC Task: https://jira.coreos.com/browse/ODC-2061

This PR adds utilities in resource-utils to fetch the pipeline and pipelineRuns considering that there is a label app.openshift.io/pipeline-ref on the resource(Deployment/Deployment Config).
Fetched data can be used in topology view and Sidebar panel

@openshift-ci-robot openshift-ci-robot added component/dev-console Related to dev-console component/shared Related to console-shared size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Oct 18, 2019

@andrewballantyne andrewballantyne left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Thanks a bunch for doing this - this will be the base for both our work.

However, a couple points need addressing below.

Comment thread frontend/packages/console-shared/src/types/resource.ts Outdated
Comment thread frontend/packages/console-shared/src/utils/resource-utils.ts Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@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?".

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

My bad, destructuring of object can be used here instead of _.get.
fixed in 3acef67

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Is it possible for pipelineRuns not to be part of the this.resources object?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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;
}

@sahil143 sahil143 Oct 18, 2019

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

Comment thread frontend/packages/console-shared/src/utils/resource-utils.ts Outdated
Comment thread frontend/packages/console-shared/src/utils/resource-utils.ts Outdated

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

as these are crd based resources, will adding optional: true make sense?

@christianvogt christianvogt Oct 18, 2019

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

This is a bad dependency.
console-shared cannot depend on dev-console.
Look at how knative plugs into the overview.

@invincibleJai invincibleJai Oct 18, 2019

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

@openshift-ci-robot openshift-ci-robot added size/L Denotes a PR that changes 100-499 lines, ignoring generated files. component/sdk Related to console-plugin-sdk and removed size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Oct 21, 2019
Comment thread frontend/packages/console-plugin-sdk/src/typings/overview.ts Outdated
@sahil143

Copy link
Copy Markdown
Contributor Author

@andrewballantyne @invincibleJai @christianvogt PR is ready for review.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

removed the single one in 61c377e

@sahil143 sahil143 Oct 22, 2019

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This single instead of an array is back because pipeline in getPipelineAndPipelineRunsForResource method is an object instead of array.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Yeah... I see that. I am wondering if we should just just return an array for the purity of the common utility.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Easier to deal with a single variant. Leave it an array for now.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

fixed in 65c3b41

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

{ [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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

added a bit better type here 61c377e

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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:

Suggested change
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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Thanks for noticing this. I was also a bit skeptical about the condition fixed in 61c377e

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Same issues here with returning undefined and the conditional issue.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

fixed in 61c377e

@sahil143

Copy link
Copy Markdown
Contributor Author

@karthikjeeyar @abhinandan13jan Please take a look at this PR.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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)?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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.

@sahil143
sahil143 force-pushed the pipeline-res-list branch 2 times, most recently from 0f582ea to 1d50f66 Compare October 22, 2019 19:24

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Any reason for the sort?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Yes, to have the latest run at start of the list because we want to show 3 latest runs on the side panel.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I wonder if this is not more suited for your usage of the code, rather than at the top level.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

A default sort can't hurt though.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Perhaps. If you're not bothered by it, I'll let it go.

Comment thread frontend/packages/dev-console/src/utils/pipeline-plugin-utils.ts Outdated
Comment thread frontend/packages/console-shared/src/types/resource.ts Outdated

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

fixed in 65c3b41

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

fixed in 65c3b41

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@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.

@christianvogt christianvogt Oct 23, 2019

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Gorkem had a suggestion. Perhaps we simply find the pipeline run with the same instance label as the deployment?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

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?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@christianvogt If a deployment doesn't have an instance label, do we fallback to metadata.name or just return null?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

After discussion decided to return null. fixed in 347fce3

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Easier to deal with a single variant. Leave it an array for now.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Although this is sample, lets not use serviceAccount field anymore

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

fixed in 347fce3

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

you can use _.has notation instead

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

fixed in 347fce3

@sahil143

Copy link
Copy Markdown
Contributor Author

/retest

@andrewballantyne

Copy link
Copy Markdown
Contributor

/retest
/lgtm

@openshift-ci-robot openshift-ci-robot added the lgtm Indicates that a PR is ready to be merged. label Oct 23, 2019
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
@openshift-ci-robot openshift-ci-robot removed the lgtm Indicates that a PR is ready to be merged. label Oct 23, 2019
@christianvogt

Copy link
Copy Markdown
Contributor

/retest

@christianvogt

Copy link
Copy Markdown
Contributor

/approve

@openshift-ci-robot openshift-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Oct 24, 2019
@christianvogt

Copy link
Copy Markdown
Contributor

/lgtm

@openshift-ci-robot openshift-ci-robot added the lgtm Indicates that a PR is ready to be merged. label Oct 24, 2019
@openshift-ci-robot

Copy link
Copy Markdown
Contributor

[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

Details 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

@andrewballantyne

Copy link
Copy Markdown
Contributor

/retest

@openshift-merge-robot
openshift-merge-robot merged commit cb03ef8 into openshift:master Oct 24, 2019
@spadgett spadgett added this to the v4.3 milestone Oct 24, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved Indicates a PR has been approved by an approver from all required OWNERS files. component/dev-console Related to dev-console component/sdk Related to console-plugin-sdk component/shared Related to console-shared lgtm Indicates that a PR is ready to be merged. 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.

8 participants