添加无法通过动态资源和 Client-go 工作的标签

问题描述

我正在使用 client-go 通过解析 yaml 文件 click code 创建资源。

但是通过非结构化界面为资源设置标签不起作用,怎么办?

    func (u *Unstructured) SetLabels(labels map[string]string) {
        if labels == nil {
            RemovenestedField(u.Object,"Metadata","labels")
            return
        }
        u.setnestedMap(labels,"labels")
    }

我的代码是这样的:

    func ApplyUnstructured(ctx context.Context,dynamicclient dynamic.Interface,restMapper Meta.RESTMapper,unstructuredobj unstructured.Unstructured,serverSide bool) (*unstructured.Unstructured,error) {
        if len(unstructuredobj.GetName()) == 0 {           
            Metadata,_ := Meta.Accessor(unstructuredobj)      
            generateName := Metadata.GetGenerateName()      
            if len(generateName) > 0 {       
                return nil,fmt.Errorf("from %s: cannot use generate name with >apply",generateName)      
            }      
        }         
    ....
    // !!!! set labels not work !!!!!!!        
                unstructuredobj.SetLabels(map[string]string {        
         "jobid":"test",} )

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)