Skip to content

Commit 4006ead

Browse files
committed
fix test
1 parent 83d9b0d commit 4006ead

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

controllers/workloads/instance_controller.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ import (
2424

2525
corev1 "k8s.io/api/core/v1"
2626
rbacv1 "k8s.io/api/rbac/v1"
27+
apierrors "k8s.io/apimachinery/pkg/api/errors"
2728
"k8s.io/apimachinery/pkg/runtime"
2829
"k8s.io/client-go/tools/record"
2930
ctrl "sigs.k8s.io/controller-runtime"
@@ -129,12 +130,15 @@ func (r *InstanceReconciler) SetupWithManager(mgr ctrl.Manager) error {
129130
func (r *InstanceReconciler) listPods(ctx context.Context, req ctrl.Request) ([]*corev1.Pod, error) {
130131
instance := &workloadsv1.Instance{}
131132
if err := r.Get(ctx, req.NamespacedName, instance); err != nil {
133+
if apierrors.IsNotFound(err) {
134+
// pod may not be created yet
135+
return nil, nil
136+
}
132137
return nil, err
133138
}
134139
matchingLabels := map[string]string{
135-
constant.AppManagedByLabelKey: constant.AppName,
136-
instanceset2.WorkloadsManagedByLabelKey: workloadsv1.InstanceSetKind,
137-
instanceset2.WorkloadsInstanceLabelKey: instance.Labels[instanceset2.WorkloadsInstanceLabelKey],
140+
constant.AppManagedByLabelKey: constant.AppName,
141+
instanceset2.WorkloadsInstanceLabelKey: instance.Labels[instanceset2.WorkloadsInstanceLabelKey],
138142
}
139143

140144
podList := &corev1.PodList{}

pkg/controller/instance/utils.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ import (
3232
workloads "github.com/apecloud/kubeblocks/apis/workloads/v1"
3333
"github.com/apecloud/kubeblocks/pkg/constant"
3434
"github.com/apecloud/kubeblocks/pkg/controller/builder"
35+
"github.com/apecloud/kubeblocks/pkg/controller/instanceset2"
3536
"github.com/apecloud/kubeblocks/pkg/controller/model"
3637
intctrlutil "github.com/apecloud/kubeblocks/pkg/controllerutil"
3738
)
@@ -204,6 +205,7 @@ func buildInstancePod(inst *workloads.Instance, revision string) (*corev1.Pod, e
204205
AddLabelsInMap(labels).
205206
AddLabels(constant.KBAppPodNameLabelKey, inst.Name). // used as a pod-service selector
206207
AddLabels(constant.KBAppInstanceTemplateLabelKey, inst.Spec.InstanceTemplateName).
208+
AddLabels(instanceset2.WorkloadsInstanceLabelKey, inst.Labels[instanceset2.WorkloadsInstanceLabelKey]). // to select pods by instanceset
207209
AddControllerRevisionHashLabel(revision).
208210
SetPodSpec(*inst.Spec.Template.Spec.DeepCopy()).
209211
GetObject()

0 commit comments

Comments
 (0)