How to pass variables to helm install --set parameters - kubernetes

I want to know if it is possible to pass variables to an helm install command's set parameter. Below is an example of what I'm looking to achieve.
appgw_name = "myappgateway"
export appgw_name
helm install applicationgw application-gateway-kubernetes-ingress/ingress-azure --set appgw.name=$appgw_name
I'm executing the above two lines as a shell script and when I try to execute them I get the below error:
Error: execution error at (ingress-azure/templates/configmap.yaml):
Please either provide appgw.applicationGatewayID or appgw.name.

The parameter will be resolved by your shell. If you write these directly from the command line you need to either export the env variable or execute then together in one line.
Try this:
export appgw_name="myappgateway"
helm install applicationgw application-gateway-kubernetes-ingress/ingress-azure --set appgw.name=${appgw_name}

Solved it. Was just a few spacings that had to be altered. The issue was with bash and had nothing to do with helm. So this is how I finally declared the variables export appgw_name="myappgateway" Just removed all the spaces and that's it. It worked like charm.

Related

Executing commands inside helm install

I'm writing a script that executes multiple helm install commands based on a config file.
In this config file the user needs to be able to specify additional arguments e.g. --set userPw="password".
Some of these arguments require retrieval of variables from somewhere.
In powershell, I can store this in a variable, and use this variable in the helm install --set argument as follows:
$mySecret = az keyvault secret show --name MYSECRET--vault-name MYVAULT| ConvertFrom-Json).value
helm install mydeployment repo/mychart -n my-namespace --set azureSecret=$mySecret
I can't do this dynamically however...
Different deployments ofcourse need different variables.
I want to use the config file rather than variables, since I don't want the users to edit the script that runs these commands.
Is something like this possible for helm install?:
helm install mydeployment repo/mychart -n my-namespace --set azureSecret=(az keyvault secret show --name MYSECRET--vault-name MYVAULT| ConvertFrom-Json).value)
In that case users would be able to put commands like this in the config file.
My syntax could be off, I tried some variations but it doesn't seem to work.
This script is only used by our team to easily deploy some stuff, so security is not an issue.
I think it isn't allowed according to:
https://github.com/helm/helm/issues/5145
Just want to make sure.
Helm in fact can't directly launch subcommands. Helm also disables the Sprig functions that can query the shell environment. The only input to templates is the values object built from the chart's values.yaml file and -f and --set options.
In a Unix-like environment you can use $(az keyvault ...) command-substitution syntax in your helm install command. (I know there are a couple of ways to run the GNU Bash shell on Windows and one of these might work.) The command you show is involved enough that writing a short script to run it would be beneficial, and if you have it in a script, your two-line Powershell script will work as well.
In a continuous-integration environment another approach that can work well is to write out a YAML values file, and then pass that via the helm install -f option. All valid JSON should be valid YAML, so you can set up e.g. a Jenkins pipeline to compute some values, make a Groovy map object, dump it as JSON to a file, and then use that as an input values file.
this is possible using simple bash command like EX. you want to get the password value from abc.txt file from your machine location you can simple do like this
helm install . --name abc --set userPw=userPw,[^"]*' /opt/abc.txt
use your bash command in inside `` to grep/sed to get the values from some file or get the values using command.

Passing CFLAGS to configure via bash variable

Just when I think I know how the shell works fairly, something comes along and stumps me. The following commands were executed on GNU bash, version 3.2.25.
I have several ./configure scripts that all share a group of common configure options, one of them being CFLAGS.
To that end, I have two variables
CFLAGS="-fPIC -O3"
COMMON_CONFIGURE_OPTIONS="CFLAGS=\"$CFLAGS\" --enable-static --disable-shared --prefix=$PREFIX"
When this gets passed to `./configure', it is done so like,
"$FOO/configure" $COMMON_CONFIGURE_OPTIONS
For the life of me, I cannot seem to get this to expand correctly. I have tried manually substituting the value of $CFLAGS into $COMMON_CONFIGURE_OPTIONS. I have tried every combination of single and double quotes under the sun. I have even tried quoting the entire "CFLAGS=..." argument.
The version I gave above yields the following (when set -x is enabled)
../configure 'CFLAGS="-fPIC' '-O3"' --enable-static --disable-shared --prefix=../install
configure: error: unrecognized option: `-O3"'
Try `../configure --help' for more information
What I expected, and what I desire, is for configure to be invoked like
./configure CFLAGS="-fPIC -O3" --enable-static --disable-shared --prefix="$PREFIX"
How can I achieve what I want, and additionally, are there good resources/tips on how to avoid this problem in the future?
To achieve what you want, I think you want to fundamentally change your approach. Assuming your configure scripts are generated by autoconf, I would suggest using a config.site file. That is, simply do something like:
mkdir -p $PREFIX/share
echo 'CFLAGS="--enable-static --disable-shared"' > $PREFIX/share/config.site
And then invoke configure as:
/path/to/configure --prefix=$PREFIX
Make sure that CONFIG_SITE is not set in the environment when you invoke configure, else the defaults will come from the file named there.

How to pass arguments to memcheck with ctest?

I want to use ctest from the command line to run my tests with memcheck and pass in arguments for the memcheck command.
I can run ctest -R my_test to run my test, and I can even run ctest -R my_test -T memcheck to run it through memcheck.
But I can't seem to find a way to pass arguments to that memcheck command, like --leak-check=full or --suppressions=/path/to/file.
After reading ctest's documentation I've tried using the -D option with CTEST_MEMCHECK_COMMAND_OPTIONS and MEMCHECK_COMMAND_OPTIONS. I also tried setting these as environment variables. None of my attempts produced any different test command. It's always:
Memory check command: /path/to/valgrind "--log-file=/path/to/build/Testing/Temporary/MemoryChecker.7.log" "-q" "--tool=memcheck" "--leak-check=yes" "--show-reachable=yes" "--num-callers=50"
How can I control the memcheck command from the ctest command line?
TL;DR
ctest --overwrite MemoryCheckCommandOptions="--leak-check=full --error-exitcode=100" \
--overwrite MemoryCheckSuppressionFile=/path/to/valgrind.suppressions \
-T memcheck
Explanation
I finally found the right way to override such variables, but unfortunately it's not easy to understand this from the documentation.
So, to help the next poor soul that needs to deal with this, here is my understanding of the various ways to set options for memcheck.
In a CTestConfig.cmake in you top-level source dir, or in a CMakeLists.txt (before calling include(CTest)), you can set MEMORYCHECK_COMMAND_OPTIONS or MEMORYCHECK_SUPPRESSIONS_FILE.
When you include(CTest), CMake will generate a DartConfiguration.tcl in your build directory and setting the aforementioned variables will populate MemoryCheckCommandOptions and MemoryCheckSuppressionFile respectively in this file.
This is the file that ctest parses in your build directory to populate its internal variables for running the memcheck step.
So, if you'd like to set you project's options for memcheck during cmake configuration, this is the way to got.
If instead you'd like to modify these options after you already have a properly configured build directory, you can:
Modify the DartConfiguration.tcl directly, but note that this will be overwritten if cmake runs again, since this file is regenerated each time cmake runs.
Use the ctest --overwrite command-line option to set these memcheck options just for that run.
Notes
I've seen mentions online of a CMAKE_MEMORYCHECK_COMMAND_OPTIONS variable. I have no idea what this variable is and I don't think cmake is aware of it in any way.
Setting CTEST_MEMORYCHECK_COMMAND_OPTIONS (the variable that is actually documented in the cmake docs) in your CTestConfig.cmake or CMakeLists.txt has no effect. It seems this variable only works in "CTest Client Scripts", which I have never used.
Unfortunately, both MEMORYCHECK_COMMAND_OPTIONS and MEMORYCHECK_SUPPRESSIONS_FILE aren't documented explicitly in cmake, only indirectly, in ctest documentation and the Testing With CTest tutorial.
When ctest is run in the build, it parses the file to populate its internal variables:
https://cmake.org/cmake/help/latest/manual/ctest.1.html#dashboard-client-via-ctest-command-line
It's not clear to me how this interacts with

Setting up Clusters and work nodes - How do I set KUBECONFIG variable in Windows 10?

I using following link to create :
https://console.bluemix.net/docs/containers/cs_tutorials.html#cs_cluster_tutorial
In Lesson3, Step 3 "Verify that the KUBECONFIG environment variable is set properly.", I am unable to set the variable KUBECONFIG.
I am able to execute the following command:
ibmcloud ks cluster-config clusternameabc
I am getting following message
The configuration for clusternameabc was downloaded successfully. Export environment variables to start using Kubernetes, with the following message:
SET KUBECONFIG=C:\Users\AAA.bluemix\plugins\container-service\clusters\customernameabc\kube-config-hou02-clusternameabc.yml
When I run the above SET command in powershell, I just get the prompt back with environment variable not set.
When I do
$Env:KUBECONFIG=C:\Users\AAA.bluemix\plugins\container-service\clusters\customernameabc\kube-config-hou02-clusternameabc.yml
Notepad gets opened and this file is shown. I want to just set the environment variable and unable to. Can someone please tell me what I am doing wrong? I tried searching and could not find answers and IBM documentation has only Mac examples.
In Powershell
1) $env:KUBECONFIG = "C:\Users\AAA.bluemix\plugins\container-service\clusters\customernameabc\kube-config-hou02-clusternameabc.yml"
2) ls env:KUBECONFIG
Slightly easier to remember.
Based on my tests, you have to wrap the value of the environment environment in double quotes, like so:
$Env:KUBECONFIG="C:\Users\AAA.bluemix\plugins\container-service\clusters\customernameabc\kube-config-hou02-clusternameabc.yml"
Then, you can check the environment variables in PowerShell via this command:
Get-ChildItem Env:
Try this:
$Env:KUBECONFIG = ibmcloud cs cluster-config --export clusternameabc | Select -First 1 | % {$_.replace("SET KUBECONFIG=","")}

Is there a way to prepend a command with a variable assignment like in bash?

In bash one can write
CFLAGS="-O2" rvm install 2.0.0
to run rvm with that specific CFLAGS . Is there anyway to do the same in fish shell?
I know about set -x but that is not exactly the same as the environment variable will be set for the whole session instead of just for that command.
According to the fish FAQ, either use:
env CFLAGS="-O2" rvm install 2.0.0
(which will not work for fish builtins or functions, only external commands), or
begin
set -lx CFLAGS="-O2"
rvm install 2.0.0
end
(which is a little clunky; there are proposals for improvement on GitHub issue #438).
You can use the env command for this:
env FOO=BAR command
Will run command with env variable FOO set to BAR.