Skip to content

Commit

Permalink
Add version
Browse files Browse the repository at this point in the history
Signed-off-by: Dominique Vernier <[email protected]>
  • Loading branch information
itdove committed May 27, 2021
1 parent eef852a commit 05abd7f
Show file tree
Hide file tree
Showing 17 changed files with 470 additions and 113 deletions.
15 changes: 5 additions & 10 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,27 +36,22 @@ Anyone can comment on issues and submit reviews for pull requests. In order to b
- The project tries to follow the following grammar for the commands:

```bash
cm <verb> <noun>
clusteradm <verb> <noun>
```

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

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

- 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.
- Each pair (verb/noum) has its own package.

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


## Resources

- Some commands needs resources files, in the project uses the `Go 1.16` `go:embed` functionality to store the resources files.
- 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).
- All resources must be accessed using unstrusctured, the project must not have api dependencies.

## Applier

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

## Client

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

## Unit tests

- 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).
- If the unit test needs files to be executed, these files are stored under the pair `<verb>/<noun>/test/unit`.
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.
- The `make test` is part of the PR acceptance and it is launched by PROW.

Expand Down
21 changes: 3 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
[comment]: # ( Copyright Contributors to the Open Cluster Management project )
# clusteradm CLI & CLI Plugin

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

## Requirements

Expand All @@ -18,21 +18,6 @@ cd clusteradmin
make build
cm
```

### Plugin

This will create a binary `oc-clusteradm` and `kubectl-clusteradm` in the `$GOPATH/go/bin` allowing you to call `oc clusteradm` or `kubectl clusteradm`
```bash
git clone https://open-cluster-management-io/clusteradm.git
cd clusteradm
make plugin
kubectl clusteradm
oc clusteradm
```
## Disclaimer

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!

## Contributing

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

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

## Cluster commands
### version

[applier](docs/applier.md)
`clusteradm version`
1 change: 1 addition & 0 deletions VERSION.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
0.0.1
6 changes: 3 additions & 3 deletions build/run-functional-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@ kind create cluster --name ${CLUSTER_NAME}
#Wait for cluster to setup
sleep 10

echo "Test clusteradm get secret"
clusteradm get secret -n default
echo "Test clusteradm version"
clusteradm version
if [ $? != 0 ]
then
ERROR_REPORT=$ERROR_REPORT+"clusteradm get secret -n default failed\n"
ERROR_REPORT=$ERROR_REPORT+"clusteradm version failed\n"
fi

if [ -z "$ERROR_REPORT" ]
Expand Down
43 changes: 41 additions & 2 deletions cmd/clusteradm.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,53 @@ package main
import (
"os"

"github.com/spf13/cobra"
"k8s.io/cli-runtime/pkg/genericclioptions"
"open-cluster-management.io/clusteradm/pkg/cmd"
"k8s.io/client-go/tools/clientcmd"
cliflag "k8s.io/component-base/cli/flag"
kubectlcmd "k8s.io/kubectl/pkg/cmd"
cmdconfig "k8s.io/kubectl/pkg/cmd/config"
"k8s.io/kubectl/pkg/cmd/options"
"k8s.io/kubectl/pkg/cmd/plugin"
cmdutil "k8s.io/kubectl/pkg/cmd/util"
"open-cluster-management.io/clusteradm/pkg/cmd/verbs"
)

func main() {
streams := genericclioptions.IOStreams{In: os.Stdin, Out: os.Stdout, ErrOut: os.Stderr}
root, _ := cmd.NewRootCmd("clusteradm", streams)
configFlags := genericclioptions.NewConfigFlags(true).WithDeprecatedPasswordFlag()
matchVersionKubeConfigFlags := cmdutil.NewMatchVersionFlags(configFlags)
f := cmdutil.NewFactory(matchVersionKubeConfigFlags)

root := newCmdVerbs("clusteradm", f, streams)

flags := root.PersistentFlags()
matchVersionKubeConfigFlags.AddFlags(flags)
flags.SetNormalizeFunc(cliflag.WarnWordSepNormalizeFunc) // Warn for "_" flags

flags.SetNormalizeFunc(cliflag.WordSepNormalizeFunc)
// From this point and forward we get warnings on flags that contain "_" separators
root.SetGlobalNormalizationFunc(cliflag.WarnWordSepNormalizeFunc)

configFlags.AddFlags(flags)
root.AddCommand(cmdconfig.NewCmdConfig(f, clientcmd.NewDefaultPathOptions(), streams))
root.AddCommand(options.NewCmdOptions(streams.Out))
//enable plugin functionality: all `os.Args[0]-<binary>` in the $PATH will be available for plugin
plugin.ValidPluginFilenamePrefixes = []string{os.Args[0]}
root.AddCommand(plugin.NewCmdPlugin(f, streams))
root.AddCommand(kubectlcmd.NewDefaultKubectlCommand())

if err := root.Execute(); err != nil {
os.Exit(1)
}
}

// NewCmdNamespace provides a cobra command wrapping NamespaceOptions
func newCmdVerbs(parent string, f cmdutil.Factory, streams genericclioptions.IOStreams) *cobra.Command {
cmd := &cobra.Command{Use: parent}
cmd.AddCommand(
verbs.NewVerbVersion("version", f, streams),
)

return cmd
}
9 changes: 5 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,13 @@ replace (
)

require (
github.com/hashicorp/golang-lru v0.5.4 // indirect
github.com/imdario/mergo v0.3.11 // indirect
github.com/onsi/gomega v1.10.1 // indirect
github.com/open-cluster-management/cm-cli v0.0.0-20210519115358-be3bb81f33d0
github.com/spf13/cobra v1.1.3
k8s.io/api v0.20.5
k8s.io/apimachinery v0.20.5
k8s.io/cli-runtime v0.20.5
k8s.io/client-go v1.5.2
k8s.io/component-base v0.20.1
k8s.io/component-base v0.20.2
k8s.io/kubectl v0.20.1
sigs.k8s.io/controller-runtime v0.8.3
)
Loading

0 comments on commit 05abd7f

Please sign in to comment.