kubernetes Kustomize修补程序进入问题- Go构造

8xiog9wr  于 2023-08-03  发布在  Kubernetes
关注(0)|答案(1)|浏览(125)

我是kustomize的新手,正试图弄清楚如何修补我通过OpenShift容器平台运行的入口。
基本配置工作正常,覆盖工作,直到我介绍了我的入口覆盖补丁。作为参考,补丁服务覆盖确实工作,所以我很确定我的结构和链接都很好,但是当同步到OpenShift(通过ArgoCD)时,我在项目上得到的错误是:
第一个月

应用回购结构

|mssql-example
├── base
│   ├── deployment.yaml
│   ├── ingress.yaml
│   ├── kustomization.yaml
│   ├── storage.yaml
│   └── service.yaml
└── overlays
    ├── nprd-dev
    │   ├── **patch-ingress.yaml**
    │   ├── patch-service.yaml
    │   └── kustomization.yaml
    ├── nprd-sit
    │   ├── patch-ingress.yaml
    │   ├── patch-service.yaml
    │   └── kustomization.yaml
    └── nprd-uat
    │   ├── patch-ingress.yaml
    │   ├── patch-service.yaml
    │   └── kustomization.yaml

字符串

mssql-example\base\ingress.yaml

---
kind: Ingress
apiVersion: networking.k8s.io/v1
metadata:
  name: mssql-example-adc
  annotations:
    ingress.citrix.com/frontend-ip: 192.168.1.10
    ingress.citrix.com/insecure-port: '1433'
    ingress.citrix.com/insecure-service-type: tcp
    kubernetes.io/ingress.class: citrix-vpx
spec:
  defaultBackend:
    service:
      name: mssql-service
      port:
        number: 31433

mssql-example\overlays\nprd-dev\kustomization.yaml

---
apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
namespace: ops-example-dev
resources:
  - ../../base
patches:
  - path: patch-ingress.yaml
    target:
      kind: Ingress
      version: v1
      name: mssql-example-adc
  - path: patch-service.yaml
    target:
      kind: Service
      version: v1
      name: mssql-example-tcp

mssql-example\overlayers\nprd-dev\patch-engage.yaml

---
- op: replace
  path: /metadata/name
  value: mssql-example-ingress-dev
- op: replace
  path: /spec/defaultBackend/service/port
  value: 31434


我认为我的路径可能是错误的,但是我似乎无法找出如何正确识别规范的替换路径,当它是defaultBackend。我尝试了/spec/defaultBackend/0/service/port和/spec/0/defaultBackend/service/port的路径,如果它是一个数组。

xurqigkl

xurqigkl1#

错误告诉你你需要知道的一切:

cannot unmarshal number into Go struct field

字符串
首先,看看初始Ingress清单的格式:

kind: Ingress
apiVersion: networking.k8s.io/v1
metadata:
  name: mssql-example-adc
  annotations:
    ingress.citrix.com/frontend-ip: 192.168.1.10
    ingress.citrix.com/insecure-port: '1433'
    ingress.citrix.com/insecure-service-type: tcp
    kubernetes.io/ingress.class: citrix-vpx
spec:
  defaultBackend:
    service:
      name: mssql-service
      port:
        number: 31433


特别注意spec.defaultBackend.service.port的结构。
现在,看看补丁生成的输出:

$ kustomize build
apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  annotations:
    ingress.citrix.com/frontend-ip: 192.168.1.10
    ingress.citrix.com/insecure-port: "1433"
    ingress.citrix.com/insecure-service-type: tcp
    kubernetes.io/ingress.class: citrix-vpx
  name: mssql-example-ingress-dev
spec:
  defaultBackend:
    service:
      name: mssql-service
      port: 31434


你看出区别了吗?您替换了一个结构化值:

port:
  number: 31433


使用整数:

port: 31434


只需将您的补丁更新为目标...service/port/number即可:

apiVersion: kustomize.config.k8s.io/v1beta1
kind: Kustomization
resources:
- ingress.yaml

patches:
  - target:
      name: mssql-example-adc
    patch: |
      - op: replace
        path: /metadata/name
        value: mssql-example-ingress-dev
      - op: replace
        path: /spec/defaultBackend/service/port/number
        value: 31434


其结果是:

apiVersion: networking.k8s.io/v1
kind: Ingress
metadata:
  annotations:
    ingress.citrix.com/frontend-ip: 192.168.1.10
    ingress.citrix.com/insecure-port: "1433"
    ingress.citrix.com/insecure-service-type: tcp
    kubernetes.io/ingress.class: citrix-vpx
  name: mssql-example-ingress-dev
spec:
  defaultBackend:
    service:
      name: mssql-service
      port:
        number: 31434

相关问题