github-action-helm3 icon indicating copy to clipboard operation
github-action-helm3 copied to clipboard

Use the default Kubeconfig or allow using it

Open NasAmin opened this issue 4 years ago • 5 comments

Hi,

First of all, thanks for creating this action! I have tried to use this action where I am deploying to an EKS cluster. So I am using other actions that sets up aws credentials and kubernetes clusters like these

      - name: Configure AWS credentials for EKS deployment
        uses: aws-actions/configure-aws-credentials@v1
        with:
          aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }}
          aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
          aws-region: ${{ secrets.EKS_REGION }}

      - name: Setup kubeconfig
        id: setup-kubeconfig
        run: |
          aws eks --region ${{ secrets.EKS_REGION }} update-kubeconfig --name ${{ secrets.EKS_CLUSTER_NAME }}

However, the entrypoint.sh script seems to be always overwriting the contents of the default kubeconfig. Can we make than optional and use a flag like USE_DEFAULT_KUBECONFIG=false. So we can then override this flag and set it to true. If true then we skip creating the kubeconfig and also the cleanup.

Is that doable?

Regards,

Nas

NasAmin avatar Jul 29 '20 14:07 NasAmin

Did some research in #19 and there are a few options. A) you grab the file from the filesystem and pass it into the action, or B) you put it in ./ (your workspace directory). Since this action runs a Docker container it doesn't have access to the default ~/ (/home/runner/) but instead has access to the workspaces you're in by default.

You can try option B out with:

      - run: mkdir ./.kube -p || true
      - run: cp ~/.kube/config ./.kube/
      - name: Deploy
        uses: WyriHaximus/github-action-helm3@use-existing-kubeconfig-when-available
        with:
          exec: helm COMMAND
      - run: rm ./.kube/config -fR

WyriHaximus avatar Jul 29 '20 20:07 WyriHaximus

@NasAmin haven't forgotten about this. The main issue lies in that this is a Docker based action, so I'm going to change it over to a nodejs based action and add helm as a bin command so that the UI doesn't change. But it should provide access to ~/.kube/config more naturally

WyriHaximus avatar Sep 15 '20 16:09 WyriHaximus

I was able to get a successful Helm deployment with this action using

      - name: Copy kubectl config to output for helm deploy
        id: kube
        run: |
          CONFIG="$(cat ${HOME}/.kube/config)"
          CONFIG="${CONFIG//'%'/'%25'}"
          CONFIG="${CONFIG//$'\n'/'%0A'}"
          CONFIG="${CONFIG//$'\r'/'%0D'}"
          echo "::set-output name=config::$CONFIG"
      - name: Deploy
        uses: WyriHaximus/github-action-helm3@v2
        with:
          exec: helm ...
          kubeconfig: '${{ steps.kube.outputs.config }}'

I needed several CONFIG set lines due to set-output truncating multiline strings

edit: re-reading your comment above, this seems like option A. Now with an example!

devsibwarra avatar Sep 24 '20 20:09 devsibwarra

So when I initially created this action, there was no Helm 3 on GA yet. These days it does, so I'm going to change this action to by just running the script provided, in #19. And also include a deprecation notice that you can now use it directly on GA without the need for an GA. Not sure about the future, but will keep the repo around for when Helm4 might popup to ensure you don't accidentally run v4 when you need v3 or something like that.

WyriHaximus avatar Sep 27 '20 15:09 WyriHaximus

For those interested: https://github.com/WyriHaximus/github-action-helm3/issues/29#issuecomment-890400386

WyriHaximus avatar Jul 31 '21 20:07 WyriHaximus