doumie7914 2019-05-02 16:00
浏览 157
已采纳

如何使用kubebuilder的client.List方法?

I'm working on a custom controller for a custom resource using kubebuilder (version 1.0.8). I have a scenario where I need to get a list of all the instances of my custom resource so I can sync up with an external database.

All the examples I've seen for kubernetes controllers use either client-go or just call the api server directly over http. However, kubebuilder has also given me this client.Client object to get and list resources. So I'm trying to use that.

After creating a client instance by using the passed in Manager instance (i.e. do mgr.GetClient()), I then tried to write some code to get the list of all the Environment resources I created.

func syncClusterWithDatabase(c client.Client, db *dynamodb.DynamoDB) {
    // Sync environments
    // Step 1 - read all the environments the cluster knows about
    clusterEnvironments := &cdsv1alpha1.EnvironmentList{}

    c.List(context.Background(), /* what do I put here? */, clusterEnvironments)
}

The example in the documentation for the List method shows:

c.List(context.Background, &result);

which doesn't even compile.

I saw a few method in the client package to limit the search to particular labels, or for a specific field with a specific value, but nothing to limit the result to a specific resource kind.

Is there a way to do this via the Client object? Should I do something else entirely?

  • 写回答

1条回答 默认 最新

  • dsilhx5830 2019-05-07 22:21
    关注

    So figured it out - the answer is to pass nil for the second parameter. The type of the output pointer determines which sort of resource it actually retrieves.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥100 连续两帧图像高速减法
  • ¥15 组策略中的计算机配置策略无法下发
  • ¥15 如何绘制动力学系统的相图
  • ¥15 对接wps接口实现获取元数据
  • ¥20 给自己本科IT专业毕业的妹m找个实习工作
  • ¥15 用友U8:向一个无法连接的网络尝试了一个套接字操作,如何解决?
  • ¥30 我的代码按理说完成了模型的搭建、训练、验证测试等工作(标签-网络|关键词-变化检测)
  • ¥50 mac mini外接显示器 画质字体模糊
  • ¥15 TLS1.2协议通信解密
  • ¥40 图书信息管理系统程序编写