Skip to content

Commit c63e4a9

Browse files
authored
Merge pull request #770 from winiciusallan/port-value-specs
port: add ValueSpecs field
2 parents ad9f76e + b3c1ede commit c63e4a9

13 files changed

Lines changed: 281 additions & 3 deletions

File tree

api/v1alpha1/port_types.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,19 @@ type FixedIPStatus struct {
121121
SubnetID string `json:"subnetID,omitempty"`
122122
}
123123

124+
type PortValueSpec struct {
125+
// key is the name of the Neutron API extension parameter.
126+
// +kubebuilder:validation:MinLength:=1
127+
// +kubebuilder:validation:MaxLength:=255
128+
// +required
129+
Key string `json:"key,omitempty"`
130+
131+
// value is the value of the Neutron API extension parameter.
132+
// +kubebuilder:validation:MaxLength:=255
133+
// +required
134+
Value *string `json:"value,omitempty"`
135+
}
136+
124137
// +kubebuilder:validation:XValidation:rule="has(self.portSecurity) && self.portSecurity == 'Disabled' ? !has(self.securityGroupRefs) : true",message="securityGroupRefs must be empty when portSecurity is set to Disabled"
125138
// +kubebuilder:validation:XValidation:rule="has(self.portSecurity) && self.portSecurity == 'Disabled' ? !has(self.allowedAddressPairs) : true",message="allowedAddressPairs must be empty when portSecurity is set to Disabled"
126139
type PortResourceSpec struct {
@@ -216,6 +229,21 @@ type PortResourceSpec struct {
216229
// operations. Only admin users can create ports with this field.
217230
// +optional
218231
TrustedVIF *bool `json:"trustedVIF,omitempty"`
232+
233+
// valueSpecs are extra parameters to include in the API request
234+
// with OpenStack. This is an extension point for the API, so what
235+
// they do and if they are supported, depends on the specific
236+
// OpenStack implementation. This was meant to work similar to the
237+
// property on Heat port resource. Since this depends on the
238+
// underlying implementation, we can't predict its fields, and
239+
// therefore, we don't know how to reconcile them in advance. Use
240+
// this field wisely and be aware of the expected behavior.
241+
// +kubebuilder:validation:MaxItems:=128
242+
// +listType=map
243+
// +listMapKey=key
244+
// +optional
245+
// +kubebuilder:validation:XValidation:rule="self == oldSelf",message="valueSpecs is immutable"
246+
ValueSpecs []PortValueSpec `json:"valueSpecs,omitempty"`
219247
}
220248

221249
type PortResourceStatus struct {

api/v1alpha1/zz_generated.deepcopy.go

Lines changed: 27 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cmd/models-schema/zz_generated.openapi.go

Lines changed: 51 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

config/crd/bases/openstack.k-orc.cloud_ports.yaml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,41 @@ spec:
407407
trusted by physical function to perform some privileged
408408
operations. Only admin users can create ports with this field.
409409
type: boolean
410+
valueSpecs:
411+
description: |-
412+
valueSpecs are extra parameters to include in the API request
413+
with OpenStack. This is an extension point for the API, so what
414+
they do and if they are supported, depends on the specific
415+
OpenStack implementation. This was meant to work similar to the
416+
property on Heat port resource. Since this depends on the
417+
underlying implementation, we can't predict its fields, and
418+
therefore, we don't know how to reconcile them in advance. Use
419+
this field wisely and be aware of the expected behavior.
420+
items:
421+
properties:
422+
key:
423+
description: key is the name of the Neutron API extension
424+
parameter.
425+
maxLength: 255
426+
minLength: 1
427+
type: string
428+
value:
429+
description: value is the value of the Neutron API extension
430+
parameter.
431+
maxLength: 255
432+
type: string
433+
required:
434+
- key
435+
- value
436+
type: object
437+
maxItems: 128
438+
type: array
439+
x-kubernetes-list-map-keys:
440+
- key
441+
x-kubernetes-list-type: map
442+
x-kubernetes-validations:
443+
- message: valueSpecs is immutable
444+
rule: self == oldSelf
410445
vnicType:
411446
description: |-
412447
vnicType specifies the type of vNIC which this port should be

internal/controllers/port/actuator.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,13 +239,23 @@ func (actuator portActuator) CreateResource(ctx context.Context, obj *orcv1alpha
239239
return nil, reconcileStatus
240240
}
241241

242+
var valueSpecs *map[string]string
243+
if len(resource.ValueSpecs) > 0 {
244+
vs := make(map[string]string, len(resource.ValueSpecs))
245+
for _, valueSpec := range resource.ValueSpecs {
246+
vs[valueSpec.Key] = *valueSpec.Value
247+
}
248+
valueSpecs = &vs
249+
}
250+
242251
createOpts := ports.CreateOpts{
243252
NetworkID: *network.Status.ID,
244253
Name: getResourceName(obj),
245254
Description: string(ptr.Deref(resource.Description, "")),
246255
ProjectID: projectID,
247256
AdminStateUp: resource.AdminStateUp,
248257
MACAddress: resource.MACAddress,
258+
ValueSpecs: valueSpecs,
249259
}
250260

251261
if len(resource.AllowedAddressPairs) > 0 {

internal/controllers/port/tests/port-create-full/00-assert.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,11 @@ resourceRefs:
3030
- apiVersion: openstack.k-orc.cloud/v1alpha1
3131
kind: subnet
3232
name: port-create-full
33-
ref: subnet
33+
ref: subnet
3434
- apiVersion: openstack.k-orc.cloud/v1alpha1
3535
kind: securitygroup
3636
name: port-create-full
37-
ref: sg
37+
ref: sg
3838
- apiVersion: openstack.k-orc.cloud/v1alpha1
3939
kind: project
4040
name: port-create-full

internal/controllers/port/tests/port-create-full/README.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@
44

55
Create a port using all available fields, and verify that the observed state corresponds to the spec.
66

7+
We're omitting the `ValueSpecs` field on purpose because we can't
8+
reliably test it, since the key-value pairs in this structure depend
9+
solely on the underlying OpenStack implementation, and thus the added
10+
fields are unpredictable.
11+
712
Also validate that the OpenStack resource uses the name from the spec when it is specified.
813

914
## Reference

pkg/clients/applyconfiguration/api/v1alpha1/portresourcespec.go

Lines changed: 14 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/clients/applyconfiguration/api/v1alpha1/portvaluespec.go

Lines changed: 48 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/clients/applyconfiguration/internal/internal.go

Lines changed: 17 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)