mirror of
https://github.com/kubevela/kubevela.git
synced 2026-08-27 16:17:34 +00:00
[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 commit6365df4737) * Fix: cue format error Signed-off-by: barnettZQG <barnett.zqg@gmail.com> (cherry picked from commit0a59d0c051) * Fix: default values and optional parameters cannot coexist Signed-off-by: barnettZQG <barnett.zqg@gmail.com> (cherry picked from commitd8e08b09d8) Co-authored-by: barnettZQG <barnett.zqg@gmail.com>
This commit is contained in:
co-authored by
barnettZQG
parent
d540491f46
commit
f8ba3d5d00
@@ -5,8 +5,6 @@ kind: TraitDefinition
|
||||
metadata:
|
||||
annotations:
|
||||
definition.oam.dev/description: Rollout the component.
|
||||
labels:
|
||||
custom.definition.oam.dev/ui-hidden: "true"
|
||||
name: rollout
|
||||
namespace: {{.Values.systemDefinitionNamespace}}
|
||||
spec:
|
||||
@@ -22,8 +20,13 @@ spec:
|
||||
namespace: context.namespace
|
||||
}
|
||||
spec: {
|
||||
targetRevisionName: parameter.targetRevision
|
||||
componentName: context.name
|
||||
if parameter.targetRevision != _|_ {
|
||||
targetRevisionName: parameter.targetRevision
|
||||
}
|
||||
if parameter.targetRevision == _|_ {
|
||||
targetRevisionName: context.revision
|
||||
}
|
||||
componentName: context.name
|
||||
rolloutPlan: {
|
||||
rolloutStrategy: "IncreaseFirst"
|
||||
if parameter.rolloutBatches != _|_ {
|
||||
@@ -37,8 +40,8 @@ spec:
|
||||
}
|
||||
}
|
||||
parameter: {
|
||||
targetRevision: *context.revision | string
|
||||
targetSize: int
|
||||
targetRevision?: string
|
||||
targetSize: int
|
||||
rolloutBatches?: [...rolloutBatch]
|
||||
batchPartition?: int
|
||||
}
|
||||
|
||||
@@ -5,8 +5,6 @@ kind: TraitDefinition
|
||||
metadata:
|
||||
annotations:
|
||||
definition.oam.dev/description: Rollout the component.
|
||||
labels:
|
||||
custom.definition.oam.dev/ui-hidden: "true"
|
||||
name: rollout
|
||||
namespace: {{.Values.systemDefinitionNamespace}}
|
||||
spec:
|
||||
@@ -22,8 +20,13 @@ spec:
|
||||
namespace: context.namespace
|
||||
}
|
||||
spec: {
|
||||
targetRevisionName: parameter.targetRevision
|
||||
componentName: context.name
|
||||
if parameter.targetRevision != _|_ {
|
||||
targetRevisionName: parameter.targetRevision
|
||||
}
|
||||
if parameter.targetRevision == _|_ {
|
||||
targetRevisionName: context.revision
|
||||
}
|
||||
componentName: context.name
|
||||
rolloutPlan: {
|
||||
rolloutStrategy: "IncreaseFirst"
|
||||
if parameter.rolloutBatches != _|_ {
|
||||
@@ -37,8 +40,8 @@ spec:
|
||||
}
|
||||
}
|
||||
parameter: {
|
||||
targetRevision: *context.revision | string
|
||||
targetSize: int
|
||||
targetRevision?: string
|
||||
targetSize: int
|
||||
rolloutBatches?: [...rolloutBatch]
|
||||
batchPartition?: int
|
||||
}
|
||||
|
||||
@@ -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()
|
||||
|
||||
@@ -1,9 +1,6 @@
|
||||
rollout: {
|
||||
type: "trait"
|
||||
annotations: {}
|
||||
labels: {
|
||||
"ui-hidden": "true"
|
||||
}
|
||||
description: "Rollout the component."
|
||||
attributes: {
|
||||
manageWorkload: true
|
||||
@@ -26,8 +23,13 @@ template: {
|
||||
namespace: context.namespace
|
||||
}
|
||||
spec: {
|
||||
targetRevisionName: parameter.targetRevision
|
||||
componentName: context.name
|
||||
if parameter.targetRevision != _|_ {
|
||||
targetRevisionName: parameter.targetRevision
|
||||
}
|
||||
if parameter.targetRevision == _|_ {
|
||||
targetRevisionName: context.revision
|
||||
}
|
||||
componentName: context.name
|
||||
rolloutPlan: {
|
||||
rolloutStrategy: "IncreaseFirst"
|
||||
if parameter.rolloutBatches != _|_ {
|
||||
@@ -42,8 +44,8 @@ template: {
|
||||
}
|
||||
|
||||
parameter: {
|
||||
targetRevision: *context.revision | string
|
||||
targetSize: int
|
||||
targetRevision?: string
|
||||
targetSize: int
|
||||
rolloutBatches?: [...rolloutBatch]
|
||||
batchPartition?: int
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user