Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

62 changes: 49 additions & 13 deletions hack/test-cmd.sh
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ TEMP_DIR=${USE_TEMP:-$(mktemp -d /tmp/openshift-cmd.XXXX)}
ETCD_DATA_DIR="${TEMP_DIR}/etcd"
VOLUME_DIR="${TEMP_DIR}/volumes"
CERT_DIR="${TEMP_DIR}/certs"
mkdir -p "${ETCD_DATA_DIR}" "${VOLUME_DIR}" "${CERT_DIR}"
CONFIG_DIR="${TEMP_DIR}/configs"
mkdir -p "${ETCD_DATA_DIR}" "${VOLUME_DIR}" "${CERT_DIR}" "${CONFIG_DIR}"

# handle profiling defaults
profile="${OPENSHIFT_PROFILE-}"
Expand Down Expand Up @@ -83,21 +84,56 @@ wait_for_url "http://${API_HOST}:${KUBELET_PORT}/healthz" "kubelet: " 0.25 80
wait_for_url "${API_SCHEME}://${API_HOST}:${API_PORT}/healthz" "apiserver: " 0.25 80
wait_for_url "${API_SCHEME}://${API_HOST}:${API_PORT}/api/v1beta1/minions/127.0.0.1" "apiserver(minions): " 0.25 80

# Set KUBERNETES_MASTER for osc
export KUBERNETES_MASTER="${API_SCHEME}://${API_HOST}:${API_PORT}"
if [[ "${API_SCHEME}" == "https" ]]; then
# Make osc use ${CERT_DIR}/admin/.kubeconfig, and ignore anything in the running user's $HOME dir
export HOME="${CERT_DIR}/admin"
export KUBECONFIG="${CERT_DIR}/admin/.kubeconfig"
fi

# profile the cli commands
export OPENSHIFT_PROFILE="${CLI_PROFILE-}"

#
# Begin tests
#

# test client not configured
[ "$(osc get services 2>&1 | grep 'no server found')" ]

# Set KUBERNETES_MASTER for osc from now on
export KUBERNETES_MASTER="${API_SCHEME}://${API_HOST}:${API_PORT}"

# Set certificates for osc from now on
if [[ "${API_SCHEME}" == "https" ]]; then
# test bad certificate
[ "$(osc get services 2>&1 | grep 'certificate signed by unknown authority')" ]

# ignore anything in the running user's $HOME dir
export HOME="${CERT_DIR}/admin"
fi

# test config files from the --config flag
osc get services --config="${CERT_DIR}/admin/.kubeconfig"

# test config files from env vars
OPENSHIFTCONFIG="${CERT_DIR}/admin/.kubeconfig" osc get services
KUBECONFIG="${CERT_DIR}/admin/.kubeconfig" osc get services

# test config files in the current directory
TEMP_PWD=`pwd`
Copy link
Contributor

Choose a reason for hiding this comment

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

$OS_ROOT should already have this dir

Copy link
Member Author

Choose a reason for hiding this comment

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

Doesn't seem to pass with $OS_ROOT, I'll leave it like that for now and fix later.

pushd ${CONFIG_DIR} >/dev/null
cp ${CERT_DIR}/admin/.kubeconfig .openshiftconfig
${TEMP_PWD}/${GO_OUT}/osc get services
mv .openshiftconfig .kubeconfig
${TEMP_PWD}/${GO_OUT}/osc get services
popd

# test config files in the home directory
mv ${CONFIG_DIR} ${HOME}/.kube
osc get services
mkdir -p ${HOME}/.config
mv ${HOME}/.kube ${HOME}/.config/openshift
mv ${HOME}/.config/openshift/.kubeconfig ${HOME}/.config/openshift/.config
osc get services
echo "config files: ok"
export OPENSHIFTCONFIG="${HOME}/.config/openshift/.config"

# from this point every command will use config from the OPENSHIFTCONFIG env var

osc get templates
osc create -f examples/sample-app/application-template-dockerbuild.json
osc get templates
Expand Down Expand Up @@ -273,14 +309,14 @@ osc describe policybinding master -n recreated-project | grep anypassword:create
echo "ex new-project: ok"

[ ! "$(openshift ex router | grep 'does not exist')"]
[ "$(openshift ex router -o yaml --credentials="${KUBECONFIG}" | grep 'openshift/origin-haproxy-')" ]
openshift ex router --create --credentials="${KUBECONFIG}"
[ "$(openshift ex router -o yaml --credentials="${OPENSHIFTCONFIG}" | grep 'openshift/origin-haproxy-')" ]
openshift ex router --create --credentials="${OPENSHIFTCONFIG}"
[ "$(openshift ex router | grep 'service exists')" ]
echo "ex router: ok"

[ ! "$(openshift ex registry | grep 'does not exist')"]
[ "$(openshift ex registry -o yaml --credentials="${KUBECONFIG}" | grep 'openshift/origin-docker-registry')" ]
openshift ex registry --create --credentials="${KUBECONFIG}"
[ "$(openshift ex registry -o yaml --credentials="${OPENSHIFTCONFIG}" | grep 'openshift/origin-docker-registry')" ]
openshift ex registry --create --credentials="${OPENSHIFTCONFIG}"
[ "$(openshift ex registry | grep 'service exists')" ]
echo "ex registry: ok"

Expand Down
3 changes: 3 additions & 0 deletions pkg/cmd/cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,13 @@ func NewCommandCLI(name, fullName string) *cobra.Command {
}

f := clientcmd.New(cmds.PersistentFlags())
in := os.Stdin
out := os.Stdout

cmds.SetUsageTemplate(templates.CliUsageTemplate())
cmds.SetHelpTemplate(templates.CliHelpTemplate())

cmds.AddCommand(cmd.NewCmdLogin(f, in, out))
cmds.AddCommand(cmd.NewCmdNewApplication(fullName, f, out))
cmds.AddCommand(cmd.NewCmdStartBuild(fullName, f, out))
cmds.AddCommand(cmd.NewCmdCancelBuild(fullName, f, out))
Expand All @@ -76,6 +78,7 @@ func NewCommandCLI(name, fullName string) *cobra.Command {
cmds.AddCommand(cmd.NewCmdLog(fullName, f, out))
cmds.AddCommand(f.NewCmdProxy(out))
cmds.AddCommand(kubecmd.NewCmdNamespace(out))
cmds.AddCommand(cmd.NewCmdProject(f, out))
cmds.AddCommand(cmd.NewCmdOptions(f, out))
cmds.AddCommand(version.NewVersionCommand(fullName))

Expand Down
56 changes: 56 additions & 0 deletions pkg/cmd/cli/cmd/login.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package cmd

import (
"fmt"
"io"

"github.com/spf13/cobra"

cmdutil "github.com/GoogleCloudPlatform/kubernetes/pkg/kubectl/cmd/util"
"github.com/openshift/origin/pkg/cmd/cli/config"
osclientcmd "github.com/openshift/origin/pkg/cmd/util/clientcmd"
)

const longDescription = `Logs in to the OpenShift server and save the session
information to a config file that will be used by every subsequent command.

First-time users of the OpenShift client must run this command to configure the server,
establish a session against it and save it to a configuration file, usually in the
user's home directory.

The information required to login, like username and password or a session token, and
the server details, can be provided through flags. If not provided, the command will
prompt for user input if needed.
`

func NewCmdLogin(f *osclientcmd.Factory, reader io.Reader, out io.Writer) *cobra.Command {
options := &LoginOptions{}

cmds := &cobra.Command{
Use: "login [--username=<username>] [--password=<password>] [--server=<server>] [--context=<context>] [--certificate-authority=<path>]",
Short: "Logs in and save the configuration",
Long: longDescription,
Run: func(cmd *cobra.Command, args []string) {
options.Reader = reader
options.ClientConfig = f.OpenShiftClientConfig

checkErr(options.GatherInfo())

forcePath := cmdutil.GetFlagString(cmd, config.OpenShiftConfigFlagName)
options.PathToSaveConfig = forcePath

newFileCreated, err := options.SaveConfig()
checkErr(err)

if newFileCreated {
fmt.Println("Welcome to OpenShift v3! Use 'osc --help' for a list of commands available.")
}
},
}

// TODO flags below should be DE-REGISTERED from the persistent flags and kept only here.
// Login is the only command that can negotiate a session token against the auth server.
cmds.Flags().StringVarP(&options.Username, "username", "u", "", "Username, will prompt if not provided")
cmds.Flags().StringVarP(&options.Password, "password", "p", "", "Password, will prompt if not provided")
return cmds
}
Loading