bottlerocket-os / bottlerocket

An operating system designed for hosting containers
https://bottlerocket.dev
Other
8.78k stars 519 forks source link

Add api types crate & update apiclient errors #4040

Closed sumukhballal closed 4 months ago

sumukhballal commented 5 months ago

Issue number:

Closes #3949

Description of changes:

  1. Added API-Types crate as discussed here. It uses common structs which are used by apiclient and apiserver. The main intention was to remove the models crate from its dependencies.
  2. Updated the apiclient side errors to match what was there before #3987

Note: A deserialization error that was there previously when running the apply subcommand does not exist anymore. The server side returns a Deserialization error which is a bit different (it is return from actix::json). The approach of changing the error to suit what we had before seemed too complex given we dont do any client side deserialization during apply. I did not see any places where apply was used, so the risk of not having it is limited.

Now:

bash-5.2# apiclient apply <<EOF
> [settings]
> asdfasdf = "foo"
> EOF
Failed to apply settings: Json deserialize error: unknown field `asdfasdf`, expected one of `aws`, `boot`, `bootstrap-containers`, `cloudformation`, `container-registry`, `dns`, `host-containers`, `kernel`, `metrics`, `motd`, `network`, `ntp`, `oci-hooks`, `pki`, `updates` at line 1 column 11

Bfore:

bash-5.1# apiclient apply <<EOF
> [settings]
> asdfasdf = "foo"
> EOF
Failed to apply settings: Failed to deserialize settings from '-' into this variant's model: unknown field `asdfasdf`, expected one of `motd`, `kubernetes`, `updates`, `host-containers`, `bootstrap-containers`, `ntp`, `network`, `kernel`, `boot`, `aws`, `metrics`, `pki`, `container-registry`, `oci-defaults`, `oci-hooks`, `cloudformation`, `dns`, `container-runtime`, `autoscaling`

Testing done:

Terms of contribution:

By submitting this pull request, I agree that this contribution is dual-licensed under the terms of both the Apache License, version 2.0, and the MIT license.

sumukhballal commented 5 months ago

Added changes to take care of feedback.