Class: KubernetesDeploy::KubernetesResource::Event
- Inherits:
-
Object
- Object
- KubernetesDeploy::KubernetesResource::Event
- Defined in:
- lib/kubernetes-deploy/kubernetes_resource.rb
Constant Summary collapse
- EVENT_SEPARATOR =
"ENDEVENT--BEGINEVENT"
- FIELD_SEPARATOR =
"ENDFIELD--BEGINFIELD"
- FIELDS =
%w( .involvedObject.kind .involvedObject.name .count .lastTimestamp .reason .message )
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(subject_kind:, last_timestamp:, reason:, message:, count:, subject_name:) ⇒ Event
constructor
A new instance of Event.
- #seen_since?(time) ⇒ Boolean
- #to_s ⇒ Object
Constructor Details
#initialize(subject_kind:, last_timestamp:, reason:, message:, count:, subject_name:) ⇒ Event
Returns a new instance of Event.
225 226 227 228 229 230 231 232 |
# File 'lib/kubernetes-deploy/kubernetes_resource.rb', line 225 def initialize(subject_kind:, last_timestamp:, reason:, message:, count:, subject_name:) @subject_kind = subject_kind @subject_name = subject_name @last_timestamp = Time.parse() @reason = reason @message = .tr("\n", '') @count = count.to_i end |
Class Method Details
.extract_all_from_go_template_blob(blob) ⇒ Object
211 212 213 214 215 216 217 218 219 220 221 222 223 |
# File 'lib/kubernetes-deploy/kubernetes_resource.rb', line 211 def self.extract_all_from_go_template_blob(blob) blob.split(EVENT_SEPARATOR).map do |event_blob| pieces = event_blob.split(FIELD_SEPARATOR, FIELDS.length) new( subject_kind: pieces[FIELDS.index(".involvedObject.kind")], subject_name: pieces[FIELDS.index(".involvedObject.name")], count: pieces[FIELDS.index(".count")], last_timestamp: pieces[FIELDS.index(".lastTimestamp")], reason: pieces[FIELDS.index(".reason")], message: pieces[FIELDS.index(".message")] ) end end |
.go_template_for(kind, name) ⇒ Object
199 200 201 202 203 204 205 206 207 208 209 |
# File 'lib/kubernetes-deploy/kubernetes_resource.rb', line 199 def self.go_template_for(kind, name) and_conditions = [ %[(eq .involvedObject.kind "#{kind}")], %[(eq .involvedObject.name "#{name}")], '(ne .reason "Started")', '(ne .reason "Created")' ] condition_start = "{{if and #{and_conditions.join(' ')}}}" field_part = FIELDS.map { |f| "{{#{f}}}" }.join(%({{print "#{FIELD_SEPARATOR}"}})) %({{range .items}}#{condition_start}#{field_part}{{print "#{EVENT_SEPARATOR}"}}{{end}}{{end}}) end |
Instance Method Details
#seen_since?(time) ⇒ Boolean
234 235 236 |
# File 'lib/kubernetes-deploy/kubernetes_resource.rb', line 234 def seen_since?(time) time.to_i <= @last_timestamp.to_i end |
#to_s ⇒ Object
238 239 240 |
# File 'lib/kubernetes-deploy/kubernetes_resource.rb', line 238 def to_s "#{@reason}: #{@message} (#{@count} events)" end |