Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
Signed-off-by: Dominique Vernier <[email protected]>
  • Loading branch information
itdove committed May 20, 2021
1 parent be3bb81 commit 66ff5b9
Show file tree
Hide file tree
Showing 112 changed files with 44 additions and 6,521 deletions.
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -24,15 +24,15 @@ deps:

.PHONY: build
build:
go install ./cmd/cm.go
go install ./cmd/clusteradm.go

.PHONY: install
install: build

.PHONY: plugin
plugin: build
cp ${GOPATH}/bin/cm ${GOPATH}/bin/oc-cm
cp ${GOPATH}/bin/cm ${GOPATH}/bin/kubectl-cm
cp ${GOPATH}/bin/clusteradm ${GOPATH}/bin/oc-clusteradm
cp ${GOPATH}/bin/clusteradm${GOPATH}/bin/kubectl-clusteradm

.PHONY: check
## Runs a set of required checks
Expand Down
10 changes: 3 additions & 7 deletions OWNERS
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
approvers:
- gurnben
- dhaiducek
- KevinFCormier
- itdove
- qiujian16

reviewers:
- gurnben
- dhaiducek
- KevinFCormier
- itdove
- itdove
- qiujian16
22 changes: 10 additions & 12 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[comment]: # ( Copyright Contributors to the Open Cluster Management project )
# Open Cluster Management CLI & CLI Plugin
# clusteeradm 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.

Expand All @@ -13,25 +13,25 @@ The binary will be installed in GOPATH/bin
### CLI

```bash
git clone https://github.com/open-cluster-management/cm-cli.git
cd cm-cli
git clone https://github.com/open-cluster-management-io/clusteradm.git
cd clusteradmin
make build
cm
```

### Plugin

This will create a binary `oc-cm` and `kubectl-cm` in the `$GOPATH/go/bin` allowing you to call `oc cm` or `kubectl cm`
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://github.com/open-cluster-management/cm-cli.git
cd cm-cli
git clone https://github.com/open-cluster-management-io/clusteradm.git
cd clusteradm
make plugin
kubectl cm
oc cm
kubectl clusteradm
oc clusteradm
```
## Disclaimer

This CLI (and plugin) is still in development, but aims to expose OCM/ACM'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!
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

Expand All @@ -43,6 +43,4 @@ The commands are composed of a verb and a noun and then a number of parameters.

## Cluster commands

[applier](docs/applier.md)

[cluster](docs/cluster.md)
[applier](docs/applier.md)
86 changes: 5 additions & 81 deletions build/run-functional-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,90 +13,14 @@ rm -rf $TEST_RESULT_DIR
mkdir -p $TEST_RESULT_DIR

kind create cluster --name ${CLUSTER_NAME}
kind get kubeconfig --name ${CLUSTER_NAME} > ${TEST_DIR}/tmp/kind.yaml
#Wait for cluster to setup
sleep 10

# Configure the kind cluster
cm applier -d $TEST_DIR/resources

echo "Test cm create cluster AWS"
cm create cluster --values $TEST_DIR/create/cluster/aws_values.yaml -o $TEST_RESULT_DIR/aws_result.yaml
diff -u $TEST_DIR/create/cluster/aws_result.yaml $TEST_RESULT_DIR/aws_result.yaml
if [ $? != 0 ]
then
ERROR_REPORT=$ERROR_REPORT+"create/cluster/deploy.sh AWS failed\n"
fi

echo "Test cm create cluster Azure"
cm create cluster --values $TEST_DIR/create/cluster/azure_values.yaml -o $TEST_RESULT_DIR/azure_result.yaml
diff -u $TEST_DIR/create/cluster/azure_result.yaml $TEST_RESULT_DIR/azure_result.yaml
if [ $? != 0 ]
then
ERROR_REPORT=$ERROR_REPORT+"cm create cluster Azure failed\n"
fi

echo "Test cm create cluster GCP"
cm create cluster --values $TEST_DIR/create/cluster/gcp_values.yaml -o $TEST_RESULT_DIR/gcp_result.yaml
diff -u $TEST_DIR/create/cluster/gcp_result.yaml $TEST_RESULT_DIR/gcp_result.yaml
if [ $? != 0 ]
then
ERROR_REPORT=$ERROR_REPORT+"cm create cluster GCP failed\n"
fi

echo "Test cm create cluster OpenStack"
cm create cluster --values $TEST_DIR/create/cluster/openstack_values.yaml -o $TEST_RESULT_DIR/openstack_result.yaml
diff -u $TEST_DIR/create/cluster/openstack_result.yaml $TEST_RESULT_DIR/openstack_result.yaml
if [ $? != 0 ]
then
ERROR_REPORT=$ERROR_REPORT+"cm create cluster OpenStack failed\n"
fi

echo "Test cm create cluster vSphere"
cm create cluster --values $TEST_DIR/create/cluster/vsphere_values.yaml -o $TEST_RESULT_DIR/vsphere_result.yaml
diff -u $TEST_DIR/create/cluster/vsphere_result.yaml $TEST_RESULT_DIR/vsphere_result.yaml
if [ $? != 0 ]
then
ERROR_REPORT=$ERROR_REPORT+"cm create cluster vSphere failed\n"
fi

echo "Test cm attach cluster manual"
cm attach cluster --values $TEST_DIR/attach/cluster/manual_values.yaml -o $TEST_RESULT_DIR/manual_result.yaml
diff -u $TEST_DIR/attach/cluster/manual_result.yaml $TEST_RESULT_DIR/manual_result.yaml
if [ $? != 0 ]
then
ERROR_REPORT=$ERROR_REPORT+"cm attach cluster manual failed\n"
fi

echo "Test cm attach cluster no values.yaml"
cm attach cluster --name mycluster -o $TEST_RESULT_DIR/manual_no_values_result.yaml
diff -u $TEST_DIR/attach/cluster/manual_no_values_result.yaml $TEST_RESULT_DIR/manual_no_values_result.yaml
if [ $? != 0 ]
then
ERROR_REPORT=$ERROR_REPORT+"cm attach cluster manual failed without values.yaml\n"
fi


echo "Test cm attach cluster kubeconfig"
cm attach cluster --values $TEST_DIR/attach/cluster/kubeconfig_values.yaml -o $TEST_RESULT_DIR/kubeconfig_result.yaml
diff -u $TEST_DIR/attach/cluster/kubeconfig_result.yaml $TEST_RESULT_DIR/kubeconfig_result.yaml
if [ $? != 0 ]
then
ERROR_REPORT=$ERROR_REPORT+"cm attach cluster kubeconfig failed\n"
fi

echo "Test cm attach cluster kubeconfig no values.yaml with kubeconfig"
cm attach cluster --name mycluster --cluster-kubeconfig $TEST_DIR/attach/cluster/fake-kubeconfig.yaml -o $TEST_RESULT_DIR/kubeconfig_no_values_result.yaml
diff -u $TEST_DIR/attach/cluster/kubeconfig_no_values_result.yaml $TEST_RESULT_DIR/kubeconfig_no_values_result.yaml
if [ $? != 0 ]
then
ERROR_REPORT=$ERROR_REPORT+"cm attach cluster kubeconfig failed without values.yaml\n"
fi

echo "Test cm attach cluster token"
cm attach cluster --values $TEST_DIR/attach/cluster/token_values.yaml -o $TEST_RESULT_DIR/token_result.yaml
diff -u $TEST_DIR/attach/cluster/token_result.yaml $TEST_RESULT_DIR/token_result.yaml
echo "Test clusteradm get secret"
clusteradm get secret -n default
if [ $? != 0 ]
then
ERROR_REPORT=$ERROR_REPORT+"cm attach cluster token failed\n"
ERROR_REPORT=$ERROR_REPORT+"clusteradm get secret -n default failed\n"
fi

if [ -z "$ERROR_REPORT" ]
Expand Down
36 changes: 12 additions & 24 deletions cmd/cm.go → cmd/clusteradm.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (

"github.com/spf13/cobra"

"github.com/open-cluster-management/cm-cli/pkg/cmd/verbs"
"github.com/open-cluster-management-io/clusteradm/pkg/cmd/verbs"
"k8s.io/cli-runtime/pkg/genericclioptions"
"k8s.io/client-go/tools/clientcmd"
cliflag "k8s.io/component-base/cli/flag"
Expand All @@ -18,51 +18,39 @@ import (

func main() {
streams := genericclioptions.IOStreams{In: os.Stdin, Out: os.Stdout, ErrOut: os.Stderr}
root := NewRootCMD("clusteradm", streams)
if err := root.Execute(); err != nil {
os.Exit(1)
}
}

// flags := pflag.NewFlagSet("cm", pflag.ExitOnError)
// pflag.CommandLine = flags
func NewRootCMD(parent string, streams genericclioptions.IOStreams) *cobra.Command {

configFlags := genericclioptions.NewConfigFlags(true).WithDeprecatedPasswordFlag()
matchVersionKubeConfigFlags := cmdutil.NewMatchVersionFlags(configFlags)
f := cmdutil.NewFactory(matchVersionKubeConfigFlags)

root := newCmdCMVerbs(f, streams)
root := newCmdCMVerbs(parent, f, streams)

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

// Normalize all flags that are coming from other packages or pre-configurations
// a.k.a. change all "_" to "-". e.g. glog package
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(plugin.NewCmdPlugin(f, streams))
// root.AddCommand(version.NewCmdVersion(f, streams))
// root.AddCommand(apiresources.NewCmdAPIVersions(f, streams))
// root.AddCommand(apiresources.NewCmdAPIResources(f, streams))
root.AddCommand(options.NewCmdOptions(streams.Out))

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

// NewCmdNamespace provides a cobra command wrapping NamespaceOptions
func newCmdCMVerbs(f cmdutil.Factory, streams genericclioptions.IOStreams) *cobra.Command {
cmd := &cobra.Command{Use: "cm"}
func newCmdCMVerbs(parent string, f cmdutil.Factory, streams genericclioptions.IOStreams) *cobra.Command {
cmd := &cobra.Command{Use: parent}
cmd.AddCommand(
verbs.NewVerb("create", f, streams),
verbs.NewVerb("get", f, streams),
// verbs.NewVerb("update", streams),
verbs.NewVerb("delete", f, streams),
// verbs.NewVerb("list", streams),
verbs.NewVerb("applier", f, streams),
verbs.NewVerb("attach", f, streams),
verbs.NewVerb("detach", f, streams),
verbs.NewVerb(parent, "get", f, streams),
)

return cmd
Expand Down
85 changes: 0 additions & 85 deletions docs/cluster.md

This file was deleted.

9 changes: 3 additions & 6 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module github.com/open-cluster-management/cm-cli
module github.com/open-cluster-management-io/clusteradm

go 1.16

Expand All @@ -9,15 +9,12 @@ replace (

require (
github.com/ghodss/yaml v1.0.0
github.com/huandu/xstrings v1.3.2 // indirect
github.com/open-cluster-management/applier v0.0.0-20210422205113-6c10f923726b
github.com/spf13/cobra v1.1.3
github.com/spf13/pflag v1.0.5
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 // indirect
k8s.io/component-base v0.20.1 // indirect
k8s.io/client-go v1.5.2
k8s.io/component-base v0.20.1
k8s.io/kubectl v0.20.1
sigs.k8s.io/controller-runtime v0.6.2
)
3 changes: 1 addition & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -295,9 +295,8 @@ github.com/hashicorp/mdns v1.0.0/go.mod h1:tL+uN++7HEJ6SQLQ2/p+z2pH24WQKWjBPkE0m
github.com/hashicorp/memberlist v0.1.3/go.mod h1:ajVTdAv/9Im8oMAAj5G31PhhMCZJV2pPBoIllUwCN7I=
github.com/hashicorp/serf v0.8.2/go.mod h1:6hOLApaqBFA1NXqRQAsxw9QxuDEvNxSQRwA/JwenrHc=
github.com/hpcloud/tail v1.0.0/go.mod h1:ab1qPbhIpdTxEkNHXyeSf5vhxWSCs/tWer42PpOxQnU=
github.com/huandu/xstrings v1.3.1 h1:4jgBlKK6tLKFvO8u5pmYjG91cqytmDCDvGh7ECVFfFs=
github.com/huandu/xstrings v1.3.1/go.mod h1:y5/lhBue+AyNmUVz9RLU9xbLR0o4KIIExikq4ovT0aE=
github.com/huandu/xstrings v1.3.2 h1:L18LIDzqlW6xN2rEkpdV8+oL/IXWJ1APd+vsdYy4Wdw=
github.com/huandu/xstrings v1.3.2/go.mod h1:y5/lhBue+AyNmUVz9RLU9xbLR0o4KIIExikq4ovT0aE=
github.com/ianlancetaylor/demangle v0.0.0-20181102032728-5e5cf60278f6/go.mod h1:aSSvb/t6k1mPoxDqO4vJh6VOCGPwU4O0C2/Eqndh1Sc=
github.com/imdario/mergo v0.3.5/go.mod h1:2EnlNZ0deacrJVfApfmtdGgDfMuh/nq6Ok1EcJh5FfA=
github.com/imdario/mergo v0.3.9/go.mod h1:2EnlNZ0deacrJVfApfmtdGgDfMuh/nq6Ok1EcJh5FfA=
Expand Down
4 changes: 2 additions & 2 deletions pkg/cmd/applierscenarios/applierscenarioreader_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ var testDir = filepath.Join("..", "..", "..", "test", "unit")
var testDirTmp = filepath.Join(testDir, "tmp")

func TestResources_Asset(t *testing.T) {
asset := "embed_test/detach/hub/managed_cluster_cr.yaml"
asset := "embed_test/namespace.yaml"
basset, errFile := ioutil.ReadFile(asset)
if errFile != nil {
t.Error(errFile)
Expand All @@ -37,7 +37,7 @@ func TestResources_Asset(t *testing.T) {
name: "Existing asset",
b: NewApplierScenarioResourcesReader(&files),
args: args{
name: "embed_test/detach/hub/managed_cluster_cr.yaml",
name: "embed_test/namespace.yaml",
},
want: basset,
wantErr: false,
Expand Down
Loading

0 comments on commit 66ff5b9

Please sign in to comment.