wireguard-chart icon indicating copy to clipboard operation
wireguard-chart copied to clipboard

wireguard-wg-generated secrets exists every sync run of ArgoCD causing it to get stuck

Open syphernl opened this issue 1 year ago • 6 comments

We're running this chart with ArgoCD. Every time it syncs it runs the job to generate the secret, this fails with

error: failed to create secret secrets "wireguard-wg-generated" already exists

and causes ArgoCD to get stuck in:

waiting for completion of hook batch/Job/wireguard-wg-gen and 6 more hooks

In order to get it to proceed we need to remove the secret, but with every new sync this is breaking again.

syphernl avatar Feb 27 '24 15:02 syphernl

Looks to be related to this: https://github.com/argoproj/argo-cd/issues/7536

Normally the hooks only run on initial install but with Argo pre-install hooks are run on every sync.

Have you tried setting the secretName to the created secret? https://github.com/bryopsida/wireguard-chart/blob/5929db46ae0a995fbc7433630b8f9eeb41901979/helm/wireguard/values.yaml#L70

That would disable the render of the hook https://github.com/bryopsida/wireguard-chart/blob/5929db46ae0a995fbc7433630b8f9eeb41901979/helm/wireguard/templates/privatekey-gen-job.yaml#L1

bryopsida avatar Feb 27 '24 22:02 bryopsida

If that doesn't work for you I can adjust the job to check if the secret already exists and exit without modifying it if it does.

bryopsida avatar Feb 27 '24 22:02 bryopsida

Thanks for your quick reply @bryopsida !

Setting secretName: wireguard-wg-generated works, but this is probably more a workaround than an actual solution as it would require you to omit the value for the initial deploy and and update it later on. It would be easier/better if the job could check if the secret exists and skip it if it does as it would simplify the deploy process (making it only 1 step rather than 2).

syphernl avatar Feb 28 '24 07:02 syphernl

@syphernl I've started working on this over here: https://github.com/bryopsida/k8s-wireguard-mgr when I roll it into the chart it will be an opt in value toggle to replace the current hook behavior which uses a configmap shell script: https://github.com/bryopsida/wireguard-chart/blob/main/helm/wireguard/scripts/gen-key.sh

There is one variation to the behavior from what I had previously mentioned. Instead of checking/fetching the secret it will attempt to create the secret and just inspect the error response and exit cleanly if the error reason is AlreadyExists.

The reason for this is I do not want to expand the role bindings to give the job access to fetch the secret, currently it only has permission to create.

https://github.com/bryopsida/wireguard-chart/blob/5929db46ae0a995fbc7433630b8f9eeb41901979/helm/wireguard/templates/privatekey-gen-job.yaml#L22

bryopsida avatar Mar 02 '24 14:03 bryopsida

Is there any updates?

dro-sh avatar Aug 09 '24 11:08 dro-sh

I started on a PR here: https://github.com/bryopsida/wireguard-chart/pull/51 but need to do some more testing etc before integrating it.

It does seem like there a few ways to work with argo with the current version of the chart

  1. Use a secrets provider such as external-secrets and have it manage the secret, at that point you can disable the secret generation hook/job just by setting the secret name: https://github.com/bryopsida/wireguard-chart/blob/146ea71033d432250ab1c716392267d426a965b8/helm/wireguard/templates/privatekey-gen-job.yaml#L1 or use another means to pre-create the secret.
  2. The script/hook can be customized using: https://github.com/bryopsida/wireguard-chart/blob/146ea71033d432250ab1c716392267d426a965b8/helm/wireguard/templates/privatekey-gen-job.yaml#L76 and https://github.com/bryopsida/wireguard-chart/blob/146ea71033d432250ab1c716392267d426a965b8/helm/wireguard/templates/privatekey-gen-job.yaml#L154, the hook image has wg + kubectl included.

bryopsida avatar Aug 10 '24 12:08 bryopsida

@dro-sh @syphernl this should be resolved in version 0.25.0

If you enable this flag

keygenJob.useWireguardManager = true

The key gen job will succeed even if the key already exists.

bryopsida avatar Aug 17 '24 14:08 bryopsida

Thanks! It works fine!

dro-sh avatar Aug 17 '24 16:08 dro-sh