Skip to content

Commit

Permalink
Merge pull request kosmos-io#602 from OrangeBao/release-0.4.0-cert
Browse files Browse the repository at this point in the history
fix: do sync after globalnode created and add retry
  • Loading branch information
duanmengkk authored May 30, 2024
2 parents fd0b73c + 8d4ba84 commit 6c2496f
Show file tree
Hide file tree
Showing 5 changed files with 77 additions and 4 deletions.
66 changes: 66 additions & 0 deletions hack/k8s-in-k8s/free_globalnodes.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
#!/bin/bash

filename="nodes.txt"
readarray -t globalnodes < "$filename"

function deleteState() {
local nodename="$1"
kubectl patch globalnodes $nodename -p '{"spec": {"state": "free"}}' --type=merge
}

function updateNodeState() {
local nodename="$1"
kubectl patch node $nodename -p '{"metadata": {"labels": {"kosmos-io/state": "free"}}}'
}

# Update the state of the global nodes
function free_globalnodes() {
local globalnode="$1"
deleteState "$globalnode"
updateNodeState "$globalnode"
}



# Function to display progress bar
show_progress() {
local progress=$1
local total=$2
local width=$3

# Calculate percentage
local percent=$((progress * 100 / total))
local num_hashes=$((percent * width / 100))

# Generate progress bar
local bar="["
for ((i = 0; i < width; i++)); do
if ((i < num_hashes)); then
bar+="#"
else
bar+=" "
fi
done
bar+="]"

# Print progress bar with percentage
printf "\rProgress: %s %d%%" "$bar" "$percent"
}

# Total steps for the task
total_steps=${#globalnodes[@]}
# Width of the progress bar
bar_width=50

# Simulate a task by looping through steps
for ((step = 1; step <= total_steps; step++)); do
# Simulate work with sleep
index=$((step - 1))
free_globalnodes ${globalnodes[index]}

# Update progress bar
show_progress $step $total_steps $bar_width
done

# Print a new line after the progress bar completes
echo
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,8 @@ func (r *GlobalNodeController) Reconcile(ctx context.Context, request reconcile.
return reconcile.Result{RequeueAfter: utils.DefaultRequeueTime}, nil
}
klog.V(4).Infof("global-node-controller: %s has been created", globalNode.Name)
return reconcile.Result{}, nil
// do sync label and taint
return reconcile.Result{RequeueAfter: utils.DefaultRequeueTime}, nil
}
klog.Errorf("get global-node %s error: %v", request.NamespacedName, err)
return reconcile.Result{RequeueAfter: utils.DefaultRequeueTime}, nil
Expand Down
2 changes: 1 addition & 1 deletion pkg/kubenest/tasks/anp.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package tasks
import (
"context"
"fmt"
apiclient "github.com/kosmos.io/kosmos/pkg/kubenest/util/api-client"
"strings"

"github.com/pkg/errors"
Expand All @@ -21,6 +20,7 @@ import (
"github.com/kosmos.io/kosmos/pkg/kubenest/constants"
"github.com/kosmos.io/kosmos/pkg/kubenest/manifest/controlplane/apiserver"
"github.com/kosmos.io/kosmos/pkg/kubenest/util"
apiclient "github.com/kosmos.io/kosmos/pkg/kubenest/util/api-client"
"github.com/kosmos.io/kosmos/pkg/kubenest/workflow"
)

Expand Down
5 changes: 4 additions & 1 deletion pkg/kubenest/tasks/coredns.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (

"github.com/kosmos.io/kosmos/pkg/kubenest/constants"
"github.com/kosmos.io/kosmos/pkg/kubenest/util"
apiclient "github.com/kosmos.io/kosmos/pkg/kubenest/util/api-client"
"github.com/kosmos.io/kosmos/pkg/kubenest/workflow"
)

Expand Down Expand Up @@ -278,7 +279,9 @@ func applyYMLTemplate(dynamicClient dynamic.Interface, manifestGlob string, temp
return errors.Wrapf(err, "Unmarshal manifest bytes data error")
}

err = util.CreateObject(dynamicClient, obj.GetNamespace(), obj.GetName(), &obj)
err = apiclient.TryRunCommand(func() error {
return util.CreateObject(dynamicClient, obj.GetNamespace(), obj.GetName(), &obj)
}, 3)
if err != nil {
return errors.Wrapf(err, "Create object error")
}
Expand Down
5 changes: 4 additions & 1 deletion pkg/kubenest/tasks/manifests_components.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (

"github.com/kosmos.io/kosmos/pkg/kubenest/constants"
"github.com/kosmos.io/kosmos/pkg/kubenest/util"
apiclient "github.com/kosmos.io/kosmos/pkg/kubenest/util/api-client"
"github.com/kosmos.io/kosmos/pkg/kubenest/workflow"
)

Expand Down Expand Up @@ -161,7 +162,9 @@ func applyTemplatedManifests(component string, dynamicClient dynamic.Interface,
}
obj = unstructured.Unstructured{Object: res}
}
err = util.CreateObject(dynamicClient, obj.GetNamespace(), obj.GetName(), &obj)
err = apiclient.TryRunCommand(func() error {
return util.CreateObject(dynamicClient, obj.GetNamespace(), obj.GetName(), &obj)
}, 3)
if err != nil {
return errors.Wrapf(err, "Create object error")
}
Expand Down

0 comments on commit 6c2496f

Please sign in to comment.