Skip to content

Conversation

@apelisse
Copy link
Member

@apelisse apelisse commented Apr 2, 2019

Implements first part of kubernetes/enhancements#926.
We still need to change the OpenAPI generation to add these extensions.

@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Apr 2, 2019
@apelisse
Copy link
Member Author

apelisse commented Apr 2, 2019

/assign @lavalamp
/cc @kwiesmueller @sttts @jennybuckley

return tr
}

func parseOneOfDiscriminator(v interface{}) (bool, error) {
Copy link
Member Author

Choose a reason for hiding this comment

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

these two functions shouldn't be here.

@k8s-ci-robot k8s-ci-robot requested a review from roycaihw April 2, 2019 18:03
@apelisse apelisse force-pushed the add-union-parsing branch from e630821 to 4f55afd Compare April 2, 2019 18:03
@apelisse
Copy link
Member Author

apelisse commented Apr 2, 2019

tests are expected to fail, there is a dependency to kubernetes-sigs/structured-merge-diff#72

Fields: map[string]string{},
}

if idiscriminator, ok := extensions["x-kubernetes-oneof-discriminator"]; ok {
Copy link
Contributor

Choose a reason for hiding this comment

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

is this a new extension or do we publish it already now?

if idiscriminator, ok := extensions["x-kubernetes-oneof-discriminator"]; ok {
discriminator, ok := idiscriminator.(string)
if !ok {
return nil, fmt.Errorf(`"x-kubernetes-oneof-discriminator" is of invalid type: %T`, idiscriminator)
Copy link
Contributor

Choose a reason for hiding this comment

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

Might be nice to print the value, too. I think %#v includes both.

for ifield, value := range fields {
field, ok := ifield.(string)
if !ok {
return nil, fmt.Errorf(`"x-kubernetes-oneof-fields": field is of invalid type: %T`, ifield)
Copy link
Contributor

@lavalamp lavalamp Apr 3, 2019

Choose a reason for hiding this comment

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

Definitely need to print the value to make this error actionable.

}

if union.Discriminator != nil && len(union.Fields) == 0 {
return nil, fmt.Errorf("discriminator set to %v, but no fields in union", *union.Discriminator)
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this actually an error?

Copy link
Contributor

Choose a reason for hiding this comment

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

How does one indicate whether or not "None" is a permitted value?

Copy link
Member Author

Choose a reason for hiding this comment

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

Is this actually an error?

What's the point? if the only thing you have a discriminator, then it's just an enum. I would suspect that they happen because of a user-error.

type:
namedType: io.k8s.api.core.v1.VsphereVirtualDiskVolumeSource
union:
fields:
Copy link
Contributor

Choose a reason for hiding this comment

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

Sorry to leave this comment here and not in an earlier change, but...
would this make more sense as "choices", where it's a list of structs which set "field" and "discriminatedBy" or something? e.g.

union:
  discriminator: type
  options:
  - fieldName: fc
    discriminatedBy: FC
  - fieldName: azureDisk
    discriminatedBy: AzureDisk
...

I think it is more understandable that way, what do you think?

Copy link
Contributor

Choose a reason for hiding this comment

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

You could even indicate a "none" option that way by permitting a single entry to have no fieldName and just a discriminatedBy.

(no strong opinion about the exact names intended)

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah, Jenny made a similar comment on the other PR, I agree. That's also much more kubernetes-style.

@apelisse apelisse force-pushed the add-union-parsing branch from 4f55afd to a2590a3 Compare April 22, 2019 17:29
@apelisse
Copy link
Member Author

Updated this pull-request and rebased it on top of #155 so that it compiles, PTAL @sttts @lavalamp

if idiscriminator, ok := extensions["x-kubernetes-union-discriminator"]; ok {
discriminator, ok := idiscriminator.(string)
if !ok {
return nil, fmt.Errorf(`"x-kubernetes-union-discriminator" is of invalid type: %#v`, idiscriminator)
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: write which type you expect

Copy link
Member Author

Choose a reason for hiding this comment

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

Very good point, I just fixed them all! Thanks, PTAL

@apelisse apelisse force-pushed the add-union-parsing branch 2 times, most recently from 9ae72f6 to f30e972 Compare April 25, 2019 23:05
@apelisse apelisse force-pushed the add-union-parsing branch from f30e972 to 0a103ed Compare April 26, 2019 20:46

}
sort.Strings(keys)
reverseMap := map[string]string{}

Choose a reason for hiding this comment

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

What's the point of keeping the values in here?

if err != nil {
return nil, err
}
if schemaUnion != nil {

Choose a reason for hiding this comment

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

Why would it be nil, should that be an error also?

@apelisse apelisse force-pushed the add-union-parsing branch from 0a103ed to 62f1ac3 Compare April 26, 2019 23:15
@apelisse
Copy link
Member Author

Fixed, PTAL

@jennybuckley
Copy link

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Apr 26, 2019
@apelisse
Copy link
Member Author

/approve

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: apelisse

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Apr 26, 2019
@k8s-ci-robot k8s-ci-robot merged commit 787f6ef into kubernetes:master Apr 26, 2019
"description": "DeploymentStrategy describes how to replace existing pods with new ones.",
"x-kubernetes-unions": [{
"discriminator": "type",
"fields-discriminated": {
Copy link
Contributor

Choose a reason for hiding this comment

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

does this mean we don't support non-discriminator unions? Would rather call it fields instead of fields-discriminated.

Copy link
Contributor

Choose a reason for hiding this comment

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

as the type is different, we would in fact need fields []string and discriminatedFields map[string]string.

Copy link
Member Author

Choose a reason for hiding this comment

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

Yeah I'll probably do that ... if discriminator is set, then fields must be unset and fields-discriminated must be set. and the other way around.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants