首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >自动化Kubernetes集群的API版本

自动化Kubernetes集群的API版本
EN

Stack Overflow用户
提问于 2020-11-20 05:25:33
回答 1查看 81关注 0票数 0

我想自动化我的自定义资源的kubedb API版本。如何获取管理bu集群的API版本,并将其传递到自动工作的代码中。我使用多个集群,每个集群由不同的Api版本管理,例如我的dev集群由kubedb.com/v1alpha1管理,但我的生产集群由kubedb.com/v1alpha2管理。所以我想根据每个集群的API版本实现自动化。

代码语言:javascript
复制
{
        pg := &unstructured.Unstructured{}
        pg.Object = map[string]interface{}{
            "kind":       "Postgres",
            "apiVersion": "kubedb.com/v1alpha1",
            "metadata": map[string]interface{}{
                "name":      instance.Name + "-timescaledb",
                "namespace": instance.Namespace,
            },
            "spec": map[string]interface{}{
                "version":     "11.1-v1",
                "storageType": "Durable",
                "storage": map[string]interface{}{
                    "storageClassName": "standard",
                    "accessModes":      []string{"ReadWriteOnce"},
                    "resources": map[string]interface{}{
                        "requests": map[string]interface{}{
                            "storage": "50Gi",
                        },
                    },
                },
                "terminationPolicy": "DoNotTerminate",
            },
        }

我想在下面的代码中用下面的apiVersion更新它

代码语言:javascript
复制
  "apiVersion": "kubedb.com/v1alpha1",
EN

回答 1

Stack Overflow用户

发布于 2020-11-21 03:07:53

这只是一张地图所以你可以打电话给

pg.Object["apiVersion"]

请参阅下面的完整示例

代码语言:javascript
复制
package main

import (
    "fmt"

    "k8s.io/apimachinery/pkg/apis/meta/v1/unstructured"
)

func main() {

    pg := &unstructured.Unstructured{}
    pg.Object = map[string]interface{}{
        "kind":       "Postgres",
        "apiVersion": "kubedb.com/v1alpha1",
        "metadata": map[string]interface{}{
            "name":      "instance.Name" + "-timescaledb",
            "namespace": "instance.Namespace",
        },
        "spec": map[string]interface{}{
            "version":     "11.1-v1",
            "storageType": "Durable",
            "storage": map[string]interface{}{
                "storageClassName": "standard",
                "accessModes":      []string{"ReadWriteOnce"},
                "resources": map[string]interface{}{
                    "requests": map[string]interface{}{
                        "storage": "50Gi",
                    },
                },
            },
            "terminationPolicy": "DoNotTerminate",
        },
    }
    // Print current apiVersion
    fmt.Println(pg.Object["apiVersion"])

    //change apiVersion
    pg.Object["apiVersion"] = "mynewVersion.Com/v1alpha4"

    // Print new apiVersion
    fmt.Println(pg.Object["apiVersion"])
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/64920268

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档