How can I retrieve the value of an annotation on a...
# kubernetes
a
How can I retrieve the value of an annotation on a kubernetes resource? ie. I have a service with the following annotations:
Copy code
metadata:
  annotations:
    <http://beta.cloud.google.com/backend-config|beta.cloud.google.com/backend-config>: '{"default": "istio-ingressgateway"}'
    <http://cloud.google.com/app-protocols|cloud.google.com/app-protocols>: '{"https":"HTTP2"}'
    <http://cloud.google.com/neg|cloud.google.com/neg>: '{"ingress": true}'
    <http://cloud.google.com/neg-status|cloud.google.com/neg-status>: '{"network_endpoint_groups":{"443":"k8s1-5487ae62-istio-system-istio-ingressgateway-443-811432aa"},"zones":["us-east1-d"]}'
I'd like to extract the value of the
<http://cloud.google.com/neg-status|cloud.google.com/neg-status>
annotation in such a way that I can use it to retrieve a gcp network endpoint group like:
Copy code
const neg = gcp.compute.getNetworkEndpointGroup({
  name: "k8s1-5487ae62-istio-system-istio-ingressgateway-443-811432aa",
  zone: "us-east1-d"
})
I'm usually ok working with outputs, but pulling something that's in json in a property of a property has got me beat right now
I've grabbed the k8s resource with
k8s.core.v1.Service.get
- just trying to figure out how best to use
$myservice.metadata.annotations.apply
to extract what I need
g
Something like this should do the trick:
Copy code
export const neg_status = svc.metadata.annotations.apply(x => {
    const status = x['<http://cloud.google.com/neg-status|cloud.google.com/neg-status>'];
    const obj = JSON.parse(status);
    return obj["network_endpoint_groups"]["443"]
})

const neg = gcp.compute.getNetworkEndpointGroup({
    name: neg_status,
    zone: "us-east1-d"
})