Status returns fields with empty strings
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.
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.
I got the above output with kubectl get subnet -o yaml.
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 should it be a mechanical change as shown in https://github.com/k-orc/openstack-resource-controller/pull/350?
Closing as completed via https://github.com/k-orc/openstack-resource-controller/pull/350.