Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

388
Visualizações
How to patch multi document yaml file on condition using yq?

Having YAML document something like:

---
apiVersion: networking.k8s.io/v1
kind: NetworkPolicy
metadata:
  name: allow-scraping
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: allow-webhooks

I am trying to get something like

---
apiVersion: **networking.k8s.io/v1beta1**
kind: NetworkPolicy
metadata:
  name: allow-scraping
---
apiVersion: apps/v1
kind: Deployment
metadata:
  name: allow-webhooks

So basically get document, if document has kind: NetworkPolicy then patch apiVersion: networking.k8s.io/v1beta1.

Ideally one liner, ideally with yq v4, but other solutions will be helpful too.

over 4 years ago · Santiago Trujillo
2 Respostas
Responde à pergunta

0

With mikefarah/yq on versions beyond 4, you could do a select and update |= operation on the required document

yq e 'select(.kind == "NetworkPolicy").apiVersion |= "networking.k8s.io/v1beta1"' yaml

The above works fine on yq version 4.6.0. Use the -i flag to replace the file in-place.

over 4 years ago · Santiago Trujillo Relatório

0

Given that other solutions will be helpful - an alternative solution would be using kustomize:

  1. Create the kustomization.yaml file:
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
- network-policy.yaml
patches:
  - target:
      kind: NetworkPolicy
      group: networking.k8s.io
      version: v1
    patch: |
      - op: replace
        path: /apiVersion
        value: networking.k8s.io/v1beta1

  1. Run
kustomize build | kubectl apply -f -

or

kubectl apply -k .
over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda