微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

如何解决添加无法通过动态资源和 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 举报,一经查实,本站将立刻删除。