Executing commands inside helm install - powershell

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.

Related

Can we pass the argument for Kubectl create command via terminal

I have deployment yaml file where I am setting up one ARG.
args['--country=usa']
It runs perfectly and pod will be up with this argument. But for different country name, I need to change this yaml for argument and then run
kubectl create -f deploy.yml command again and again
Is there any way to pass this arg through create command
I tried kubectl create -f deploy.yml '--country=usa' but it seems like this is not the correct way to pass it
Unfortunately, there is no simple way to do that.
Here are some related questions.
Using env variable and configmap:
How to pass command line argument to kubectl create command
Using Helm:
Kubernetes Deployment - Pass arguments

How to pass variables to helm install --set parameters

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.

How to split a CLI command in Azure Devops over multiple lines? (Running on Windows)

I am running the following in a CLI task on Azure Devops (inline)
rem Create the Service Plan
call az appservice plan create --resource-group %RESOURCE_GROUP% --name %SERVICE_NAME% --sku B1
Whch works just fine. However, I'm having to scroll to see the whole thing and I have other commands which are even longer. So I'm trying to split it over multiple lines so I can see more clearly what is going on.
Looking at Microsoft Docs it looked like the solution was to put a backslash on the end of each line. So I tried:
I've tried:
rem Create the Service Plan
call az appservice plan create \
--resource-group %RESOURCE_GROUP% \
--name %APP_SERVICE_NAME% \
--sku B1
Which didn't work. I then read something that recommended the back-tick/back-quote at the end of each line:
rem Create the Service Plan
call az appservice plan create `
--resource-group %RESOURCE_GROUP% `
--name %APP_SERVICE_NAME% `
--sku B1
This also didn't work. Any help greatly appreciated.
Never mind. Worked it out. Turns out you need to use '^'
rem Create the Service Plan
call az appservice plan create ^
--resource-group %RESOURCE_GROUP% ^
--name %APP_SERVICE_NAME% ^
--sku B1
For me the ` character is working. I posted earlier that it wasn't but I was inadvertently using the wrong character.
(That post seems to have been deleted by a moderator though I'm not sure why - perhaps because it was more of a "me too" than an answer, but it did add that the above "^" solution doesn't work for me).
In case it was the same issue as I had, ensure the "Backtick" you use is the correct one (it's immediately to the left of "1" on my microsoft keyboard). I was trying to use a ' in the failed attempt as the CLI docs were reading made it hard to distinguish.
The character that you need to use to specify that the command is split over multiple lines, depends on the environment in where the CLI command is run.
In other words, it depends on the scriptType property of the AzureCLI#2 command.
Powershell/Powershell Core: use a backtick `
bash: use backslash \
batch: use accent circonflexe ^
from azure cloud shell, type AZ, then copy paste the az command with \ for multiple line will not work.
but there is a fix, you click on the + sign like a adding a folder sign, it will bring a full page Azure Cloud Shell window, change to Bash from the pull down (default is Poweshell), then you see prompt changed to name#Azure:~$, now you can use az commend with \ for multiple lines.

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

passing :rails_env in capistrano to chef/cookbook/monit/mongrel.conf

How do we pass the :rails_env vairable so that it recognizes what version we are into i.e. staging, production, demo
We are trying to get the :rails_env from the deploy.rb in capistrano to pass to cookbook and then to monit and then create a mongrel.conf file with different values for the environment (demo..production). In mongrel.erb, we can pick up this variable/parameter and set the RAILS_ENV=xxxx
in the command line, want to specify what deployment we are doing -- cap chef:bootstrap production
this "production" sets the :rails_env in deploy.rb
Set the environment variable in your shell (command line) before running your scripts and let your scripts pick up it's value i.e.:
export RAILS_ENV=production
You can access the value of RAILS_ENV using $RAILS_ENV in your scripts. Here's an example of somebody doing something similar at Pivotal Labs:
http://pivotallabs.com/users/steve/blog/articles/1286-chef-solo-is-great-you-might-not-need-client-server-