使用 kubectl 生成 yaml 输出导致分割线

问题描述

我正在尝试使用 kubectl --dry-run 生成 yaml 输出

当我运行这个

$ kubectl create configmap my-config-map  -o yaml --dry-run=client | kubectl annotate -f- --dry-run=client -o yaml --local this-is-my-target-directory='{{ template "This.is.long.path.for.some.value" . }}'

我得到以下输出,其中注释被分成 2 行。

apiVersion: v1
kind: ConfigMap
Metadata:
  annotations:
    this-is-my-target-directory: '{{ template "This.is.long.path.for.some.value" .
      }}'
  creationTimestamp: null
  name: my-config-map

我想要的输出是注释应该在一行中。如下图

apiVersion: v1
kind: ConfigMap
Metadata:
  annotations:
    this-is-my-target-directory: '{{ template "This.is.long.path.for.some.value" . }}'
  creationTimestamp: null
  name: my-config-map

如果我减小字符串的大小,它就会变成 1 行。我在文档中找不到任何关于行长的信息。谁能指导我如何解决这个问题?

解决方法

我认为你找不到任何东西,因为这是一个完全有效的 yaml。所以我想你可以直接使用它,而无需将大括号放在同一行。