Skip to content

Commit

Permalink
Prefer autoscaler/v2beta2 (dhall-lang#113)
Browse files Browse the repository at this point in the history
  • Loading branch information
Gabriella439 authored Feb 28, 2020
1 parent 0f12913 commit ea3cf30
Showing 1 changed file with 23 additions and 2 deletions.
25 changes: 23 additions & 2 deletions src/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -138,9 +138,30 @@ getVersion ModelName{..} =
Left _ -> Nothing
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
| otherwise =
Nothing

preferStableResource :: DuplicateHandler
preferStableResource (_, names) =
return (List.maximumBy (Ord.comparing getVersion) names)
preferStableResource (_, names) = do
let issue112 = Ord.comparing getAutoscaling

let defaultComparison = Ord.comparing getVersion

let comparison = issue112 <> defaultComparison

return (List.maximumBy comparison names)

skipDuplicatesHandler :: DuplicateHandler
skipDuplicatesHandler = const Nothing
Expand Down

0 comments on commit ea3cf30

Please sign in to comment.