Not able to use dynamic array structure while using --set flag - kubernetes-helm

set using an array list destroy the values yaml structure
I have powershell script to set a collection of values to a single key in values.yaml
Script
But when I execute the The script The value passed like this
Script result
Actually I want the values like this, But i got this structure only use the set flag like this helm upgrade testing testconfig --set "KeyvautCollection={may0,may1}"
Expected result
I want to pass a dynamic array along with --set flag

Related

Helm - view generated values from multiple value files

I have multiple values file that Helm will merge together. I'd like to see the resulting values file but I'm not sure how I would do that.
I could run this command and this would result in the generated manifests, but I really just want to see the resulting values file instead.
helm template . -f values.yaml -f values-prod.yaml

Azure DevOps Pipelines- incorrect value in variables declaration

I am using the CI/CD capabilities of Azure DevOps in order to build our micro-services.
One of the tasks I have inside the pipeline is a Bash Task that assign & execute variable declaration for further use in the same job.
When trying to gather the variable after the declaration I'm getting the output {.
The file I'm trying to read its data assigned to a variable is a JSON file, contains a JSON formatted data.
The file called pipeline_1.json, just to make sure that its inside the folder I need before trying to read it.
That is the command that takes the output to the variable.
And finally the output.
My insight was its printing only the first line of the JSON file because its formatted but when tried to format it as simple text it gives the same results
Based on your description, it seems that you need to get the value in the Json file.
You can try to use the following bash script:
For example:
Json file:
{
"AA": {
"BB": "TEST",
"CC": "XXX"
}
}
Bash script:
token1=($(jq -r '.AA.BB' pipeline_1.json))
echo "##vso[task.setvariable variable=token1;]$token1"
Then you can get the correct value in the json file.

ansible giving error whereas in k8s command runs fine on server

Does anyone face this issue. there is no other way if a secret is create it to ignore already exist error, below is the command which runs fine with out of secret/license configured as compared to secret/license created (which happens first time)
kubectl create secret generic license --save-config --dry-run=true --from-file=/tmp/ansibleworkspace/license -n {{ appNameSpace }} -o yaml | kubectl apply -f -
It runs fine if I run it on a k8s cluster
Below is the error while executing it through ansible.
Error: unknown shorthand flag: 'f' in -f
Examples:
# Create a new secret named my-secret with keys for each file in folder bar
kubectl create secret generic my-secret --from-file=path/to/bar
# Create a new secret named my-secret with specified keys instead of names on disk
kubectl create secret generic my-secret --from-file=ssh-privatekey=~/.ssh/id_rsa --from-file=ssh-publickey=~/.ssh/id_rsa.pub
# Create a new secret named my-secret with key1=supersecret and key2=topsecret
kubectl create secret generic my-secret --from-literal=key1=supersecret --from-literal=key2=topsecret
# Create a new secret named my-secret using a combination of a file and a literal
kubectl create secret generic my-secret --from-file=ssh-privatekey=~/.ssh/id_rsa --from-literal=passphrase=topsecret
# Create a new secret named my-secret from an env file
kubectl create secret generic my-secret --from-env-file=path/to/bar.env
Options:
--allow-missing-template-keys=true: If true, ignore any errors in templates when a field or map key is missing in the template. Only applies to golang and jsonpath output formats.
--append-hash=false: Append a hash of the secret to its name.
--dry-run=false: If true, only print the object that would be sent, without sending it.
--from-env-file='': Specify the path to a file to read lines of key=val pairs to create a secret (i.e. a Docker .env file).
--from-file=[]: Key files can be specified using their file path, in which case a default name will be given to them, or optionally with a name and file path, in which case the given name will be used. Specifying a directory will iterate each named file in the directory that is a valid secret key.
--from-literal=[]: Specify a key and literal value to insert in secret (i.e. mykey=somevalue)
--generator='secret/v1': The name of the API generator to use.
-o, --output='': Output format. One of: json|yaml|name|go-template|go-template-file|template|templatefile|jsonpath|jsonpath-file.
--save-config=false: If true, the configuration of current object will be saved in its annotation. Otherwise, the annotation will be unchanged. This flag is useful when you want to perform kubectl apply on this object in the future.
--template='': Template string or path to template file to use when -o=go-template, -o=go-template-file. The template format is golang templates [http://golang.org/pkg/text/template/#pkg-overview].
--type='': The type of secret to create
--validate=true: If true, use a schema to validate the input before sending it
Usage:
kubectl create secret generic NAME [--type=string] [--from-file=[key=]source] [--from-literal=key1=value1] [--dry-run] [options]
Use "kubectl options" for a list of global command-line options (applies to all commands).
unknown shorthand flag: 'f' in -f
Since you haven't given any details about the context you are running the command, I can only provide an answer based on my guess.
Explanation:
I suppose that you use the command module in your Ansible playbook and this is the cause of your issue. As you can read in module description:
The given command will be executed on all selected nodes. It will not be processed through the shell, so variables like $HOME and
operations like "<", ">", "|", ";" and "&" will not
work (use the shell module if you need these features).
and in your command you use "|" character, which cannot be interpreted properly as it is not processed through the shell. Note that the error you get:
Error: unknown shorthand flag: 'f' in -f
is related with incorrect use of kubectl create secret generic which simply doesn't have such option. Since "|" character is not interpreted by the command module, the proceeding command:
kubectl apply -f -
is treated as a part of:
kubectl create secret generic
(which is confirmed by the error you get, followed by the correct usage examples).
Solution:
As recommended in the above quoted docs, use the shell module instead:
If you want to run a command through the shell (say you are using <,
>, |, etc), you actually want the shell module instead.

Can I have multiple values.yaml files for Helm

Can I have multiple values.yaml files in a Helm chart?
Something like mychart/templates/internalValues.yaml, mychart/templates/customSettings.yaml, etc?
Accessing properties in a values.yaml file can be done by {{ .Values.property1 }}.
How would I reference the properties in these custom values.yaml files?
Yes, it's possible to have multiple values files with Helm. Just use the --values flag (or -f).
Example:
helm install ./path --values ./internalValues.yaml --values ./customSettings.yaml
You can also pass in a single value using --set.
Example:
helm install ./path --set username=ADMIN --set password=${PASSWORD}
From the official documentation:
There are two ways to pass configuration data during install:
--values (or -f): Specify a YAML file with overrides. This can be specified multiple times and the rightmost file will take precedence
--set (and its variants --set-string and --set-file): Specify overrides on the command line.
If both are used, --set values are merged into --values with higher precedence. Overrides specified with --set are persisted in a configmap. Values that have been --set can be viewed for a given release with helm get values . Values that have been --set can be cleared by running helm upgrade with --reset-values specified.
Helm by default will only use the values.yaml file in the root directory of your chart.
You can ask it to load additional values files when you install. For instance, if you have any settings that point to different databases in different environments:
helm install . -f values.production.yaml
You could also get a similar effect by bundling additional settings as a file, and asking Helm to read the bundled file. Helm provides an undocumented fromYaml template function which can parse the file, so in principle you can do something like
{{- $v := $.Files.Get "more-values.yaml" | fromYaml }}
foo: {{ $v.bar }}
Just to update : As per the current official documentation --set & --values will not be merged
To override values in a chart, use either the '--values' flag and pass in a file or use the '--set' flag and pass configuration from the command line, to force a string value use '--set-string'. In case a value is large and therefore you want not to use neither '--values' nor '--set', use '--set-file' to read the single large value from file.
Also :
You can specify the '--values'/'-f' flag multiple times. The priority will be given to the last (right-most) file specified.

I want to use the output of `gcloud` in a script, but the format changes. What should I do?

I’m using the command gcloud compute instances list in a script, but I’m worried that the exact output format isn’t static. What should I do?
You should use the --format flag, available for most gcloud commands.
For instance, if you’d like to get the exact same output as the current (as of the time of writing of this answer) format, you can run:
$ gcloud compute instances list --format="table(
name,
zone.basename(),
machineType.basename(),
scheduling.preemptible.yesno(yes=true, no=''),
networkInterfaces[0].networkIP:label=INTERNAL_IP,
networkInterfaces[0].accessConfigs[0].natIP:label=EXTERNAL_IP,
status
)"
The output of this command will not change between releases, even if the default output of the command does (unless the resource being formatted changes; this should be rare).1 Showing the default format for resources in commands is a work in progress.2
You can also specify a format like YAML or JSON for machine-readable output:
$ gcloud compute instances list --format=yaml
$ gcloud compute instances list --format=json
Note that this output contains much more information than is present in the default output for this command; this is the information you have to work with when constructing a custom format.
CSV is another format option. Like table, it requires a projection–a specification for how to print each row.3
$ gcloud compute instances list --format="csv(name,zone,status)"
name,zone,status
example-instance,us-central1-f,RUNNING
...
For more information on the formatting capabilities of gcloud, see the output of gcloud topic formats and gcloud topic projections.
You can see all possible fields by running gcloud compute instances list --format=flattened.
For some commands, like gcloud beta test android locales list, you can pass the --verbosity=info flag and look for INFO: Display format.
This is because CSV data cannot be nested like JSON or YAML, and the data structures being printed may be nested.