1

I am trying to annotate my deployment with multiline yaml format configuration, but getting invalid format exception.(I have controller to parse this custom annotation)

apiVersion: apps/v1
kind: Deployment
metadata:
  annotations:
    autoscale/max_replica: "5"
    autoscale/min_replica: "1"
    autoscale/metricObjects : |
    - type: Object
      object:
        metric:
            name: requests-per-second
        describedObject:
            apiVersion: networking.k8s.io/v1
            kind: Ingress
            name: main-route
        target:
            type: Value
            value: 2k
      metricQuery :
        aggregator_window : '5m'
        metric_aggregator : 'sum'
    deployment.kubernetes.io/revision: "1"
  creationTimestamp: "2023-05-17T11:40:14Z"
  generation: 4
  labels:
    app: hello-node
  name: hello-node
  namespace: default
  resourceVersion: "182022"
  uid: f0f3273d-c762-4a6d-83aa-64a37353e183
spec:

getting invalid format for autoscale/metricObjects annotations, tried > instead of | but same error.

However putting entire annotation value inside "" accepts the annotation values but this gets translated to

 autoscale/metricObjects: ' - type: Object object: metric: name: requests-per-second                                                                                           │
│       describedObject: apiVersion: networking.k8s.io/v1 kind: Ingress name: main-route                                                                                            │
│       target: type: Value value: 2k metricQuery : aggregator_window : ''5m'' metric_aggregator                                                                                    │
│       : ''sum'''                                                                                                                                                                  │
│     autoscale/min_replica: "1"                                                                                                                                                    │
│     deployment.kubernetes.io/revision: "1"

which is failing in unmarshaling to struct, not sure what is the right way to mention such configuration in annotation.?

 annotations:
    deployment.kubernetes.io/revision: "1"
    autoscale/min_replica : 1
    autoscale/max_replica : 5
    autoscale/metricObjects : "
    - type: Object
      object:
        metric:
            name: requests-per-second
        describedObject:
            apiVersion: networking.k8s.io/v1
            kind: Ingress
            name: main-route
        target:
            type: Value
            value: 2k
      metricQuery : 
        aggregator_window : '5m'
        metric_aggregator : 'sum' "
  creationTimestamp: "2023-05-17T11:40:14Z"

I could get this working and the working format is

apiVersion: apps/v1
kind: Deployment
metadata:
  annotations:
    deployment.kubernetes.io/revision: "1"
    autoscale.mars.salesforce.com/minReplica : "1"
    autoscale.mars.salesforce.com/maxReplica : "5"
    autoscale.mars.salesforce.com/metricObjects : |
      - type: Object
        object:
          metric:
              name: requests-per-second
          describedObject:
              apiVersion: networking.k8s.io/v1
              kind: Ingress
              name: main-route
          target:
              type: Value
              value: 20
        metricQuery : 
          aggregatorWindow : '5m'
          aggregatorFunction : 'sum' 
  labels:
    app: hello-node
  name: hello-node
  namespace: test
spec:

issue was with indentation, it need sot haven only blank spaces and I was giving tabs as well.

0 Answers0