-
Notifications
You must be signed in to change notification settings - Fork 35
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
use endpoint name as container port name and service port name #128
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -97,7 +97,7 @@ func TestConvertEnvs(t *testing.T) { | |
} | ||
|
||
func TestConvertPorts(t *testing.T) { | ||
endpointsNames := []string{"endpoint1", "endpoint2"} | ||
endpointsNames := []string{"endpoint1", "endpoint2", "a-very-long-port-name-before-endpoint-length-limit-8080"} | ||
endpointsPorts := []int{8080, 9090} | ||
tests := []struct { | ||
name string | ||
|
@@ -114,7 +114,23 @@ func TestConvertPorts(t *testing.T) { | |
}, | ||
want: []corev1.ContainerPort{ | ||
{ | ||
Name: "8080-tcp", | ||
Name: endpointsNames[0], | ||
ContainerPort: int32(endpointsPorts[0]), | ||
Protocol: "TCP", | ||
}, | ||
}, | ||
}, | ||
{ | ||
name: "One Endpoint with >15 chars length", | ||
endpoints: []v1.Endpoint{ | ||
{ | ||
Name: endpointsNames[2], | ||
TargetPort: endpointsPorts[0], | ||
}, | ||
}, | ||
want: []corev1.ContainerPort{ | ||
{ | ||
Name: "port-8080", | ||
ContainerPort: int32(endpointsPorts[0]), | ||
Protocol: "TCP", | ||
}, | ||
|
@@ -134,12 +150,12 @@ func TestConvertPorts(t *testing.T) { | |
}, | ||
want: []corev1.ContainerPort{ | ||
{ | ||
Name: "8080-tcp", | ||
Name: endpointsNames[0], | ||
ContainerPort: int32(endpointsPorts[0]), | ||
Protocol: "TCP", | ||
}, | ||
{ | ||
Name: "9090-tcp", | ||
Name: endpointsNames[1], | ||
ContainerPort: int32(endpointsPorts[1]), | ||
Protocol: "TCP", | ||
}, | ||
|
@@ -652,7 +668,7 @@ func TestGetPodTemplateSpec(t *testing.T) { | |
|
||
func TestGetServiceSpec(t *testing.T) { | ||
|
||
endpointNames := []string{"port-8080-1", "port-8080-2", "port-9090"} | ||
endpointNames := []string{"port-8080-url", "port-9090-url", "a-very-long-port-name-before-endpoint-length-limit-8080"} | ||
|
||
tests := []struct { | ||
name string | ||
|
@@ -663,7 +679,7 @@ func TestGetServiceSpec(t *testing.T) { | |
wantPorts []corev1.ServicePort | ||
}{ | ||
{ | ||
name: "multiple endpoints share the same port", | ||
name: "multiple endpoints have different ports", | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This test should cover most of our scenarios since we have validation on unique ports but should we handle the exception case as well where There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we do not specifially do tests for |
||
containerComponents: []v1.Component{ | ||
{ | ||
Name: "testcontainer1", | ||
|
@@ -676,37 +692,40 @@ func TestGetServiceSpec(t *testing.T) { | |
}, | ||
{ | ||
Name: endpointNames[1], | ||
TargetPort: 8080, | ||
TargetPort: 9090, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
labels: map[string]string{}, | ||
labels: map[string]string{ | ||
"component": "testcomponent", | ||
}, | ||
wantPorts: []corev1.ServicePort{ | ||
{ | ||
Name: "port-8080", | ||
Name: endpointNames[0], | ||
Port: 8080, | ||
TargetPort: intstr.FromInt(8080), | ||
}, | ||
{ | ||
Name: endpointNames[1], | ||
Port: 9090, | ||
TargetPort: intstr.FromInt(9090), | ||
}, | ||
}, | ||
}, | ||
{ | ||
name: "multiple endpoints have different ports", | ||
name: "long port name before endpoint length limit to <=15", | ||
containerComponents: []v1.Component{ | ||
{ | ||
Name: "testcontainer1", | ||
ComponentUnion: v1.ComponentUnion{ | ||
Container: &v1.ContainerComponent{ | ||
Endpoints: []v1.Endpoint{ | ||
{ | ||
Name: endpointNames[0], | ||
TargetPort: 8080, | ||
}, | ||
{ | ||
Name: endpointNames[2], | ||
TargetPort: 9090, | ||
TargetPort: 8080, | ||
}, | ||
}, | ||
}, | ||
|
@@ -722,11 +741,6 @@ func TestGetServiceSpec(t *testing.T) { | |
Port: 8080, | ||
TargetPort: intstr.FromInt(8080), | ||
}, | ||
{ | ||
Name: "port-9090", | ||
Port: 9090, | ||
TargetPort: intstr.FromInt(9090), | ||
}, | ||
}, | ||
}, | ||
{ | ||
|
@@ -755,7 +769,7 @@ func TestGetServiceSpec(t *testing.T) { | |
Container: &v1.ContainerComponent{ | ||
Endpoints: []v1.Endpoint{ | ||
{ | ||
Name: endpointNames[2], | ||
Name: endpointNames[1], | ||
TargetPort: 9090, | ||
}, | ||
}, | ||
|
@@ -768,7 +782,7 @@ func TestGetServiceSpec(t *testing.T) { | |
}, | ||
wantPorts: []corev1.ServicePort{ | ||
{ | ||
Name: "port-9090", | ||
Name: endpointNames[1], | ||
Port: 9090, | ||
TargetPort: intstr.FromInt(9090), | ||
}, | ||
|
@@ -784,7 +798,7 @@ func TestGetServiceSpec(t *testing.T) { | |
Container: &v1.ContainerComponent{ | ||
Endpoints: []v1.Endpoint{ | ||
{ | ||
Name: endpointNames[2], | ||
Name: endpointNames[1], | ||
TargetPort: 9090, | ||
}, | ||
}, | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -347,7 +347,7 @@ const JsonSchema220 = `{ | |
}, | ||
"name": { | ||
"type": "string", | ||
"maxLength": 63, | ||
"maxLength": 15, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. do we have corresponding updates in our API docs to show the new max length? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. the spec is the api doc |
||
"pattern": "^[a-z0-9]([-a-z0-9]*[a-z0-9])?$" | ||
}, | ||
"path": { | ||
|
@@ -372,6 +372,7 @@ const JsonSchema220 = `{ | |
"type": "boolean" | ||
}, | ||
"targetPort": { | ||
"description": "The port number should be unique.", | ||
"type": "integer" | ||
} | ||
}, | ||
|
@@ -618,7 +619,7 @@ const JsonSchema220 = `{ | |
}, | ||
"name": { | ||
"type": "string", | ||
"maxLength": 63, | ||
"maxLength": 15, | ||
"pattern": "^[a-z0-9]([-a-z0-9]*[a-z0-9])?$" | ||
}, | ||
"path": { | ||
|
@@ -643,6 +644,7 @@ const JsonSchema220 = `{ | |
"type": "boolean" | ||
}, | ||
"targetPort": { | ||
"description": "The port number should be unique.", | ||
"type": "integer" | ||
} | ||
}, | ||
|
@@ -719,7 +721,7 @@ const JsonSchema220 = `{ | |
}, | ||
"name": { | ||
"type": "string", | ||
"maxLength": 63, | ||
"maxLength": 15, | ||
"pattern": "^[a-z0-9]([-a-z0-9]*[a-z0-9])?$" | ||
}, | ||
"path": { | ||
|
@@ -744,6 +746,7 @@ const JsonSchema220 = `{ | |
"type": "boolean" | ||
}, | ||
"targetPort": { | ||
"description": "The port number should be unique.", | ||
"type": "integer" | ||
} | ||
}, | ||
|
@@ -1231,7 +1234,7 @@ const JsonSchema220 = `{ | |
}, | ||
"name": { | ||
"type": "string", | ||
"maxLength": 63, | ||
"maxLength": 15, | ||
"pattern": "^[a-z0-9]([-a-z0-9]*[a-z0-9])?$" | ||
}, | ||
"path": { | ||
|
@@ -1255,6 +1258,7 @@ const JsonSchema220 = `{ | |
"type": "boolean" | ||
}, | ||
"targetPort": { | ||
"description": "The port number should be unique.", | ||
"type": "integer" | ||
} | ||
}, | ||
|
@@ -1493,7 +1497,7 @@ const JsonSchema220 = `{ | |
}, | ||
"name": { | ||
"type": "string", | ||
"maxLength": 63, | ||
"maxLength": 15, | ||
"pattern": "^[a-z0-9]([-a-z0-9]*[a-z0-9])?$" | ||
}, | ||
"path": { | ||
|
@@ -1517,6 +1521,7 @@ const JsonSchema220 = `{ | |
"type": "boolean" | ||
}, | ||
"targetPort": { | ||
"description": "The port number should be unique.", | ||
"type": "integer" | ||
} | ||
}, | ||
|
@@ -1591,7 +1596,7 @@ const JsonSchema220 = `{ | |
}, | ||
"name": { | ||
"type": "string", | ||
"maxLength": 63, | ||
"maxLength": 15, | ||
"pattern": "^[a-z0-9]([-a-z0-9]*[a-z0-9])?$" | ||
}, | ||
"path": { | ||
|
@@ -1615,6 +1620,7 @@ const JsonSchema220 = `{ | |
"type": "boolean" | ||
}, | ||
"targetPort": { | ||
"description": "The port number should be unique.", | ||
"type": "integer" | ||
} | ||
}, | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We are changing a user provided name underneath the covers if length exceeds 15 characters. It'll be good to warn them of these changes ahead of time (via cmd line, log, and/or doc)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes. This change is because we want to unify the service port name & the container port name. since service port does not accept starting with a number (has to be alphabet), thus we use the convention
port-<number>
@valaparthvi FYI.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does the warning need to happen on the
odo
side?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
correct