name: InstallKarpenter
description: 'Installs Go Downloads and installs Karpenter Dependencies'
inputs:
  account_id:
    description: "Account ID to access AWS"
    required: true
  role:
    description: "Role to access AWS"
    required: true
  region:
    description: "Region to access AWS"
    required: true
  ecr_account_id:
    description: "Account ID for the ECR repo"
    required: true
  ecr_region:
    description: "Region for the ECR repo"
    required: true
  cluster_name:
    description: 'Name of the cluster to be launched by eksctl'
    required: true
  k8s_version:
    description: 'Version of Kubernetes to use for the launched cluster'
    default: "1.31"
  git_ref:
    description: "The git commit, tag, or branch to check out. Requires a corresponding Karpenter snapshot release"
  private_cluster:
    description: "Whether the cluster is private or not. Valid values are 'true' or 'false'"
    default: 'false'
runs:
  using: "composite"
  steps:
  - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
    with:
      ref: ${{ inputs.git_ref }}
  - uses: ./.github/actions/e2e/install-helm
    with:
      version: v3.12.3 # Pinned to this version since v3.13.0 has issues with anonymous pulls: https://github.com/helm/helm/issues/12423
  # Label namespace to enforce security stranded and scrape prometheus metrics
  # https://kubernetes.io/docs/concepts/security/pod-security-standards/
  - name: add labels to kube-system namespace
    shell: bash
    run: |
      kubectl label ns kube-system scrape=enabled --overwrite=true
      kubectl label ns kube-system pod-security.kubernetes.io/warn=restricted --overwrite=true
  - name: login to ecr via docker
    uses: docker/login-action@9780b0c442fbb1117ed29e0efdff1e18412f7567 # v3.3.0
    with:
      registry: ${{ inputs.ecr_account_id }}.dkr.ecr.${{ inputs.ecr_region }}.amazonaws.com
      logout: true
  - name: install-karpenter
    shell: bash
    env:
      ECR_ACCOUNT_ID: ${{ inputs.ecr_account_id }}
      ECR_REGION: ${{ inputs.ecr_region }}
      ACCOUNT_ID: ${{ inputs.account_id }}
      CLUSTER_NAME: ${{ inputs.cluster_name }}
      PRIVATE_CLUSTER: ${{ inputs.private_cluster }}
    run: |
      ./test/hack/e2e_scripts/install_karpenter.sh
  - name: diff-karpenter
    shell: bash
    env:
      ECR_ACCOUNT_ID: ${{ inputs.ecr_account_id }}
      ECR_REGION: ${{ inputs.ecr_region }}
    run: |
      ./test/hack/e2e_scripts/diff_karpenter.sh
