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

Add modeled types for URLs and Kubernetes resources #549

Merged
merged 1 commit into from
Nov 21, 2019
Merged

Conversation

tjkirch
Copy link
Contributor

@tjkirch tjkirch commented Nov 21, 2019

This improves errors when API requests are formatted or specified incorrectly,
for example mixing up fields in user data.


Depends on #546.

Testing done:

All of the updated fields now give clear(er) errors if given invalid values.

invalid cluster name:

ip-192-168-96-10 login: [   36.633092] moondog[2906]: Error sending PATCH to /settings: Status 400 when requesting unix://2f72756e2f6170692e736f636b:0/settings: Json deserialize error: Unable to deserialize into KubernetesClusterName: Given invalid cluster name 'https://16D8E306F5C75C5BF9C7FDA2A4DFAC90.yl4.us-west-2.eks.amazonaws.com': cluster names must be valid Kubernetes label values at line 1 column 1562

invalid label key:

ip-192-168-111-172 login: [   42.262331] moondog[2906]: Error sending PATCH to /settings: Status 400 when requesting unix://2f72756e2f6170692e736f636b:0/settings: Json deserialize error: Unable to deserialize into KubernetesLabelKey: Kubernetes label key given invalid input: nope! at line 1 column 1585

invalid label value:

ip-192-168-121-191 login: [   37.405680] moondog[2886]: Error sending PATCH to /settings: Status 400 when requesting unix://2f72756e2f6170692e736f636b:0/settings: Json deserialize error: Unable to deserialize into KubernetesLabelValue: Kubernetes label value given invalid input: nope! at line 1 column 1603

invalid taint value:

ip-192-168-111-69 login: [   37.754373] moondog[2896]: Error sending PATCH to /settings: Status 400 when requesting unix://2f72756e2f6170692e736f636b:0/settings: Json deserialize error: Unable to deserialize into KubernetesTaintValue: Kubernetes taint value given invalid input: nope: at line 1 column 1639

invalid target base url:

ip-192-168-110-167 login: [   38.560481] moondog[2909]: Error sending PATCH to /settings: Status 400 when requesting unix://2f72756e2f6170692e736f636b:0/settings: Json deserialize error: Unable to deserialize into Url: Given invalid URL '@' at line 1 column 1638

invalid metadata base url:

ip-192-168-122-202 login: [   37.392408] moondog[2890]: Error sending PATCH to /settings: Status 400 when requesting unix://2f72756e2f6170692e736f636b:0/settings: Json deserialize error: Unable to deserialize into Url: Given invalid URL '@' at line 1 column 1640

invalid ntp server:

ip-192-168-103-237 login: [   38.465212] moondog[2890]: Error sending PATCH to /settings: Status 400 when requesting unix://2f72756e2f6170692e736f636b:0/settings: Json deserialize error: Unable to deserialize into Url: Given invalid URL '@' at line 1 column 1632

invalid host container source:

ip-192-168-114-155 login: [   37.887258] moondog[2903]: Error sending PATCH to /settings: Status 400 when requesting unix://2f72756e2f6170692e736f636b:0/settings: Json deserialize error: Unable to deserialize into Url: Given invalid URL '@' at line 1 column 83

invalid api server:

ip-192-168-117-242 login: [   36.848683] moondog[2886]: Error sending PATCH to /settings: Status 400 when requesting unix://2f72756e2f6170692e736f636b:0/settings: Json deserialize error: Unable to deserialize into Url: Given invalid URL '@' at line 1 column 76

Here I screwed up a boolean:

ip-192-168-121-182 login: [   43.285066] moondog[2916]: Error sending PATCH to /settings: Status 400 when requesting unix://2f72756e2f6170692e736f636b:0/settings: Json deserialize error: invalid type: string "true", expected a boolean at line 1 column 72

You'll note that some of the errors look the same and don't specify the exact setting that was invalid. I don't think people are likely to specify the same invalid value multiple times and be confused, but I recognize that it could be improved and would like to in the future. Same point for potentially over-verbose errors.


With all of the modified fields specified with "normal" values, everything was happy and the instance joined my cluster. I checked the config files populated by these values and they looked right.

Also, because I haven't tested this before, I made sure to test a node taint; I was able to see the taint, and then run a pod on it, but only if I specified a toleration.

$ kubectl get nodes -o json | jq '.items[].spec.taints'
[
  {
    "effect": "NoSchedule",
    "key": "tjk/taint",
    "value": "howdy"
  }
]

$ kubectl run -i -t busybox --image=busybox --restart=Never --overrides='{ "spec": { "tolerations": [{"key": "tjk/taint", "operator": "Exists", "effect": "NoSchedule"}]}}'
If you don't see a command prompt, try pressing enter.
/ # 

Copy link
Contributor

@zmrow zmrow left a comment

Choose a reason for hiding this comment

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

I'm still a little bit nervous about being too strict about some of these types, but given the specs you found I feel good about the decisions that were made here.

Just a few comments.

@@ -282,3 +303,401 @@ mod test_valid_identifier {
assert!(Identifier::try_from("💝").is_err());
}
}

// =^..^= =^..^= =^..^= =^..^= =^..^= =^..^= =^..^= =^..^= =^..^=
Copy link
Contributor

Choose a reason for hiding this comment

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

😸

Comment on lines +327 to +330
// It's very common to specify URLs without a scheme, so we add one and see if that
// fixes parsing.
let prefixed = format!("http://{}", input);
if let Ok(_) = prefixed.parse::<url::Url>() {
Copy link
Contributor

Choose a reason for hiding this comment

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

I like this approach!

workspaces/api/apiserver/src/modeled_types.rs Outdated Show resolved Hide resolved
This improves errors when API requests are formatted or specified incorrectly,
for example mixing up fields in user data.
@tjkirch
Copy link
Contributor Author

tjkirch commented Nov 21, 2019

This push just clarifies error messages for unit tests that fail, making the Url tests consistent with others.

Copy link
Contributor

@zmrow zmrow left a comment

Choose a reason for hiding this comment

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

🍹

Copy link
Contributor

@etungsten etungsten left a comment

Choose a reason for hiding this comment

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

🦃


#[snafu(display("{} must match '{}', given: {}", thing, pattern, input))]
Pattern {
thing: String,
Copy link
Contributor

Choose a reason for hiding this comment

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

small nit: Could there be a better way to represent this field? Maybe modeled-type?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's not exactly that, it's a descriptive string regarding the... thing... the error might be about. It's a bit more general than modeled type. Perhaps desc?

@tjkirch tjkirch changed the base branch from display-errors to develop November 21, 2019 21:24
@tjkirch tjkirch merged commit 5b91ec5 into develop Nov 21, 2019
@tjkirch tjkirch deleted the model-more branch November 21, 2019 21:25
@iliana iliana added this to the v0.2.0 milestone Nov 21, 2019
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.

4 participants