keyvalue-kubernetes-configmap 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 825c7440d8b693ea5b399827979fb7822e3b9d4311510765f0a23b656ad8adeb
4
+ data.tar.gz: 30a0615800198d86725f301f4caf588fbd28c97f7a48d334b6ad9caa731595db
5
+ SHA512:
6
+ metadata.gz: ebdebb6f7528b38c24389d8e1eba7702e5481001f30ab8e99a745dcdd0ca28c5d1d4e1a5de4157d960b2cc314a5c3fb5d03da540a27fb323ddb1f306e8ad0a42
7
+ data.tar.gz: 585dfd38d5733a8b6fe985c0e9071fd5d38e288179ba6c3b71782f2f6c6694a3b0301013ba41412fa8eb81c948658c2d13f10ed3b9eb27d72089a93e43467761
@@ -0,0 +1,38 @@
1
+ require 'json'
2
+ require 'keyvalue/kubernetes/configmap/version'
3
+ require 'keyvalue/kubernetes/configmap/kubernetes_client_factory'
4
+
5
+ module KeyValue
6
+ module Kubernetes
7
+ module Configmap
8
+ class Client
9
+ include KubernetesClientFactory
10
+
11
+ def initialize(kubernetesClient = nil)
12
+ @k8sClient = kubernetesClient || create_client()
13
+ end
14
+
15
+ def readKey(keyName)
16
+ begin
17
+ configmap = @k8sClient.get_config_map(keyName, 'default')
18
+ JSON.parse(configmap.data.value)
19
+ rescue Kubeclient::ResourceNotFoundError
20
+ raise Exception.new "Key '#{keyName}' not found"
21
+ end
22
+ end
23
+
24
+ def updateKey(keyName, value)
25
+ begin
26
+ @k8sClient.patch_config_map(
27
+ keyName,
28
+ { :data => { :value => value.to_json } },
29
+ 'default'
30
+ )
31
+ rescue Kubeclient::ResourceNotFoundError
32
+ raise Exception.new "Key '#{keyName}' not found"
33
+ end
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,40 @@
1
+ require 'kubeclient'
2
+
3
+ module KeyValue
4
+ module Kubernetes
5
+ module Configmap
6
+ module KubernetesClientFactory
7
+
8
+ def create_client(path_to_kubeconfig_file = nil)
9
+ if path_to_kubeconfig_file or ENV['KUBECONFIG']
10
+ config = Kubeclient::Config.read(path_to_kubeconfig_file || ENV['KUBECONFIG'])
11
+
12
+ Kubeclient::Client.new(
13
+ config.context.api_endpoint,
14
+ 'v1',
15
+ ssl_options: config.context.ssl_options,
16
+ auth_options: config.context.auth_options,
17
+ )
18
+ else
19
+ # in-cluster authentication
20
+ auth_options = {
21
+ bearer_token_file: '/var/run/secrets/kubernetes.io/serviceaccount/token'
22
+ }
23
+ ssl_options = {}
24
+ if File.exist?("/var/run/secrets/kubernetes.io/serviceaccount/ca.crt")
25
+ ssl_options[:ca_file] = "/var/run/secrets/kubernetes.io/serviceaccount/ca.crt"
26
+ end
27
+
28
+ Kubeclient::Client.new(
29
+ 'https://kubernetes.default.svc',
30
+ 'v1',
31
+ auth_options: auth_options,
32
+ ssl_options: ssl_options
33
+ )
34
+ end
35
+
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,7 @@
1
+ module KeyValue
2
+ module Kubernetes
3
+ module Configmap
4
+ VERSION = "1.0.0"
5
+ end
6
+ end
7
+ end
metadata ADDED
@@ -0,0 +1,118 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: keyvalue-kubernetes-configmap
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Oriol Soriano
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2020-02-23 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: kubeclient
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: 4.6.0
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: 4.6.0
27
+ - !ruby/object:Gem::Dependency
28
+ name: bdd
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: 0.1.5
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: 0.1.5
41
+ - !ruby/object:Gem::Dependency
42
+ name: uuid
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 2.3.0
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 2.3.0
55
+ - !ruby/object:Gem::Dependency
56
+ name: jsonpath
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: 1.0.5
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 1.0.5
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '3.9'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '3.9'
83
+ description:
84
+ email:
85
+ - oriolsoriano@gmail.com
86
+ executables: []
87
+ extensions: []
88
+ extra_rdoc_files: []
89
+ files:
90
+ - lib/keyvalue/kubernetes/configmap.rb
91
+ - lib/keyvalue/kubernetes/configmap/kubernetes_client_factory.rb
92
+ - lib/keyvalue/kubernetes/configmap/version.rb
93
+ homepage: https://github.com/ureesoriano/keyvalue-kubernetes-configmap-ruby
94
+ licenses:
95
+ - MIT
96
+ metadata:
97
+ homepage_uri: https://github.com/ureesoriano/keyvalue-kubernetes-configmap-ruby
98
+ source_code_uri: https://github.com/ureesoriano/keyvalue-kubernetes-configmap-ruby
99
+ post_install_message:
100
+ rdoc_options: []
101
+ require_paths:
102
+ - lib
103
+ required_ruby_version: !ruby/object:Gem::Requirement
104
+ requirements:
105
+ - - ">="
106
+ - !ruby/object:Gem::Version
107
+ version: 2.3.0
108
+ required_rubygems_version: !ruby/object:Gem::Requirement
109
+ requirements:
110
+ - - ">="
111
+ - !ruby/object:Gem::Version
112
+ version: '0'
113
+ requirements: []
114
+ rubygems_version: 3.1.2
115
+ signing_key:
116
+ specification_version: 4
117
+ summary: key-value store backed by kubernetes configmaps
118
+ test_files: []