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

Adds an Unknown variant to the list of possible mirrord targets for future compat. #2553

Merged
merged 42 commits into from
Jul 5, 2024

Conversation

meowjesty
Copy link
Member

@meowjesty meowjesty commented Jun 26, 2024

  1. Changes the TargetSpec from having an Option<Target> field to an KubeTarget enum, which can take either a Known(Target) or an Unknown(String):
    • custom deserialization, allowing us to convert a valid kubernetes target, which we don't know about in mirrord, into an KubeTarget::Unknown;

@meowjesty meowjesty linked an issue Jun 26, 2024 that may be closed by this pull request
@Razz4780 Razz4780 self-requested a review July 1, 2024 15:17
@Razz4780
Copy link
Contributor

Razz4780 commented Jul 1, 2024

Have you tried changing TargetCrd instead? Maybe we can wrap Target in there into some enum :V
Sth like:

#[derive(Deserialize, ...)
#[serde(untagged)]
pub enum SafeTarget {
  KnownTarget(Target),
  UnknownTarget {
    #[serde(rename = "type")]
    type_: String,
  },
}

The necessary use of unreachables here is uncanny and I'm sad :<
Also Unknown being displayed as an empty string and other code depending on it :<

@meowjesty
Copy link
Member Author

Changed it to an enum, please look into the operator PR to see if it's better now.

Name suggestions are welcome, I was thinking KubeTarget, as this type encapsulates any kube target, known and unknown to us.

@Razz4780
Copy link
Contributor

Razz4780 commented Jul 4, 2024

Changed it to an enum, please look into the operator PR to see if it's better now.

Name suggestions are welcome, I was thinking KubeTarget, as this type encapsulates any kube target, known and unknown to us.

Looks better imho ^^

Copy link
Contributor

@Razz4780 Razz4780 left a comment

Choose a reason for hiding this comment

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

I think this change could touch only mirrord_operator. Would be nice, because unknown targets are only relevant for maintaining forward compatibility with the operator. New wrapper type could be moved to mirrord_operator::crd and the rest of OSS code could stay unaware of its existence. You wouldn't need to change mirrord_config or mirrord_kube

mirrord/config/src/target.rs Outdated Show resolved Hide resolved
Copy link
Contributor

@Razz4780 Razz4780 left a comment

Choose a reason for hiding this comment

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

Some nits + could you add a unit tests asserting that this change is backwards compatible? In test submodule, you could declare a struct like TargetSpecLegacy (with all the derives) that matches previous format and check how:

  1. Serialized legacy type with target None deserializes into new type
  2. Serialized legacy type with some target deserializes into new type
  3. New type deserializes from some unknown target type
  4. Legacy type deserializes from the serialized new type

mirrord/operator/src/client.rs Outdated Show resolved Hide resolved
mirrord/operator/src/client.rs Outdated Show resolved Hide resolved
mirrord/kube/src/error.rs Outdated Show resolved Hide resolved
mirrord/operator/src/crd.rs Outdated Show resolved Hide resolved
Copy link
Contributor

@Razz4780 Razz4780 left a comment

Choose a reason for hiding this comment

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

Neat!

@meowjesty meowjesty enabled auto-merge July 5, 2024 14:17
@meowjesty meowjesty added this pull request to the merge queue Jul 5, 2024
Merged via the queue into metalbear-co:main with commit e4d9056 Jul 5, 2024
16 checks passed
@meowjesty meowjesty deleted the issue/2515/unkown-target-v2 branch July 5, 2024 14:55
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.

Add Unknown variant for Target
2 participants