登录
首页 >  Golang >  Go问答

Kubernetes集群的自动化API版本

来源:stackoverflow

时间:2024-03-12 10:18:27 292浏览 收藏

今天golang学习网给大家带来了《Kubernetes集群的自动化API版本》,其中涉及到的知识点包括等等,无论你是小白还是老手,都适合看一看哦~有好的建议也欢迎大家在评论留言,若是看完有所收获,也希望大家能多多点赞支持呀!一起加油学习~

问题内容

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

{
        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

"apiVersion": "kubedb.com/v1alpha1",

解决方案


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

pg.object["apiversion"]

请参阅下面的完整示例

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"])
}

好了,本文到此结束,带大家了解了《Kubernetes集群的自动化API版本》,希望本文对你有所帮助!关注golang学习网公众号,给大家分享更多Golang知识!

声明:本文转载于:stackoverflow 如有侵犯,请联系study_golang@163.com删除
相关阅读
更多>
最新阅读
更多>
课程推荐
更多>