plugins/kubernetes/app/models/kubernetes/resource_status.rb
def events(type: nil)
      name = @resource.dig_fetch(:metadata, :name)
      namespace = @resource.dig(:metadata, :namespace)
      selector = [
        "involvedObject.name=#{name}",
        "involvedObject.kind=#{@kind}",
      ]
      selector << "involvedObject.uid=#{@pod.uid}" if @pod
      selector << "type=#{type}" if type
      SamsonKubernetes.retry_on_connection_errors do
        events = @client.get_events(
          namespace: namespace,
          field_selector: selector.join(",")
        ).fetch(:items)

        # ignore events from before the deploy, comparing strings for speed
        events.select! { |e| last_timestamp(e) >= @start }

        # https://github.com/kubernetes/kubernetes/issues/29838
        events.sort_by! { |e| last_timestamp(e) }

        events
      end
    rescue *SamsonKubernetes.connection_errors => e
      # similar to kubernetes/resource.rb error handling
      error_location = "#{name} #{namespace} #{@deploy_group.name}"
      raise Samson::Hooks::UserError, "Kubernetes error #{error_location}: #{e.message}"
    end
# do not rely on uid, when creation fails we don't get one
do not rely on uid, when creation fails we don't get one
do not rely on uid when creation fails we don ' t get one
def events(type: nil)
      name = @resource.dig_fetch(:metadata, :name)
      namespace = @resource.dig(:metadata, :namespace)
      selector = [
        "involvedObject.name=#{name}",
        "involvedObject.kind=#{@kind}",
      ]
      selector << "involvedObject.uid=#{@pod.uid}" if @pod
      selector << "type=#{type}" if type
      SamsonKubernetes.retry_on_connection_errors do
        events = @client.get_events(
          namespace: namespace,
          field_selector: selector.join(",")
        ).fetch(:items)
        events.select! { |e| last_timestamp(e) >= @start }
        events.sort_by! { |e| last_timestamp(e) }
        events
      end
    rescue *SamsonKubernetes.connection_errors => e
      error_location = "#{name} #{namespace} #{@deploy_group.name}"
      raise Samson::Hooks::UserError, "Kubernetes error #{error_location}: #{e.message}"
    end
def events ( type : nil ) name = @resource . dig_fetch ( :metadata , :name ) namespace = @resource . dig ( :metadata , :namespace ) selector = [ "involvedObject.name=#{name}" , "involvedObject.kind=#{@kind}" , ] selector << "involvedObject.uid=#{@pod.uid}" if @pod selector << "type=#{type}" if type SamsonKubernetes . retry_on_connection_errors do events = @client . get_events ( namespace : namespace , field_selector : selector . join ( "," ) ) . fetch ( :items ) events . select! { | e | last_timestamp ( e ) >= @start } events . sort_by! { | e | last_timestamp ( e ) } events end rescue * SamsonKubernetes . connection_errors => e error_location = "#{name} #{namespace} #{@deploy_group.name}" raise Samson :: Hooks :: UserError , "Kubernetes error #{error_location}: #{e.message}" end
do not rely on uid, when creation fails we don't get one
do not rely on uid when creation fails we don ' t get one
# ignore events from before the deploy, comparing strings for speed # https://github.com/kubernetes/kubernetes/issues/29838 # similar to kubernetes/resource.rb error handling
type