Skip to content

Commit

Permalink
Adds host port to pods
Browse files Browse the repository at this point in the history
  • Loading branch information
nickschuch committed Apr 11, 2019
1 parent a49c1f6 commit 62cf19a
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 0 deletions.
4 changes: 4 additions & 0 deletions internal/kubernetes/core/v1/pod/container/port/expand.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ func Expand(in []interface{}) ([]corev1.ContainerPort, error) {
if port, ok := value[FieldContainerPort]; ok {
ports[key].ContainerPort = int32(port.(int))
}

if port, ok := value[FieldHostPort]; ok {
ports[key].HostPort = int32(port.(int))
}
}

return ports, nil
Expand Down
7 changes: 7 additions & 0 deletions internal/kubernetes/core/v1/pod/container/port/fields.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ const (
FieldName = "name"
// FieldContainerPort used to identify the port which is being exposed from the container.
FieldContainerPort = "container"
// FieldHostPort used to identify the port which is being exposed from the host.
FieldHostPort = "host"
)

// Fields returns the fields for this package.
Expand All @@ -29,6 +31,11 @@ func Fields() *schema.Schema {
Type: schema.TypeInt,
Optional: true,
},
FieldHostPort: {
Description: "Port to receive requests from the host",
Type: schema.TypeInt,
Optional: true,
},
},
},
}
Expand Down
4 changes: 4 additions & 0 deletions internal/kubernetes/core/v1/pod/container/port/flatten.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ func Flatten(in []corev1.ContainerPort) []interface{} {
row[FieldContainerPort] = value.ContainerPort
}

if value.HostPort > 0 {
row[FieldHostPort] = value.HostPort
}

flattened[key] = row
}

Expand Down

0 comments on commit 62cf19a

Please sign in to comment.