Skip to content

Comments

[kube-config-manager] Fix updating configmap by a hook#557

Merged
yalosev merged 1 commit intomainfrom
fix-update-configmap
Jan 31, 2025
Merged

[kube-config-manager] Fix updating configmap by a hook#557
yalosev merged 1 commit intomainfrom
fix-update-configmap

Conversation

@miklezzzz
Copy link
Contributor

@miklezzzz miklezzzz commented Jan 27, 2025

Overview

Updating the addon-operator's configmap by a hook had been broken after one of many refactorings. The module's config values would be updated in the operator's runtime, yet not in the configmap.
This pr mends that functional.

What this PR does / why we need it

Closes #536

Special notes for your reviewer

@miklezzzz miklezzzz added the bug Something isn't working label Jan 27, 2025
@miklezzzz miklezzzz self-assigned this Jan 27, 2025
Signed-off-by: Mikhail Scherba <mikhail.scherba@flant.com>
@miklezzzz miklezzzz force-pushed the fix-update-configmap branch from 34d39e6 to 9906f8a Compare January 27, 2025 09:58
@miklezzzz
Copy link
Contributor Author

hook config

bash-5.1# cat modules/001-sysctl-tuner/hooks/test-hook.sh 
#!/bin/bash

if [[ $1 == "--config" ]] ; then
  cat <<EOF
{
  "configVersion":"v1",
  "beforeHelm": 1,
  "afterHelm": 1,
  "afterDeleteHelm": 1
}
EOF
exit 0
fi

binding=$(jq -r '.[0].binding' "${BINDING_CONTEXT_PATH}")
echo "Binding: $binding"
if [[ $binding == "beforeHelm" ]]; then
cat > $CONFIG_VALUES_JSON_PATCH_PATH <<EOF
    [{"op":"add", "path":"/sysctlTuner/param11", "value":"value11"}]
EOF
echo "Patching: $binding"
fi

before

bash-5.1# ./addon-operator module values sysctl-tuner
env: testing2
param11: value11


kubectl get cm addon-operator -o yaml
apiVersion: v1
data:
  global: |
    param12: value12
    test: test
  sysctlTuner: |
    env: testing2
    param11: value11
  sysctlTunerEnabled: "true"
  testModule: |
    val: val1
kind: ConfigMap
metadata:
  name: addon-operator
  namespace: default

after

bash-5.1# ./addon-operator module values sysctl-tuner
env: testing2
param11: value11


kubectl get cm addon-operator -o yaml
apiVersion: v1
data:
  global: |
    param12: value12
    test: test
  sysctlTuner: |
    env: testing2
    param11: value11
  sysctlTunerEnabled: "true"
  testModule: |
    val: val1
kind: ConfigMap
metadata:
  name: addon-operator
  namespace: default

@miklezzzz miklezzzz marked this pull request as ready for review January 27, 2025 10:20
@miklezzzz
Copy link
Contributor Author

"error":"module hook 'v0.7.104/hooks/test-hook.sh': set kube module config failed: saving patch values in ModuleConfig is forbidden",

@yalosev yalosev merged commit a14efc5 into main Jan 31, 2025
9 checks passed
@yalosev yalosev deleted the fix-update-configmap branch January 31, 2025 13:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

using $CONFIG_VALUES_JSON_PATCH_PATH in someModule hooks but it not work

3 participants