Skip to content

Commit

Permalink
Merge pull request #964 from EmilienM/profile_support
Browse files Browse the repository at this point in the history
getOrCreatePort: add support to configure port Profile
  • Loading branch information
k8s-ci-robot authored Aug 12, 2021
2 parents 829ecdf + 0bfd0a0 commit 4debc1f
Show file tree
Hide file tree
Showing 8 changed files with 85 additions and 2 deletions.
5 changes: 5 additions & 0 deletions api/v1alpha4/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,11 @@ type PortOpts struct {
// The virtual network interface card (vNIC) type that is bound to the neutron port.
VNICType string `json:"vnicType,omitempty"`

// A dictionary that enables the application running on the specified
// host to pass and receive virtual network interface (VIF) port-specific
// information to the plug-in.
Profile map[string]string `json:"profile,omitempty"`

// DisablePortSecurity enables or disables the port security when set.
// When not set, it takes the value of the corresponding field at the network level.
DisablePortSecurity *bool `json:"disablePortSecurity,omitempty"`
Expand Down
7 changes: 7 additions & 0 deletions api/v1alpha4/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -1306,6 +1306,14 @@ spec:
create the port. If unspecified, create the port on
the default cluster network.
type: string
profile:
additionalProperties:
type: string
description: A dictionary that enables the application
running on the specified host to pass and receive
virtual network interface (VIF) port-specific information
to the plug-in.
type: object
projectId:
type: string
securityGroups:
Expand Down Expand Up @@ -1747,6 +1755,14 @@ spec:
create the port. If unspecified, create the port on
the default cluster network.
type: string
profile:
additionalProperties:
type: string
description: A dictionary that enables the application
running on the specified host to pass and receive
virtual network interface (VIF) port-specific information
to the plug-in.
type: object
projectId:
type: string
securityGroups:
Expand Down Expand Up @@ -2016,6 +2032,13 @@ spec:
the port. If unspecified, create the port on the default
cluster network.
type: string
profile:
additionalProperties:
type: string
description: A dictionary that enables the application running
on the specified host to pass and receive virtual network
interface (VIF) port-specific information to the plug-in.
type: object
projectId:
type: string
securityGroups:
Expand Down Expand Up @@ -2197,6 +2220,13 @@ spec:
the port. If unspecified, create the port on the default
cluster network.
type: string
profile:
additionalProperties:
type: string
description: A dictionary that enables the application running
on the specified host to pass and receive virtual network
interface (VIF) port-specific information to the plug-in.
type: object
projectId:
type: string
securityGroups:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,14 @@ spec:
which to create the port. If unspecified,
create the port on the default cluster network.
type: string
profile:
additionalProperties:
type: string
description: A dictionary that enables the application
running on the specified host to pass and
receive virtual network interface (VIF) port-specific
information to the plug-in.
type: object
projectId:
type: string
securityGroups:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -596,6 +596,13 @@ spec:
the port. If unspecified, create the port on the default cluster
network.
type: string
profile:
additionalProperties:
type: string
description: A dictionary that enables the application running
on the specified host to pass and receive virtual network
interface (VIF) port-specific information to the plug-in.
type: object
projectId:
type: string
securityGroups:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -545,6 +545,14 @@ spec:
create the port. If unspecified, create the port on
the default cluster network.
type: string
profile:
additionalProperties:
type: string
description: A dictionary that enables the application
running on the specified host to pass and receive
virtual network interface (VIF) port-specific information
to the plug-in.
type: object
projectId:
type: string
securityGroups:
Expand Down
5 changes: 4 additions & 1 deletion docs/book/src/clusteropenstack/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ spec:
## Ports
A server can also be connected to networks by describing what ports to create. Describing a server's connection with `ports` allows for finer and more advanced configuration. For example, you can specify per-port security groups, fixed IPs or VNIC type.
A server can also be connected to networks by describing what ports to create. Describing a server's connection with `ports` allows for finer and more advanced configuration. For example, you can specify per-port security groups, fixed IPs, VNIC type or profile.

```yaml
apiVersion: infrastructure.cluster.x-k8s.io/v1alpha4
Expand All @@ -232,6 +232,9 @@ spec:
ipAddress: <your-fixed-ip>
securityGroups:
- <your-security-group-id>
profile:
capabilities:
- <capability>
```

Any such ports are created in addition to ports used for connections to networks or subnets.
Expand Down
17 changes: 16 additions & 1 deletion pkg/cloud/services/compute/instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -518,7 +518,7 @@ func (s *Service) getOrCreatePort(eventObject runtime.Object, clusterName string
CreateOptsBuilder: createOpts,
HostID: portOpts.HostID,
VNICType: portOpts.VNICType,
Profile: nil,
Profile: getPortProfile(portOpts.Profile),
}

mc = metrics.NewMetricPrometheusContext("port", "create")
Expand All @@ -532,6 +532,21 @@ func (s *Service) getOrCreatePort(eventObject runtime.Object, clusterName string
return port, nil
}

func getPortProfile(p map[string]string) map[string]interface{} {
portProfile := make(map[string]interface{})
for k, v := range p {
portProfile[k] = v
}
// We need return nil if there is no profiles
// to have backward compatible defaults.
// To set profiles, your tenant needs this permission:
// rule:create_port and rule:create_port:binding:profile
if len(portProfile) == 0 {
return nil
}
return portProfile
}

func (s *Service) getOrCreateTrunk(eventObject runtime.Object, clusterName, trunkName, portID string) (*trunks.Trunk, error) {
mc := metrics.NewMetricPrometheusContext("trunk", "list")
allPages, err := trunks.List(s.networkClient, trunks.ListOpts{
Expand Down

0 comments on commit 4debc1f

Please sign in to comment.