Skip to content

Commit

Permalink
Fix that Pod ports without a name were being sent to Felix (#1544)
Browse files Browse the repository at this point in the history
  • Loading branch information
caseydavenport authored Nov 11, 2021
1 parent 45c7e11 commit 4031ee7
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -122,11 +122,15 @@ func convertWorkloadEndpointV2ToV1Value(val interface{}) (interface{}, error) {
// Convert the EndpointPort type from the API pkg to the v1 model equivalent type
ports := []model.EndpointPort{}
for _, port := range v3res.Spec.Ports {
ports = append(ports, model.EndpointPort{
Name: port.Name,
Protocol: port.Protocol.ToV1(),
Port: port.Port,
})
// The v1 API doesn't yet support ports which have no name. However, this is allowed on the
// v3 API and used by the CNI plugin only. Filter these out since Felix doesn't use them anyway.
if port.Name != "" {
ports = append(ports, model.EndpointPort{
Name: port.Name,
Protocol: port.Protocol.ToV1(),
Port: port.Port,
})
}
}

// Make sure there are no "namespace" or "serviceaccount" labels on the wep
Expand Down
10 changes: 8 additions & 2 deletions lib/validator/v3/validator_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,12 @@ func init() {
Protocol: protoUDP,
Port: 1234,
}, false),
Entry("should accept EndpointPort with empty name but HostPort specified", libapiv3.WorkloadEndpointPort{
Name: "",
Protocol: protoUDP,
Port: 1234,
HostPort: 2345,
}, true),
Entry("should reject EndpointPort with no protocol", libapiv3.WorkloadEndpointPort{
Name: "a-valid-port",
Port: 1234,
Expand Down Expand Up @@ -905,7 +911,7 @@ func init() {
api.IPPool{
ObjectMeta: v1.ObjectMeta{Name: "pool.name"},
Spec: api.IPPoolSpec{
CIDR: netv4_4,
CIDR: netv4_4,
AllowedUses: []api.IPPoolAllowedUse{
api.IPPoolAllowedUseWorkload,
api.IPPoolAllowedUseTunnel,
Expand All @@ -916,7 +922,7 @@ func init() {
api.IPPool{
ObjectMeta: v1.ObjectMeta{Name: "pool.name"},
Spec: api.IPPoolSpec{
CIDR: netv4_4,
CIDR: netv4_4,
AllowedUses: []api.IPPoolAllowedUse{
"Garbage",
},
Expand Down

0 comments on commit 4031ee7

Please sign in to comment.