Skip to content

Commit

Permalink
Merge pull request #6 from itdove/init-cmd
Browse files Browse the repository at this point in the history
Init cmd
  • Loading branch information
openshift-merge-robot authored Jun 3, 2021
2 parents 05abd7f + 37c57d5 commit ea3a619
Show file tree
Hide file tree
Showing 46 changed files with 2,433 additions and 95 deletions.
4 changes: 2 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,14 +36,14 @@ 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
clusteradm <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.
- Each pair (verb/[noum]) has its own package.

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

Expand Down
24 changes: 24 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,28 @@ The commands are composed of a verb and a noun and then a number of parameters.

### version

Display the clusteradm version and the kubeversion

`clusteradm version`

### init

Initialize the hub by deploying the hub side resources to manage clusters.

`clusteradm init`

it returns the command line to launch on the spoke to join the hub.

### join

Install the agent on the spoke.

`clusteradm join --hub-token <token> --hub-apiserver <hub_apiserver_url> --cluster_name c1`

it returns the command line to launch on the hub the accept the spoke onboarding.

### accept

Accept the CSRs on the hub to approve the spoke clusters to join the hub.

`clustardm accept --clusters <cluster1>, <cluster2>,....`
58 changes: 56 additions & 2 deletions build/run-functional-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ export KUBECONFIG=$TEST_DIR/tmp/kind.yaml
rm -rf $TEST_RESULT_DIR
mkdir -p $TEST_RESULT_DIR

kind create cluster --name ${CLUSTER_NAME}
export KUBECONFIG=$TEST_DIR/tmp/config.yaml
kind create cluster --name ${CLUSTER_NAME}-hub --config $TEST_DIR/kind-config/kind119-hub.yaml
kind create cluster --name ${CLUSTER_NAME}-spoke
#Wait for cluster to setup
sleep 10

Expand All @@ -23,6 +25,57 @@ then
ERROR_REPORT=$ERROR_REPORT+"clusteradm version failed\n"
fi

kubectl config use-context kind-${CLUSTER_NAME}-hub
CMDINITRESULT=`clusteradm init`
if [ $? != 0 ]
then
echo "init command result: "$CMDINITRESULT
ERROR_REPORT=$ERROR_REPORT+"clusteradm init failed\n"
else
echo "init command result: "$CMDINITRESULT
echo $CMDINITRESULT
fi

CMDJOIN=`echo $CMDINITRESULT | cut -d ':' -f2,3,4 | cut -d '<' -f1`
CMDJOIN="$CMDJOIN c1"
echo "Join command: "$CMDJOIN
kubectl config use-context kind-${CLUSTER_NAME}-spoke
CMDJOINRESULT=`$CMDJOIN`
if [ $? != 0 ]
then
echo "join command result: " $CMDJOINRESULT
ERROR_REPORT=$ERROR_REPORT+"clusteradm join failed\n"
else
echo "join command result: " $CMDJOINRESULT
fi

echo "Sleep 2 min to stabilize"
# we need to wait 2 min but once we will have watch status monitor
# we will not need to sleep anymore
sleep 120

CMDACCEPT=`echo $CMDJOINRESULT | cut -d ':' -f2`
CMDACCEPT="$CMDACCEPT c1"
echo "accept command: "$CMDACCEPT
kubectl config use-context kind-${CLUSTER_NAME}-hub
CMDACCEPTRESULT=`$CMDACCEPT`
if [ $? != 0 ]
then
echo "accept command result: "$CMDACCEPTRESULT
ERROR_REPORT=$ERROR_REPORT+"clusteradm accept failed\n"
else
echo "accept command result: "$CMDACCEPTRESULT
fi

echo $CMDACCEPTRESULT | grep approved
if [ $? != 0 ]
then
echo "accept command result: "$CMDACCEPTRESULT
ERROR_REPORT=$ERROR_REPORT+"no CSR get approved\n"
else
echo "accept command result: "$CMDACCEPTRESULT
fi

if [ -z "$ERROR_REPORT" ]
then
echo "Success"
Expand All @@ -31,4 +84,5 @@ else
exit 1
fi

kind delete cluster --name $CLUSTER_NAME
kind delete cluster --name $CLUSTER_NAME-hub
kind delete cluster --name $CLUSTER_NAME-spoke
5 changes: 3 additions & 2 deletions cmd/clusteradm.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ import (
"k8s.io/cli-runtime/pkg/genericclioptions"
"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"
Expand Down Expand Up @@ -39,7 +38,6 @@ func main() {
//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)
Expand All @@ -51,6 +49,9 @@ func newCmdVerbs(parent string, f cmdutil.Factory, streams genericclioptions.IOS
cmd := &cobra.Command{Use: parent}
cmd.AddCommand(
verbs.NewVerbVersion("version", f, streams),
verbs.NewVerbInit("init", f, streams),
verbs.NewVerbJoin("join", f, streams),
verbs.NewVerbAccept("accept", f, streams),
)

return cmd
Expand Down
6 changes: 0 additions & 6 deletions docs/applier.md

This file was deleted.

25 changes: 17 additions & 8 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,26 @@ go 1.16

replace (
github.com/go-logr/logr => github.com/go-logr/logr v0.4.0
k8s.io/client-go => k8s.io/client-go v0.20.4
k8s.io/client-go => k8s.io/client-go v0.21.0
)

require (
github.com/open-cluster-management/cm-cli v0.0.0-20210519115358-be3bb81f33d0
github.com/Masterminds/goutils v1.1.1 // indirect
github.com/Masterminds/semver v1.5.0 // indirect
github.com/Masterminds/sprig v2.22.0+incompatible
github.com/ghodss/yaml v1.0.0
github.com/huandu/xstrings v1.3.2 // indirect
github.com/mitchellh/copystructure v1.2.0 // indirect
github.com/openshift/library-go v0.0.0-20210521084623-7392ea9b02ca
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.2
k8s.io/kubectl v0.20.1
k8s.io/api v0.21.1
k8s.io/apiextensions-apiserver v0.21.1
k8s.io/apimachinery v0.21.1
k8s.io/cli-runtime v0.21.0
k8s.io/client-go v0.21.1
k8s.io/component-base v0.21.1
k8s.io/klog v1.0.0
k8s.io/kubectl v0.21.0
open-cluster-management.io/api v0.0.0-20210519100835-bb9d4652f920
sigs.k8s.io/controller-runtime v0.8.3
)
Loading

0 comments on commit ea3a619

Please sign in to comment.