From ea3cf306fba6a30971fee3a93d945c304ce3821d Mon Sep 17 00:00:00 2001 From: Gabriel Gonzalez Date: Fri, 28 Feb 2020 09:02:14 -0800 Subject: [PATCH] Prefer `autoscaler/v2beta2` (#113) Fixes https://github.com/dhall-lang/dhall-kubernetes/issues/112 --- src/Main.hs | 25 +++++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) diff --git a/src/Main.hs b/src/Main.hs index 3068cabff..c2f2abd82 100644 --- a/src/Main.hs +++ b/src/Main.hs @@ -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