Skip to content

Commit d695148

Browse files
committed
Add examples for loading kubeconfig and in cluster config
1 parent 7261011 commit d695148

File tree

2 files changed

+79
-11
lines changed

2 files changed

+79
-11
lines changed

kubernetes-client/README.md

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,52 @@
22

33
## Example
44

5+
### Load KubeConfig file
6+
7+
```haskell
8+
import Control.Concurrent.STM (atomically, newTVar)
9+
import Kubernetes.Client (KubeConfigSource (..), kubeClient)
10+
import Kubernetes.OpenAPI (Accept (..), MimeJSON (..), dispatchMime)
11+
12+
import qualified Data.Map as Map
13+
import qualified Kubernetes.OpenAPI.API.CoreV1 as CoreV1
14+
15+
main :: IO ()
16+
main = do
17+
oidcCache <- atomically $ newTVar $ Map.fromList []
18+
(mgr, kcfg) <- kubeClient oidcCache $ KubeConfigFile "/path/to/kubeconfig"
19+
dispatchMime
20+
mgr
21+
kcfg
22+
(CoreV1.listPodForAllNamespaces (Accept MimeJSON))
23+
>>= print
24+
```
25+
26+
### Load InCluster Config
27+
28+
```haskell
29+
import Control.Concurrent.STM (atomically, newTVar)
30+
import Data.Function ((&))
31+
import Kubernetes.Client (KubeConfigSource (..), kubeClient)
32+
import Kubernetes.OpenAPI (Accept (..), MimeJSON (..), dispatchMime)
33+
import Network.TLS (credentialLoadX509)
34+
35+
import qualified Data.Map as Map
36+
import qualified Kubernetes.OpenAPI.API.CoreV1 as CoreV1
37+
38+
main :: IO ()
39+
main = do
40+
oidcCache <- atomically $ newTVar $ Map.fromList []
41+
(mgr, kcfg) <- kubeClient oidcCache KubeConfigCluster
42+
dispatchMime
43+
mgr
44+
kcfg
45+
(CoreV1.listPodForAllNamespaces (Accept MimeJSON))
46+
>>= print
47+
```
48+
49+
### Load config from URL and paths
50+
551
```haskell
652
{-# LANGUAGE OverloadedStrings #-}
753

kubernetes-client/example/App.hs

Lines changed: 33 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,18 +2,20 @@
22

33
module Main where
44

5-
import Data.Function ((&))
6-
import Kubernetes.Client (defaultTLSClientParams,
7-
disableServerCertValidation,
8-
disableServerNameValidation,
9-
disableValidateAuthMethods,
10-
loadPEMCerts, newManager,
11-
setCAStore, setClientCert,
12-
setMasterURI, setTokenAuth)
13-
import Kubernetes.OpenAPI (Accept (..), MimeJSON (..),
14-
dispatchMime, newConfig)
5+
import Control.Concurrent.STM (atomically, newTVar)
6+
import Data.Function ((&))
7+
import Kubernetes.Client (KubeConfigSource (..), defaultTLSClientParams,
8+
disableServerCertValidation,
9+
disableServerNameValidation,
10+
disableValidateAuthMethods, kubeClient,
11+
loadPEMCerts, newManager, setCAStore,
12+
setClientCert, setMasterURI, setTokenAuth)
13+
import Kubernetes.OpenAPI (Accept (..), MimeJSON (..), dispatchMime,
14+
newConfig)
15+
import Network.TLS (credentialLoadX509)
16+
17+
import qualified Data.Map as Map
1518
import qualified Kubernetes.OpenAPI.API.CoreV1 as CoreV1
16-
import Network.TLS (credentialLoadX509)
1719

1820
example :: IO ()
1921
example = do
@@ -42,5 +44,25 @@ example = do
4244
(CoreV1.listPodForAllNamespaces (Accept MimeJSON))
4345
>>= print
4446

47+
exampleWithKubeConfig :: IO ()
48+
exampleWithKubeConfig = do
49+
oidcCache <- atomically $ newTVar $ Map.fromList []
50+
(mgr, kcfg) <- kubeClient oidcCache $ KubeConfigFile "/path/to/kubeconfig"
51+
dispatchMime
52+
mgr
53+
kcfg
54+
(CoreV1.listPodForAllNamespaces (Accept MimeJSON))
55+
>>= print
56+
57+
exampleWithInClusterConfig :: IO ()
58+
exampleWithInClusterConfig = do
59+
oidcCache <- atomically $ newTVar $ Map.fromList []
60+
(mgr, kcfg) <- kubeClient oidcCache KubeConfigCluster
61+
dispatchMime
62+
mgr
63+
kcfg
64+
(CoreV1.listPodForAllNamespaces (Accept MimeJSON))
65+
>>= print
66+
4567
main :: IO ()
4668
main = return ()

0 commit comments

Comments
 (0)