/
githubmirror
/
kubernetes
Обзор
Документация
Войти
/
githubmirror
/
kubernetes
Код
Запросы
0
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
pkg/probe/util.go
52 строки
1 KB
Yaroslav Borbat
probe: clarify error for unresolved named probe ports
26 июн 2026, 11:21
26 июн 2026, 11:21
46ab4b2
Код
Авторство
О чём код?
/* Copyright 2022 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 probe import ( "fmt" v1 "k8s.io/api/core/v1" "k8s.io/apimachinery/pkg/util/intstr" ) func ResolveContainerPort(param intstr.IntOrString, container *v1.Container) (int, error) { port := -1 var err error switch param.Type { case intstr.Int: port = param.IntValue() case intstr.String: if port, err = findPortByName(container, param.StrVal); err != nil { return port, err } default: return port, fmt.Errorf("intOrString had no kind: %+v", param) } if port > 0 && port < 65536 { return port, nil } return port, fmt.Errorf("invalid port number: %v", port) } // findPortByName is a helper function to look up a port in a container by name. func findPortByName(container *v1.Container, portName string) (int, error) { for _, port := range container.Ports { if port.Name == portName { return int(port.ContainerPort), nil } } return 0, fmt.Errorf("port %q not found", portName) }