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

Support login to the integrated registry via CLI #18930

Merged

Conversation

smarterclayton
Copy link
Contributor

Adds a new oc image login command that allows the user to easily log
in to the integrated registry. By default it tries to use the current
user token (but supports -z for service accounts) and looks up the
public or internal hostname by finding image streams in the current
namespace or the 'openshift' namespace (which is usually populated).

This did highlight that openshift ansible is not setting externalRegistryHostname by default in the install which it should be doing.

@openshift-ci-robot openshift-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Mar 10, 2018
@openshift-ci-robot openshift-ci-robot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Mar 10, 2018
@smarterclayton
Copy link
Contributor Author

@bparees for 90% of clusters this will do the right thing once we start forcing registryExternalHostname, since everyone is going to have stuff in openshift. Eventually when david's changes for logging /metrics route publishing to config map land we can also push the registry URL.

@bparees
Copy link
Contributor

bparees commented Mar 11, 2018

i don't suppose i could convince you that it should be "oc registry" and not "oc image"?

@smarterclayton
Copy link
Contributor Author

smarterclayton commented Mar 11, 2018 via email

@bparees
Copy link
Contributor

bparees commented Mar 11, 2018

if we have commands that work on both images and registries would we want
two top level commands?

I would not say we have commands that work on both images+registries, i'd say we have some commands that work on registries, and commands that work on images.

oc image mirror

operates on images

oc image rebase

operates on images

oc image login

operates on registries

oc image import

operates on images

oc image add-layer

operates on images

If we later want to have a registry info command are we going to be happy calling it "oc image info"?

@openshift-ci-robot openshift-ci-robot added size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. and removed size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Mar 18, 2018
@smarterclayton
Copy link
Contributor Author

/retest

@smarterclayton smarterclayton force-pushed the login_to_registry branch 5 times, most recently from d63f899 to d79b771 Compare March 20, 2018 15:23
@smarterclayton
Copy link
Contributor Author

/test all

@smarterclayton
Copy link
Contributor Author

this is updated with feedback and adds a registry info command that functions a bit like whoami for scripting interactions with the server.

@smarterclayton
Copy link
Contributor Author

/retest

@smarterclayton
Copy link
Contributor Author

/retest

Copy link
Contributor

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

One small nit but overall lgtm.

if ref, err := imageapi.ParseDockerImageReference(registry); err == nil {
o.HostPort = ref.Registry
if internal {
fmt.Fprintf(o.ErrOut, "info: Using internal registry hostname %s\n", o.HostPort)
Copy link
Contributor

Choose a reason for hiding this comment

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

If this is info, use o.Out not o.ErrOut, the latter is only for warning and errors.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We should be using stderr for anything that is not directly tied to the output of the command.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Info, warning, and error are all stderr.

Copy link
Contributor

Choose a reason for hiding this comment

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

Warning and error -> stderr, if info should be possible to hide use glog with different levels. Any other info is info that should put to stdout just like the rest of the output b/c it's relevant to the user.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No, it shouldn’t. Info is not glog. Info is information relevant to the user that is not a warning. It is not normal output. Stdout is data for processing. Glog is not human facing the way info is.

Copy link
Contributor Author

@smarterclayton smarterclayton Mar 27, 2018

Choose a reason for hiding this comment

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

$ grep -R --include=*.go -E "\"info:" pkg/
pkg//oc/admin/migrate/etcd/ttl.go:	fmt.Fprintf(o.Out, "info: Lease #%d with TTL %d created\n", lease.ID, lease.TTL)
pkg//oc/admin/migrate/etcd/ttl.go:	fmt.Fprintf(o.Out, "info: Attaching lease to %d entries\n", len(objectsResp.Kvs))
pkg//oc/admin/migrate/etcd/ttl.go:		fmt.Fprintf(o.Out, "info: Lease already attached to %d entries, no change made\n", alreadyAttached)
pkg//oc/admin/migrate/migrator.go:		fmt.Fprintf(out, "info: to rerun only failing resources, add --include=%s\n", strings.Join(t.resourcesWithErrors.List(), ","))
pkg//oc/admin/router/router.go:			fmt.Fprintf(errout, "info: password for stats user %s has been set to %s\n", cfg.StatsUsername, cfg.StatsPassword)
pkg//oc/cli/cmd/image/mirror/mirror.go:				fmt.Fprintf(o.ErrOut, "info: Filtered all images from %s, skipping\n", src.ref)
pkg//oc/cli/cmd/logs.go:		o.KubeLogOptions.Out.Write([]byte(fmt.Sprintf("info: Logs available at %s\n", urlString)))
pkg//oc/cli/cmd/set/buildhook.go:			fmt.Fprintf(o.Err, "info: %s %q was not changed\n", info.Mapping.Resource, info.Name)
pkg//oc/cli/cmd/set/buildsecret.go:			fmt.Fprintf(o.Err, "info: %s %q was not changed\n", info.Mapping.Resource, info.Name)
pkg//oc/cli/cmd/set/deploymenthook.go:			fmt.Fprintf(o.Err, "info: %s %q was not changed\n", info.Mapping.Resource, info.Name)
pkg//oc/cli/cmd/set/imagelookup.go:			fmt.Fprintf(o.Err, "info: %s %q was not changed\n", info.Mapping.Resource, info.Name)
pkg//oc/cli/cmd/set/probe.go:			fmt.Fprintf(o.Err, "info: %s %q was not changed\n", info.Mapping.Resource, info.Name)
pkg//oc/cli/cmd/set/routebackends.go:			fmt.Fprintf(o.Err, "info: %s %q was not changed\n", info.Mapping.Resource, info.Name)
pkg//oc/cli/cmd/set/triggers.go:			fmt.Fprintf(o.Err, "info: %s %q was not changed\n", info.Mapping.Resource, info.Name)
pkg//oc/cli/cmd/set/volume.go:			fmt.Fprintf(v.Err, "info: %s %q was not changed\n", info.Mapping.Resource, info.Name)
pkg//oc/cli/cmd/set/volume.go:		fmt.Fprintf(v.Err, "info: Generated volume name: %s\n", name)
pkg//oc/cli/util/clientcmd/factory.go:		glog.V(1).Infof("info: the output version specified is invalid. %s\n", defaultVersionInfo)

Copy link
Contributor Author

@smarterclayton smarterclayton Mar 27, 2018

Choose a reason for hiding this comment

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

All glog output goes to stderr, but info: is effectively v(0) without the prefix (the prefix is not useful for a human interacting with a cli). The user should have the information. The user should not have to filter that out, i.e.:

$ curl https://$( oc registry info )

shouldn't send info: The registry is internal to curl - it should print that on stderr so the shell captures only the url, not the output

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The TTL command is outputting to stdout because it prints nothing else.

@smarterclayton smarterclayton added the lgtm Indicates that a PR is ready to be merged. label Mar 27, 2018
@smarterclayton
Copy link
Contributor Author

If no other comments marking.

@smarterclayton
Copy link
Contributor Author

/retest

@bparees
Copy link
Contributor

bparees commented Mar 28, 2018

nothing from me

Copy link
Contributor

@bparees bparees left a comment

Choose a reason for hiding this comment

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

i lied

)

var (
loginDesc = templates.LongDesc(`
Copy link
Contributor

Choose a reason for hiding this comment

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

infoDesc


Experimental: This command is under active development and may change without notice.`)

loginExample = templates.Examples(`
Copy link
Contributor

Choose a reason for hiding this comment

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

infoExample

Use: "info ",
Short: "Print info about the integrated registry",
Long: loginDesc,
Example: fmt.Sprintf(loginExample, name+" login"),
Copy link
Contributor

Choose a reason for hiding this comment

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

infoExample

cmd := &cobra.Command{
Use: "info ",
Short: "Print info about the integrated registry",
Long: loginDesc,
Copy link
Contributor

Choose a reason for hiding this comment

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

infoDesc

@mfojtik
Copy link
Contributor

mfojtik commented Mar 28, 2018

/hold

@openshift-ci-robot openshift-ci-robot added the do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. label Mar 28, 2018
@openshift-ci-robot openshift-ci-robot removed the lgtm Indicates that a PR is ready to be merged. label Mar 28, 2018
@openshift-ci-robot
Copy link

New changes are detected. LGTM label has been removed.

@smarterclayton smarterclayton added lgtm Indicates that a PR is ready to be merged. and removed do-not-merge/hold Indicates that a PR should not merge because someone has issued a /hold command. labels Mar 28, 2018
@smarterclayton
Copy link
Contributor Author

/retest

2 similar comments
@smarterclayton
Copy link
Contributor Author

/retest

@smarterclayton
Copy link
Contributor Author

/retest

@smarterclayton
Copy link
Contributor Author

smarterclayton commented Mar 30, 2018 via email

@smarterclayton
Copy link
Contributor Author

smarterclayton commented Mar 30, 2018 via email

@openshift-bot
Copy link
Contributor

/retest

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

@smarterclayton
Copy link
Contributor Author

/retest

@openshift-bot openshift-bot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Mar 30, 2018
Adds a new `oc registry login` command that allows the user to easily log
in to the integrated registry. By default it tries to use the current
user token (but supports `-z` for service accounts) and looks up the
public or internal hostname by finding image streams in the current
namespace or the 'openshift' namespace (which is usually populated).

Also add `oc registry info` for fetching the current registry DNS name.
@openshift-ci-robot
Copy link

New changes are detected. LGTM label has been removed.

@openshift-ci-robot openshift-ci-robot removed the lgtm Indicates that a PR is ready to be merged. label Mar 30, 2018
@openshift-ci-robot
Copy link

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: smarterclayton

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 openshift-bot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Mar 30, 2018
@openshift-ci-robot openshift-ci-robot added size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. and removed size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. labels Mar 30, 2018
@smarterclayton smarterclayton added the lgtm Indicates that a PR is ready to be merged. label Mar 30, 2018
@openshift-merge-robot openshift-merge-robot merged commit 0e7ae24 into openshift:master Mar 31, 2018
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. lgtm Indicates that a PR is ready to be merged. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants