如何解析多个对象的引用

我正在使用go-client库。

我正在搜索工作负载中的装入机密。 br>
在我的示例中,我们有两个工作负载: daemonset </ code>和 deployments </ code>。

尽管它们都是不同的对象,但是它们具有相似的结构:</ p>

  type DaemonSet struct {
metav1.TypeMetajson:“,inline”
metav1.ObjectMetajson:“ metadata,omitempty” protobuf:“ bytes,1,opt,name = metadata“
Spec DaemonSetSpecjson:” spec,omitempty“ protobuf:” bytes,2,opt,name = spec“
Status DaemonSetStatus
json:” status,omitempty“ protobuf:” bytes,3,opt ,name = status“`
}

type部署结构{
metav1.TypeMetajson:”,inline“
metav1.ObjectMetajson:” metadata,omitempty“ protobuf:” bytes,1 ,opt,name =元数据“
Spec DeploymentSpec
json:” spec,omitempty“ protobuf:” bytes,2,opt,name = spec“
Status DeploymentStatus`json:” status,omitempty“ protobuf:” bytes 3,选择,名字=状态“'\ N}
</代码 > </ pre>

我收到以下错误:</ p>


未解决的引用</ p>
</ blockquote>

发生这种情况是因为编译不知道我指的是什么对象: v1beta2.DaemonSetList </ code>或 v1beta2.DeploymentList </ code>。 </ p>

如何为他们两个人解决? </ p>

”在此处输入图片描述“ </ p>
</ div>

展开原文

原文

I am using the go-client library.
I am searching for mounted secrets inside the workload.
In my example we have two workloads: daemonset and deployments.
Although both of them are different objects, they have similar structure:

type DaemonSet struct {
    metav1.TypeMeta `json:",inline"`
    metav1.ObjectMeta `json:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"`
    Spec DaemonSetSpec `json:"spec,omitempty" protobuf:"bytes,2,opt,name=spec"`
    Status DaemonSetStatus `json:"status,omitempty" protobuf:"bytes,3,opt,name=status"`
}


type Deployment struct {
    metav1.TypeMeta `json:",inline"`
    metav1.ObjectMeta `json:"metadata,omitempty" protobuf:"bytes,1,opt,name=metadata"`
    Spec DeploymentSpec `json:"spec,omitempty" protobuf:"bytes,2,opt,name=spec"`
    Status DeploymentStatus `json:"status,omitempty" protobuf:"bytes,3,opt,name=status"`
}

I am getting errors of:

Unresolved reference

This happens because the compilation doesn't know what object I am referring to: v1beta2.DaemonSetList or v1beta2.DeploymentList.

How can I resolve it for both of them ?

enter image description here

1个回答

no. This happens because your variable controllerList is not declared in the right scope.

it must be declared in the common scope shared by both the for loop and the switch statement, the parent scope, IE the if controllerName != ....

** Note that to post on SO you must NOT include screenshot of the code, but provide a minimal reproducible example of the code, copy && pasted && linted in your post.

douwu7168
douwu7168 我在第一个for循环之后使用了var controllerList [] interface {}和var workload Items Interface {}。 现在,它可以识别工作负荷项目。
大约一年之前 回复
dsfovbm931034814
dsfovbm931034814 使controllerList成为[] interface {}类型的切片并对其进行处理
大约一年之前 回复
dongzhong3688
dongzhong3688 问题是我无法放置controllerList共享范围,因为在每种情况下我都在投射适当的对象。
大约一年之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐