openstack-resource-controller icon indicating copy to clipboard operation
openstack-resource-controller copied to clipboard

Status returns fields with empty strings

Open mandre opened this issue 11 months ago • 4 comments

Creating a minimal subnet with:

apiVersion: openstack.k-orc.cloud/v1alpha1
kind: Network
metadata:
  name: create-minimal
spec:
  cloudCredentialsRef:
    cloudName: devstack
    secretName: openstack-clouds
  managementPolicy: managed
  resource:
    description: create-minimal
---
apiVersion: openstack.k-orc.cloud/v1alpha1
kind: Subnet
metadata:
  name: create-minimal
spec:
  cloudCredentialsRef:
    cloudName: devstack
    secretName: openstack-clouds
  managementPolicy: managed
  networkRef: create-minimal
  resource:
    ipVersion: 4
    cidr: 192.168.0.0/24

Returns an object with the following status:

status:
  resource:
    name: create-minimal
    description: ""
    allocationPools:
      - start: 192.168.0.2
        end: 192.168.0.254
    cidr: 192.168.0.0/24
    dnsPublishFixedIP: false
    enableDHCP: true
    gatewayIP: 192.168.0.1
    ipVersion: 4
    ipv6AddressMode: ""
    ipv6RAMode: ""

This is surprising to see description, ipv6AddressMode, and ipv6RAMode as they all have an omitempty tag and shouldn't be returned.

mandre avatar Jan 23 '25 16:01 mandre

When you say 'returns an object', how did you generate this output? As you point out these fields have omitempty, so they should not be emitted when marshalling the object if they have a zero value. This would be true regardless of how that value was set.

mdbooth avatar Apr 10 '25 10:04 mdbooth

I got the above output with kubectl get subnet -o yaml.

mandre avatar Apr 10 '25 11:04 mandre

After a helpful conversation with a colleague I realised I've had a fundamental misunderstanding here: kubectl is rendering the object's stored values in full, as it does not have our json marshalling rules and omitempty is not represented in the CRD. So in order to prevent these zero values from being returned we're going to have to avoid setting them in the first place. This means that if we don't want a particular zero value to be displayed we must not set it on the apply configuration when setting the resource status.

mdbooth avatar Apr 10 '25 12:04 mdbooth

@mdbooth should it be a mechanical change as shown in https://github.com/k-orc/openstack-resource-controller/pull/350?

mandre avatar Apr 14 '25 15:04 mandre

Closing as completed via https://github.com/k-orc/openstack-resource-controller/pull/350.

mandre avatar Oct 02 '25 13:10 mandre