-
Notifications
You must be signed in to change notification settings - Fork 243
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
add container name validation during creation and push #3959
add container name validation during creation and push #3959
Conversation
Signed-off-by: Stephanie <yangcao@redhat.com>
Signed-off-by: Stephanie <yangcao@redhat.com>
Codecov Report
@@ Coverage Diff @@
## master #3959 +/- ##
==========================================
+ Coverage 43.28% 43.30% +0.01%
==========================================
Files 147 147
Lines 12412 12431 +19
==========================================
+ Hits 5373 5383 +10
- Misses 6471 6480 +9
Partials 568 568
Continue to review full report at Codecov.
|
Signed-off-by: Stephanie <yangcao@redhat.com>
@yangcao77 this seems like something that can be tested via unit test? So can we write a unit test instead of integration? |
@girishramnani The validation code added is mainly inside the cli modules, so IMO integration test is the better place to test for. |
pkg/odo/cli/component/push.go
Outdated
@@ -175,6 +176,28 @@ func (po *PushOptions) Validate() (err error) { | |||
// If Devfile is present we do not need to validate the below S2I checks | |||
// TODO: Perhaps one day move Devfile validation to here instead? | |||
if util.CheckPathExists(po.DevfilePath) { | |||
spinner := log.Spinner("Validating K8s Resources Name") |
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.
What about just Validating devfile component
as the spinner text, like odo create
has?
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.
updated
Signed-off-by: Stephanie <yangcao@redhat.com>
pkg/odo/cli/component/push.go
Outdated
if err != nil { | ||
return err | ||
} | ||
containerComponents := adaptersCommon.GetDevfileContainerComponents(po.Devfile.Data) |
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.
we can extract https://github.com/openshift/odo/pull/3959/files#diff-6e3a2602ffd394e9a73d4fbf1388be8dR185-R190 out into a helper function and use it in create as well.
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.
containerComponents := adaptersCommon.GetDevfileContainerComponents(devObj.Data)
for _, comp := range containerComponents {
err := util.ValidateK8sResourceName("container name", comp.Name)
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.
updated to use unit tests instead of integration tests
/approve |
/retest |
[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 |
Signed-off-by: Stephanie <yangcao@redhat.com>
Signed-off-by: Stephanie <yangcao@redhat.com>
/retest |
pkg/devfile/validate/validate.go
Outdated
@@ -44,3 +47,15 @@ func ValidateDevfileData(data interface{}) error { | |||
return nil | |||
|
|||
} | |||
|
|||
// ValidateContatinerName validates whether the container name is valid for K8 | |||
func ValidateContatinerName(devfileData data.DevfileData) error { |
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.
typo
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.
updated
pkg/odo/cli/component/push.go
Outdated
@@ -175,6 +176,25 @@ func (po *PushOptions) Validate() (err error) { | |||
// If Devfile is present we do not need to validate the below S2I checks | |||
// TODO: Perhaps one day move Devfile validation to here instead? | |||
if util.CheckPathExists(po.DevfilePath) { | |||
spinner := log.Spinner("Validating devfile component") | |||
defer spinner.End(false) |
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.
we should validate under one spinner
$ odo push
✓ Validating devfile component [91679ns]
Validation
✓ Validating the devfile [22104ns]
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.
updated
/lgtm Reviewed and looks good! Thanks @yangcao77 |
/retest Please review the full test history for this PR and help us cut down flakes. |
5 similar comments
/retest Please review the full test history for this PR and help us cut down flakes. |
/retest Please review the full test history for this PR and help us cut down flakes. |
/retest Please review the full test history for this PR and help us cut down flakes. |
/retest Please review the full test history for this PR and help us cut down flakes. |
/retest Please review the full test history for this PR and help us cut down flakes. |
Signed-off-by: Stephanie yangcao@redhat.com
What type of PR is this?
/kind bug
/area devfile
What does does this PR do / why we need it:
Add validation for devfile container name during component creation, and push. Block the action if the container name is not a valid K8s resourece name.
Which issue(s) this PR fixes:
Fixes #3698
PR acceptance criteria:
Unit test
Integration test
Documentation
I have read the test guidelines
How to test changes / Special notes to the reviewer:
test component creation:
create a devfile with a long container name, and run
odo create --devfile <devfile path>
test odo push:
odo create nodejs --starter
modify the devfile to use a long container name
run
odo push