mirror of
https://github.com/kubernetes/kubernetes.git
synced 2026-06-09 08:55:55 -04:00
Merge pull request #134766 from tallclair/dead-code
Delete dead code in pkg/kubelet/lifecycle
This commit is contained in:
commit
e4d85d1c13
2 changed files with 0 additions and 66 deletions
|
|
@ -23,13 +23,11 @@ import (
|
|||
"io"
|
||||
"net/http"
|
||||
"net/url"
|
||||
"strconv"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
v1 "k8s.io/api/core/v1"
|
||||
"k8s.io/apimachinery/pkg/types"
|
||||
"k8s.io/apimachinery/pkg/util/intstr"
|
||||
utilfeature "k8s.io/apiserver/pkg/util/feature"
|
||||
"k8s.io/client-go/tools/record"
|
||||
"k8s.io/klog/v2"
|
||||
|
|
@ -106,29 +104,6 @@ func (hr *handlerRunner) Run(ctx context.Context, containerID kubecontainer.Cont
|
|||
}
|
||||
}
|
||||
|
||||
// resolvePort attempts to turn an IntOrString port reference into a concrete port number.
|
||||
// If portReference has an int value, it is treated as a literal, and simply returns that value.
|
||||
// If portReference is a string, an attempt is first made to parse it as an integer. If that fails,
|
||||
// an attempt is made to find a port with the same name in the container spec.
|
||||
// If a port with the same name is found, it's ContainerPort value is returned. If no matching
|
||||
// port is found, an error is returned.
|
||||
func resolvePort(portReference intstr.IntOrString, container *v1.Container) (int, error) {
|
||||
if portReference.Type == intstr.Int {
|
||||
return portReference.IntValue(), nil
|
||||
}
|
||||
portName := portReference.StrVal
|
||||
port, err := strconv.Atoi(portName)
|
||||
if err == nil {
|
||||
return port, nil
|
||||
}
|
||||
for _, portSpec := range container.Ports {
|
||||
if portSpec.Name == portName {
|
||||
return int(portSpec.ContainerPort), nil
|
||||
}
|
||||
}
|
||||
return -1, fmt.Errorf("couldn't find port: %v in %v", portReference, container)
|
||||
}
|
||||
|
||||
func (hr *handlerRunner) runSleepHandler(ctx context.Context, seconds int64) error {
|
||||
if !utilfeature.DefaultFeatureGate.Enabled(features.PodLifecycleSleepAction) {
|
||||
return nil
|
||||
|
|
|
|||
|
|
@ -41,47 +41,6 @@ import (
|
|||
"k8s.io/kubernetes/test/utils/ktesting"
|
||||
)
|
||||
|
||||
func TestResolvePort(t *testing.T) {
|
||||
for _, testCase := range []struct {
|
||||
container *v1.Container
|
||||
stringPort string
|
||||
expected int
|
||||
}{
|
||||
{
|
||||
stringPort: "foo",
|
||||
container: &v1.Container{
|
||||
Ports: []v1.ContainerPort{{Name: "foo", ContainerPort: int32(80)}},
|
||||
},
|
||||
expected: 80,
|
||||
},
|
||||
{
|
||||
container: &v1.Container{},
|
||||
stringPort: "80",
|
||||
expected: 80,
|
||||
},
|
||||
{
|
||||
container: &v1.Container{
|
||||
Ports: []v1.ContainerPort{
|
||||
{Name: "bar", ContainerPort: int32(80)},
|
||||
},
|
||||
},
|
||||
stringPort: "foo",
|
||||
expected: -1,
|
||||
},
|
||||
} {
|
||||
port, err := resolvePort(intstr.FromString(testCase.stringPort), testCase.container)
|
||||
if testCase.expected != -1 && err != nil {
|
||||
t.Fatalf("unexpected error while resolving port: %s", err)
|
||||
}
|
||||
if testCase.expected == -1 && err == nil {
|
||||
t.Errorf("expected error when a port fails to resolve")
|
||||
}
|
||||
if testCase.expected != port {
|
||||
t.Errorf("failed to resolve port, expected %d, got %d", testCase.expected, port)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
type fakeContainerCommandRunner struct {
|
||||
Cmd []string
|
||||
ID kubecontainer.ContainerID
|
||||
|
|
|
|||
Loading…
Reference in a new issue