[Backport release-1.2] Fix: can not collector pod list with rollout trait (#3240)

* Fix: can not collector pod list with rollout trait

Signed-off-by: barnettZQG <barnett.zqg@gmail.com>
(cherry picked from commit 6365df4737)

* Fix: cue format error

Signed-off-by: barnettZQG <barnett.zqg@gmail.com>
(cherry picked from commit 0a59d0c051)

* Fix: default values and optional parameters cannot coexist

Signed-off-by: barnettZQG <barnett.zqg@gmail.com>
(cherry picked from commit d8e08b09d8)

Co-authored-by: barnettZQG <barnett.zqg@gmail.com>
This commit is contained in:
github-actions[bot]
2022-02-14 13:05:44 +08:00
committed by GitHub
co-authored by barnettZQG
parent d540491f46
commit f8ba3d5d00
4 changed files with 57 additions and 22 deletions
+30 -3
View File
@@ -203,9 +203,7 @@ func NewPodCollector(gvk schema.GroupVersionKind) PodCollector {
if collector, ok := podCollectorMap[gvk]; ok {
return collector
}
return func(cli client.Client, obj *unstructured.Unstructured, cluster string) ([]*unstructured.Unstructured, error) {
return nil, nil
}
return velaComponentPodCollector
}
// standardWorkloadPodCollector collect pods created by standard workload
@@ -402,6 +400,35 @@ func helmReleasePodCollector(cli client.Client, obj *unstructured.Unstructured,
return collectedPods, nil
}
func velaComponentPodCollector(cli client.Client, obj *unstructured.Unstructured, cluster string) ([]*unstructured.Unstructured, error) {
ctx := multicluster.ContextWithClusterName(context.Background(), cluster)
listOpts := []client.ListOption{
client.MatchingLabels(map[string]string{"app.oam.dev/component": obj.GetName()}),
client.InNamespace(obj.GetNamespace()),
}
podList := corev1.PodList{}
if err := cli.List(ctx, &podList, listOpts...); err != nil {
return nil, err
}
pods := make([]*unstructured.Unstructured, len(podList.Items))
for i := range podList.Items {
pod, err := oamutil.Object2Unstructured(podList.Items[i])
if err != nil {
return nil, err
}
pod.SetGroupVersionKind(
corev1.SchemeGroupVersion.WithKind(
reflect.TypeOf(corev1.Pod{}).Name(),
),
)
pods[i] = pod
}
return pods, nil
}
func getEventFieldSelector(obj *unstructured.Unstructured) fields.Selector {
field := fields.Set{}
field["involvedObject.name"] = obj.GetName()