Skip to content

Commit 34ee557

Browse files
committed
wip
1 parent 53e41ad commit 34ee557

File tree

4 files changed

+14
-11
lines changed

4 files changed

+14
-11
lines changed

pkg/controller/instance/utils.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -367,5 +367,5 @@ func newLifecycleAction(inst *workloads.Instance, objects []client.Object, pod *
367367
pods = append(pods, objects[i].(*corev1.Pod))
368368
}
369369
return lifecycle.New(inst.Namespace, clusterName, compName,
370-
lifecycleActions, inst.Spec.LifecycleActions.TemplateVars, pod, pods...)
370+
lifecycleActions, inst.Spec.LifecycleActions.TemplateVars, pod, pods)
371371
}

pkg/controller/instanceset/reconciler_update.go

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,11 @@ func (r *updateReconciler) switchover(tree *kubebuilderx.ObjectTree, its *worklo
279279
return nil
280280
}
281281

282-
lfa, err := newLifecycleAction(its, nil, pod)
282+
pods := make([]*corev1.Pod, 0)
283+
for _, object := range tree.List(&corev1.Pod{}) {
284+
pods = append(pods, object.(*corev1.Pod))
285+
}
286+
lfa, err := newLifecycleAction(its, pods, pod)
283287
if err != nil {
284288
return err
285289
}
@@ -318,7 +322,11 @@ func (r *updateReconciler) reconfigureConfig(tree *kubebuilderx.ObjectTree, its
318322
itsCopy.Spec.LifecycleActions = &workloads.LifecycleActions{}
319323
}
320324
itsCopy.Spec.LifecycleActions.Reconfigure = config.Reconfigure
321-
lfa, err := newLifecycleAction(itsCopy, nil, pod)
325+
pods := make([]*corev1.Pod, 0)
326+
for _, object := range tree.List(&corev1.Pod{}) {
327+
pods = append(pods, object.(*corev1.Pod))
328+
}
329+
lfa, err := newLifecycleAction(itsCopy, pods, pod)
322330
if err != nil {
323331
return err
324332
}

pkg/controller/instanceset/utils.go

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ import (
3030
"k8s.io/apimachinery/pkg/util/intstr"
3131
"k8s.io/apimachinery/pkg/util/sets"
3232
"k8s.io/utils/integer"
33-
"sigs.k8s.io/controller-runtime/pkg/client"
3433

3534
kbappsv1 "github.com/apecloud/kubeblocks/apis/apps/v1"
3635
workloads "github.com/apecloud/kubeblocks/apis/workloads/v1"
@@ -203,19 +202,15 @@ func getMemberUpdateStrategy(its *workloads.InstanceSet) workloads.MemberUpdateS
203202
return updateStrategy
204203
}
205204

206-
func newLifecycleAction(its *workloads.InstanceSet, objects []client.Object, pod *corev1.Pod) (lifecycle.Lifecycle, error) {
205+
func newLifecycleAction(its *workloads.InstanceSet, pods []*corev1.Pod, pod *corev1.Pod) (lifecycle.Lifecycle, error) {
207206
var (
208207
clusterName = its.Labels[constant.AppInstanceLabelKey]
209208
compName = its.Labels[constant.KBAppComponentLabelKey]
210209
lifecycleActions = &kbappsv1.ComponentLifecycleActions{
211210
Switchover: its.Spec.LifecycleActions.Switchover,
212211
Reconfigure: its.Spec.LifecycleActions.Reconfigure,
213212
}
214-
pods []*corev1.Pod
215213
)
216-
for i := range objects {
217-
pods = append(pods, objects[i].(*corev1.Pod))
218-
}
219214
return lifecycle.New(its.Namespace, clusterName, compName,
220-
lifecycleActions, its.Spec.LifecycleActions.TemplateVars, pod, pods...)
215+
lifecycleActions, its.Spec.LifecycleActions.TemplateVars, pod, pods)
221216
}

pkg/controller/lifecycle/lifecycle.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ func New(namespace, clusterName, compName string, lifecycleActions *appsv1.Compo
6565
return nil, fmt.Errorf("pods must be provided to call lifecycle actions")
6666
}
6767
if pod == nil {
68-
pod = pods[0]
68+
return nil, fmt.Errorf("target pod must be provided to call lifecycle actions")
6969
}
7070
return &kbagent{
7171
namespace: namespace,

0 commit comments

Comments
 (0)