Skip to content

Commit

Permalink
fix: all tests serial
Browse files Browse the repository at this point in the history
  • Loading branch information
renescheepers committed Jul 21, 2022
1 parent 9770318 commit 2edd0b3
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
2 changes: 1 addition & 1 deletion lib/krane/cluster_resource_discovery.rb
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ def resource_hash(path, namespaced, blob)
end

def fetch_crds
raw_json, err, st = kubectl.run("get", "CustomResourceDefinition", output: "json", attempts: 5,
raw_json, err, st = kubectl.run("get", "CustomResourceDefinition.apiextensions.k8s.io", output: "json", attempts: 5,
use_namespace: false)
if st.success?
JSON.parse(raw_json)["items"]
Expand Down
16 changes: 10 additions & 6 deletions lib/krane/kubernetes_resource.rb
Original file line number Diff line number Diff line change
Expand Up @@ -361,14 +361,14 @@ def debug_message(cause = nil, info_hash = {})
def fetch_events(kubectl)
return {} unless exists?

out, _err, st = kubectl.run("get", "events", "--output=go-template=#{Event.go_template_for(group, kind, name)}",
out, err, st = kubectl.run("get", "events", "--output=go-template=#{Event.go_template_for(group, kind, name)}",
log_failure: false, use_namespace: !global?)

return {} unless st.success?
raise FatalKubeAPIError, "Error retrieving events: #{err}" unless st.success?

event_collector = Hash.new { |hash, key| hash[key] = [] }
Event.extract_all_from_go_template_blob(out).each_with_object(event_collector) do |candidate, events|
events[id] << candidate.to_s if candidate.seen_since?(@deploy_started_at - 60.seconds)
events[id] << candidate.to_s if candidate.seen_since?(@deploy_started_at - 5.seconds)
end
end

Expand Down Expand Up @@ -442,7 +442,8 @@ class Event

def self.go_template_for(group, kind, name)
and_conditions = [
# First check that the API version is of equal lenght or longer than the group.
'.involvedObject.apiVersion',
# First check that the API version is of equal length or longer than the group.
%[(gt (len .involvedObject.apiVersion) (len \"#{group}\"))],
# Check that the API version starts with the group.
%[(eq (slice .involvedObject.apiVersion 0 (len \"#{group}\")) \"#{group}\")],
Expand All @@ -455,9 +456,12 @@ def self.go_template_for(group, kind, name)
'(ne .reason "Pulling")',
'(ne .reason "Pulled")',
]
condition_start = "{{if and #{and_conditions.join(' ')}}}"

and_conditions_string = and_conditions.map { |c| "{{if #{c}}}" }.join("")
ends = "{{end}}" * and_conditions.length

field_part = FIELDS.map { |f| "{{#{f}}}" }.join(%({{print "#{FIELD_SEPARATOR}"}}))
%({{range .items}}#{condition_start}#{field_part}{{print "#{EVENT_SEPARATOR}"}}{{end}}{{end}})
%({{range .items}}#{and_conditions_string}#{field_part}{{print "#{EVENT_SEPARATOR}"}}#{ends}{{end}})
end

def self.extract_all_from_go_template_blob(blob)
Expand Down
4 changes: 0 additions & 4 deletions lib/krane/task_config.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,5 @@ def kubeclient_builder
def cluster_resource_discoverer
@cluster_resource_discoverer ||= ClusterResourceDiscovery.new(task_config: self)
end

def fetch_resources
@fetch_resources ||= cluster_resource_discoverer.fetch_resources(namespaced: false)
end
end
end

0 comments on commit 2edd0b3

Please sign in to comment.