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

Use volume components from the devfile #3584

Merged
merged 9 commits into from
Jul 24, 2020

Conversation

maysunfaisal
Copy link
Contributor

@maysunfaisal maysunfaisal commented Jul 15, 2020

Signed-off-by: Maysun J Faisal maysun.j.faisal@ibm.com

What type of PR is this?
/kind feature

What does does this PR do / why we need it:

  • utilizes the Volume components from the devfile - refer the devfile v2 schema
  • can now customize volume size using the devfile volume component
  • updates func and variable names to differentiate between container components and volume components from the devfile for better readability
  • unit & integration tests

Which issue(s) this PR fixes:

Fixes #3407

PR acceptance criteria:

How to test changes / Special notes to the reviewer:

  • confirm that there can not be duplicate volume components in a devfile:
components:
  - container:
      name: tools
      image: maysunfaisal/springbootbuild
      memoryLimit: 768Mi
      command: ['tail']
      args: [ '-f', '/dev/null']
      mountSources: true
      volumeMounts:
        - name: first
          path: /data
  - container:
      name: runtime
      image: maysunfaisal/springbootruntime
      memoryLimit: 768Mi
      command: ['tail']
      args: [ '-f', '/dev/null']
      endpoints:
        - name: '8080/tcp'
          configuration:
            public: true
          targetPort: 8080
      mountSources: false
      volumeMounts:
        - name: first
          path: /data
  - volume:
      name: secondvol
  - volume:
      name: secondvol
      size: 10Gi
  • use this spring devfile components and change the container volume mounts to either firstvol, secondvol, thirdvol and odo push. When using
  1. firstvol though not defined in volume components, will be implicitly added with a default size of 5Gi
  2. secondvol will use a default size of 5Gi since its size is not mentioend
  3. thirdvol will use the mentioned size of 10Gi
components:
  - container:
      name: tools
      image: maysunfaisal/springbootbuild
      memoryLimit: 768Mi
      command: ['tail']
      args: [ '-f', '/dev/null']
      mountSources: true
      volumeMounts:
        - name: firstvol
          path: /data
  - container:
      name: runtime
      image: maysunfaisal/springbootruntime
      memoryLimit: 768Mi
      command: ['tail']
      args: [ '-f', '/dev/null']
      endpoints:
        - name: '8080/tcp'
          configuration:
            public: true
          targetPort: 8080
      mountSources: false
      volumeMounts:
        - name: firstvol
          path: /data
  - volume:
      name: secondvol
  - volume:
      name: thirdvol
      size: 10Gi

@openshift-ci-robot openshift-ci-robot added the kind/feature Categorizes issue as a feature request. For PRs, that means that the PR is the implementation label Jul 15, 2020
@maysunfaisal
Copy link
Contributor Author

maysunfaisal commented Jul 15, 2020

@adisky @johnmcollier Can you pls help review this PR since you both worked with volumes code and converting v1 to v2 schema..

@maysunfaisal
Copy link
Contributor Author

/retest

@codecov
Copy link

codecov bot commented Jul 16, 2020

Codecov Report

Merging #3584 into master will increase coverage by 0.21%.
The diff coverage is 80.20%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master    #3584      +/-   ##
==========================================
+ Coverage   45.51%   45.73%   +0.21%     
==========================================
  Files         121      122       +1     
  Lines       12187    12237      +50     
==========================================
+ Hits         5547     5596      +49     
- Misses       6089     6090       +1     
  Partials      551      551              
Impacted Files Coverage Δ
pkg/devfile/adapters/kubernetes/utils/utils.go 52.80% <0.00%> (ø)
pkg/testingutil/devfile.go 0.00% <0.00%> (ø)
pkg/devfile/validate/errors.go 40.00% <40.00%> (ø)
pkg/devfile/adapters/docker/component/utils.go 66.76% <75.00%> (ø)
pkg/devfile/validate/components.go 93.10% <95.23%> (+11.28%) ⬆️
pkg/devfile/adapters/common/command.go 96.36% <100.00%> (ø)
pkg/devfile/adapters/common/utils.go 87.67% <100.00%> (+23.87%) ⬆️
pkg/devfile/adapters/docker/component/adapter.go 57.43% <100.00%> (ø)
pkg/devfile/adapters/docker/storage/utils.go 77.02% <100.00%> (ø)
pkg/devfile/adapters/docker/utils/utils.go 82.82% <100.00%> (ø)
... and 3 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update f990ac8...137119d. Read the comment docs.

@@ -92,7 +92,8 @@ type CommandNames struct {
AdapterName string
}

func isComponentSupported(component common.DevfileComponent) bool {
// isComponentAContainer returns a bool if the component is a container
func isComponentAContainer(component common.DevfileComponent) bool {
Copy link
Contributor

Choose a reason for hiding this comment

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

Wouldn’t this be cleaner if it was a method on the component called IsContainer?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated!

@@ -101,6 +102,15 @@ func isComponentSupported(component common.DevfileComponent) bool {
return false
}

// isComponentAVolume returns a bool if the component is a volume
func isComponentAVolume(component common.DevfileComponent) bool {
Copy link
Contributor

Choose a reason for hiding this comment

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

Same as above?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updated!

@maysunfaisal
Copy link
Contributor Author

/retest


// containerNameToVolumes is a map of the Devfile container name to the Devfile container Volumes
containerNameToVolumes := make(map[string][]DevfileVolume)
for _, containerComp := range containerComponents {
Copy link
Member

Choose a reason for hiding this comment

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

Any way we can avoid 3 nested for loops? What about by creating / using a map of vol name -> volume components?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

updated

pkg/devfile/adapters/common/command.go Show resolved Hide resolved
pkg/devfile/adapters/common/utils_test.go Show resolved Hide resolved
pkg/devfile/validate/components_test.go Show resolved Hide resolved

// Only testing this in Kubernetes because odo OpenShift CI
// sets the min pvc storage size to 100Gi
if os.Getenv("KUBERNETES") == "true" {
Copy link
Contributor

Choose a reason for hiding this comment

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

Can we add this condition in JustAfterEach()

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not sure what the point is in JustAfterEach? in AfterEach we remove the namespace/project. So the pvc will be gone by then.

@adisky
Copy link
Contributor

adisky commented Jul 17, 2020

@maysun we are verifying valid volume size at very later stage

when i inserted an invalid volume size, i got this error and odo push failed.

$ odo push --show-log

Validation
 ✓  Validating the devfile [48381ns]

Creating Kubernetes resources for component my-vol
 ✗  Failed to start component with name my-vol. Error: Failed to create the component: unable to create or update component: Error creating PVC for firstvol: unable to parse size: ghjk: quantities must match the regular expression '^([+-]?[0-9.]+)([eEinumkKMGTP]*[-+]?[0-9]*)$'

when i checked kubectl get deployment, it had already created the deployment which is waiting for pvc's to get created.
IMO we should validate volume size before creating any kubernetes resources.

Also could we update the error message to something like volume size should be of format <size>Gi e.g. 3Gi

@maysunfaisal
Copy link
Contributor Author

maysunfaisal commented Jul 20, 2020

@adisky good point reg validation. I will move it much earlier.

However, I do not think we should make our own validation regex or give an example like "2Gi/2Mi" because there are a lot of units and ways to write storage as evident from the Kube documentation(and also from the kube client api regex error):

You can express memory as a plain integer or as a fixed-point integer using one of these suffixes: E, P, T, G, M, K. You can also use the power-of-two equivalents: Ei, Pi, Ti, Gi, Mi, Ki. For example, the following represent roughly the same value:

128974848, 129e6, 129M, 123Mi

from https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/

I will just use the Kube Client for validation and wrap it around like this:
size 2Girrr for volume component mycomponent is invalid: quantities must match the regular expression '^([+-]?[0-9.]+)([eEinumkKMGTP]*[-+]?[0-9]*)$'

@adisky
Copy link
Contributor

adisky commented Jul 20, 2020

@maysunfaisal agreed, just give one or two example at the end of regex message.

@maysunfaisal
Copy link
Contributor Author

maysunfaisal commented Jul 20, 2020

@adisky how does this sound to you:

$ odo push
 ✗  size 2Girrr for volume component something2 is invalid: quantities must match the regular expression '^([+-]?[0-9.]+)([eEinumkKMGTP]*[-+]?[0-9]*)$'. Example - 2Gi, 1024Mi

@maysunfaisal
Copy link
Contributor Author

@adisky @johnmcollier PR updated for review feedback, pls help re-review, thx!

Copy link
Member

@johnmcollier johnmcollier left a comment

Choose a reason for hiding this comment

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

Changes look good.

@openshift-ci-robot openshift-ci-robot added the lgtm Indicates that a PR is ready to be merged. Required by Prow. label Jul 20, 2020
@maysunfaisal
Copy link
Contributor Author

/retest

ErrorNoComponents = "no components present"
ErrorNoContainerComponent = fmt.Sprintf("odo requires atleast one component of type '%s' in devfile", common.ContainerComponentType)
ErrorNoComponents = "no components present"
ErrorNoContainerComponent = fmt.Sprintf("odo requires atleast one component of type '%s' in devfile", common.ContainerComponentType)
Copy link
Contributor

Choose a reason for hiding this comment

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

can we have proper error types defined? instead of using variables
https://github.com/openshift/odo/pull/3549/files#diff-5fd81db0ba5aa2ae5579e01facb598e8R6

Copy link
Contributor Author

Choose a reason for hiding this comment

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

so you're saying we should have a struct for each err types?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

updated

@mik-dass
Copy link
Contributor

Implicit storage have been removed from the schema devfile/api#101 yesterday. We can drop the support for that too.

@maysunfaisal
Copy link
Contributor Author

maysunfaisal commented Jul 21, 2020

@mik-dass oh wow I had implicit volumes with this PR but I checked the schema and there was no implicit volumes and removed it. And now I have to add it back again 😭

EDIT - I meant to say I had non implicit volumes with this PR before it was removed.

@adisky
Copy link
Contributor

adisky commented Jul 22, 2020

@maysunfaisal Thanks
/lgtm

@openshift-ci-robot openshift-ci-robot added the lgtm Indicates that a PR is ready to be merged. Required by Prow. label Jul 22, 2020
@openshift-ci-robot openshift-ci-robot removed the lgtm Indicates that a PR is ready to be merged. Required by Prow. label Jul 22, 2020
@maysunfaisal
Copy link
Contributor Author

/retest

Signed-off-by: Maysun J Faisal <maysun.j.faisal@ibm.com>
Signed-off-by: Maysun J Faisal <maysun.j.faisal@ibm.com>
Signed-off-by: Maysun J Faisal <maysun.j.faisal@ibm.com>
Signed-off-by: Maysun J Faisal <maysun.j.faisal@ibm.com>
Signed-off-by: Maysun J Faisal <maysun.j.faisal@ibm.com>
Signed-off-by: Maysun J Faisal <maysun.j.faisal@ibm.com>
Signed-off-by: Maysun J Faisal <maysun.j.faisal@ibm.com>
Signed-off-by: Maysun J Faisal <maysun.j.faisal@ibm.com>
Signed-off-by: Maysun J Faisal <maysun.j.faisal@ibm.com>
Copy link
Member

@johnmcollier johnmcollier left a comment

Choose a reason for hiding this comment

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

/lgtm

@openshift-ci-robot openshift-ci-robot added the lgtm Indicates that a PR is ready to be merged. Required by Prow. label Jul 23, 2020
@mik-dass
Copy link
Contributor

[odo] ✗ Waiting for component to start [4m]

494

[odo] I0723 22:04:36.264017 10370 occlient.go:1855] Quitting collect events

495

[odo] ✗ waited 4m0s but couldn't find running pod matching selector: 'deploymentconfig=nodejs-app'

/retest

@kadel
Copy link
Member

kadel commented Jul 24, 2020

/approve

@openshift-ci-robot
Copy link
Collaborator

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: kadel

The full list of commands accepted by this bot can be found here.

The pull request process is described here

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

@openshift-ci-robot openshift-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. Required by Prow. label Jul 24, 2020
@openshift-bot
Copy link

/retest

Please review the full test history for this PR and help us cut down flakes.

3 similar comments
@openshift-bot
Copy link

/retest

Please review the full test history for this PR and help us cut down flakes.

@openshift-bot
Copy link

/retest

Please review the full test history for this PR and help us cut down flakes.

@openshift-bot
Copy link

/retest

Please review the full test history for this PR and help us cut down flakes.

@openshift-merge-robot openshift-merge-robot merged commit c89c1ab into redhat-developer:master Jul 24, 2020
cdrage pushed a commit to cdrage/odo that referenced this pull request Jul 30, 2020
* Volume components devfile

Signed-off-by: Maysun J Faisal <maysun.j.faisal@ibm.com>

* Volume Component integration tests

Signed-off-by: Maysun J Faisal <maysun.j.faisal@ibm.com>

* Vol Component Feedback 1

Signed-off-by: Maysun J Faisal <maysun.j.faisal@ibm.com>

* Vol Component Feedback 2

Signed-off-by: Maysun J Faisal <maysun.j.faisal@ibm.com>

* Vol Component Feedback 3

Signed-off-by: Maysun J Faisal <maysun.j.faisal@ibm.com>

* Container component volMount & volume component dependency

Signed-off-by: Maysun J Faisal <maysun.j.faisal@ibm.com>

* Fix rebased test

Signed-off-by: Maysun J Faisal <maysun.j.faisal@ibm.com>

* Remove devfile v1 tests

Signed-off-by: Maysun J Faisal <maysun.j.faisal@ibm.com>

* Update rebased tests

Signed-off-by: Maysun J Faisal <maysun.j.faisal@ibm.com>
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. Required by Prow. kind/feature Categorizes issue as a feature request. For PRs, that means that the PR is the implementation lgtm Indicates that a PR is ready to be merged. Required by Prow.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Allow volume definition to be shared across containers in a devfile
10 participants