/
githubmirror
/
kubernetes
Обзор
Документация
Войти
/
githubmirror
/
kubernetes
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
pkg/scheduler/framework/plugins/defaultbinder/default_binder.go
76 строк
2 KB
Antoni Basista
Add retrying for Bind API calls. With podGroup scheduling we do not want transient connection interruption to stop binding of whole group of pods
07 май 2026, 19:03
07 май 2026, 19:03
2c5a15d
Код
Авторство
О чём код?
/* Copyright 2020 The Kubernetes Authors. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. */ package defaultbinder import ( "context" v1 "k8s.io/api/core/v1" metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" "k8s.io/apimachinery/pkg/runtime" "k8s.io/klog/v2" fwk "k8s.io/kube-scheduler/framework" "k8s.io/kubernetes/pkg/scheduler/framework/plugins/names" "k8s.io/kubernetes/pkg/scheduler/util" ) // Name of the plugin used in the plugin registry and configurations. const Name = names.DefaultBinder // DefaultBinder binds pods to nodes using a k8s client. type DefaultBinder struct { handle fwk.Handle } var _ fwk.BindPlugin = &DefaultBinder{} // New creates a DefaultBinder. func New(_ context.Context, _ runtime.Object, handle fwk.Handle) (fwk.Plugin, error) { return &DefaultBinder{handle: handle}, nil } // Name returns the name of the plugin. func (b DefaultBinder) Name() string { return Name } // Bind binds pods to nodes using the k8s client. func (b DefaultBinder) Bind(ctx context.Context, state fwk.CycleState, p *v1.Pod, nodeName string) *fwk.Status { logger := klog.FromContext(ctx) binding := &v1.Binding{ ObjectMeta: metav1.ObjectMeta{Namespace: p.Namespace, Name: p.Name, UID: p.UID}, Target: v1.ObjectReference{Kind: "Node", Name: nodeName}, } if b.handle.APICacher() != nil { // When API cacher is available, use it to bind the pod. onFinish, err := b.handle.APICacher().BindPod(binding) if err != nil { return fwk.AsStatus(err) } err = b.handle.APICacher().WaitOnFinish(ctx, onFinish) if err != nil { return fwk.AsStatus(err) } return nil } logger.V(3).Info("Attempting to bind pod to node", "pod", klog.KObj(p), "node", klog.KRef("", nodeName)) err := util.BindPod(ctx, b.handle.ClientSet(), binding) if err != nil { return fwk.AsStatus(err) } return nil }