I am trying to use jq in the following to get a status on my pod "my pod":
curl '127.0.0.1:8080/api/v1/pods' | jq -r '.items[] | select(.metadata.name)'
This give me a ton of json, more specific how do you read json from k8s api - to get the status of a pod - running or not?
If I get items within a pod:
curl '127.0.0.1:8080/api/v1/pods' | jq -r 'select(.items[].metadata.name="go-test-volume1").items[]
Sure enough I get a list, but which one to chose - there is a status.phase in all of them?
In the case of a status of CrashLoopBackOff:
curl '127.0.0.1:8080/api/v1/pods' |
jq -r '.items[] | select(.metadata.name == "my-pod").status.phase'
Will show it as Running?
This is what you need :
curl '127.0.0.1:8080/api/v1/pods' |
jq -r '.items[] | select(.metadata.name == "my-pod").status.phase'
This will give you the right status:
curl '127.0.0.1:8080/api/v1/pods' |
jq -r '.items[] | select(.metadata.name == "my-pod).status.containerStatuses[0].state'
Related
I'm trying to make a simple filtering script using AWS cli + jq (powershell or cmd in Windows).
aws iam list-roles | jq -c '.Roles[].RoleName | select(startswith ("blabla"))'
But getting this error:
jq: error: AD_/0 is not defined at <top-level>, line 1:
.Roles[].RoleName | select(startswith (AD_))
jq: 1 compile error
But using jqplay.org with same JSON everything works well.
Any thoughts?
thanks!
aws iam list-roles | jq -c '.Roles[].RoleName | select(startswith ("blabla"))'
blabla_rolename_1
It looks like you might be missing a string after the startswith function. Try adding a string in quotes after startswith:
aws iam list-roles | jq -c '.Roles[].RoleName | select(startswith("blabla"))'
If you still get an error, you can try running the jq command without the -c flag to see the full output from jq, which might give you more information about the error.
aws iam list-roles | jq '.Roles[].RoleName | select(startswith("blabla"))
AFAIK Powershell does not support single quotes. Use double quotes and escaped double quotes instead:
aws iam list-roles | jq -c ".Roles[].RoleName | select(startswith (\"blabla\"))"
I have an issue to list loadbalancers on open stack using cli
from#ge ~
$ openstack loadbalancer list
public endpoint for load-balancer service not found
from#ge ~
$ export | grep OS_
declare -x OS_AUTH_TYPE="password"
declare -x OS_AUTH_URL="http://192.168.20.33:5000/v3"
declare -x OS_IDENTITY_API_VERSION="3"
declare -x OS_PASSWORD="XXXXXX"
declare -x OS_PROJECT_NAME="project-name"
declare -x OS_TENANT_NAME="tenant-name"
declare -x OS_USERNAME="from"
declare -x OS_USER_DOMAIN_ID="default"
from#ge ~
$ echo "endpoint list" | openstack
You are not authorized to perform the requested action: identity:list_endpoints. (HTTP 403) (Request-ID: req-aec8b22e-d3ad-4116-b7bb-52545f641667)
I've tried to set OS_REGION_NAME to RegionOne, but I get the same result
Any tip ?
load-balancer service not found
It seems that the load balance service not work, have you deployment Octavia service successful?
identity:list_endpoints. (HTTP 403)
According to the official document, it's Forbidden about the authorization.
The identity was successfully authenticated but it is not authorized to perform the requested action.
Maybe there is a miss-configuration of the admin's roles in keystone, you should check it in database first.
Ok thanks for your answers.
I finally managed to play with load balancers using neutron cli:
$ neutron
neutron CLI is deprecated and will be removed in the future. Use openstack CLI instead.
(neutron) lbaas-loadbalancer-list
+--------------------------------------+------------------------+----------------+---------------------+----------+
| id | name | vip_address | provisioning_status | provider |
+--------------------------------------+------------------------+----------------+---------------------+----------+
| 00f3453d-8738-4eb6-b362-aefc8dfaeea6 | lb1 | 192.168.36.93 | ACTIVE | haproxy |
| 090e062d-d6cc-4ebe-bcbf-165d5c21051d | lb2 | 192.168.36.169 | ACTIVE | haproxy |
| 0c244567-8f49-4be0-9055-17fa903d4619 | lb3 | 192.168.36.43 | ACTIVE | haproxy |
I'm using:
GET https://localhost/api/v4/search?scope=projects&search=test
to find project named "test" , but I get not only project named "test" but "qtest", "testot" or "test1" too.
Is it possible to get only exact name?
According to the Projects API, no. It will return all projects that contain your search string, but you should be able to filter the results once you retrieve it.
The available options are sort and order_by. You can order by the fields id, name, created_at, and last_activity_at
One may use jq to filter the returned results from a fuzzy search:
project_name="test"
curl --silent --show-error --location \
"https://gitlab.com/api/v4/search?scope=projects&search=${project_name}" \
--header "PRIVATE-TOKEN: ${GITLAB_COM_API_PRIVATE_TOKEN}" | jq \
--raw-output --arg project_name "${project_name}" '.[] | \
select(.name == $project_name)'
Of course, this returns 12 projects. Which one is mine?
It is far better if you can include a namespace.
project_path_with_namespace="$username/test"
curl --silent --show-error --location \
"https://gitlab.com/api/v4/search?scope=projects&search=${project_path_with_namespace}" \
--header "PRIVATE-TOKEN: ${GITLAB_COM_API_PRIVATE_TOKEN}" | jq \
--arg path_with_namespace "${project_path_with_namespace}" '.[] | \
select(.path_with_namespace == $path_with_namespace)'
Now the search is not fuzzy and will always return a precise result so long as such a project exists at that path.
I want to get the volumes details from the stopped ec2 instance. I need to get instance id and volumed id in same line as given below.
aws ec2 describe-instances --region us-east-1 --profile <profile name> --filter Name=instance-state-name,Values=stopped,shutting-down | jq '.Reservations[].Instances[] | .InstanceId, .BlockDeviceMappings[].Ebs.VolumeId'
Actual Output
"i-f5ada1f18"
"vol-66a8adas2a2d"
"i-bb064fda12140"
"vol-52951f1dss9"
"i-3e1059sc5asd"
"vol-0da2ds122846"
Expected output
"i-f5ada1f18 vol-66a8adas2a2d"
"i-bb064fda12140 vol-52951f1dss9"
"i-3e1059sc5asd vol-0da2ds122846"
You can try below command with AWK and sed
aws ec2 describe-instances --region us-west-2 --filter Name=instance-state-name,Values=stopped,shutting-down | jq '.Reservations[].Instances[] | .InstanceId, .BlockDeviceMappings[].Ebs.VolumeId' | awk 'NR%2{printf "%s ",$0;next;}1' | sed 's/"//g' | sed 's/^/"/' |sed 's/$/"/'
ouput
"i-36e9e2c0 vol-480d085a"
"i-090225ee5bbeb6cad vol-0f719c8f188bbec98"
I had downloaded jq and trying to get a hang of it on Windows.
I am able to run some basic queries in jq but when I am trying to use select with jq I am getting the below mentioned message.
Below is the command which I am executing.
curl --basic -u admin:admin http://XX.XX.XX.XX:8080/mmc-console-3.7.3/api/deployments | jq .data[] | select(.name=="TestAccount").id
curl --basic -u admin:admin http://XX.XX.XX.XX:8080/mmc-console-3.7.3/api/deployments | jq .data[] | select(.name==\"TestAccount\").id
Output
select is not recognized as an internal or external command
I have jq in my path but not sure what I have to add in my path so that it can recognize `select as a command.
You need to quote the JQ expression, e.g.:
curl --basic -u admin:admin http://XX.XX.XX.XX:8080/mmc-console-3.7.3/api/deployments | jq '.data[] | select(.name=="TestAccount").id'