Skip to content

Commit 4ea2dab

Browse files
committed
simplify cabal
1 parent 2f861c1 commit 4ea2dab

File tree

1 file changed

+1
-84
lines changed

1 file changed

+1
-84
lines changed

kubernetes-webhook-haskell.cabal

Lines changed: 1 addition & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -11,90 +11,7 @@ category: Web
1111
build-type: Simple
1212
extra-source-files: README.md
1313
cabal-version: >=1.10
14-
description:
15-
This library lets you create [Kubernetes Admission Webhooks](https://kubernetes.io/docs/reference/access-authn-authz/extensible-admission-controllers/) in Haskell.
16-
17-
Using webhooks in Kubernetes requires some configuration, in the [dhall](./dhall) directory you can find some useful templates that you can reuse to deploy your webhooks. [cert-manager](https://cert-manager.io/docs/) is required to be installed in the cluster to use the templates.
18-
19-
Example webhook using Servant:
20-
```hs
21-
module Kubernetes.Example
22-
( startApp,
23-
app,
24-
)
25-
where
26-
27-
import Control.Monad.IO.Class
28-
import qualified Data.Aeson as A
29-
import qualified Data.ByteString as BS
30-
import qualified Data.HashMap.Strict as HM
31-
import Data.Text
32-
import GHC.Generics
33-
import qualified Kubernetes.Webhook as W
34-
import Network.Wai
35-
import Network.Wai.Handler.Warp
36-
import Network.Wai.Handler.WarpTLS
37-
import Servant
38-
import System.Environment
39-
40-
type API =
41-
"mutate" :> ReqBody '[JSON] W.AdmissionReviewRequest :> Post '[JSON] W.AdmissionReviewResponse
42-
43-
data Toleration
44-
= Toleration
45-
{ effect :: Maybe TolerationEffect,
46-
key :: Maybe Text,
47-
operator :: Maybe TolerationOperator,
48-
tolerationSeconds :: Maybe Integer,
49-
value :: Maybe Text
50-
}
51-
deriving (Generic, A.ToJSON)
52-
53-
data TolerationEffect = NoSchedule | PreferNoSchedule | NoExecute deriving (Generic, A.ToJSON)
54-
55-
data TolerationOperator = Exists | Equal deriving (Generic, A.ToJSON)
56-
57-
testToleration :: Toleration
58-
testToleration =
59-
Toleration
60-
{ effect = Just NoSchedule,
61-
key = Just "dedicated",
62-
operator = Just Equal,
63-
tolerationSeconds = Nothing,
64-
value = Just "test"
65-
}
66-
67-
startApp :: IO ()
68-
startApp = do
69-
let tlsOpts = tlsSettings "/certs/tls.crt" "/certs/tls.key"
70-
warpOpts = setPort 8080 defaultSettings
71-
runTLS tlsOpts warpOpts app
72-
73-
app :: Application
74-
app = serve api server
75-
76-
api :: Proxy API
77-
api = Proxy
78-
79-
server :: Server API
80-
server = mutate
81-
82-
mutate :: W.AdmissionReviewRequest -> Handler W.AdmissionReviewResponse
83-
mutate req = pure $ W.mutatingWebhook req (\_ -> Right W.Allowed) addToleration
84-
85-
addToleration :: W.Patch
86-
addToleration =
87-
W.Patch
88-
[ W.PatchOperation
89-
{ op = W.Add,
90-
path = "/spec/tolerations/-",
91-
from = Nothing,
92-
value = Just $ A.toJSON testToleration
93-
}
94-
]
95-
```
96-
97-
14+
description: This library lets you create [Kubernetes Admission Webhooks](https://kubernetes.io/docs/reference/access-authn-authz/extensible-admission-controllers/) in Haskell.
9815

9916
library
10017
hs-source-dirs: src

0 commit comments

Comments
 (0)