Introduce cluster get-kubeconfig command

This command will be used to retrieve kubeconfig from from leveraging
cluster or from document model. Particular implementation will be
added in further commits to make it easier for review.

Change-Id: If9e35dd90fdfcad6fa60a3cc4fab76ec1cb57f62
Signed-off-by: Ruslan Aliev <raliev@mirantis.com>
Related-To: #374
This commit is contained in:
Ruslan Aliev 2020-11-19 19:01:46 -06:00
parent 4e7053bfb5
commit 9cde986a31
7 changed files with 140 additions and 0 deletions

View File

@ -43,6 +43,7 @@ func NewClusterCommand(cfgFactory config.Factory) *cobra.Command {
clusterRootCmd.AddCommand(NewStatusCommand(cfgFactory))
clusterRootCmd.AddCommand(resetsatoken.NewResetCommand(cfgFactory))
clusterRootCmd.AddCommand(checkexpiration.NewCheckCommand(cfgFactory))
clusterRootCmd.AddCommand(NewGetKubeconfigCommand())
return clusterRootCmd
}

View File

@ -0,0 +1,52 @@
/*
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
https://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.
*/
package cluster
import (
"github.com/spf13/cobra"
"opendev.org/airship/airshipctl/pkg/errors"
)
const (
getKubeconfigLong = `
Retrieve cluster kubeconfig and save it to file or stdout.
`
getKubeconfigExample = `
# Retrieve target-cluster kubeconfig and print it to stdout
airshipctl cluster get-kubeconfig target-cluster
`
)
// NewGetKubeconfigCommand creates a command which retrieves cluster kubeconfig
func NewGetKubeconfigCommand() *cobra.Command {
cmd := &cobra.Command{
Use: "get-kubeconfig [cluster_name]",
Short: "Retrieve kubeconfig for a desired cluster",
Long: getKubeconfigLong[1:],
Example: getKubeconfigExample[1:],
Args: cobra.ExactArgs(1),
RunE: getKubeconfigRunE(),
}
return cmd
}
// getKubeconfigRunE returns a function to cobra command to be executed in runtime
func getKubeconfigRunE() func(cmd *cobra.Command, args []string) error {
return func(cmd *cobra.Command, args []string) error {
return errors.ErrNotImplemented{What: "cluster get-kubeconfig is not implemented yet"}
}
}

View File

@ -0,0 +1,35 @@
/*
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
https://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.
*/
package cluster_test
import (
"testing"
"opendev.org/airship/airshipctl/cmd/cluster"
"opendev.org/airship/airshipctl/testutil"
)
func TestNewKubeConfigCommandCmd(t *testing.T) {
tests := []*testutil.CmdTest{
{
Name: "cluster-get-kubeconfig-cmd-with-help",
CmdLine: "--help",
Cmd: cluster.NewGetKubeconfigCommand(),
},
}
for _, testcase := range tests {
testutil.RunTest(t, testcase)
}
}

View File

@ -6,6 +6,7 @@ Usage:
Available Commands:
check-certificate-expiration Check for expiring TLS certificates, secrets and kubeconfigs in the kubernetes cluster
get-kubeconfig Retrieve kubeconfig for a desired cluster
help Help about any command
init Deploy cluster-api provider components
move Move Cluster API objects, provider specific objects and all dependencies to the target cluster

View File

@ -0,0 +1,12 @@
Retrieve cluster kubeconfig and save it to file or stdout.
Usage:
get-kubeconfig [cluster_name] [flags]
Examples:
# Retrieve target-cluster kubeconfig and print it to stdout
airshipctl cluster get-kubeconfig target-cluster
Flags:
-h, --help help for get-kubeconfig

View File

@ -25,6 +25,7 @@ such as getting status and deploying initial infrastructure.
* [airshipctl](airshipctl.md) - A unified entrypoint to various airship components
* [airshipctl cluster check-certificate-expiration](airshipctl_cluster_check-certificate-expiration.md) - Check for expiring TLS certificates, secrets and kubeconfigs in the kubernetes cluster
* [airshipctl cluster get-kubeconfig](airshipctl_cluster_get-kubeconfig.md) - Retrieve kubeconfig for a desired cluster
* [airshipctl cluster init](airshipctl_cluster_init.md) - Deploy cluster-api provider components
* [airshipctl cluster move](airshipctl_cluster_move.md) - Move Cluster API objects, provider specific objects and all dependencies to the target cluster
* [airshipctl cluster rotate-sa-token](airshipctl_cluster_rotate-sa-token.md) - Rotate tokens of Service Accounts

View File

@ -0,0 +1,38 @@
## airshipctl cluster get-kubeconfig
Retrieve kubeconfig for a desired cluster
### Synopsis
Retrieve cluster kubeconfig and save it to file or stdout.
```
airshipctl cluster get-kubeconfig [cluster_name] [flags]
```
### Examples
```
# Retrieve target-cluster kubeconfig and print it to stdout
airshipctl cluster get-kubeconfig target-cluster
```
### Options
```
-h, --help help for get-kubeconfig
```
### Options inherited from parent commands
```
--airshipconf string Path to file for airshipctl configuration. (default "$HOME/.airship/config")
--debug enable verbose output
```
### SEE ALSO
* [airshipctl cluster](airshipctl_cluster.md) - Manage Kubernetes clusters