From cc50406c4ced9be74e2aa22b431eff7db172b42f Mon Sep 17 00:00:00 2001 From: ilan-pinto <57443637+ilan-pinto@users.noreply.github.com> Date: Tue, 30 Nov 2021 11:46:21 +0200 Subject: [PATCH] This is a combination of 2 commits. (#77) fixed #68 - added timeout flag short flag name fixed PR comments added tested for timeout removed timout from Options.go Signed-off-by: Ilan Pinto --- .copyrightignore | 3 +- build/run-functional-tests.sh | 50 ++++++++++++++++++++++- pkg/cmd/join/exec.go | 6 +-- pkg/cmd/join/options.go | 1 + pkg/genericclioptions/clusteradm_flags.go | 4 +- 5 files changed, 58 insertions(+), 6 deletions(-) diff --git a/.copyrightignore b/.copyrightignore index f61550b37..4f64eac87 100644 --- a/.copyrightignore +++ b/.copyrightignore @@ -2,4 +2,5 @@ .copyrightignore _generated.go test/functional/resources/hive_v1_clusterdeployment_crd.yaml -vendor \ No newline at end of file +vendor +SECURITY.md \ No newline at end of file diff --git a/build/run-functional-tests.sh b/build/run-functional-tests.sh index fc285eb81..dd7d25a77 100755 --- a/build/run-functional-tests.sh +++ b/build/run-functional-tests.sh @@ -25,8 +25,10 @@ function init_hub() { function join_hub() { echo "join_hub 1st parameter: "$1 >&2 echo "join_hub 2nd parameter: "$2 >&2 + echo "join_hub 3nd parameter: "$3 >&2 + echo "join_hub 4nd parameter: "$4 >&2 local _CMDJOIN=`echo "$1" | cut -d ':' -f2-4 | cut -d '<' -f1` - _CMDJOIN="$_CMDJOIN $2" + _CMDJOIN="$_CMDJOIN $2 $3 $4" local _CMDJOINRESULT=`$_CMDJOIN` if [ $? != 0 ] then @@ -83,6 +85,35 @@ function joinscenario() { fi } +function joinscenario_with_timeout() { + echo "joinscenario 1st parameter: "$1 >&2 + echo "joinscenario 2nd parameter: "$2 >&2 + echo "joinscenario 3nd parameter: "$3 >&2 + echo "init cluster" >&2 + kubectl config use-context kind-${CLUSTER_NAME}-hub + CMDINITRESULT=$(init_hub) + echo "init command result: "$CMDINITRESULT >&2 + + echo "join hub" >&2 + kubectl config use-context kind-${CLUSTER_NAME}-c1 + CMDJOINRESULT=$(join_hub "${CMDINITRESULT}" $1 $2 $3) + echo "join command result: "$CMDJOINRESULT >&2 + + echo "Wait 4 min maximum to stabilize" >&2 + + kubectl config use-context kind-${CLUSTER_NAME}-hub + CMDACCEPTRESULT=$(accept_cluster "${CMDJOINRESULT}") + echo $CMDACCEPTRESULT | grep approved + if [ $? != 0 ] + then + echo "accept command result: "$CMDACCEPTRESULT >&2 + ERROR_REPORT=$ERROR_REPORT+"no CSR get approved\n" + else + echo "accept command result: "$CMDACCEPTRESULT >&2 + fi +} + + function gettokenscenario() { echo "gettokenscenario 1st parameter: "$1 >&2 echo "gettokenscenario 2nd parameter: "$2 >&2 @@ -175,6 +206,23 @@ gettokenscenario c2 kind delete cluster --name ${CLUSTER_NAME}-hub kind delete cluster --name ${CLUSTER_NAME}-c2 +echo "with timeout" +echo "-------------------------------------" + +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}-c1 +#Wait for cluster to setup +echo "Sleep 10 sec" +sleep 10 + +echo "Joining with timeout" +echo "-------------------------------------" +joinscenario_with_timeout c1 --timeout 400 +kind delete cluster --name ${CLUSTER_NAME}-hub +kind delete cluster --name ${CLUSTER_NAME}-c1 + + if [ -z "$ERROR_REPORT" ] then echo "Success" diff --git a/pkg/cmd/join/exec.go b/pkg/cmd/join/exec.go index 9600f19d1..d4060a465 100644 --- a/pkg/cmd/join/exec.go +++ b/pkg/cmd/join/exec.go @@ -56,7 +56,7 @@ func (o *Options) validate() error { return nil } -func (o *Options) run() error { +func (o *Options,) run() error { output := make([]string, 0) reader := scenario.GetScenarioResourcesReader() @@ -120,9 +120,9 @@ func (o *Options) run() error { if err != nil { return err } - output = append(output, out...) + output = append(output, out...) - err = waitUntilConditionIsTrue(o.ClusteradmFlags.KubectlFactory, 300) + err = waitUntilConditionIsTrue(o.ClusteradmFlags.KubectlFactory, int64(o.ClusteradmFlags.Timeout) ) if err != nil { return err } diff --git a/pkg/cmd/join/options.go b/pkg/cmd/join/options.go index f9a7cdd99..f50ca60ca 100644 --- a/pkg/cmd/join/options.go +++ b/pkg/cmd/join/options.go @@ -20,6 +20,7 @@ type Options struct { values Values //The file to output the resources will be sent to the file. outputFile string + } //Values: The values used in the template diff --git a/pkg/genericclioptions/clusteradm_flags.go b/pkg/genericclioptions/clusteradm_flags.go index f79012004..a7af930b0 100644 --- a/pkg/genericclioptions/clusteradm_flags.go +++ b/pkg/genericclioptions/clusteradm_flags.go @@ -9,7 +9,8 @@ import ( type ClusteradmFlags struct { KubectlFactory cmdutil.Factory //if set the resources will be sent to stdout instead of being applied - DryRun bool + DryRun bool; + Timeout int } // NewClusteradmFlags returns ClusteradmFlags with default values set @@ -21,4 +22,5 @@ func NewClusteradmFlags(f cmdutil.Factory) *ClusteradmFlags { func (f *ClusteradmFlags) AddFlags(flags *pflag.FlagSet) { flags.BoolVar(&f.DryRun, "dry-run", false, "If set the generated resources will be displayed but not applied") + flags.IntVar(&f.Timeout, "timeout", 300, "extend timeout from 300 secounds ") }