Skip to content

Commit 05abd7f

Browse files
committed
Add version
Signed-off-by: Dominique Vernier <[email protected]>
1 parent eef852a commit 05abd7f

File tree

17 files changed

+470
-113
lines changed

17 files changed

+470
-113
lines changed

CONTRIBUTING.md

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -36,27 +36,22 @@ Anyone can comment on issues and submit reviews for pull requests. In order to b
3636
- The project tries to follow the following grammar for the commands:
3737

3838
```bash
39-
cm <verb> <noun>
39+
clusteradm <verb> <noun>
4040
```
4141

4242
- A number of verbs are already defined in [verbs](pkg/cmd/verbs/verbs.go), if you would like to add a new verb or noun, please contact the [OWNERS](OWNERS).
4343

4444
- The noun represents the object on which the verb applies.
4545

46-
- Each pair (verb/noum) has its own package. For example [create/cluster](pkg/cmd/delete/cluster/cmd.go) package contains the code to create a cluster.
46+
- Each pair (verb/noum) has its own package.
4747

48-
- Inside the package, the code is split in 3 files: The [cmd.go](pkg/cmd/create/cluster/cmd.go) which creates the cobra command, the [options.go](pkg/cmd/create/cluster/options.go) which defines the different option parameters for the command and the the [exec.go](pkg/cmd/create/cluster/exec.go) which contains the code to execute the command.
48+
- Inside the package, the code is split in 3 files: The [cmd.go](pkg/cmd/version/cmd.go) which creates the cobra command, the [options.go](pkg/cmd/version/options.go) which defines the different option parameters for the command and the the [exec.go](pkg/cmd/version/exec.go) which contains the code to execute the command.
4949

5050

5151
## Resources
5252

5353
- Some commands needs resources files, in the project uses the `Go 1.16` `go:embed` functionality to store the resources files.
54-
- Each command package contains its own resources in the scenario package. The scenario package contains one go file which provides the `go:embed` `embed.FS` files. For example [resources.go](pkg/cmd/create/cluster/scenario/resources.go).
55-
- All resources must be accessed using unstrusctured, the project must not have api dependencies.
56-
57-
## Applier
58-
59-
- This project relies on the [applier](https://github.com/open-cluster-management/applier) to create, update or delete kubernetes resources. The applier allows you to create templated resources and these templates are parsed with a provided values files and then applied in the kubernetes cluster. For example, the [scenario](pkg/cmd/create/cluster/scenario) contains the templated resources to create a managed cluster on a hub.
54+
- Each command package contains its own resources in the scenario package. The scenario package contains one go file which provides the `go:embed` `embed.FS` files.
6055

6156
## Client
6257

@@ -70,7 +65,7 @@ as it uses also the parameters like `--server` or `--kubeconfig` to generate the
7065

7166
## Unit tests
7267

73-
- If the unit test needs files to be executed, these files are stored under the pair `<verb>/<noun>/test/unit` like [values-fake/yaml](pkg/cmd/detach/cluster/test/unit/values-fake.yaml).
68+
- If the unit test needs files to be executed, these files are stored under the pair `<verb>/<noun>/test/unit`.
7469
A total coverage is shown when running `make test`. For the time being, the `cmd.go` and `client.go` are excluded from the total coverage.
7570
- The `make test` is part of the PR acceptance and it is launched by PROW.
7671

README.md

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
[comment]: # ( Copyright Contributors to the Open Cluster Management project )
22
# clusteradm CLI & CLI Plugin
33

4-
A CLI and kubernetes CLI plugin that allows you to interact with OCM/ACM to provision and managed your Hybrid Cloud presence from the command-line.
4+
A CLI and kubernetes CLI plugin that allows you to interact with open-cluster-management to manage your Hybrid Cloud presence from the command-line.
55

66
## Requirements
77

@@ -18,21 +18,6 @@ cd clusteradmin
1818
make build
1919
cm
2020
```
21-
22-
### Plugin
23-
24-
This will create a binary `oc-clusteradm` and `kubectl-clusteradm` in the `$GOPATH/go/bin` allowing you to call `oc clusteradm` or `kubectl clusteradm`
25-
```bash
26-
git clone https://open-cluster-management-io/clusteradm.git
27-
cd clusteradm
28-
make plugin
29-
kubectl clusteradm
30-
oc clusteradm
31-
```
32-
## Disclaimer
33-
34-
This CLI (and plugin) is still in development, but aims to expose CNCF's functional through a useful and lightweight CLI and kubectl/oc CLI plugin. Some features may not be present, fully implemented, and it might be buggy!
35-
3621
## Contributing
3722

3823
See our [Contributing Document](CONTRIBUTING.md) for more information.
@@ -41,6 +26,6 @@ See our [Contributing Document](CONTRIBUTING.md) for more information.
4126

4227
The commands are composed of a verb and a noun and then a number of parameters.
4328

44-
## Cluster commands
29+
### version
4530

46-
[applier](docs/applier.md)
31+
`clusteradm version`

VERSION.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
0.0.1

build/run-functional-tests.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@ kind create cluster --name ${CLUSTER_NAME}
1616
#Wait for cluster to setup
1717
sleep 10
1818

19-
echo "Test clusteradm get secret"
20-
clusteradm get secret -n default
19+
echo "Test clusteradm version"
20+
clusteradm version
2121
if [ $? != 0 ]
2222
then
23-
ERROR_REPORT=$ERROR_REPORT+"clusteradm get secret -n default failed\n"
23+
ERROR_REPORT=$ERROR_REPORT+"clusteradm version failed\n"
2424
fi
2525

2626
if [ -z "$ERROR_REPORT" ]

cmd/clusteradm.go

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,53 @@ package main
55
import (
66
"os"
77

8+
"github.com/spf13/cobra"
89
"k8s.io/cli-runtime/pkg/genericclioptions"
9-
"open-cluster-management.io/clusteradm/pkg/cmd"
10+
"k8s.io/client-go/tools/clientcmd"
11+
cliflag "k8s.io/component-base/cli/flag"
12+
kubectlcmd "k8s.io/kubectl/pkg/cmd"
13+
cmdconfig "k8s.io/kubectl/pkg/cmd/config"
14+
"k8s.io/kubectl/pkg/cmd/options"
15+
"k8s.io/kubectl/pkg/cmd/plugin"
16+
cmdutil "k8s.io/kubectl/pkg/cmd/util"
17+
"open-cluster-management.io/clusteradm/pkg/cmd/verbs"
1018
)
1119

1220
func main() {
1321
streams := genericclioptions.IOStreams{In: os.Stdin, Out: os.Stdout, ErrOut: os.Stderr}
14-
root, _ := cmd.NewRootCmd("clusteradm", streams)
22+
configFlags := genericclioptions.NewConfigFlags(true).WithDeprecatedPasswordFlag()
23+
matchVersionKubeConfigFlags := cmdutil.NewMatchVersionFlags(configFlags)
24+
f := cmdutil.NewFactory(matchVersionKubeConfigFlags)
25+
26+
root := newCmdVerbs("clusteradm", f, streams)
27+
28+
flags := root.PersistentFlags()
29+
matchVersionKubeConfigFlags.AddFlags(flags)
30+
flags.SetNormalizeFunc(cliflag.WarnWordSepNormalizeFunc) // Warn for "_" flags
31+
32+
flags.SetNormalizeFunc(cliflag.WordSepNormalizeFunc)
33+
// From this point and forward we get warnings on flags that contain "_" separators
34+
root.SetGlobalNormalizationFunc(cliflag.WarnWordSepNormalizeFunc)
35+
36+
configFlags.AddFlags(flags)
37+
root.AddCommand(cmdconfig.NewCmdConfig(f, clientcmd.NewDefaultPathOptions(), streams))
38+
root.AddCommand(options.NewCmdOptions(streams.Out))
39+
//enable plugin functionality: all `os.Args[0]-<binary>` in the $PATH will be available for plugin
40+
plugin.ValidPluginFilenamePrefixes = []string{os.Args[0]}
41+
root.AddCommand(plugin.NewCmdPlugin(f, streams))
42+
root.AddCommand(kubectlcmd.NewDefaultKubectlCommand())
43+
1544
if err := root.Execute(); err != nil {
1645
os.Exit(1)
1746
}
1847
}
48+
49+
// NewCmdNamespace provides a cobra command wrapping NamespaceOptions
50+
func newCmdVerbs(parent string, f cmdutil.Factory, streams genericclioptions.IOStreams) *cobra.Command {
51+
cmd := &cobra.Command{Use: parent}
52+
cmd.AddCommand(
53+
verbs.NewVerbVersion("version", f, streams),
54+
)
55+
56+
return cmd
57+
}

go.mod

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,13 @@ replace (
88
)
99

1010
require (
11-
github.com/hashicorp/golang-lru v0.5.4 // indirect
12-
github.com/imdario/mergo v0.3.11 // indirect
13-
github.com/onsi/gomega v1.10.1 // indirect
11+
github.com/open-cluster-management/cm-cli v0.0.0-20210519115358-be3bb81f33d0
1412
github.com/spf13/cobra v1.1.3
13+
k8s.io/api v0.20.5
14+
k8s.io/apimachinery v0.20.5
1515
k8s.io/cli-runtime v0.20.5
1616
k8s.io/client-go v1.5.2
17-
k8s.io/component-base v0.20.1
17+
k8s.io/component-base v0.20.2
1818
k8s.io/kubectl v0.20.1
19+
sigs.k8s.io/controller-runtime v0.8.3
1920
)

0 commit comments

Comments
 (0)