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

dhall-openapi: Fix autoscaler preference #2562

Merged
merged 1 commit into from
Dec 28, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 13 additions & 14 deletions dhall-openapi/openapi-to-dhall/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -144,29 +144,28 @@ getVersion ModelName{..} =
Right version -> Just version

-- https://github.com/dhall-lang/dhall-kubernetes/issues/112
data Autoscaling = AutoscalingV1 | AutoscalingV2beta1 | AutoscalingV2beta2
deriving (Eq, Ord)

getAutoscaling :: ModelName -> Maybe Autoscaling
getAutoscaling ModelName{..}
| Text.isPrefixOf "io.k8s.api.autoscaling.v1" unModelName =
Just AutoscalingV1
| Text.isPrefixOf "io.k8s.api.autoscaling.v2beta1" unModelName =
Just AutoscalingV2beta1
| Text.isPrefixOf "io.k8s.api.autoscaling.v2beta2" unModelName =
Just AutoscalingV2beta2
-- https://github.com/dhall-lang/dhall-kubernetes/issues/191
comparingAutoscaling :: ModelName -> ModelName -> Ordering
comparingAutoscaling modelNameL modelNameR
| isAutoscaling modelNameL && isAutoscaling modelNameR =
case (getVersion modelNameL, getVersion modelNameR) of
(Just (Version Production 1), Just (Version (Beta _) 2)) -> LT
(Just (Version (Beta _) 2), Just (Version Production 1)) -> GT
_ -> mempty
| otherwise =
Nothing
mempty
where
isAutoscaling ModelName{..} =
Text.isPrefixOf "io.k8s.api.autoscaling." unModelName

isK8sNative :: ModelName -> Bool
isK8sNative ModelName{..} = Text.isPrefixOf "io.k8s." unModelName

preferStableResource :: DuplicateHandler
preferStableResource (_, names) = do
let issue112 = Ord.comparing getAutoscaling
let k8sOverCrd = Ord.comparing isK8sNative
let defaultComparison = Ord.comparing getVersion
let comparison = issue112 <> k8sOverCrd <> defaultComparison
let comparison = comparingAutoscaling <> k8sOverCrd <> defaultComparison
return (List.maximumBy comparison names)

skipDuplicatesHandler :: DuplicateHandler
Expand Down
Loading