move Kubernetes.ClientHelper to its own package to minimize changes to the generated code

This commit is contained in:
Shimin Guo
2018-01-29 06:27:29 +00:00
parent c0923b91bf
commit 96652da057
7 changed files with 91 additions and 55 deletions

9
kubernetes-client-helper/.gitignore vendored Normal file
View File

@@ -0,0 +1,9 @@
.stack-work
src/highlight.js
src/style.css
dist
dist-newstyle
cabal.project.local
.cabal-sandbox
cabal.sandbox.config
*.cabal

View File

@@ -0,0 +1,52 @@
# kubernetes-client-helper
Library of convenience functions for working with the `kubernetes` package.
## Example
Include the following packages as dependencies:
- kubernetes
- kubernetes-client-helper
- tls
```haskell
{-# LANGUAGE OverloadedStrings #-}
module Main where
import Data.Function ((&))
import qualified Kubernetes.API.CoreV1
import Kubernetes.Client (dispatchMime)
import Kubernetes.ClientHelper
import Kubernetes.Core (newConfig)
import Kubernetes.MimeTypes (Accept (..), MimeJSON (..))
import Network.TLS (credentialLoadX509)
main :: IO ()
main = do
-- We need to first create a Kubernetes.Core.KubernetesConfig and a Network.HTTP.Client.Manager.
-- Currently we need to construct these objects manually. Work is underway to construct these
-- objects automatically from a kubeconfig file. See https://github.com/kubernetes-client/haskell/issues/2.
kcfg <-
newConfig
& fmap (setMasterURI "https://mycluster.example.com") -- fill in master URI
& fmap (setTokenAuth "mytoken") -- if using token auth
& fmap disableValidateAuthMethods -- if using client cert auth
myCAStore <- loadPEMCerts "/path/to/ca.crt" -- if using custom CA certs
myCert <- -- if using client cert
credentialLoadX509 "/path/to/client.crt" "/path/to/client.key"
>>= either error return
tlsParams <-
defaultTLSClientParams
& fmap disableServerNameValidation -- if master address is specified as an IP address
& fmap disableServerCertValidation -- if you don't want to validate the server cert at all (insecure)
& fmap (setCAStore myCAStore) -- if using custom CA certs
& fmap (setClientCert myCert) -- if using client cert
manager <- newManager tlsParams
dispatchMime
manager
kcfg
(Kubernetes.API.CoreV1.listPodForAllNamespaces (Accept MimeJSON))
>>= print
```
s

View File

@@ -0,0 +1,23 @@
name: kubernetes-client-helper
version: 0.1.0.0
library:
source-dirs: src
dependencies:
- base >=4.7 && <5.0
- kubernetes == 0.1.0.0
- pem
- x509
- tls
- x509-system
- x509-store
- data-default-class
- connection
- x509-validation
- http-client >=0.5 && <0.6
- http-client-tls
- bytestring >=0.10.0 && <0.11
- text >=0.11 && <1.3
- safe-exceptions <0.2

View File

@@ -6,48 +6,6 @@ Targeted swagger version: 2.0
OpenAPI-Specification: https://github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md
## Example
## Usage
```haskell
{-# LANGUAGE OverloadedStrings #-}
module Main where
import Data.Function ((&))
import qualified Kubernetes.API.CoreV1
import Kubernetes.Client (dispatchMime)
import Kubernetes.ClientHelper
import Kubernetes.Core (newConfig)
import Kubernetes.MimeTypes (Accept (..), MimeJSON (..))
import Network.TLS (credentialLoadX509)
main :: IO ()
main = do
-- We need to first create a Kubernetes.Core.KubernetesConfig and a Network.HTTP.Client.Manager.
-- Currently we need to construct these objects manually. Work is underway to construct these
-- objects automatically from a kubeconfig file. See https://github.com/kubernetes-client/haskell/issues/2.
kcfg <-
newConfig
& fmap (setMasterURI "https://mycluster.example.com") -- fill in master URI
& fmap (setTokenAuth "mytoken") -- if using token auth
& fmap disableValidateAuthMethods -- if using client cert auth
myCAStore <- loadPEMCerts "/path/to/ca.crt" -- if using custom CA certs
myCert <- -- if using client cert
credentialLoadX509 "/path/to/client.crt" "/path/to/client.key"
>>= either error return
tlsParams <-
defaultTLSClientParams
& fmap disableServerNameValidation -- if master address is specified as an IP address
& fmap disableServerCertValidation -- if you don't want to validate the server cert at all (insecure)
& fmap (setCAStore myCAStore) -- if using custom CA certs
& fmap (setClientCert myCert) -- if using client cert
manager <- newManager tlsParams
dispatchMime
manager
kcfg
(Kubernetes.API.CoreV1.listPodForAllNamespaces (Accept MimeJSON))
>>= print
```
You'll need the following additional package:
- tls
Please refer to the README of the `kubernetes-client-helper` package.

View File

@@ -57,15 +57,6 @@ library
, unordered-containers
, vector >=0.10.9 && <0.13
, katip >=0.4 && < 0.6
-- below are manually added deps
, pem
, x509
, tls
, x509-system
, x509-store
, data-default-class
, connection
, x509-validation
exposed-modules:
Kubernetes
Kubernetes.API.Admissionregistration
@@ -126,8 +117,6 @@ library
Kubernetes.MimeTypes
Kubernetes.Model
Kubernetes.ModelLens
-- below are hand-written modules
Kubernetes.ClientHelper
other-modules:
Paths_kubernetes
default-language: Haskell2010

5
stack.yaml Normal file
View File

@@ -0,0 +1,5 @@
resolver: lts-10.0
extra-deps:
packages:
- kubernetes
- kubernetes-client-helper