-
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
287-format pod container port name #51
Changes from 5 commits
bc08a6c
04e1965
b64790a
dc087b1
d1a5b24
811bcb2
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 | ||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -5,10 +5,9 @@ import ( | |||||||||||||||||||||||
"path/filepath" | ||||||||||||||||||||||||
"strings" | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
v1 "github.com/devfile/api/pkg/apis/workspaces/v1alpha2" | ||||||||||||||||||||||||
v1 "github.com/devfile/api/v2/pkg/apis/workspaces/v1alpha2" | ||||||||||||||||||||||||
"github.com/devfile/library/pkg/devfile/parser" | ||||||||||||||||||||||||
"github.com/devfile/library/pkg/devfile/parser/data/v2/common" | ||||||||||||||||||||||||
"github.com/devfile/library/pkg/util" | ||||||||||||||||||||||||
buildv1 "github.com/openshift/api/build/v1" | ||||||||||||||||||||||||
routev1 "github.com/openshift/api/route/v1" | ||||||||||||||||||||||||
appsv1 "k8s.io/api/apps/v1" | ||||||||||||||||||||||||
|
@@ -34,13 +33,25 @@ func convertEnvs(vars []v1.EnvVar) []corev1.EnvVar { | |||||||||||||||||||||||
// convertPorts converts endpoint variables from the devfile structure to kubernetes ContainerPort | ||||||||||||||||||||||||
func convertPorts(endpoints []v1.Endpoint) []corev1.ContainerPort { | ||||||||||||||||||||||||
containerPorts := []corev1.ContainerPort{} | ||||||||||||||||||||||||
portMap := make(map[string]bool) | ||||||||||||||||||||||||
for _, endpoint := range endpoints { | ||||||||||||||||||||||||
name := strings.TrimSpace(util.GetDNS1123Name(strings.ToLower(endpoint.Name))) | ||||||||||||||||||||||||
name = util.TruncateString(name, 15) | ||||||||||||||||||||||||
var portProtocol corev1.Protocol | ||||||||||||||||||||||||
portNumber := int32(endpoint.TargetPort) | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
if endpoint.Protocol == v1.UDPEndpointProtocol { | ||||||||||||||||||||||||
portProtocol = corev1.ProtocolUDP | ||||||||||||||||||||||||
} else { | ||||||||||||||||||||||||
portProtocol = corev1.ProtocolTCP | ||||||||||||||||||||||||
} | ||||||||||||||||||||||||
name := fmt.Sprintf("%d-%s", portNumber, strings.ToLower(string(portProtocol))) | ||||||||||||||||||||||||
if _, exist := portMap[name]; exist { | ||||||||||||||||||||||||
continue | ||||||||||||||||||||||||
} | ||||||||||||||||||||||||
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.
Suggested change
would probably do this way but upto you 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. updated |
||||||||||||||||||||||||
portMap[name] = true | ||||||||||||||||||||||||
containerPorts = append(containerPorts, corev1.ContainerPort{ | ||||||||||||||||||||||||
Name: name, | ||||||||||||||||||||||||
ContainerPort: int32(endpoint.TargetPort), | ||||||||||||||||||||||||
ContainerPort: portNumber, | ||||||||||||||||||||||||
Protocol: portProtocol, | ||||||||||||||||||||||||
}) | ||||||||||||||||||||||||
} | ||||||||||||||||||||||||
return containerPorts | ||||||||||||||||||||||||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,13 +6,13 @@ import ( | |
"strings" | ||
"testing" | ||
|
||
"github.com/devfile/api/pkg/attributes" | ||
"github.com/devfile/api/v2/pkg/attributes" | ||
"github.com/devfile/library/pkg/devfile/parser" | ||
"github.com/devfile/library/pkg/devfile/parser/data/v2/common" | ||
"github.com/devfile/library/pkg/testingutil" | ||
buildv1 "github.com/openshift/api/build/v1" | ||
|
||
v1 "github.com/devfile/api/pkg/apis/workspaces/v1alpha2" | ||
v1 "github.com/devfile/api/v2/pkg/apis/workspaces/v1alpha2" | ||
|
||
corev1 "k8s.io/api/core/v1" | ||
"k8s.io/apimachinery/pkg/api/resource" | ||
|
@@ -108,8 +108,9 @@ func TestConvertPorts(t *testing.T) { | |
}, | ||
want: []corev1.ContainerPort{ | ||
{ | ||
Name: endpointsNames[0], | ||
Name: "8080-tcp", | ||
ContainerPort: int32(endpointsPorts[0]), | ||
Protocol: "TCP", | ||
}, | ||
}, | ||
}, | ||
|
@@ -127,12 +128,14 @@ func TestConvertPorts(t *testing.T) { | |
}, | ||
want: []corev1.ContainerPort{ | ||
{ | ||
Name: endpointsNames[0], | ||
Name: "8080-tcp", | ||
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. Just noticed, can you update teh test case name, it seems wrong 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. updated |
||
ContainerPort: int32(endpointsPorts[0]), | ||
Protocol: "TCP", | ||
}, | ||
{ | ||
Name: endpointsNames[1], | ||
Name: "9090-tcp", | ||
ContainerPort: int32(endpointsPorts[1]), | ||
Protocol: "TCP", | ||
}, | ||
}, | ||
}, | ||
|
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.
thinking if we should call these aliases
devfileApiv2
🤔 it will be less confusing as well