Skip to content

Commit 52e4275

Browse files
zmbergfurykerry
authored andcommitted
sandbox add scaleexpectation for create pod
Signed-off-by: liheng <liheng.zms@alibaba-inc.com>
1 parent d2fe50c commit 52e4275

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

pkg/controller/sandbox/core/common_control.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ import (
3131

3232
agentsv1alpha1 "github.com/openkruise/agents/api/v1alpha1"
3333
"github.com/openkruise/agents/pkg/utils"
34+
"github.com/openkruise/agents/pkg/utils/expectations"
3435
"github.com/openkruise/agents/pkg/utils/inplaceupdate"
3536
)
3637

@@ -304,9 +305,10 @@ func (r *commonControl) createPod(ctx context.Context, box *agentsv1alpha1.Sandb
304305
})
305306
}
306307
pod.Spec.Volumes = append(pod.Spec.Volumes, volumes...)
307-
308+
ScaleExpectation.ExpectScale(GetControllerKey(box), expectations.Create, box.Name)
308309
err := r.Create(ctx, pod)
309310
if err != nil && !errors.IsAlreadyExists(err) {
311+
ScaleExpectation.ObserveScale(GetControllerKey(box), expectations.Create, box.Name)
310312
logger.Error(err, "create pod failed")
311313
return nil, err
312314
}

pkg/controller/sandbox/core/util.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ import (
2323
agentsv1alpha1 "github.com/openkruise/agents/api/v1alpha1"
2424
"github.com/openkruise/agents/pkg/utils"
2525
corev1 "k8s.io/api/core/v1"
26+
"k8s.io/apimachinery/pkg/types"
27+
"sigs.k8s.io/controller-runtime/pkg/client"
2628
)
2729

2830
// HashSandbox calculates the hash value using sandbox.spec.template
@@ -58,3 +60,7 @@ func GeneratePVCName(templateName, sandboxName string) (string, error) {
5860

5961
return name, nil
6062
}
63+
64+
func GetControllerKey(obj client.Object) string {
65+
return types.NamespacedName{Namespace: obj.GetNamespace(), Name: obj.GetName()}.String()
66+
}

0 commit comments

Comments
 (0)