Clusterpedia 第一个版本 -- Clusterpedia 0.1.0 正式发布,即日起进入版本迭代阶段。相比于初期的 0.0.8 和 0.0.9-alpha,0.1.0 添加了很多功能,并且做了一些不兼容的更新。
如果由 0.0.9-alpha 升级的话,可以参考 Upgrade to Clusterpedia 0.1.0
https://clusterpedia.io/blog/2022/02/15/upgrade-to-clusterpedia-0.1.0/
01
重要功能
我们先介绍一下在 0.1.0 中增加的四大重要的功能:
-
对 Not Ready 的集群进行资源检索时,增加了 Warning 提醒
-
增强了原生 Field Selector 的能力
-
根据父辈或者祖辈的 Owner 来进行查询
-
响应数据携带 remaining item count
资源检索时的 Warning 提醒
集群由于某些原因处于非 Ready 的状态时,资源通常也无法正常同步,在获取到该集群内的资源时,会通过 Warnning 提醒来告知用户集群异常,并且获取到的资源可能并不是实时准确的。
$ kubectl get pediacluster
NAME APISERVER VERSION STATUS
cluster-1 https://10.6.100.10:6443 v1.22.2 ClusterSynchroStop
$ kubectl --cluster cluster-1 get pods
Warning: cluster-1 is not ready and the resources obtained may be inaccurate, reason: ClusterSynchroStop
CLUSTER NAME READY STATUS RESTARTS AGE
cluster-1 fake-pod-698dfbbd5b-64fsx 1/1 Running 0 68d
cluster-1 fake-pod-698dfbbd5b-9ftzh 1/1 Running 0 39d
cluster-1 fake-pod-698dfbbd5b-rk74p 1/1 Running 0 39d
cluster-1 quickstart-ingress-nginx-admission-create--1-kxlnn 0/1 Completed 0 126d
强化 Field Selector
原生 kubernetes 对于 Field Selector 的支持非常有限,默认只支持 metadata.namespace 和 metadata.name 字段的过滤,尽管一些特定的资源会支持一些特殊的字段,但是使用起来还是比较局限,操作符只能支持 =, ==, !=。
# kubernetes/pkg
$ grep AddFieldLabelConversionFunc . -r
./apis/core/v1/conversion.go: err := scheme.AddFieldLabelConversionFunc(SchemeGroupVersion.WithKind("Pod"),
./apis/core/v1/conversion.go: err = scheme.AddFieldLabelConversionFunc(SchemeGroupVersion.WithKind("Node"),
./apis/core/v1/conversion.go: err = scheme.AddFieldLabelConversionFunc(SchemeGroupVersion.WithKind("ReplicationController"),
./apis/core/v1/conversion.go: return scheme.AddFieldLabelConversionFunc(SchemeGroupVersion.WithKind("Event"),
./apis/core/v1/conversion.go: return scheme.AddFieldLabelConversionFunc(SchemeGroupVersion.WithKind("Namespace"),
./apis/core/v1/conversion.go: return scheme.AddFieldLabelConversionFunc(SchemeGroupVersion.WithKind("Secret"),
./apis/certificates/v1/conversion.go: return scheme.AddFieldLabelConversionFunc(SchemeGroupVersion.WithKind("CertificateSigningRequest"),
./apis/certificates/v1beta1/conversion.go: return scheme.AddFieldLabelConversionFunc(SchemeGroupVersion.WithKind("CertificateSigningRequest"),
./apis/batch/v1/conversion.go: return scheme.AddFieldLabelConversionFunc(SchemeGroupVersion.WithKind("Job"),
./apis/batch/v1beta1/conversion.go: err = scheme.AddFieldLabelConversionFunc(SchemeGroupVersion.WithKind(kind),
./apis/events/v1/conversion.go: return scheme.AddFieldLabelConversionFunc(SchemeGroupVersion.WithKind("Event"),
./apis/events/v1beta1/conversion.go: return scheme.AddFieldLabelConversionFunc(SchemeGroupVersion.WithKind("Event"),
./apis/apps/v1beta2/conversion.go: if err := scheme.AddFieldLabelConversionFunc(SchemeGroupVersion.WithKind("StatefulSet"),
./apis/apps/v1beta1/conversion.go: if err := scheme.AddFieldLabelConversionFunc(SchemeGroupVersion.WithKind("StatefulSet"),
Clusterpedia 在兼容原生 Field Selector 的基础上,不仅仅支持了更加灵活的字段过滤,还支持和 Label Selector 相同的操作符:!, =, !=, ==, in, notin。
例如我们可以像 label selector 一样,通过 annotations 过滤资源。
kubectl get deploy --field-selector="metadata.annotations['test.io'] in (value1, value2)"
更多详情
https://clusterpedia.io/zh-cn/docs/usage/search/multi-cluster/#%E5%AD%97%E6%AE%B5%E8%BF%87%E6%BB%A4
根据父辈或者祖辈 Owner 进行查询
Kubernetes 资源之间通常会存在一种 Owner 关系, 例如
apiVersion: v1
kind: Pod
metadata:
ownerReferences:
- apiVersion: apps/v1
blockOwnerDeletion: true
controller: true
kind: ReplicaSet
name: fake-pod-698dfbbd5b
uid: d5bf2bdd-47d2-4932-84fb-98bde486d244
Clusterpedia 不仅支持根据 Owner 查询,还支持对 Owner 进行辈分提升来根据祖辈或者更高辈分的 Owner 来检索资源。
例如可以通过 Deployment 获取相应的所有 pods。
当前暂时只支持通过 Owner UID 来查询资源, 使用 Owner Name 来进行查询的功能尚在讨论中,可以在 issue: Support for searching resources by owner 参与讨论。
$ DEPLOY_UID=$(kubectl --cluster cluster-1 get deploy fake-deploy -o jsonpath="{.metadata.uid}")
$ kubectl --cluster cluster-1 get pods -l \
"internalstorage.clusterpedia.io/owner-uid=$DEPLOY_UID,\
internalstorage.clusterpedia.io/owner-seniority=1"
更多详情
https://clusterpedia.io/zh-cn/docs/usage/search/multi-cluster/#%E6%A0%B9%E6%8D%AE%E7%88%B6%E8%BE%88%E4%BB%A5%E5%8F%8A%E7%A5%96%E8%BE%88-owner-%E6%9F%A5%E8%AF%A2
响应数据内携带剩余资源数量
在一些 UI 场景下,往往需要获取当前检索条件下的资源总量。
Kubernetes 响应的 ListMeta 中 RemainingItemCount 字段表示剩余的资源数量。
type ListMeta struct {
...
// remainingItemCount is the number of subsequent items in the list which are not included in this
// list response. If the list request contained label or field selectors, then the number of
// remaining items is unknown and the field will be left unset and omitted during serialization.
// If the list is complete (either because it is not chunking or because this is the last chunk),
// then there are no more remaining items and this field will be left unset and omitted during
// serialization.
// Servers older than v1.15 do not set this field.
// The intended use of the remainingItemCount is *estimating* the size of a collection. Clients
// should not rely on the remainingItemCount to be set or to be exact.
// +optional
RemainingItemCount *int64 `json:"remainingItemCount,omitempty" protobuf:"bytes,4,opt,name=remainingItemCount"`
}
复用 ListMeta.RemainingItemCount,通过简单计算便可以获取当前检索条件下的资源总量: total = offset + len(list.items) + list.metadata.remainingItemCount
该功能需要搭配分页功能一起使用
$ kubectl get --raw="/apis/clusterpedia.io/v1beta1/resources/apis/apps/v1/deployments?withRemainingCount&limit=1" | jq
{
"kind": "DeploymentList",
"apiVersion": "apps/v1",
"metadata": {
"remainingItemCount": 24
},
"items": [
...
]
}
更多详情
https://clusterpedia.io/zh-cn/docs/usage/search/multi-cluster/#%E5%93%8D%E5%BA%94%E6%90%BA%E5%B8%A6%E5%89%A9%E4%BD%99%E8%B5%84%E6%BA%90%E6%95%B0%E9%87%8F%E4%BF%A1%E6%81%AF
02
更新总览
-
用于资源检索的 pedia.clusterpedia.io/v1alpha1 更改为 clusterpedia.io/v1beta1 (https://github.com/clusterpedia-io/clusterpedia/pull/73)
-
优化了 PediaCluster 结构, 并且将 clusters.clusterpedia.io/v1alpha1 组更改为 cluster.clusterpedia.io/v1alpha2 (https://github.com/clusterpedia-io/clusterpedia/pull/27; https://github.com/clusterpedia-io/clusterpedia/pull/67; https://github.com/clusterpedia-io/clusterpedia/pull/76; https://github.com/clusterpedia-io/clusterpedia/pull/74; https://github.com/clusterpedia-io/clusterpedia/pull/78)
-
支持自定义资源的收集和搜索 (https://github.com/clusterpedia-io/clusterpedia/pull/10)
-
将插入到资源中的集群信息由 labels 移动到 annotations 中 (https://github.com/clusterpedia-io/clusterpedia/pull/37)
-
添加了存储组件 postgres 的部署 yaml
APIServer
-
支持响应数据携带 RemainingItemCount 和 Continue 字段 (https://github.com/clusterpedia-io/clusterpedia/pull/33)
-
增强了对 Field Selector 支持,在兼容原生 Field Selector 的同时,还支持和 Label Selector 相同的复杂操作符 (https://github.com/clusterpedia-io/clusterpedia/pull/36)
-
指定查询未同步异常的集群内的资源时增加了 Warning 提醒 (https://github.com/clusterpedia-io/clusterpedia/pull/35)
-
为了保持用于分页的 Limit query 一致,将 search label 由 search.clusterpedia.io/size 修改为 search.clusterpedia.io/limit (https://github.com/clusterpedia-io/clusterpedia/pull/42)
Bug Fixes
-
修复 requestInfo 在解析命名空间资源时,依然设置 requestInfo.Namespace 字段 (https://github.com/clusterpedia-io/clusterpedia/pull/17)
-
修复了内置资源在同步时,指定版本导致资源同步状态显示异常的问题 (https://github.com/clusterpedia-io/clusterpedia/pull/58)
ClusterSynchro Manager
-
clustersynchro manager 可以通过 feature gates 来裁剪 managedFields 和 last-applied-configuration 字段 (https://github.com/clusterpedia-io/clusterpedia/pull/19)
Bug Fixes
-
修复了 PediaCluster Status 更新相关的问题 (https://github.com/clusterpedia-io/clusterpedia/pull/11; https://github.com/clusterpedia-io/clusterpedia/pull/24; https://github.com/clusterpedia-io/clusterpedia/pull/23;https://github.com/clusterpedia-io/clusterpedia/pull/22)
-
修复了 clustersynchro manager 的 leader election (https://github.com/clusterpedia-io/clusterpedia/pull/15)
Default Storage Layer
-
默认存储层不再为用户提供默认的排序顺序,由用户来主动设置排序 (https://github.com/clusterpedia-io/clusterpedia/pull/44)
-
增加了一些索引,并且修复了 gorm 忽略空字段的问题 (https://github.com/clusterpedia-io/clusterpedia/pull/41)
-
支持了根据父辈或者祖辈 owner 进行查询 (https://github.com/clusterpedia-io/clusterpedia/pull/50)
Bug Fixes
-
修复了 JSON SQL 的生成 (https://github.com/clusterpedia-io/clusterpedia/pull/60; https://github.com/clusterpedia-io/clusterpedia/pull/62; https://github.com/clusterpedia-io/clusterpedia/pull/78)
-
修复了过滤 CollectionResource 时,获取的资源不准确的问题 (https://github.com/clusterpedia-io/clusterpedia/pull/61)
以上就是 Clusterpedia 0.1.0 的版本内容介绍,非常欢迎大家使用和参与讨论。