8000 app/add: Use the image name as a default name for app by nhlfr · Pull Request #3802 · rkt/rkt · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
This repository was archived by the owner on Feb 24, 2020. It is now read-only.

app/add: Use the image name as a default name for app #3802

Merged
merged 1 commit into from
Sep 28, 2017

Conversation

nhlfr
Copy link
Contributor
@nhlfr nhlfr commented Sep 19, 2017

The help message in "app add" sucommand suggests that --name flag is optional, but it wasn't. This commit fixes the desired behaviour.

Fixes #3801

Copy link
Member
@lucab lucab left a comment

Choose a reason for hiding this comment

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

Good catch. However I'd probably move the splitting logic in its own func defaultAppName(imageName string) (string, error) helper.

rkt/app_add.go Outdated
}
partsSlash := strings.Split(partsColon[0], "/")
if len(partsSlash) < 1 {
stderr.Println("invalid image name, cannot use it as an app name")
Copy link
Member

Choose a reason for hiding this comment

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

This seems to be missing a return 254?

@jellonek
Copy link
Contributor

IMO instead of parsing the url by hand you should use ParseDockerURL from appc/docker2aci which is already used e.x. in pkg/distribution/docker.go.

+1 for extracting that to separate func with proper name and a docstring.

Also - missing unittest ;)

@lucab
Copy link
Member
lucab commented Sep 19, 2017

@jellonek I guess the input is an ACI name though. I'm not sure if we already have some helper around in appc to extract the last component.

@nhlfr
Copy link
Contributor Author
nhlfr commented Sep 19, 2017

@lucab I haven't found any, but I need to take a deeper look at rkt run. Maybe we can split the login into a helper and use it both in rkt add and rkt app add.

@nhlfr nhlfr force-pushed the nhlfr/app-name-default branch 4 times, most recently from d9b12e9 to 30f6c81 Compare September 28, 2017 13:04
@nhlfr
Copy link
Contributor Author
nhlfr commented Sep 28, 2017

@lucab ok, we've found the function that rkt run uses to extract a default app name from image name. That helper function was in stage0/ package, I moved it to common/

@jellonek tests added ;)

@iaguis PTAL

Copy link
Member
@iaguis iaguis left a comment

Choose a reason for hiding this comment

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

Some comments.

common/common.go Outdated
@@ -539,3 +539,17 @@ func GetOSArch() (os string, arch string) {
os, arch, _ = types.ToAppcOSArch(runtime.GOOS, arch, flavor)
return os, arch
}

// ImageNameToAppName converts the full nale of image to an app name without special
Copy link
Member

Choose a reason for hiding this comment

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

nale -> name

rkt/app_add.go Outdated
@@ -111,6 +112,15 @@ func runAppAdd(cmd *cobra.Command, args []string) (exit int) {
}
rktApps.Last().ImageID = *img

if rktApps.Last().Name == "" {
appName, err := common.ImageNameToAppName(types.ACIdentifier(args[1]))
Copy link
Member

Choose a reason for hiding this comment

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

Not sure I like that app names include the version or result on weird things like etcd-v2-0-0-linux-amd64-aci since it's not consistent with anything we do.

You can add

app.Name = appName.String()

here https://github.com/rkt/rkt/pull/3802/files#diff-71a7d6d46a80cd343d272145a7de0cf2L68

And get rid of the changes in this file (rkt/app_add.go) and things should work. So https://github.com/coreos/etcd/releases/download/v2.0.0/etcd-v2.0.0-linux-amd64.aci will have a name of etcd and coreos.com/etcd:v2.0.10 too.

Wdyt?

Copy link
Contributor Author
@nhlfr nhlfr Sep 28, 2017

Choose a reason for hiding this comment

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

I don't understand it. Why we need to do anything more in stage0? What change brings the explicit conversion to string? Will it magically cut versions from the name? I don't think so, if it doesn't work like that in our unit test - and the change you proposed is not going to change results of that unit test.

Copy link
Member

Choose a reason for hiding this comment

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

My point is we're already calling ImageNameToAppName in stage0, but we're not using the name afterwards. And I don't want names like these:

75545b2a	etcd-v2-0-10			coreos.com/etcd:v2.0.10		exited	14 minutes ago	14 minutes ago	
		etcd-v2-0-0-linux-amd64-aci	coreos.com/etcd:v2.0.0							

Maybe it's easier to explain with code: kinvolk@13f0944

Copy link
Member
@iaguis iaguis Sep 28, 2017

Choose a reason for hiding this comment

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

To complete my comment, ImageNameToAppName should be applied to image names, not to image "URLs" like coreos.com/etcd:v2.0.10 or https://github.com/coreos/etcd/releases/download/v2.0.0/etcd-v2.0.0-linux-amd64.aci and that's what we're doing in rkt/app_add.go

@nhlfr nhlfr force-pushed the nhlfr/app-name-default branch from 30f6c81 to 0cf0c05 Compare September 28, 2017 15:05
The help message in "app add" sucommand suggests that --name
flag is optional, but it wasn't. This commit fixes the desired
behaviour.

Fixes rkt#3801
@nhlfr nhlfr force-pushed the nhlfr/app-name-default branch from 0cf0c05 to 91fc588 Compare September 28, 2017 15:06
@nhlfr
Copy link
Contributor Author
nhlfr commented Sep 28, 2017

@iaguis done

Copy link
Member
@iaguis iaguis left a comment

Choose a reason for hiding this comment

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

Thanks. LGTM if green

@iaguis iaguis merged commit 0134aff into rkt:master Sep 28, 2017
@nhlfr nhlfr deleted the nhlfr/app-name-default branch September 28, 2017 16:10
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

"rkt app add" should use image name as a default name
4 participants
0