Skip to content

Commit

Permalink
Merge pull request #15717 from fabianofranz/569_cli_plugins
Browse files Browse the repository at this point in the history
Automatic merge from submit-queue (batch tested with PRs 15717, 15947)

Enable CLI plugins in oc

Trello story: https://trello.com/c/o6UiTkxv

Adds support to CLI plugins under the `oc plugin` command. Basically the same functionality and same subcommand already present upstream. 

This is required for enabling the service catalog commands under `oc`, which will be distributed as plugins.

@liggitt one upstream commit for a feature that didn't make the 1.7 cut upstream
@openshift/cli-review @smarterclayton prease review
@sspeiche @pmorie FYI
  • Loading branch information
openshift-merge-robot authored Aug 26, 2017
2 parents d8cb876 + 607f80b commit 020fe35
Show file tree
Hide file tree
Showing 26 changed files with 565 additions and 42 deletions.
49 changes: 49 additions & 0 deletions contrib/completions/bash/oc
Original file line number Diff line number Diff line change
Expand Up @@ -13401,6 +13401,54 @@ _oc_patch()
noun_aliases+=("users")
}

_oc_plugin()
{
last_command="oc_plugin"
commands=()

flags=()
two_word_flags=()
local_nonpersistent_flags=()
flags_with_completion=()
flags_completion=()

flags+=("--as=")
flags+=("--as-group=")
flags+=("--certificate-authority=")
flags_with_completion+=("--certificate-authority")
flags_completion+=("_filedir")
flags+=("--client-certificate=")
flags_with_completion+=("--client-certificate")
flags_completion+=("_filedir")
flags+=("--client-key=")
flags_with_completion+=("--client-key")
flags_completion+=("_filedir")
flags+=("--cluster=")
flags+=("--config=")
flags_with_completion+=("--config")
flags_completion+=("_filedir")
flags+=("--context=")
flags+=("--insecure-skip-tls-verify")
flags+=("--log-flush-frequency=")
flags+=("--loglevel=")
flags+=("--logspec=")
flags+=("--match-server-version")
flags+=("--namespace=")
flags_with_completion+=("--namespace")
flags_completion+=("__oc_get_namespaces")
two_word_flags+=("-n")
flags_with_completion+=("-n")
flags_completion+=("__oc_get_namespaces")
flags+=("--request-timeout=")
flags+=("--server=")
flags+=("--token=")
flags+=("--user=")

must_have_one_flag=()
must_have_one_noun=()
noun_aliases=()
}

_oc_policy_add-role-to-group()
{
last_command="oc_policy_add-role-to-group"
Expand Down Expand Up @@ -17777,6 +17825,7 @@ _oc()
commands+=("observe")
commands+=("options")
commands+=("patch")
commands+=("plugin")
commands+=("policy")
commands+=("port-forward")
commands+=("process")
Expand Down
52 changes: 52 additions & 0 deletions contrib/completions/bash/openshift
Original file line number Diff line number Diff line change
Expand Up @@ -19286,6 +19286,57 @@ _openshift_cli_patch()
noun_aliases+=("users")
}

_openshift_cli_plugin()
{
last_command="openshift_cli_plugin"
commands=()

flags=()
two_word_flags=()
local_nonpersistent_flags=()
flags_with_completion=()
flags_completion=()

flags+=("--as=")
flags+=("--as-group=")
flags+=("--azure-container-registry-config=")
flags+=("--certificate-authority=")
flags_with_completion+=("--certificate-authority")
flags_completion+=("_filedir")
flags+=("--client-certificate=")
flags_with_completion+=("--client-certificate")
flags_completion+=("_filedir")
flags+=("--client-key=")
flags_with_completion+=("--client-key")
flags_completion+=("_filedir")
flags+=("--cluster=")
flags+=("--config=")
flags_with_completion+=("--config")
flags_completion+=("_filedir")
flags+=("--context=")
flags+=("--google-json-key=")
flags+=("--insecure-skip-tls-verify")
flags+=("--log-flush-frequency=")
flags+=("--loglevel=")
flags+=("--logspec=")
flags+=("--match-server-version")
flags+=("--namespace=")
flags_with_completion+=("--namespace")
flags_completion+=("__oc_get_namespaces")
two_word_flags+=("-n")
flags_with_completion+=("-n")
flags_completion+=("__oc_get_namespaces")
flags+=("--request-timeout=")
flags+=("--server=")
flags+=("--token=")
flags+=("--user=")
flags+=("--version")

must_have_one_flag=()
must_have_one_noun=()
noun_aliases=()
}

_openshift_cli_policy_add-role-to-group()
{
last_command="openshift_cli_policy_add-role-to-group"
Expand Down Expand Up @@ -23797,6 +23848,7 @@ _openshift_cli()
commands+=("observe")
commands+=("options")
commands+=("patch")
commands+=("plugin")
commands+=("policy")
commands+=("port-forward")
commands+=("process")
Expand Down
49 changes: 49 additions & 0 deletions contrib/completions/zsh/oc
Original file line number Diff line number Diff line change
Expand Up @@ -13550,6 +13550,54 @@ _oc_patch()
noun_aliases+=("users")
}

_oc_plugin()
{
last_command="oc_plugin"
commands=()

flags=()
two_word_flags=()
local_nonpersistent_flags=()
flags_with_completion=()
flags_completion=()

flags+=("--as=")
flags+=("--as-group=")
flags+=("--certificate-authority=")
flags_with_completion+=("--certificate-authority")
flags_completion+=("_filedir")
flags+=("--client-certificate=")
flags_with_completion+=("--client-certificate")
flags_completion+=("_filedir")
flags+=("--client-key=")
flags_with_completion+=("--client-key")
flags_completion+=("_filedir")
flags+=("--cluster=")
flags+=("--config=")
flags_with_completion+=("--config")
flags_completion+=("_filedir")
flags+=("--context=")
flags+=("--insecure-skip-tls-verify")
flags+=("--log-flush-frequency=")
flags+=("--loglevel=")
flags+=("--logspec=")
flags+=("--match-server-version")
flags+=("--namespace=")
flags_with_completion+=("--namespace")
flags_completion+=("__oc_get_namespaces")
two_word_flags+=("-n")
flags_with_completion+=("-n")
flags_completion+=("__oc_get_namespaces")
flags+=("--request-timeout=")
flags+=("--server=")
flags+=("--token=")
flags+=("--user=")

must_have_one_flag=()
must_have_one_noun=()
noun_aliases=()
}

_oc_policy_add-role-to-group()
{
last_command="oc_policy_add-role-to-group"
Expand Down Expand Up @@ -17926,6 +17974,7 @@ _oc()
commands+=("observe")
commands+=("options")
commands+=("patch")
commands+=("plugin")
commands+=("policy")
commands+=("port-forward")
commands+=("process")
Expand Down
52 changes: 52 additions & 0 deletions contrib/completions/zsh/openshift
Original file line number Diff line number Diff line change
Expand Up @@ -19435,6 +19435,57 @@ _openshift_cli_patch()
noun_aliases+=("users")
}

_openshift_cli_plugin()
{
last_command="openshift_cli_plugin"
commands=()

flags=()
two_word_flags=()
local_nonpersistent_flags=()
flags_with_completion=()
flags_completion=()

flags+=("--as=")
flags+=("--as-group=")
flags+=("--azure-container-registry-config=")
flags+=("--certificate-authority=")
flags_with_completion+=("--certificate-authority")
flags_completion+=("_filedir")
flags+=("--client-certificate=")
flags_with_completion+=("--client-certificate")
flags_completion+=("_filedir")
flags+=("--client-key=")
flags_with_completion+=("--client-key")
flags_completion+=("_filedir")
flags+=("--cluster=")
flags+=("--config=")
flags_with_completion+=("--config")
flags_completion+=("_filedir")
flags+=("--context=")
flags+=("--google-json-key=")
flags+=("--insecure-skip-tls-verify")
flags+=("--log-flush-frequency=")
flags+=("--loglevel=")
flags+=("--logspec=")
flags+=("--match-server-version")
flags+=("--namespace=")
flags_with_completion+=("--namespace")
flags_completion+=("__oc_get_namespaces")
two_word_flags+=("-n")
flags_with_completion+=("-n")
flags_completion+=("__oc_get_namespaces")
flags+=("--request-timeout=")
flags+=("--server=")
flags+=("--token=")
flags+=("--user=")
flags+=("--version")

must_have_one_flag=()
must_have_one_noun=()
noun_aliases=()
}

_openshift_cli_policy_add-role-to-group()
{
last_command="openshift_cli_policy_add-role-to-group"
Expand Down Expand Up @@ -23946,6 +23997,7 @@ _openshift_cli()
commands+=("observe")
commands+=("options")
commands+=("patch")
commands+=("plugin")
commands+=("policy")
commands+=("port-forward")
commands+=("process")
Expand Down
1 change: 1 addition & 0 deletions docs/man/man1/.files_generated_oc
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ oc-new-project.1
oc-observe.1
oc-options.1
oc-patch.1
oc-plugin.1
oc-policy-add-role-to-group.1
oc-policy-add-role-to-user.1
oc-policy-can-i.1
Expand Down
1 change: 1 addition & 0 deletions docs/man/man1/.files_generated_openshift
Original file line number Diff line number Diff line change
Expand Up @@ -285,6 +285,7 @@ openshift-cli-new-project.1
openshift-cli-observe.1
openshift-cli-options.1
openshift-cli-patch.1
openshift-cli-plugin.1
openshift-cli-policy-add-role-to-group.1
openshift-cli-policy-add-role-to-user.1
openshift-cli-policy-can-i.1
Expand Down
3 changes: 3 additions & 0 deletions docs/man/man1/oc-plugin.1
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
This file is autogenerated, but we've stopped checking such files into the
repository to reduce the need for rebases. Please run hack/generate-docs.sh to
populate this file.
3 changes: 3 additions & 0 deletions docs/man/man1/openshift-cli-plugin.1
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
This file is autogenerated, but we've stopped checking such files into the
repository to reduce the need for rebases. Please run hack/generate-docs.sh to
populate this file.
1 change: 1 addition & 0 deletions pkg/oc/cli/cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ func NewCommandCLI(name, fullName string, in io.Reader, out, errout io.Writer) *
experimental.AddCommand()
cmds.AddCommand(experimental)

cmds.AddCommand(cmd.NewCmdPlugin(fullName, f, in, out, errout))
if name == fullName {
cmds.AddCommand(cmd.NewCmdVersion(fullName, f, out, cmd.VersionOptions{PrintClientFeatures: true}))
}
Expand Down
4 changes: 4 additions & 0 deletions pkg/oc/cli/cmd/wrappers.go
Original file line number Diff line number Diff line change
Expand Up @@ -757,3 +757,7 @@ func NewCmdAuth(fullName string, f *clientcmd.Factory, out, errout io.Writer) *c
cmd := kcmdauth.NewCmdAuth(f, out, errout)
return cmd
}

func NewCmdPlugin(fullName string, f *clientcmd.Factory, in io.Reader, out, errout io.Writer) *cobra.Command {
return kcmd.NewCmdPlugin(f, in, out, errout)
}
1 change: 0 additions & 1 deletion pkg/oc/cli/kubectl_compat_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@ var MissingCommands = sets.NewString(
// TODO commands to assess
"apiversions",
"clusterinfo",
"plugin",
"resize",
"rollingupdate",
"run-container",
Expand Down
70 changes: 70 additions & 0 deletions test/cmd/plugins.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
#!/bin/bash
source "$(dirname "${BASH_SOURCE}")/../../hack/lib/init.sh"
trap os::test::junit::reconcile_output EXIT

os::test::junit::declare_suite_start "cmd/plugin"

# top-level plugin command
os::cmd::expect_success_and_text "KUBECTL_PLUGINS_PATH=test/testdata/plugin/plugins oc -h 2>&1" 'Runs a command-line plugin'

# no plugins
os::cmd::expect_failure_and_text "oc plugin 2>&1" 'no plugins installed'

# single plugins path
os::cmd::expect_success_and_text "KUBECTL_PLUGINS_PATH=test/testdata/plugin/plugins oc plugin 2>&1" 'Echoes for test-cmd'
os::cmd::expect_success_and_text "KUBECTL_PLUGINS_PATH=test/testdata/plugin/plugins oc plugin 2>&1" 'The wonderful new plugin-based get!'
os::cmd::expect_success_and_text "KUBECTL_PLUGINS_PATH=test/testdata/plugin/plugins oc plugin 2>&1" 'The tremendous plugin that always fails!'
os::cmd::expect_success_and_not_text "KUBECTL_PLUGINS_PATH=test/testdata/plugin/plugins oc plugin 2>&1" 'The hello plugin'
os::cmd::expect_success_and_not_text "KUBECTL_PLUGINS_PATH=test/testdata/plugin/plugins oc plugin 2>&1" 'Incomplete plugin'
os::cmd::expect_success_and_not_text "KUBECTL_PLUGINS_PATH=test/testdata/plugin/plugins oc plugin 2>&1" 'no plugins installed'

# multiple plugins path
os::cmd::expect_success_and_text "KUBECTL_PLUGINS_PATH=test/testdata/plugin/plugins/:test/testdata/plugin/plugins2/ oc plugin -h 2>&1" 'Echoes for test-cmd'
os::cmd::expect_success_and_text "KUBECTL_PLUGINS_PATH=test/testdata/plugin/plugins/:test/testdata/plugin/plugins2/ oc plugin -h 2>&1" 'The wonderful new plugin-based get!'
os::cmd::expect_success_and_text "KUBECTL_PLUGINS_PATH=test/testdata/plugin/plugins/:test/testdata/plugin/plugins2/ oc plugin -h 2>&1" 'The tremendous plugin that always fails!'
os::cmd::expect_success_and_text "KUBECTL_PLUGINS_PATH=test/testdata/plugin/plugins/:test/testdata/plugin/plugins2/ oc plugin -h 2>&1" 'The hello plugin'
os::cmd::expect_success_and_not_text "KUBECTL_PLUGINS_PATH=test/testdata/plugin/plugins/:test/testdata/plugin/plugins2/ oc plugin -h 2>&1" 'Incomplete plugin'

# don't override existing commands
os::cmd::expect_success_and_text "KUBECTL_PLUGINS_PATH=test/testdata/plugin/plugins/:test/testdata/plugin/plugins2/ oc get -h 2>&1" 'Display one or many resources'
os::cmd::expect_success_and_not_text "KUBECTL_PLUGINS_PATH=test/testdata/plugin/plugins/:test/testdata/plugin/plugins2/ oc get -h 2>&1" 'The wonderful new plugin-based get'

# plugin help
os::cmd::expect_success_and_text "KUBECTL_PLUGINS_PATH=test/testdata/plugin/plugins/:test/testdata/plugin/plugins2/ oc plugin hello -h 2>&1" 'The hello plugin is a new plugin used by test-cmd to test multiple plugin locations.'
os::cmd::expect_success_and_text "KUBECTL_PLUGINS_PATH=test/testdata/plugin/plugins/:test/testdata/plugin/plugins2/ oc plugin hello -h 2>&1" 'Usage:'

# run plugin
os::cmd::expect_success_and_text "KUBECTL_PLUGINS_PATH=test/testdata/plugin/plugins/:test/testdata/plugin/plugins2/ oc plugin hello 2>&1" '#hello#'
os::cmd::expect_success_and_text "KUBECTL_PLUGINS_PATH=test/testdata/plugin/plugins/:test/testdata/plugin/plugins2/ oc plugin echo 2>&1" 'This plugin works!'
os::cmd::expect_failure_and_text "KUBECTL_PLUGINS_PATH=test/testdata/plugin/plugins oc plugin hello 2>&1" 'unknown command'
os::cmd::expect_failure_and_text "KUBECTL_PLUGINS_PATH=test/testdata/plugin/plugins oc plugin error 2>&1" 'error: exit status 1'

# plugin tree
os::cmd::expect_success_and_text "KUBECTL_PLUGINS_PATH=test/testdata/plugin/plugins oc plugin tree 2>&1" 'Plugin with a tree of commands'
os::cmd::expect_success_and_text "KUBECTL_PLUGINS_PATH=test/testdata/plugin/plugins oc plugin tree 2>&1" 'The first child of a tree'
os::cmd::expect_success_and_text "KUBECTL_PLUGINS_PATH=test/testdata/plugin/plugins oc plugin tree 2>&1" 'The second child of a tree'
os::cmd::expect_success_and_text "KUBECTL_PLUGINS_PATH=test/testdata/plugin/plugins oc plugin tree 2>&1" 'The third child of a tree'
os::cmd::expect_success_and_text "KUBECTL_PLUGINS_PATH=test/testdata/plugin/plugins oc plugin tree child1 --help 2>&1" 'The first child of a tree'
os::cmd::expect_success_and_not_text "KUBECTL_PLUGINS_PATH=test/testdata/plugin/plugins oc plugin tree child1 --help 2>&1" 'The second child'
os::cmd::expect_success_and_not_text "KUBECTL_PLUGINS_PATH=test/testdata/plugin/plugins oc plugin tree child1 --help 2>&1" 'child2'
os::cmd::expect_success_and_text "KUBECTL_PLUGINS_PATH=test/testdata/plugin/plugins oc plugin tree child1 2>&1" 'child one'
os::cmd::expect_success_and_not_text "KUBECTL_PLUGINS_PATH=test/testdata/plugin/plugins oc plugin tree child1 2>&1" 'child1'
os::cmd::expect_success_and_not_text "KUBECTL_PLUGINS_PATH=test/testdata/plugin/plugins oc plugin tree child1 2>&1" 'The first child'

# plugin env
os::cmd::expect_success_and_text "KUBECTL_PLUGINS_PATH=test/testdata/plugin/plugins oc plugin env -h 2>&1" "This is a flag 1"
os::cmd::expect_success_and_text "KUBECTL_PLUGINS_PATH=test/testdata/plugin/plugins oc plugin env -h 2>&1" "This is a flag 2"
os::cmd::expect_success_and_text "KUBECTL_PLUGINS_PATH=test/testdata/plugin/plugins oc plugin env -h 2>&1" "This is a flag 3"
output_message=$()
os::cmd::expect_success_and_text "KUBECTL_PLUGINS_PATH=test/testdata/plugin/plugins oc plugin env --test1=value1 -t value2 2>&1" 'KUBECTL_PLUGINS_CURRENT_NAMESPACE'
os::cmd::expect_success_and_text "KUBECTL_PLUGINS_PATH=test/testdata/plugin/plugins oc plugin env --test1=value1 -t value2 2>&1" 'KUBECTL_PLUGINS_CALLER'
os::cmd::expect_success_and_text "KUBECTL_PLUGINS_PATH=test/testdata/plugin/plugins oc plugin env --test1=value1 -t value2 2>&1" 'KUBECTL_PLUGINS_DESCRIPTOR_COMMAND=./env.sh'
os::cmd::expect_success_and_text "KUBECTL_PLUGINS_PATH=test/testdata/plugin/plugins oc plugin env --test1=value1 -t value2 2>&1" 'KUBECTL_PLUGINS_DESCRIPTOR_SHORT_DESC=The plugin envs plugin'
os::cmd::expect_success_and_text "KUBECTL_PLUGINS_PATH=test/testdata/plugin/plugins oc plugin env --test1=value1 -t value2 2>&1" 'KUBECTL_PLUGINS_GLOBAL_FLAG_CONFIG'
os::cmd::expect_success_and_text "KUBECTL_PLUGINS_PATH=test/testdata/plugin/plugins oc plugin env --test1=value1 -t value2 2>&1" 'KUBECTL_PLUGINS_GLOBAL_FLAG_REQUEST_TIMEOUT=0'
os::cmd::expect_success_and_text "KUBECTL_PLUGINS_PATH=test/testdata/plugin/plugins oc plugin env --test1=value1 -t value2 2>&1" 'KUBECTL_PLUGINS_LOCAL_FLAG_TEST1=value1'
os::cmd::expect_success_and_text "KUBECTL_PLUGINS_PATH=test/testdata/plugin/plugins oc plugin env --test1=value1 -t value2 2>&1" 'KUBECTL_PLUGINS_LOCAL_FLAG_TEST2=value2'
os::cmd::expect_success_and_text "KUBECTL_PLUGINS_PATH=test/testdata/plugin/plugins oc plugin env --test1=value1 -t value2 2>&1" 'KUBECTL_PLUGINS_LOCAL_FLAG_TEST3=default'

echo "oc plugin: ok"
os::test::junit::declare_suite_end
4 changes: 4 additions & 0 deletions test/testdata/plugin/plugins/echo/plugin.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
name: "echo"
shortDesc: "Echoes for test-cmd"
longDesc: "Long description for the test-cmd echo plugin"
command: "echo This plugin works!"
17 changes: 17 additions & 0 deletions test/testdata/plugin/plugins/env/env.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/bin/bash

# Copyright 2017 The Kubernetes Authors.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

env | grep 'KUBECTL_PLUGINS' | sort
Loading

0 comments on commit 020fe35

Please sign in to comment.