-
Notifications
You must be signed in to change notification settings - Fork 0
/
convert.go
32 lines (26 loc) · 1017 Bytes
/
convert.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
package common
import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"github.com/argoproj/argo/pkg/apis/workflow"
wfv1 "github.com/argoproj/argo/pkg/apis/workflow/v1alpha1"
)
func ConvertCronWorkflowToWorkflow(cronWf *wfv1.CronWorkflow) (*wfv1.Workflow, error) {
newTypeMeta := metav1.TypeMeta{
Kind: workflow.WorkflowKind,
APIVersion: cronWf.TypeMeta.APIVersion,
}
newObjectMeta := metav1.ObjectMeta{}
newObjectMeta.GenerateName = cronWf.Name + "-"
newObjectMeta.Labels = make(map[string]string)
newObjectMeta.Labels[LabelKeyCronWorkflow] = cronWf.Name
if instanceId, ok := cronWf.GetLabels()[LabelKeyControllerInstanceID]; ok {
newObjectMeta.Labels[LabelKeyControllerInstanceID] = instanceId
}
wf := &wfv1.Workflow{
TypeMeta: newTypeMeta,
ObjectMeta: newObjectMeta,
Spec: cronWf.Spec.WorkflowSpec,
}
wf.SetOwnerReferences(append(wf.GetOwnerReferences(), *metav1.NewControllerRef(cronWf, wfv1.SchemeGroupVersion.WithKind(workflow.CronWorkflowKind))))
return wf, nil
}