Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

2.6 RC1 - sidecar plugin - spec.parameters.dynamic.command do not have in env ARGOCD_ENV_* variables #11812

Closed
gabrielfsousa opened this issue Dec 22, 2022 · 0 comments · Fixed by #11815
Labels
bug Something isn't working cherry-pick/2.6 component:cmp Config Management Plugin related issues

Comments

@gabrielfsousa
Copy link

sidecar plugin - spec.parameters.dynamic.command do not have in env ARGOCD_ENV_* variables

generate.command is working as expected

kind: ConfigManagementPlugin

apiVersion: argoproj.io/v1alpha1
kind: ConfigManagementPlugin
metadata:
  name: miracle-plugin
  namespace: argocd
spec:
  generate:
    command: ["miracle-plugin.sh"]
  parameters:
    dynamic:
      command: ["miracle-plugin-param.sh"]
  discover:
    find:
      command: [sh, -c, find . -name *.yaml]

miracle-plugin-param.sh

set -eo pipefail

me=`basename "$0"`
helm=()
conf=()
kustomize=()
valuesfile=''
conffile=''

cat <<EOF >> /home/argocd/miracle-param.log
------ $( date +"%Y-%m-%dT%H:%M:%S%z" ) ------
ARGOCD_ENV_CLUSTER == $ARGOCD_ENV_CLUSTER
ARGOCD_ENV_ENV     == $ARGOCD_ENV_ENV
ARGOCD_ENV_APPNS   == $ARGOCD_ENV_APPNS
--------------------------------------
EOF

for file in base/chart/* targets/$ARGOCD_ENV_CLUSTER/$ARGOCD_ENV_ENV/$ARGOCD_ENV_APPNS/chart/* ; do
  if [[ $file =~ value ]]; then
    helm+=($file)
  fi
done

for file in base/c*.yaml targets/$ARGOCD_ENV_CLUSTER/$ARGOCD_ENV_ENV/$ARGOCD_ENV_APPNS/c*.yaml ; do
  if [[ $file =~ c*.yaml ]]; then
    conf+=($file)
  fi
done

for line in ${helm[@]}; do
  if [[ $line =~ value ]]; then
    valuesfile+=" $(pwd)/$line "
  fi
done

for line in ${conf[@]}; do
  if [[ $line =~ c*.yaml ]]; then
    conffile+=" $(pwd)/$line "
  fi
done

HELMPARAMS=$(yq e -o=p $conffile $valuesfile | jq --compact-output --slurp --raw-input '
  {
    name: "helm-parameters",
    title: "Helm Parameters",
    tooltip: "Parameters to override when generating manifests with Helm",
    collectionType: "map",
    map: (. | split("\n") | map(select(. != "") | capture("(?<key>.*) = (?<value>.*)")) | from_entries)
  }' )

echo $HELMPARAMS | jq --slurp

image

image

image

miracle-plugin.sh
generate.command is working as expected

set -eo pipefail

me=`basename "$0"`
helm=()
conf=()
kustomize=()
valuesfile=''
conffile=''

for file in base/chart/* targets/$ARGOCD_ENV_CLUSTER/$ARGOCD_ENV_ENV/$ARGOCD_ENV_APPNS/chart/* ; do
  if [[ $file =~ value ]]; then
    helm+=($file)
  fi
done

for file in base/c*.yaml targets/$ARGOCD_ENV_CLUSTER/$ARGOCD_ENV_ENV/$ARGOCD_ENV_APPNS/c*.yaml ; do
  if [[ $file =~ c*.yaml ]]; then
    conf+=($file)
  fi
done

for line in ${helm[@]}; do
  if [[ $line =~ value ]]; then
    valuesfile+=" -f $(pwd)/$line "
  fi
done

for line in ${conf[@]}; do
  if [[ $line =~ c*.yaml ]]; then
    conffile+=" $(pwd)/$line "
  fi
done

for file in targets/$ARGOCD_ENV_CLUSTER/$ARGOCD_ENV_ENV/$ARGOCD_ENV_APPNS/kustomize/* ; do
  if [[ $file =~ kustomization ]]; then
    kustomize+=($file)
  fi
done

if [ ${#kustomize[@]} == 1 ]; then
  arg="${kustomize[0]%/*}/"
  kustomize build $(pwd)/$arg > /home/argocd/${ARGOCD_ENV_CLUSTER}_${ARGOCD_ENV_ENV}_${ARGOCD_ENV_APPNS}.yaml
  kustomize build $(pwd)/$arg
  kustcmd+="kustomize build $(pwd)/$arg"
fi

export YQ_ENV_HELM_REPO_URL=$(yq ea '. as $item ireduce ({}; . * $item )'  $conffile | yq '.helm.repo')
export YQ_ENV_HELM_RELEASE_NAME=$(yq ea '. as $item ireduce ({}; . * $item )'  $conffile | yq '.helm.release')
export YQ_ENV_HELM_CHART_VERSION=$(yq ea '. as $item ireduce ({}; . * $item )'  $conffile | yq '.helm.version')
export YQ_ENV_HELM_CHART_NAME=$(yq ea '. as $item ireduce ({}; . * $item )'  $conffile | yq '.helm.chart')

if [ ! -z "${valuesfile}" ]; then
            helm template --insecure-skip-tls-verify --version $YQ_ENV_HELM_CHART_VERSION --repo $YQ_ENV_HELM_REPO_URL --namespace $ARGOCD_APP_NAMESPACE $YQ_ENV_HELM_CHART_NAME --name-template=$YQ_ENV_HELM_RELEASE_NAME $valuesfile >> /home/argocd/${ARGOCD_ENV_CLUSTER}_${ARGOCD_ENV_ENV}_${ARGOCD_ENV_APPNS}.yaml
            helm template --insecure-skip-tls-verify --version $YQ_ENV_HELM_CHART_VERSION --repo $YQ_ENV_HELM_REPO_URL --namespace $ARGOCD_APP_NAMESPACE $YQ_ENV_HELM_CHART_NAME --name-template=$YQ_ENV_HELM_RELEASE_NAME $valuesfile
  helmcmd+="helm template --insecure-skip-tls-verify --version $YQ_ENV_HELM_CHART_VERSION --repo $YQ_ENV_HELM_REPO_URL --namespace $ARGOCD_APP_NAMESPACE $YQ_ENV_HELM_CHART_NAME --name-template=$YQ_ENV_HELM_RELEASE_NAME $valuesfile"
fi

cat <<EOF >> /home/argocd/miracle.log
------ $( date +"%Y-%m-%dT%H:%M:%S%z" ) ------
ARGOCD_ENV_APPNAME   == $ARGOCD_ENV_APPNAME
ARGOCD_ENV_CLUSTER   == $ARGOCD_ENV_CLUSTER
ARGOCD_APP_NAME      == $ARGOCD_APP_NAME
ARGOCD_APP_NAMESPACE == $ARGOCD_APP_NAMESPACE

     helm == ${helm[@]}
     conf == ${conf[@]}
kustomize == ${kustomize[@]}

command executed:
$helmcmd
$kustcmd
--------------------------------------
EOF
@gabrielfsousa gabrielfsousa added the bug Something isn't working label Dec 22, 2022
@crenshaw-dev crenshaw-dev added component:cmp Config Management Plugin related issues cherry-pick/2.6 labels Dec 22, 2022
crenshaw-dev added a commit to crenshaw-dev/argo-cd that referenced this issue Dec 22, 2022
Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com>
crenshaw-dev added a commit that referenced this issue Mar 22, 2023
* fix: pass env when getting param announcement (#11812)

Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com>

* use same method as other methods

Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com>

* better tests

Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com>

* make sure env var tests are meaningful

Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com>

---------

Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com>
gcp-cherry-pick-bot bot pushed a commit that referenced this issue Mar 22, 2023
* fix: pass env when getting param announcement (#11812)

Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com>

* use same method as other methods

Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com>

* better tests

Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com>

* make sure env var tests are meaningful

Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com>

---------

Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com>
crenshaw-dev added a commit that referenced this issue Mar 23, 2023
* fix: pass env when getting param announcement (#11812)



* use same method as other methods



* better tests



* make sure env var tests are meaningful



---------

Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com>
Co-authored-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com>
yyzxw pushed a commit to yyzxw/argo-cd that referenced this issue Aug 9, 2023
…roj#11815)

* fix: pass env when getting param announcement (argoproj#11812)

Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com>

* use same method as other methods

Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com>

* better tests

Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com>

* make sure env var tests are meaningful

Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com>

---------

Signed-off-by: Michael Crenshaw <350466+crenshaw-dev@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working cherry-pick/2.6 component:cmp Config Management Plugin related issues
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants