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

Bug 1970805: Replace slashes in suggested ImageStream name #922

Merged
merged 1 commit into from Oct 14, 2021

Conversation

alicerum
Copy link

@alicerum alicerum commented Sep 8, 2021

When figuring out an image stream name for created build objects, SuggestName function can return name with slashes in some situations.

It is important to hold correct data (that including slashes, too) in the ImageRef object, because it is used in other places and can lead to errors.

SuggestName method of the ImageRef however, should return name without slashes when suggesting name for an ImageStream.

@openshift-ci
Copy link
Contributor

openshift-ci bot commented Sep 8, 2021

@alicerum: This pull request references Bugzilla bug 1970805, which is invalid:

  • expected the bug to target the "4.10.0" release, but it targets "4.9.0" instead

Comment /bugzilla refresh to re-evaluate validity if changes to the Bugzilla bug are made, or edit the title of this pull request to link to a different bug.

In response to this:

Bug 1970805: Replace slashes in suggested ImageStream name

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@openshift-ci openshift-ci bot added bugzilla/severity-low Referenced Bugzilla bug's severity is low for the branch this PR is targeting. bugzilla/invalid-bug Indicates that a referenced Bugzilla bug is invalid for the branch this PR is targeting. labels Sep 8, 2021
@alicerum
Copy link
Author

alicerum commented Sep 8, 2021

/bugzilla refresh

@openshift-ci
Copy link
Contributor

openshift-ci bot commented Sep 8, 2021

@alicerum: This pull request references Bugzilla bug 1970805, which is valid. The bug has been moved to the POST state. The bug has been updated to refer to the pull request using the external bug tracker.

3 validation(s) were run on this bug
  • bug is open, matching expected state (open)
  • bug target release (4.10.0) matches configured target release for branch (4.10.0)
  • bug is in the state NEW, which is one of the valid states (NEW, ASSIGNED, ON_DEV, POST, POST)

Requesting review from QA contact:
/cc @jitendar-singh

In response to this:

/bugzilla refresh

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

@openshift-ci openshift-ci bot added bugzilla/valid-bug Indicates that a referenced Bugzilla bug is valid for the branch this PR is targeting. and removed bugzilla/invalid-bug Indicates that a referenced Bugzilla bug is invalid for the branch this PR is targeting. labels Sep 8, 2021
Copy link
Contributor

@gabemontero gabemontero 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 openshift-ci bot added the lgtm Indicates that a PR is ready to be merged. label Sep 8, 2021
@alicerum
Copy link
Author

alicerum commented Sep 8, 2021

/retest

Comment on lines 245 to 278
if r.AsImageStream {
// in some certain situations, suggested ImageStream name might contain slashes
// in this case we want to replace it with dashes, referenced object might
// contain said dashes, but imagestream must cannot
// example: https://bugzilla.redhat.com/show_bug.cgi?id=1970805
name = strings.ReplaceAll(name, "/", "-")
}
Copy link
Member

Choose a reason for hiding this comment

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

I think we could future-proof this some by eliminating the r.AsImageStream check and just always replacing slashes with dashes.

Suggested change
if r.AsImageStream {
// in some certain situations, suggested ImageStream name might contain slashes
// in this case we want to replace it with dashes, referenced object might
// contain said dashes, but imagestream must cannot
// example: https://bugzilla.redhat.com/show_bug.cgi?id=1970805
name = strings.ReplaceAll(name, "/", "-")
}
// in some certain situations, suggested ImageStream name might contain slashes
// in this case we want to replace it with dashes, referenced object might
// contain said dashes, but imagestream must cannot
// example: https://bugzilla.redhat.com/show_bug.cgi?id=1970805
name = strings.ReplaceAll(name, "/", "-")

Copy link
Author

Choose a reason for hiding this comment

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

At first I was going to argue that this is only the ImageStream issue, and other types of image references must be left intact, but after giving it a thought, I realized that you are right.
SuggestedName is used to generate names or part of names for internal k8s objects, and those names must follow the DNS standard, hence, no slashes. I think it is safe to assume we will never need slashes in any names here.

Do you think we might go even further and replace all the non[alphanumeric, dash or dot] symbols here?

Copy link
Member

Choose a reason for hiding this comment

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

So, basically replace this with a regexp that replaces all non-valid characters with dashes? I think that sounds like a great idea.

Copy link
Author

Choose a reason for hiding this comment

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

@coreydaley yeah, [^0-9a-zA-Z-.] should do the trick. From what I read, k8s names should go along with rfc1123, which references rfc952, which says, only alphanumeric, dots and dashes are allowed in a hostname. So, I thought it might be better to go with this more uniform approach rather than just slashes.

pkg/helpers/newapp/app/imageref.go Outdated Show resolved Hide resolved
pkg/helpers/newapp/app/imageref_test.go Outdated Show resolved Hide resolved
pkg/helpers/newapp/app/imageref_test.go Outdated Show resolved Hide resolved
pkg/helpers/newapp/app/imageref_test.go Outdated Show resolved Hide resolved
pkg/helpers/newapp/app/imageref_test.go Outdated Show resolved Hide resolved
@openshift-ci openshift-ci bot removed the lgtm Indicates that a PR is ready to be merged. label Sep 8, 2021
@alicerum
Copy link
Author

alicerum commented Sep 9, 2021

/retest

Comment on lines +236 to +248
switch {
case r.Stream != nil:
name = r.Stream.Name
case len(r.ObjectName) > 0:
name = r.ObjectName
case len(r.Reference.Name) > 0:
name = r.Reference.Name
Copy link
Member

Choose a reason for hiding this comment

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

+1, love seeing switch statements instead of multiple if or if/else

)

func init() {
dnsNamePattern = regexp.MustCompile("[^a-zA-Z0-9-.]")
Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Author

Choose a reason for hiding this comment

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

ah, so no dots either. thanks.

@coreydaley
Copy link
Member

/lgtm

@openshift-ci openshift-ci bot added the lgtm Indicates that a PR is ready to be merged. label Sep 9, 2021
@coreydaley
Copy link
Member

/assign @adambkaplan

@coreydaley
Copy link
Member

/retest

Comment on lines 48 to 52
var (
dnsNamePattern *regexp.Regexp
)

func init() {
dnsNamePattern = regexp.MustCompile("[^a-zA-Z0-9-]")
}

Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
var (
dnsNamePattern *regexp.Regexp
)
func init() {
dnsNamePattern = regexp.MustCompile("[^a-zA-Z0-9-]")
}
var (
dnsNamePattern *regexp.Regexp = regexp.MustCompile("[^a-zA-Z0-9-]")
)

I don't think you need this init here, the regexp can just be a var, unless there is a specific reason to use init that I am missing?

@openshift-bot
Copy link
Contributor

/retest-required

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

10 similar comments
@openshift-bot
Copy link
Contributor

/retest-required

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

@openshift-bot
Copy link
Contributor

/retest-required

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

@openshift-bot
Copy link
Contributor

/retest-required

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

@openshift-bot
Copy link
Contributor

/retest-required

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

@openshift-bot
Copy link
Contributor

/retest-required

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

@openshift-bot
Copy link
Contributor

/retest-required

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

@openshift-bot
Copy link
Contributor

/retest-required

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

@openshift-bot
Copy link
Contributor

/retest-required

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

@openshift-bot
Copy link
Contributor

/retest-required

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

@openshift-bot
Copy link
Contributor

/retest-required

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

@adambkaplan
Copy link
Contributor

/hold

Something appears to be broken;

FAILURE after 1.000s: test/cmd/printer.sh:8: executing 'oc new-app openshift/nodejs' expecting success: the command returned the wrong error code
Standard output from the command:
warning: Cannot find git. Ensure that it is installed and in your path. Git is required to work with git repositories.

Standard error from the command:
W0924 14:21:58.794600     126 dockerimagelookup.go:300] container image remote registry lookup failed: you may not have access to the container image "docker.io/openshift/nodejs:latest"
error: multiple images or templates matched "openshift/nodejs"

Argument 'openshift/nodejs' was classified as an image, image~source, or loaded template reference.

The argument "openshift/nodejs" could apply to the following container images, OpenShift image streams, or templates:

* Template "nodejs-postgresql-example" in project "openshift"
  Use --template="openshift/nodejs-postgresql-example" to specify this image or template

* Template "nodejs-postgresql-persistent" in project "openshift"
  Use --template="openshift/nodejs-postgresql-persistent" to specify this image or template

* Image stream "jenkins-agent-nodejs" (tag "v4.0") in project "openshift"
  Use --image-stream="openshift/jenkins-agent-nodejs:v4.0" to specify this image or template

* Image stream "nodejs" in project "openshift"
  Use --image-stream="openshift/nodejs" --allow-missing-imagestream-tags to specify this image or template

@openshift-ci openshift-ci bot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Sep 24, 2021
@alicerum
Copy link
Author

alicerum commented Oct 4, 2021

/retest

1 similar comment
@adambkaplan
Copy link
Contributor

/retest

@adambkaplan
Copy link
Contributor

@soltysh looks like another broken test for e2e-agnostic-cmd

Running test/cmd/help.sh:22: executing 'oc adm ca' expecting failure and text 'Manage certificates'...
FAILURE after 0.000s: test/cmd/help.sh:22: executing 'oc adm ca' expecting failure and text 'Manage certificates': the output content test failed
There was no output from the command.
Standard error from the command:
error: unknown command "ca"
See 'oc adm -h' for help and examples
[ERROR] hack/lib/cmd.sh:41: `return "${return_code}"` exited with status 1.

@alicerum
Copy link
Author

/retest

1 similar comment
@alicerum
Copy link
Author

/retest

@alicerum
Copy link
Author

@adambkaplan finally test has passed

@openshift-ci openshift-ci bot removed the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Oct 13, 2021
Copy link
Member

@soltysh soltysh left a comment

Choose a reason for hiding this comment

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

/hold cancel

@openshift-ci
Copy link
Contributor

openshift-ci bot commented Oct 13, 2021

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: adambkaplan, alicerum, coreydaley, gabemontero, soltysh

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-bot
Copy link
Contributor

/retest-required

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

5 similar comments
@openshift-bot
Copy link
Contributor

/retest-required

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

@openshift-bot
Copy link
Contributor

/retest-required

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

@openshift-bot
Copy link
Contributor

/retest-required

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

@openshift-bot
Copy link
Contributor

/retest-required

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

@openshift-bot
Copy link
Contributor

/retest-required

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

@openshift-merge-robot openshift-merge-robot merged commit 3f24f58 into openshift:master Oct 14, 2021
@openshift-ci
Copy link
Contributor

openshift-ci bot commented Oct 14, 2021

@alicerum: All pull requests linked via external trackers have merged:

Bugzilla bug 1970805 has been moved to the MODIFIED state.

In response to this:

Bug 1970805: Replace slashes in suggested ImageStream name

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

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. bugzilla/severity-low Referenced Bugzilla bug's severity is low for the branch this PR is targeting. bugzilla/valid-bug Indicates that a referenced Bugzilla bug is valid for the branch this PR is targeting. lgtm Indicates that a PR is ready to be merged.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

7 participants