Skip to content

Commit 96652da

Browse files
author
Shimin Guo
committed
move Kubernetes.ClientHelper to its own package to minimize changes to the generated code
1 parent c0923b9 commit 96652da

File tree

7 files changed

+91
-55
lines changed

7 files changed

+91
-55
lines changed

kubernetes-client-helper/.gitignore

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
.stack-work
2+
src/highlight.js
3+
src/style.css
4+
dist
5+
dist-newstyle
6+
cabal.project.local
7+
.cabal-sandbox
8+
cabal.sandbox.config
9+
*.cabal

kubernetes-client-helper/README.md

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
# kubernetes-client-helper
2+
3+
Library of convenience functions for working with the `kubernetes` package.
4+
5+
## Example
6+
7+
Include the following packages as dependencies:
8+
- kubernetes
9+
- kubernetes-client-helper
10+
- tls
11+
12+
```haskell
13+
{-# LANGUAGE OverloadedStrings #-}
14+
15+
module Main where
16+
17+
import Data.Function ((&))
18+
import qualified Kubernetes.API.CoreV1
19+
import Kubernetes.Client (dispatchMime)
20+
import Kubernetes.ClientHelper
21+
import Kubernetes.Core (newConfig)
22+
import Kubernetes.MimeTypes (Accept (..), MimeJSON (..))
23+
import Network.TLS (credentialLoadX509)
24+
25+
main :: IO ()
26+
main = do
27+
-- We need to first create a Kubernetes.Core.KubernetesConfig and a Network.HTTP.Client.Manager.
28+
-- Currently we need to construct these objects manually. Work is underway to construct these
29+
-- objects automatically from a kubeconfig file. See https://github.com/kubernetes-client/haskell/issues/2.
30+
kcfg <-
31+
newConfig
32+
& fmap (setMasterURI "https://mycluster.example.com") -- fill in master URI
33+
& fmap (setTokenAuth "mytoken") -- if using token auth
34+
& fmap disableValidateAuthMethods -- if using client cert auth
35+
myCAStore <- loadPEMCerts "/path/to/ca.crt" -- if using custom CA certs
36+
myCert <- -- if using client cert
37+
credentialLoadX509 "/path/to/client.crt" "/path/to/client.key"
38+
>>= either error return
39+
tlsParams <-
40+
defaultTLSClientParams
41+
& fmap disableServerNameValidation -- if master address is specified as an IP address
42+
& fmap disableServerCertValidation -- if you don't want to validate the server cert at all (insecure)
43+
& fmap (setCAStore myCAStore) -- if using custom CA certs
44+
& fmap (setClientCert myCert) -- if using client cert
45+
manager <- newManager tlsParams
46+
dispatchMime
47+
manager
48+
kcfg
49+
(Kubernetes.API.CoreV1.listPodForAllNamespaces (Accept MimeJSON))
50+
>>= print
51+
```
52+
s

kubernetes-client-helper/package.yaml

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
name: kubernetes-client-helper
2+
version: 0.1.0.0
3+
library:
4+
source-dirs: src
5+
dependencies:
6+
- base >=4.7 && <5.0
7+
- kubernetes == 0.1.0.0
8+
- pem
9+
- x509
10+
- tls
11+
- x509-system
12+
- x509-store
13+
- data-default-class
14+
- connection
15+
- x509-validation
16+
- http-client >=0.5 && <0.6
17+
- http-client-tls
18+
- bytestring >=0.10.0 && <0.11
19+
- text >=0.11 && <1.3
20+
- safe-exceptions <0.2
21+
22+
23+

kubernetes/README.md

Lines changed: 2 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -6,48 +6,6 @@ Targeted swagger version: 2.0
66

77
OpenAPI-Specification: https://github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md
88

9-
## Example
9+
## Usage
1010

11-
```haskell
12-
{-# LANGUAGE OverloadedStrings #-}
13-
14-
module Main where
15-
16-
import Data.Function ((&))
17-
import qualified Kubernetes.API.CoreV1
18-
import Kubernetes.Client (dispatchMime)
19-
import Kubernetes.ClientHelper
20-
import Kubernetes.Core (newConfig)
21-
import Kubernetes.MimeTypes (Accept (..), MimeJSON (..))
22-
import Network.TLS (credentialLoadX509)
23-
24-
main :: IO ()
25-
main = do
26-
-- We need to first create a Kubernetes.Core.KubernetesConfig and a Network.HTTP.Client.Manager.
27-
-- Currently we need to construct these objects manually. Work is underway to construct these
28-
-- objects automatically from a kubeconfig file. See https://github.com/kubernetes-client/haskell/issues/2.
29-
kcfg <-
30-
newConfig
31-
& fmap (setMasterURI "https://mycluster.example.com") -- fill in master URI
32-
& fmap (setTokenAuth "mytoken") -- if using token auth
33-
& fmap disableValidateAuthMethods -- if using client cert auth
34-
myCAStore <- loadPEMCerts "/path/to/ca.crt" -- if using custom CA certs
35-
myCert <- -- if using client cert
36-
credentialLoadX509 "/path/to/client.crt" "/path/to/client.key"
37-
>>= either error return
38-
tlsParams <-
39-
defaultTLSClientParams
40-
& fmap disableServerNameValidation -- if master address is specified as an IP address
41-
& fmap disableServerCertValidation -- if you don't want to validate the server cert at all (insecure)
42-
& fmap (setCAStore myCAStore) -- if using custom CA certs
43-
& fmap (setClientCert myCert) -- if using client cert
44-
manager <- newManager tlsParams
45-
dispatchMime
46-
manager
47-
kcfg
48-
(Kubernetes.API.CoreV1.listPodForAllNamespaces (Accept MimeJSON))
49-
>>= print
50-
```
51-
52-
You'll need the following additional package:
53-
- tls
11+
Please refer to the README of the `kubernetes-client-helper` package.

kubernetes/kubernetes.cabal

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -57,15 +57,6 @@ library
5757
, unordered-containers
5858
, vector >=0.10.9 && <0.13
5959
, katip >=0.4 && < 0.6
60-
-- below are manually added deps
61-
, pem
62-
, x509
63-
, tls
64-
, x509-system
65-
, x509-store
66-
, data-default-class
67-
, connection
68-
, x509-validation
6960
exposed-modules:
7061
Kubernetes
7162
Kubernetes.API.Admissionregistration
@@ -126,8 +117,6 @@ library
126117
Kubernetes.MimeTypes
127118
Kubernetes.Model
128119
Kubernetes.ModelLens
129-
-- below are hand-written modules
130-
Kubernetes.ClientHelper
131120
other-modules:
132121
Paths_kubernetes
133122
default-language: Haskell2010

stack.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
resolver: lts-10.0
2+
extra-deps:
3+
packages:
4+
- kubernetes
5+
- kubernetes-client-helper

0 commit comments

Comments
 (0)