Fix: Enhance workflow context generation (#6925)

* Feat: Enhance workflow context generation to include application labels and annotations

Signed-off-by: Chaitanyareddy0702 <chaitanyareddy0702@gmail.com>

* Fix: Add application labels and annotations to workflow context generation

Signed-off-by: Chaitanyareddy0702 <chaitanyareddy0702@gmail.com>

* Fix: add comments

Signed-off-by: Chaitanyareddy0702 <chaitanyareddy0702@gmail.com>

---------

Signed-off-by: Chaitanyareddy0702 <chaitanyareddy0702@gmail.com>
This commit is contained in:
Chaitanyareddy0702
2025-09-29 20:36:51 +05:30
committed by GitHub
parent af1ce628d1
commit 8aabc9f789
3 changed files with 35 additions and 0 deletions

View File

View File

@@ -508,6 +508,7 @@ func getComponentResources(ctx context.Context, manifest *types.ComponentManifes
return workload, traits, nil
}
// generateContextDataFromApp builds the process context for workflow (non-component) execution.
func generateContextDataFromApp(app *v1beta1.Application, appRev string) velaprocess.ContextData {
data := velaprocess.ContextData{
Namespace: app.Namespace,
@@ -519,5 +520,12 @@ func generateContextDataFromApp(app *v1beta1.Application, appRev string) velapro
data.WorkflowName = app.Annotations[oam.AnnotationWorkflowName]
data.PublishVersion = app.Annotations[oam.AnnotationPublishVersion]
}
// pass labels and annotations to workflow context
if len(app.Labels) > 0 {
data.AppLabels = app.Labels
}
if len(app.Annotations) > 0 {
data.AppAnnotations = app.Annotations
}
return data
}

View File

@@ -289,4 +289,31 @@ var _ = Describe("Test Application workflow generator", func() {
_, _, err = handler.GenerateApplicationSteps(logCtx, app, appParser, af)
Expect(err).NotTo(BeNil())
})
It("Test workflow context contains app labels and annotations", func() {
app := &oamcore.Application{
TypeMeta: metav1.TypeMeta{Kind: "Application", APIVersion: "core.oam.dev/v1beta1"},
ObjectMeta: metav1.ObjectMeta{
Name: "app-with-meta",
Namespace: namespaceName,
Labels: map[string]string{"team": "platform", "env": "prod"},
Annotations: map[string]string{"description": "meta test", "owner": "sre"},
},
Spec: oamcore.ApplicationSpec{Components: []common.ApplicationComponent{}},
}
ctxData := generateContextDataFromApp(app, "apprev-with-meta")
Expect(ctxData.AppLabels).To(Equal(app.Labels))
Expect(ctxData.AppAnnotations).To(Equal(app.Annotations))
})
It("Test workflow context empty labels annotations", func() {
app := &oamcore.Application{
TypeMeta: metav1.TypeMeta{Kind: "Application", APIVersion: "core.oam.dev/v1beta1"},
ObjectMeta: metav1.ObjectMeta{Name: "app-without-meta", Namespace: namespaceName},
Spec: oamcore.ApplicationSpec{Components: []common.ApplicationComponent{}},
}
ctxData := generateContextDataFromApp(app, "apprev-without-meta")
Expect(ctxData.AppLabels).To(BeNil())
Expect(ctxData.AppAnnotations).To(BeNil())
})
})