栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Go语言

k8s crd如何使用map[string]interface{}

Go语言 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

k8s crd如何使用map[string]interface{}

只需要在object字段里面添加类型x-kubernetes-preserve-unknown-fields: true就可以

apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
  name: mines.test.io
spec:
  group: test.io
  versions:
    - name: v1
      served: true
      storage: true
      schema:
        openAPIV3Schema:
          type: object
          properties:
            spec:
              type: object
              properties:
                template:
                  type: object
                  x-kubernetes-preserve-unknown-fields: true
                replicas:
                  type: integer
            status:
              type: object
              properties:
                 label:
                   type: string
  scope: Namespaced
  names:
    plural: mines
    singular: mine
    kind: Mine
    shortNames:
      - mn

然后创建这个资源的时候就可以直接使用podtemplate

apiVersion: test.io/v1
kind: Mine
metadata:
  name: test
  labels:
    app: test
spec:
  template:
    metadata:
      labels:
        app: test
    spec:
      containers:
        - name: nginx
          images: nginx:1.12.2
          ports:
            - containerPort: 8080
  replicas: 3

 spec的struct定义为

type SpecMine struct {
	PodTemplate v12.PodTemplateSpec `json:"template"`
	Replicas int32 `json:"replicas"`
}

就可以获取到yaml里面设置的pod的template

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/990434.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号