Skip to content

Commit

Permalink
This is a combination of 2 commits. (#77)
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
ilan-pinto authored Nov 30, 2021
1 parent bd474f3 commit cc50406
Show file tree
Hide file tree
Showing 5 changed files with 58 additions and 6 deletions.
3 changes: 2 additions & 1 deletion .copyrightignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@
.copyrightignore
_generated.go
test/functional/resources/hive_v1_clusterdeployment_crd.yaml
vendor
vendor
SECURITY.md
50 changes: 49 additions & 1 deletion build/run-functional-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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"
Expand Down
6 changes: 3 additions & 3 deletions pkg/cmd/join/exec.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down Expand Up @@ -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
}
Expand Down
1 change: 1 addition & 0 deletions pkg/cmd/join/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 3 additions & 1 deletion pkg/genericclioptions/clusteradm_flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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 ")
}

0 comments on commit cc50406

Please sign in to comment.