mirror of
https://github.com/k3s-io/kubernetes.git
synced 2025-09-06 11:42:14 +00:00
Rename Service.ContainerPort to TargetPort in v1b3
Fix all callers and examples. Part of multi-port service cleanup.
This commit is contained in:
@@ -35,7 +35,8 @@ func (ServiceGenerator) ParamNames() []GeneratorParam {
|
||||
{"public-ip", false},
|
||||
{"create-external-load-balancer", false},
|
||||
{"protocol", false},
|
||||
{"container-port", false},
|
||||
{"container-port", false}, // alias of target-port
|
||||
{"target-port", false},
|
||||
}
|
||||
}
|
||||
|
||||
@@ -75,15 +76,18 @@ func (ServiceGenerator) Generate(params map[string]string) (runtime.Object, erro
|
||||
Selector: selector,
|
||||
},
|
||||
}
|
||||
containerPort, found := params["container-port"]
|
||||
if found && len(containerPort) > 0 {
|
||||
if cPort, err := strconv.Atoi(containerPort); err != nil {
|
||||
service.Spec.ContainerPort = util.NewIntOrStringFromString(containerPort)
|
||||
targetPort, found := params["target-port"]
|
||||
if !found {
|
||||
targetPort, found = params["container-port"]
|
||||
}
|
||||
if found && len(targetPort) > 0 {
|
||||
if portNum, err := strconv.Atoi(targetPort); err != nil {
|
||||
service.Spec.TargetPort = util.NewIntOrStringFromString(targetPort)
|
||||
} else {
|
||||
service.Spec.ContainerPort = util.NewIntOrStringFromInt(cPort)
|
||||
service.Spec.TargetPort = util.NewIntOrStringFromInt(portNum)
|
||||
}
|
||||
} else {
|
||||
service.Spec.ContainerPort = util.NewIntOrStringFromInt(port)
|
||||
service.Spec.TargetPort = util.NewIntOrStringFromInt(port)
|
||||
}
|
||||
if params["create-external-load-balancer"] == "true" {
|
||||
service.Spec.CreateExternalLoadBalancer = true
|
||||
|
@@ -46,9 +46,9 @@ func TestGenerateService(t *testing.T) {
|
||||
"foo": "bar",
|
||||
"baz": "blah",
|
||||
},
|
||||
Port: 80,
|
||||
Protocol: "TCP",
|
||||
ContainerPort: util.NewIntOrStringFromInt(1234),
|
||||
Port: 80,
|
||||
Protocol: "TCP",
|
||||
TargetPort: util.NewIntOrStringFromInt(1234),
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -69,9 +69,9 @@ func TestGenerateService(t *testing.T) {
|
||||
"foo": "bar",
|
||||
"baz": "blah",
|
||||
},
|
||||
Port: 80,
|
||||
Protocol: "UDP",
|
||||
ContainerPort: util.NewIntOrStringFromString("foobar"),
|
||||
Port: 80,
|
||||
Protocol: "UDP",
|
||||
TargetPort: util.NewIntOrStringFromString("foobar"),
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -97,9 +97,9 @@ func TestGenerateService(t *testing.T) {
|
||||
"foo": "bar",
|
||||
"baz": "blah",
|
||||
},
|
||||
Port: 80,
|
||||
Protocol: "TCP",
|
||||
ContainerPort: util.NewIntOrStringFromInt(1234),
|
||||
Port: 80,
|
||||
Protocol: "TCP",
|
||||
TargetPort: util.NewIntOrStringFromInt(1234),
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -121,10 +121,10 @@ func TestGenerateService(t *testing.T) {
|
||||
"foo": "bar",
|
||||
"baz": "blah",
|
||||
},
|
||||
Port: 80,
|
||||
Protocol: "UDP",
|
||||
PublicIPs: []string{"1.2.3.4"},
|
||||
ContainerPort: util.NewIntOrStringFromString("foobar"),
|
||||
Port: 80,
|
||||
Protocol: "UDP",
|
||||
PublicIPs: []string{"1.2.3.4"},
|
||||
TargetPort: util.NewIntOrStringFromString("foobar"),
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -150,7 +150,7 @@ func TestGenerateService(t *testing.T) {
|
||||
Port: 80,
|
||||
Protocol: "UDP",
|
||||
PublicIPs: []string{"1.2.3.4"},
|
||||
ContainerPort: util.NewIntOrStringFromString("foobar"),
|
||||
TargetPort: util.NewIntOrStringFromString("foobar"),
|
||||
CreateExternalLoadBalancer: true,
|
||||
},
|
||||
},
|
||||
|
Reference in New Issue
Block a user