-
Notifications
You must be signed in to change notification settings - Fork 594
Description
If a CRD defined via protobuf contains a primitive int64/uint64 field, it will be impossible to set using kubernetes client-go. The API server will log a validation error along these lines:
E0614 20:35:54.474243 1 fieldmanager.go:210] "[SHOULD NOT HAPPEN] failed to update managedFields" err=<
failed to convert new object (helloworld/helloworld-helloworld-svc-clust-4ea60913c1118639503f1f3012b53e9; networking.istio.io/v1beta1, Kind=DestinationRule) to smd typed: errors:
.spec.trafficPolicy.portLevelSettings[0].loadBalancer.consistentHash.maglev.tableSize: expected numeric (int or float), got string
> VersionKind="networking.istio.io/v1beta1, Kind=DestinationRule" namespace="helloworld" name="helloworld-helloworld-svc-clust-4ea60913c1118639503f1f3012b53e9"
Error returned by client-go:
Status: "Failure",
Message: "DestinationRule.networking.istio.io \"helloworld-helloworld-svc-clust-4ea60913c1118639503f1f3012b53e9\" is invalid: [spec.trafficPolicy.portLevelSettings[0].loadBalancer.consistentHash.maglev.tableSize: Invalid value: \"string\": spec.trafficPolicy.portLevelSettings[0].loadBalancer.consistentHash.maglev.tableSize in body must be of type integer: \"string\"]",
Reason: "Invalid",
Details: {
Name: "helloworld-helloworld-svc-clust-4ea60913c1118639503f1f3012b53e9",
Group: "networking.istio.io",
Kind: "DestinationRule",
UID: "",
Causes: [
{
Type: "FieldValueTypeInvalid",
Message: "Invalid value: \"string\": spec.trafficPolicy.portLevelSettings[0].loadBalancer.consistentHash.maglev.tableSize in body must be of type integer: \"string\"",
Field: "spec.trafficPolicy.portLevelSettings[0].loadBalancer.consistentHash.maglev.tableSize",
},
],
RetryAfterSeconds: 0,
},
There are two issues at hand: the first is that protobuf json encoder serializes int64/uint64 as double-quoted strings:
https://github.com/golang/protobuf/blob/v1.4.2/jsonpb/encode.go#L543. The other issue is that cue generates validation schema based on the protobuf and uses an "integer" as the field type.
For example, in a DestinationRule protobuf, Maglev load balancer has a configuration option to set its table size, which is a uint64: https://github.com/istio/api/blob/master/networking/v1beta1/destination_rule.proto#L540. A corresponding OpenAPI schema defines the field as "integer": https://github.com/istio/api/blob/master/kubernetes/customresourcedefinitions.gen.yaml#L397
Version (include the output of istioctl version --remote and kubectl version)
>= 1.16.0
client-go: v1.17.2, apimachinery: v0.26.4