Skip to content

Commit 60786e3

Browse files
committed
remove temp struct and add new Unmarshal logic
1 parent 00aefc8 commit 60786e3

5 files changed

Lines changed: 52 additions & 13 deletions

File tree

api/v1alpha1/port_types.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,9 @@ type PortResourceSpec struct {
213213

214214
// propagateUplinkStatus represents the uplink status propagation of
215215
// the port.
216+
// The field is now immutable due to a limitation on
217+
// Dalmatian (2024.2) release, we should address this later.
218+
// https://github.com/k-orc/openstack-resource-controller/pull/641#discussion_r2905989136
216219
// +optional
217220
// +kubebuilder:validation:XValidation:rule="self == oldSelf",message="propagateUplinkStatus is immutable"
218221
PropagateUplinkStatus *bool `json:"propagateUplinkStatus,omitempty"`

cmd/models-schema/zz_generated.openapi.go

Lines changed: 1 addition & 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: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,9 @@ spec:
381381
description: |-
382382
propagateUplinkStatus represents the uplink status propagation of
383383
the port.
384+
The field is now immutable due to a limitation on
385+
Dalmatian (2024.2) release, we should address this later.
386+
https://github.com/k-orc/openstack-resource-controller/pull/641#discussion_r2905989136
384387
type: boolean
385388
x-kubernetes-validations:
386389
- message: propagateUplinkStatus is immutable

internal/osclients/networking.go

Lines changed: 44 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package osclients
1818

1919
import (
2020
"context"
21+
"encoding/json"
2122
"fmt"
2223
"iter"
2324

@@ -52,19 +53,34 @@ type NetworkExt struct {
5253
provider.NetworkProviderExt
5354
}
5455

55-
// NOTE(winiciusallan): This is a temporary extension struct to
56-
// workaround a missing pointer on Gophercloud and must be
57-
// removed in future releases.
58-
// See https://github.com/gophercloud/gophercloud/issues/3605
59-
type PortTmpExt struct {
60-
PropagateUplinkStatusPtr *bool `json:"propagate_uplink_status,omitempty"`
61-
}
62-
6356
type PortExt struct {
6457
ports.Port
6558
portsecurity.PortSecurityExt
6659
portsbinding.PortsBindingExt
67-
PortTmpExt //nolint:govet
60+
61+
PropagateUplinkStatusPtr *bool `json:"propagate_uplink_status,omitempty"`
62+
}
63+
64+
func (p *PortExt) UnmarshalJSON(b []byte) error {
65+
if err := json.Unmarshal(b, &p.Port); err != nil {
66+
return err
67+
}
68+
if err := json.Unmarshal(b, &p.PortSecurityExt); err != nil {
69+
return err
70+
}
71+
if err := json.Unmarshal(b, &p.PortsBindingExt); err != nil {
72+
return err
73+
}
74+
75+
var tmp struct {
76+
PropagateUplinkStatusPtr *bool `json:"propagate_uplink_status"`
77+
}
78+
if err := json.Unmarshal(b, &tmp); err != nil {
79+
return err
80+
}
81+
82+
p.PropagateUplinkStatusPtr = tmp.PropagateUplinkStatusPtr
83+
return nil
6884
}
6985

7086
type NetworkClient interface {
@@ -189,13 +205,30 @@ func (c networkClient) UpdateFloatingIP(ctx context.Context, id string, opts flo
189205

190206
func (c networkClient) ListPort(ctx context.Context, opts ports.ListOptsBuilder) iter.Seq2[*PortExt, error] {
191207
extractPortExt := func(p pagination.Page) ([]PortExt, error) {
192-
var resources []PortExt
193-
err := ports.ExtractPortsInto(p, &resources)
208+
bodyMap, ok := p.(ports.PortPage).Body.(map[string]interface{})
209+
if !ok {
210+
return nil, fmt.Errorf("unexpected body type: %T", p.(ports.PortPage).Body)
211+
}
212+
213+
portsData, ok := bodyMap["ports"]
214+
if !ok {
215+
return nil, fmt.Errorf("ports key not found in response")
216+
}
217+
218+
// Marshal and unmarshal to trigger UnmarshalJSON
219+
jsonData, err := json.Marshal(portsData)
194220
if err != nil {
195221
return nil, err
196222
}
223+
224+
var resources []PortExt
225+
if err := json.Unmarshal(jsonData, &resources); err != nil {
226+
return nil, err
227+
}
228+
197229
return resources, nil
198230
}
231+
199232
pager := ports.List(c.serviceClient, opts)
200233
return func(yield func(*PortExt, error) bool) {
201234
_ = pager.EachPage(ctx, yieldPage(extractPortExt, yield))

website/docs/crd-reference.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2739,7 +2739,7 @@ _Appears in:_
27392739
| `projectRef` _[KubernetesNameRef](#kubernetesnameref)_ | projectRef is a reference to the ORC Project this resource is associated with.<br />Typically, only used by admin. | | MaxLength: 253 <br />MinLength: 1 <br />Optional: \{\} <br /> |
27402740
| `macAddress` _string_ | macAddress is the MAC address of the port. | | MaxLength: 32 <br />Optional: \{\} <br /> |
27412741
| `hostID` _[HostID](#hostid)_ | hostID specifies the host where the port will be bound.<br />Note that when the port is attached to a server, OpenStack may<br />rebind the port to the server's actual compute host, which may<br />differ from the specified hostID if no matching scheduler hint<br />is used. In this case the port's status will reflect the actual<br />binding host, not the value specified here. | | MaxProperties: 1 <br />MinProperties: 1 <br />Optional: \{\} <br /> |
2742-
| `propagateUplinkStatus` _boolean_ | propagateUplinkStatus represents the uplink status propagation of<br />the port. | | Optional: \{\} <br /> |
2742+
| `propagateUplinkStatus` _boolean_ | propagateUplinkStatus represents the uplink status propagation of<br />the port.<br />The field is now immutable due to a limitation on<br />Dalmatian (2024.2) release, we should address this later.<br />https://github.com/k-orc/openstack-resource-controller/pull/641#discussion_r2905989136 | | Optional: \{\} <br /> |
27432743

27442744

27452745
#### PortResourceStatus

0 commit comments

Comments
 (0)