Skip to content

argocd kcl plugin rendering is slow and file.modpath is cached by different kcl modules #1421

@riven-blade

Description

@riven-blade

General Question

argo logs
time="2024-06-19T05:40:54Z" level=info msg="finished streaming call with code OK" grpc.code=OK grpc.method=GenerateManifest grpc.service=plugin.ConfigManagementPluginService grpc.start_time="2024-06-19T05:40:41Z" grpc.time_ms=13448.232 span.kind=server system=grpc
time="2024-06-19T05:41:36Z" level=info msg="finished streaming call with code OK" grpc.code=OK grpc.method=MatchRepository grpc.service=plugin.ConfigManagementPluginService grpc.start_time="2024-06-19T05:41:23Z" grpc.time_ms=13530.473 span.kind=server system=grpc
time="2024-06-19T05:41:50Z" level=info msg="finished streaming call with code OK" grpc.code=OK grpc.method=GetParametersAnnouncement grpc.service=plugin.ConfigManagementPluginService grpc.start_time="2024-06-19T05:41:36Z" grpc.time_ms=13499.884 span.kind=server system=grpc

Plug-in configuration

apiVersion: v1
kind: ConfigMap
metadata:
  name: kcl-plugin-config
  namespace: argocd
data:
  # Sometimes, the ArgoCD runs the kcl run command twice simultaneously,
  # leading to a race condition in the usage of files inside the
  # KCL_CACHE_PATH and KCL_PKG_PATH directories.
  plugin.yaml: |
    apiVersion: argoproj.io/v1alpha1
    kind: ConfigManagementPlugin
    metadata:
      name: kcl
    spec:
      version: v1.0
      discover:
        fileName: "./kcl.yaml"
      generate:
        command: [/home/argocd/generate.sh]
spec:
  template:
    spec:
      containers:
      - name: kcl-plugin
        command: [/tini]
        args:
          - /var/run/argocd/argocd-cmp-server
#          - --
#          - --loglevel=debug
        image: kcllang/kcllang-cmp-plugin
        securityContext:
          runAsNonRoot: true
          runAsUser: 999
        volumeMounts:
          - mountPath: /var/run/argocd
            name: var-files
          - mountPath: /home/argocd/cmp-server/plugins
            name: plugins
          # Remove this volumeMount if you've chosen to bake the config file into the sidecar image.
          - mountPath: /home/argocd/cmp-server/config/plugin.yaml
            subPath: plugin.yaml
            name: kcl-plugin-config
          # Starting with v2.4, do NOT mount the same tmp volume as the repo-server container. The filesystem separation helps
          # mitigate path traversal attacks.
          - mountPath: /tmp
            name: cmp-tmp
      volumes:
      - configMap:
          name: kcl-plugin-config
        name: kcl-plugin-config
      - emptyDir: {}
        name: cmp-tmp

images: kcllang/kcllang-cmp-plugin

shell

#!/bin/bash

# Set up temporary directories and file
export KCL_CACHE_PATH=$(mktemp -d /tmp/kcl_cache.XXXXXXXXXX)
export KCL_PKG_PATH=$(mktemp -d /tmp/kcl_pkg.XXXXXXXXXX)
tempfile=$(mktemp)

# Prepare KCL parameters from environment variables
KCL_PARAMS=""
for var in $(env); do
  if [[ "$var" == ARGOCD_ENV_param_* ]]; then
    var_name=${var%%=*}        # Extract the name of the variable up to the first '='
    var_value=${var#*=}        # Extract the value of the variable after the first '='
    clean_name=${var_name#ARGOCD_ENV_param_}
    KCL_PARAMS+="-D ${clean_name}=${var_value} "
  fi
done

# Trim the trailing space from KCL_PARAMS if necessary
KCL_PARAMS="${KCL_PARAMS% }"

# Run the KCL command with parameters and handle errors
if kcl run $KCL_PARAMS -q -o "$tempfile" 2>/dev/null; then
  cat "$tempfile"
  rm "$tempfile"
else
  error=$?
  echo "Error running kcl with code $error"
  exit $error
fi

Metadata

Metadata

Assignees

Labels

bugSomething isn't workingruntimeIssues or PRs related to kcl runtime including value and value opertions

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions