Skip to content

Commit

Permalink
fix yurtstaticset workerpod reset error (openyurtio#1526)
Browse files Browse the repository at this point in the history
  • Loading branch information
JameKeal committed Jun 9, 2023
1 parent a41d320 commit e574070
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 5 deletions.
5 changes: 3 additions & 2 deletions pkg/controller/yurtstaticset/upgradeinfo/upgrade_info.go
Original file line number Diff line number Diff line change
Expand Up @@ -88,8 +88,9 @@ func New(c client.Client, instance *appsv1alpha1.YurtStaticSet, workerPodName, h
}
}

// The name format of worker pods are `WorkerPodName-NodeName-Hash` Todo: may lead to mismatch
if strings.Contains(pod.Name, workerPodName) {
// The name format of worker pods are `WorkerPodName-YssName-NodeName-Hash`
name := workerPodName + instance.Name
if strings.Contains(pod.Name, name) {
// initialize worker pod info
if err := initWorkerPodInfo(nodeName, hash, &podList.Items[i], infos); err != nil {
return nil, err
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ func newNodes(nodeNames []string) []client.Object {
func newPod(podName string, nodeName string, namespace string, isStaticPod bool) *corev1.Pod {
pod := &corev1.Pod{
ObjectMeta: metav1.ObjectMeta{
Name: UpgradeWorkerPodPrefix + rand.String(10),
Name: UpgradeWorkerPodPrefix + podName + "-" + rand.String(10),
Namespace: namespace,
},
Spec: corev1.PodSpec{NodeName: nodeName},
Expand Down
4 changes: 2 additions & 2 deletions pkg/controller/yurtstaticset/yurtstaticset_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ const (
hostPathVolumeSourcePath = hostPathVolumeMountPath

// UpgradeWorkerPodPrefix is the name prefix of worker pod which used for static pod upgrade
UpgradeWorkerPodPrefix = "yurt-static-set-upgrade-worker-"
UpgradeWorkerPodPrefix = "yss-upgrade-worker-"
UpgradeWorkerContainerName = "upgrade-worker"

ArgTmpl = "/usr/local/bin/node-servant static-pod-upgrade --name=%s --namespace=%s --manifest=%s --hash=%s --mode=%s"
Expand Down Expand Up @@ -499,7 +499,7 @@ func (r *ReconcileYurtStaticSet) removeUnusedPods(pods []*corev1.Pod) error {
func createUpgradeWorker(c client.Client, instance *appsv1alpha1.YurtStaticSet, nodes []string, hash, mode, img string) error {
for _, node := range nodes {
pod := upgradeWorker.DeepCopy()
pod.Name = UpgradeWorkerPodPrefix + util.Hyphen(node, hash)
pod.Name = UpgradeWorkerPodPrefix + instance.Name + "-" + util.Hyphen(node, hash)
pod.Namespace = instance.Namespace
pod.Spec.NodeName = node
metav1.SetMetaDataAnnotation(&pod.ObjectMeta, StaticPodHashAnnotation, hash)
Expand Down

0 comments on commit e574070

Please # to comment.