plugins/kubernetes/app/models/kubernetes/role_validator.rb
def validate_name_kinds_are_unique
      # do not validate on global since we hope to be on namespace soon
      return if !@project || !@project.override_resource_names?

      # ignore services where we generate their names
      elements = @elements.reject { |e| !e[:kind] || (e[:kind] == "Service" && !self.class.keep_name?(e)) }

      # group by kind+name and to sure we have no duplicates
      groups = elements.group_by do |e|
        user_supplied = (ALLOWED_DUPLICATE_KINDS.include?(e.fetch(:kind)) || self.class.keep_name?(e))
        [e.fetch(:kind), e.dig(:metadata, :namespace), user_supplied ? e.dig(:metadata, :name) : "hardcoded"]
      end.values
      bad = groups.select { |group| group.size > 1 }
      return if bad.empty?

      bad_kinds = bad.map { |g| g.first[:kind] }
      @errors <<
        "Only use 1 per kind #{bad_kinds.join(", ")} in a role\n" \
        "To bypass: assign a namespace to the project, or set metadata.annotations.samson/keep_name=\"true\""
    end
# template_filler.rb sets name for everything except for IMMUTABLE_NAME_KINDS, keep_name, and Service
# we make sure users dont use the same name on the same kind twice, to avoid them overwriting each other
# if they run in the default namespace
template_filler.rb sets name for everything except for IMMUTABLE_NAME_KINDS, keep_name, and Service
we make sure users dont use the same name on the same kind twice, to avoid them overwriting each other
if they run in the default namespace
template_filler . rb sets name for everything except for IMMUTABLE_NAME_KINDS keep_name and Service we make sure users dont use the same name on the same kind twice to avoid them overwriting each other if they run in the default namespace
def validate_name_kinds_are_unique
      return if !@project || !@project.override_resource_names?
      elements = @elements.reject { |e| !e[:kind] || (e[:kind] == "Service" && !self.class.keep_name?(e)) }
      groups = elements.group_by do |e|
        user_supplied = (ALLOWED_DUPLICATE_KINDS.include?(e.fetch(:kind)) || self.class.keep_name?(e))
        [e.fetch(:kind), e.dig(:metadata, :namespace), user_supplied ? e.dig(:metadata, :name) : "hardcoded"]
      end.values
      bad = groups.select { |group| group.size > 1 }
      return if bad.empty?
      bad_kinds = bad.map { |g| g.first[:kind] }
      @errors <<
        "Only use 1 per kind #{bad_kinds.join(", ")} in a role\n" \
        "To bypass: assign a namespace to the project, or set metadata.annotations.samson/keep_name=\"true\""
    end
def validate_name_kinds_are_unique return if ! @project || ! @project . override_resource_names? elements = @elements . reject { | e | ! e [ :kind ] || ( e [ :kind ] == "Service" && ! self . class . keep_name? ( e ) ) } groups = elements . group_by do | e | user_supplied = ( ALLOWED_DUPLICATE_KINDS . include? ( e . fetch ( :kind ) ) || self . class . keep_name? ( e ) ) [ e . fetch ( :kind ) , e . dig ( :metadata , :namespace ) , user_supplied ? e . dig ( :metadata , :name ) : "hardcoded" ] end . values bad = groups . select { | group | group . size > 1 } return if bad . empty? bad_kinds = bad . map { | g | g . first [ :kind ] } @errors << "Only use 1 per kind #{bad_kinds.join(", ")} in a role\n" "To bypass: assign a namespace to the project, or set metadata.annotations.samson/keep_name=\"true\"" end
template_filler.rb sets name for everything except for IMMUTABLE_NAME_KINDS, keep_name, and Service
we make sure users dont use the same name on the same kind twice, to avoid them overwriting each other
if they run in the default namespace
template_filler . rb sets name for everything except for IMMUTABLE_NAME_KINDS keep_name and Service we make sure users dont use the same name on the same kind twice to avoid them overwriting each other if they run in the default namespace
# do not validate on global since we hope to be on namespace soon # ignore services where we generate their names # group by kind+name and to sure we have no duplicates