diff --git a/lib/krane/cluster_resource_discovery.rb b/lib/krane/cluster_resource_discovery.rb index 7e59272e7..ea44fe266 100644 --- a/lib/krane/cluster_resource_discovery.rb +++ b/lib/krane/cluster_resource_discovery.rb @@ -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"] diff --git a/lib/krane/kubernetes_resource.rb b/lib/krane/kubernetes_resource.rb index 0d682f1ab..bb05248a9 100644 --- a/lib/krane/kubernetes_resource.rb +++ b/lib/krane/kubernetes_resource.rb @@ -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 @@ -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}\")], @@ -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) diff --git a/lib/krane/task_config.rb b/lib/krane/task_config.rb index 18ae6d51d..5d2670123 100644 --- a/lib/krane/task_config.rb +++ b/lib/krane/task_config.rb @@ -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