kubernetes-operator 0.0.1 → 0.0.2

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.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +25 -5
  3. data/lib/kubernetes-operator.rb +40 -35
  4. metadata +3 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c172c29b434156c033e913d2a75f2ca3d4e0167aca5a97d8beedc3b54624d790
4
- data.tar.gz: 8365a0305165569330e73566c307243c2184817a0343b0db38f3d9fe92a937b0
3
+ metadata.gz: fea623164ec2a233bfca10f01311607bb48ccc75bbb5608d0c119cd551a86699
4
+ data.tar.gz: 52bb5c2f22dfd0af819f98f61a47a66a8109f4006b2b5b7efb209c73b25f08cb
5
5
  SHA512:
6
- metadata.gz: bd3ef139436194830920678f1f5a3d8c0b06580b45c3dd6af92542d438c524743335bc4c3fb856e2a3bd0b37a80637a00ea278fe6ef102c6394dd549533c1032
7
- data.tar.gz: 8b75159dae0de65a1a6d687f864036f569b0aeb57281061881f56e58e894986ed46b55ffea665a958a0fb3afb8d5bfc75a1c92d61c9a185cc77f17ecba6d9ea7
6
+ metadata.gz: 58b5c57faec3ad7fb0a3bf87919b33708872400f687d5216a606e3037f318a704f0d776f874d3749cb09710d87500a4c9c7fbc75f3b421bd103d0a997c01af28
7
+ data.tar.gz: 90ae44767237c5a5613e3af416d170ac29d9af338674933b1c95e5c2c5f02589af9372241fd00a131d907c892d7d0a932a571fea8bce88361991dc9bb9587847
data/README.md CHANGED
@@ -1,12 +1,32 @@
1
- # example usage
2
- crdGroup = "familykuntzsch.de"
1
+ # Ruby Kubernetes Operator
2
+ If you do not want to create your operators for kubernetes in golang, it is difficult to find good frameworks. This gem is used to implement a few basic functions and to quickly create your own operators based on ruby. It is not a framework, so the YAML CRDs still have to be created by hand.
3
+
4
+ ## How it works?
5
+ - Watch changes on CR.
6
+ - Trigger Actions for Add,Update or Delete
7
+ - Handle the finalizer on create and after delete
8
+
9
+ ![KubernetesOperator.png](KubernetesOperator.png)
10
+
11
+ ## Installation
12
+ The gem is hosted on [rubygems.org](https://rubygems.org/gems/kubernetes-operator), so you can install it with ...
13
+ ```
14
+ gem install kubernetes-operator
15
+ ```
16
+ ... or with bundler in your Gemfile.
17
+
18
+ ## Example
19
+
20
+ ```
21
+ crdGroup = "exmaple.com"
3
22
  crdVersion = "v1alpha1"
4
- crdPlural = "fuconfigs"
23
+ crdPlural = "myres"
5
24
 
6
25
  def my_custom_action(obj,k8sclient)
7
- puts "==> Im cool as fu (#{obj["metadata"]["crd_status"]} of #{obj["metadata"]["name"]})"
26
+ puts "Do some cool stuff for #{obj["metadata"]["crd_status"]} action of #{obj["metadata"]["name"]}"
8
27
  end
9
28
 
10
29
  opi = KubernetesOperator.new(crdGroup,crdVersion,crdPlural)
11
30
  opi.setAddMethod(method(:my_custom_action))
12
- opi.run()
31
+ opi.run()
32
+ ```
@@ -57,6 +57,10 @@ class KubernetesOperator
57
57
  @sleepTimer = nr
58
58
  end
59
59
 
60
+ def setScopeNamespaces(lst)
61
+ @lstOfNamespaces = lst
62
+ end
63
+
60
64
 
61
65
  # Controller
62
66
  def run
@@ -74,48 +78,49 @@ class KubernetesOperator
74
78
  _uid = _i["metadata"]["uid"]
75
79
  _v = _i["metadata"]["resourceVersion"]
76
80
 
77
- _from_cache = @store.transaction{@store[_uid]}
81
+ if @lstOfNamespaces == nil || @lstOfNamespaces.contains(_i["metadata"]["namespace"])
82
+ _from_cache = @store.transaction{@store[_uid]}
78
83
 
79
- unless _from_cache
80
- # Add finalizer and refresh version number
81
- _i[:metadata][:finalizers] = ["#{@crdPlural}.#{@crdVersion}.#{@crdGroup}"]
82
- _i2 = @k8sclient.api(@crdGroup+"/"+@crdVersion).resource(@crdPlural).update_resource(_i)
83
- _v = _i2["metadata"]["resourceVersion"]
84
+ unless _from_cache
85
+ # Add finalizer and refresh version number
86
+ _i[:metadata][:finalizers] = ["#{@crdPlural}.#{@crdVersion}.#{@crdGroup}"]
87
+ _i2 = @k8sclient.api(@crdGroup+"/"+@crdVersion).resource(@crdPlural).update_resource(_i)
88
+ _v = _i2["metadata"]["resourceVersion"]
84
89
 
85
- # Cache last version of ressources
86
- @store.transaction do
87
- @store[_uid] = _v
88
- @store.commit
89
- end
90
+ # Cache last version of ressources
91
+ @store.transaction do
92
+ @store[_uid] = _v
93
+ @store.commit
94
+ end
90
95
 
91
- # call the action method
92
- _i["metadata"]["crd_status"] = "add"
93
- @addMethod.call(_i,@k8sclient)
94
- else
95
- # only trigger action on change or delete event
96
- unless _from_cache == _v
97
- if _i["metadata"]["deletionTimestamp"]
98
- # remove finalizers
99
- _i[:metadata][:finalizers] = []
100
- @k8sclient.api(@crdGroup+"/"+@crdVersion).resource(@crdPlural).update_resource(_i)
101
-
102
- # call the action method
103
- _i["metadata"]["crd_status"] = "delete"
104
- @deleteMethod.call(_i,@k8sclient)
105
- else
106
- # store new version in cache
107
- @store.transaction do
108
- @store[_uid] = _v
109
- @store.commit
96
+ # call the action method
97
+ _i["metadata"]["crd_status"] = "add"
98
+ @addMethod.call(_i,@k8sclient)
99
+ else
100
+ # only trigger action on change or delete event
101
+ unless _from_cache == _v
102
+ if _i["metadata"]["deletionTimestamp"]
103
+ # remove finalizers
104
+ _i[:metadata][:finalizers] = []
105
+ @k8sclient.api(@crdGroup+"/"+@crdVersion).resource(@crdPlural).update_resource(_i)
106
+
107
+ # call the action method
108
+ _i["metadata"]["crd_status"] = "delete"
109
+ @deleteMethod.call(_i,@k8sclient)
110
+ else
111
+ # store new version in cache
112
+ @store.transaction do
113
+ @store[_uid] = _v
114
+ @store.commit
115
+ end
116
+
117
+ # call the action method
118
+ _i["metadata"]["crd_status"] = "update"
119
+ @updateMethod.call(_i,@k8sclient)
110
120
  end
111
-
112
- # call the action method
113
- _i["metadata"]["crd_status"] = "update"
114
- @updateMethod.call(_i,@k8sclient)
115
121
  end
116
122
  end
117
123
  end
118
-
119
124
  end
120
125
 
121
126
  # Done
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kubernetes-operator
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tobias Kuntzsch
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-03-23 00:00:00.000000000 Z
11
+ date: 2020-03-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: k8s-client
@@ -50,7 +50,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
50
50
  - !ruby/object:Gem::Version
51
51
  version: '0'
52
52
  requirements: []
53
- rubygems_version: 3.0.8
53
+ rubygems_version: 3.0.3
54
54
  signing_key:
55
55
  specification_version: 4
56
56
  summary: lib