Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

k8s: use NullableString instead of StringValue for preconditions #383

Merged
merged 1 commit into from
Sep 11, 2020

Conversation

gkleiman
Copy link
Contributor

@gkleiman gkleiman commented Sep 8, 2020

Description

The UpdatePods API uses nullable string values to represent
annotations/labels preconditions. A null annotation value means that a
pod should only be updated if the corresponding annotation is not
currently set.

grpc-gateway deserializes a null StringValue as a empty string instead
of as a null pointer. This makes it impossible to use the current API to
express that an annotation should not be set.

This change introduces a new NullableString protobuf type to work
around this issue.

Testing Performed

Unit tests + manual tests with a browser.

The UpdatePods API uses nullable string values to represent
annotations/labels preconditions. A null annotation value means that a
pod should only be updated if the corresponding annotation is not
currently set.

grpc-gateway deserializes a null `StringValue` as a empty string instead
of as a null pointer. This makes it impossible to use the current API to
express that an annotation should not be set.

This change introduces a new `NullableString` protobuf type to work
around this issue.
@gkleiman gkleiman requested a review from a team as a code owner September 8, 2020 20:29
Comment on lines +280 to +285
message NullableString {
oneof kind {
google.protobuf.NullValue null = 1;
string value = 2;
}
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not clear on why this diverges from the way that string value is written i.e.

message StringValue {
  // The string value.
  string value = 1;
}

also would prefer we make whatever solution it is global and copy all of the wrappers over to clutch/api/api/v1/wrappers.proto.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I went for this approach in order to make it very explicit that the value is nullable and how to express a null value.

I don't however have a strong preference for the current version vs copying the wrapper types to Clutch — if you prefer the latter let me know and I'll update the PR.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, though the wrapper types are poorly named (NullableString is a better name for sure), I don't want to introduce a new concept when the core proto ecosystem already has one. Simply copying the wrapper types into our own file to circumvent the pbjson flattening is to me the best fix and clearly communicates our intent.

in documenting that file we can refer to protobufjs/protobuf.js#677 and https://github.com/protocolbuffers/protobuf-go/blob/3f7a61f89bb6813f89d981d1870ed68da0b3c3f1/encoding/protojson/well_known_types.go#L35-L44

@danielhochman danielhochman merged commit 40ecaf1 into main Sep 11, 2020
@danielhochman danielhochman deleted the gkleiman-add-nullablestring branch September 11, 2020 18:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants