0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

k8s: Dynatrace Operator YAMLをyqで一括名前変更

Posted at

前回 Dynatrace Operator YAML マニフェストファイルを分割しました。以下のようなファイル群がある状態です。

$  ls
Operator140_00  Operator140_04  Operator140_08  Operator140_12  Operator140_16  Operator140_20
Operator140_01  Operator140_05  Operator140_09  Operator140_13  Operator140_17  Operator140_21
Operator140_02  Operator140_06  Operator140_10  Operator140_14  Operator140_18  Operator140_22
Operator140_03  Operator140_07  Operator140_11  Operator140_15  Operator140_19  Operator140_23

このファイル名を意味あるものに変えようと思います。ファイルの内容中に意味のある文字列があるのでそれらをyqコマンドで抜き出してみます。

$ yq .kind Operator140_07
CustomResourceDefinition
$ yq .metadata.name Operator140_07
dynakubes.dynatrace.com
$ yq '.kind += "_"|.kind += .metadata.name|.kind' Operator140_07
CustomResourceDefinition_dynakubes.dynatrace.com

ユニークな文字列として使えそうですね。一括名前変換してlsで一覧してみました。

$ for i in *; do  mv $i $(yq '.kind += "_"|.kind += .metadata.name|.kind' $i).yaml; done
$ ls -l
total 324
-rwxrwxrwx 1 kinoue kinoue    577 Dec  4 00:06 ClusterRoleBinding_dynatrace-kubernetes-monitoring.yaml
-rwxrwxrwx 1 kinoue kinoue    510 Dec  4 00:06 ClusterRoleBinding_dynatrace-operator.yaml
-rwxrwxrwx 1 kinoue kinoue    504 Dec  4 00:06 ClusterRoleBinding_dynatrace-webhook.yaml
-rwxrwxrwx 1 kinoue kinoue   1896 Dec  4 00:06 ClusterRole_dynatrace-kubernetes-monitoring.yaml
-rwxrwxrwx 1 kinoue kinoue   2129 Dec  4 00:06 ClusterRole_dynatrace-operator.yaml
-rwxrwxrwx 1 kinoue kinoue   1896 Dec  4 00:06 ClusterRole_dynatrace-webhook.yaml
-rwxrwxrwx 1 kinoue kinoue 217416 Dec  4 00:06 CustomResourceDefinition_dynakubes.dynatrace.com.yaml
-rwxrwxrwx 1 kinoue kinoue  33502 Dec  4 00:06 CustomResourceDefinition_edgeconnects.dynatrace.com.yaml
-rwxrwxrwx 1 kinoue kinoue   3872 Dec  4 00:06 Deployment_dynatrace-operator.yaml
-rwxrwxrwx 1 kinoue kinoue   4711 Dec  4 00:06 Deployment_dynatrace-webhook.yaml
-rwxrwxrwx 1 kinoue kinoue   1992 Dec  4 00:06 MutatingWebhookConfiguration_dynatrace-webhook.yaml
-rwxrwxrwx 1 kinoue kinoue    332 Dec  4 00:06 PodDisruptionBudget_dynatrace-webhook.yaml
-rwxrwxrwx 1 kinoue kinoue    487 Dec  4 00:06 RoleBinding_dynatrace-operator.yaml
-rwxrwxrwx 1 kinoue kinoue    506 Dec  4 00:06 RoleBinding_dynatrace-webhook.yaml
-rwxrwxrwx 1 kinoue kinoue   3076 Dec  4 00:06 Role_dynatrace-operator.yaml
-rwxrwxrwx 1 kinoue kinoue   1624 Dec  4 00:06 Role_dynatrace-webhook.yaml
-rwxrwxrwx 1 kinoue kinoue    905 Dec  4 00:06 ServiceAccount_dynatrace-activegate.yaml
-rwxrwxrwx 1 kinoue kinoue    942 Dec  4 00:06 ServiceAccount_dynatrace-dynakube-oneagent.yaml
-rwxrwxrwx 1 kinoue kinoue    904 Dec  4 00:06 ServiceAccount_dynatrace-edgeconnect.yaml
-rwxrwxrwx 1 kinoue kinoue    938 Dec  4 00:06 ServiceAccount_dynatrace-kubernetes-monitoring.yaml
-rwxrwxrwx 1 kinoue kinoue    897 Dec  4 00:06 ServiceAccount_dynatrace-operator.yaml
-rwxrwxrwx 1 kinoue kinoue    893 Dec  4 00:06 ServiceAccount_dynatrace-webhook.yaml
-rwxrwxrwx 1 kinoue kinoue   1092 Dec  4 00:06 Service_dynatrace-webhook.yaml
-rwxrwxrwx 1 kinoue kinoue   1889 Dec  4 00:06 ValidatingWebhookConfiguration_dynatrace-webhook.yaml

参考になれば!

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?