Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(server): consistent actor email label. Fixes #14121 #14122

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -147,10 +147,12 @@ func init() {
}`, &cwftObj3)
}

const userEmailLabel = "my-sub.at.your.org"

func getClusterWorkflowTemplateServer() (clusterwftmplpkg.ClusterWorkflowTemplateServiceServer, context.Context) {
kubeClientSet := fake.NewSimpleClientset()
wfClientset := wftFake.NewSimpleClientset(&unlabelled, &cwftObj2, &cwftObj3)
ctx := context.WithValue(context.WithValue(context.WithValue(context.TODO(), auth.WfKey, wfClientset), auth.KubeKey, kubeClientSet), auth.ClaimsKey, &types.Claims{Claims: jwt.Claims{Subject: "my-sub"}})
ctx := context.WithValue(context.WithValue(context.WithValue(context.TODO(), auth.WfKey, wfClientset), auth.KubeKey, kubeClientSet), auth.ClaimsKey, &types.Claims{Claims: jwt.Claims{Subject: "my-sub"}, Email: "[email protected]"})
return NewClusterWorkflowTemplateServer(instanceid.NewService("my-instanceid"), nil, nil), ctx
}

Expand Down Expand Up @@ -180,6 +182,7 @@ func TestWorkflowTemplateServer_CreateClusterWorkflowTemplate(t *testing.T) {
// ensure the label is added
assert.Contains(t, cwftRsp.Labels, common.LabelKeyControllerInstanceID)
assert.Contains(t, cwftRsp.Labels, common.LabelKeyCreator)
assert.Equal(t, userEmailLabel, cwftRsp.Labels[common.LabelKeyCreatorEmail])
})
}

Expand Down Expand Up @@ -239,6 +242,7 @@ func TestWorkflowTemplateServer_LintClusterWorkflowTemplate(t *testing.T) {
require.NoError(t, err)
assert.Contains(t, resp.Labels, common.LabelKeyControllerInstanceID)
assert.Contains(t, resp.Labels, common.LabelKeyCreator)
assert.Equal(t, userEmailLabel, resp.Labels[common.LabelKeyCreatorEmail])
})

t.Run("Without param values", func(t *testing.T) {
Expand Down Expand Up @@ -266,6 +270,7 @@ func TestWorkflowTemplateServer_UpdateClusterWorkflowTemplate(t *testing.T) {
require.NoError(t, err)
assert.Contains(t, cwftRsp.Labels, common.LabelKeyActor)
assert.Equal(t, string(creator.ActionUpdate), cwftRsp.Labels[common.LabelKeyAction])
assert.Equal(t, userEmailLabel, cwftRsp.Labels[common.LabelKeyActorEmail])
assert.Equal(t, "alpine:latest", cwftRsp.Spec.Templates[0].Container.Image)
})
t.Run("Unlabelled", func(t *testing.T) {
Expand Down
5 changes: 4 additions & 1 deletion server/cronworkflow/cron_workflow_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,8 @@ metadata:
wftmplStore := workflowtemplate.NewWorkflowTemplateClientStore()
cwftmplStore := clusterworkflowtemplate.NewClusterWorkflowTemplateClientStore()
server := NewCronWorkflowServer(instanceid.NewService("my-instanceid"), wftmplStore, cwftmplStore, nil)
ctx := context.WithValue(context.WithValue(context.TODO(), auth.WfKey, wfClientset), auth.ClaimsKey, &types.Claims{Claims: jwt.Claims{Subject: "my-sub"}})
ctx := context.WithValue(context.WithValue(context.TODO(), auth.WfKey, wfClientset), auth.ClaimsKey, &types.Claims{Claims: jwt.Claims{Subject: "my-sub"}, Email: "[email protected]"})
userEmailLabel := "my-sub.at.your.org"

t.Run("CreateCronWorkflow", func(t *testing.T) {
created, err := server.CreateCronWorkflow(ctx, &cronworkflowpkg.CreateCronWorkflowRequest{
Expand All @@ -79,6 +80,7 @@ metadata:
assert.NotNil(t, wf)
assert.Contains(t, wf.Labels, common.LabelKeyControllerInstanceID)
assert.Contains(t, wf.Labels, common.LabelKeyCreator)
assert.Equal(t, userEmailLabel, wf.Labels[common.LabelKeyCreatorEmail])
})
t.Run("ListCronWorkflows", func(t *testing.T) {
cronWfs, err := server.ListCronWorkflows(ctx, &cronworkflowpkg.ListCronWorkflowsRequest{Namespace: "my-ns"})
Expand Down Expand Up @@ -107,6 +109,7 @@ metadata:
cronWf, err := server.UpdateCronWorkflow(ctx, &cronworkflowpkg.UpdateCronWorkflowRequest{Namespace: "my-ns", CronWorkflow: &cronWf})
assert.Contains(t, cronWf.Labels, common.LabelKeyActor)
assert.Equal(t, string(creator.ActionUpdate), cronWf.Labels[common.LabelKeyAction])
assert.Equal(t, userEmailLabel, cronWf.Labels[common.LabelKeyActorEmail])
require.NoError(t, err)
assert.NotNil(t, cronWf)
})
Expand Down
12 changes: 11 additions & 1 deletion server/workflow/workflow_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -572,6 +572,8 @@ const clusterworkflowtmpl = `
}
`

const userEmailLabel = "my-sub.at.your.org"

func getWorkflowServer() (workflowpkg.WorkflowServiceServer, context.Context) {
var unlabelledObj, wfObj1, wfObj2, wfObj3, wfObj4, wfObj5, failedWfObj v1alpha1.Workflow
var wftmpl v1alpha1.WorkflowTemplate
Expand Down Expand Up @@ -625,7 +627,7 @@ func getWorkflowServer() (workflowpkg.WorkflowServiceServer, context.Context) {
})
wfClientset := v1alpha.NewSimpleClientset(&unlabelledObj, &wfObj1, &wfObj2, &wfObj3, &wfObj4, &wfObj5, &failedWfObj, &wftmpl, &cronwfObj, &cwfTmpl)
wfClientset.PrependReactor("create", "workflows", generateNameReactor)
ctx := context.WithValue(context.WithValue(context.WithValue(context.TODO(), auth.WfKey, wfClientset), auth.KubeKey, kubeClientSet), auth.ClaimsKey, &types.Claims{Claims: jwt.Claims{Subject: "my-sub"}})
ctx := context.WithValue(context.WithValue(context.WithValue(context.TODO(), auth.WfKey, wfClientset), auth.KubeKey, kubeClientSet), auth.ClaimsKey, &types.Claims{Claims: jwt.Claims{Subject: "my-sub"}, Email: "[email protected]"})
listOptions := &metav1.ListOptions{}
instanceIdSvc := instanceid.NewService("my-instanceid")
instanceIdSvc.With(listOptions)
Expand Down Expand Up @@ -676,6 +678,7 @@ func TestCreateWorkflow(t *testing.T) {
assert.NotNil(t, wf)
assert.Contains(t, wf.Labels, common.LabelKeyControllerInstanceID)
assert.Contains(t, wf.Labels, common.LabelKeyCreator)
assert.Equal(t, userEmailLabel, wf.Labels[common.LabelKeyCreatorEmail])
}

type testWatchWorkflowServer struct {
Expand Down Expand Up @@ -814,11 +817,13 @@ func TestSuspendResumeWorkflow(t *testing.T) {
assert.True(t, *wf.Spec.Suspend)
assert.Contains(t, wf.Labels, common.LabelKeyActor)
assert.Equal(t, string(creator.ActionSuspend), wf.Labels[common.LabelKeyAction])
assert.Equal(t, userEmailLabel, wf.Labels[common.LabelKeyActorEmail])
wf, err = server.ResumeWorkflow(ctx, &workflowpkg.WorkflowResumeRequest{Name: wf.Name, Namespace: wf.Namespace})
require.NoError(t, err)
assert.NotNil(t, wf)
assert.Contains(t, wf.Labels, common.LabelKeyActor)
assert.Equal(t, string(creator.ActionResume), wf.Labels[common.LabelKeyAction])
assert.Equal(t, userEmailLabel, wf.Labels[common.LabelKeyActorEmail])
assert.Nil(t, wf.Spec.Suspend)
}

Expand Down Expand Up @@ -855,6 +860,7 @@ func TestTerminateWorkflow(t *testing.T) {
assert.Equal(t, v1alpha1.ShutdownStrategyTerminate, wf.Spec.Shutdown)
assert.Contains(t, wf.Labels, common.LabelKeyActor)
assert.Equal(t, string(creator.ActionTerminate), wf.Labels[common.LabelKeyAction])
assert.Equal(t, userEmailLabel, wf.Labels[common.LabelKeyActorEmail])
require.NoError(t, err)

rsmWfReq = workflowpkg.WorkflowTerminateRequest{
Expand All @@ -877,6 +883,7 @@ func TestStopWorkflow(t *testing.T) {
assert.Equal(t, v1alpha1.WorkflowRunning, wf.Status.Phase)
assert.Contains(t, wf.Labels, common.LabelKeyActor)
assert.Equal(t, string(creator.ActionStop), wf.Labels[common.LabelKeyAction])
assert.Equal(t, userEmailLabel, wf.Labels[common.LabelKeyActorEmail])
}

func TestResubmitWorkflow(t *testing.T) {
Expand Down Expand Up @@ -956,6 +963,7 @@ func TestSubmitWorkflowFromResource(t *testing.T) {
assert.NotNil(t, wf)
assert.Contains(t, wf.Labels, common.LabelKeyControllerInstanceID)
assert.Contains(t, wf.Labels, common.LabelKeyCreator)
assert.Equal(t, userEmailLabel, wf.Labels[common.LabelKeyCreatorEmail])
})
t.Run("SubmitFromCronWorkflow", func(t *testing.T) {
wf, err := server.SubmitWorkflow(ctx, &workflowpkg.WorkflowSubmitRequest{
Expand All @@ -967,6 +975,7 @@ func TestSubmitWorkflowFromResource(t *testing.T) {
assert.NotNil(t, wf)
assert.Contains(t, wf.Labels, common.LabelKeyControllerInstanceID)
assert.Contains(t, wf.Labels, common.LabelKeyCreator)
assert.Equal(t, userEmailLabel, wf.Labels[common.LabelKeyCreatorEmail])
})
t.Run("SubmitFromClusterWorkflowTemplate", func(t *testing.T) {
wf, err := server.SubmitWorkflow(ctx, &workflowpkg.WorkflowSubmitRequest{
Expand All @@ -978,5 +987,6 @@ func TestSubmitWorkflowFromResource(t *testing.T) {
assert.NotNil(t, wf)
assert.Contains(t, wf.Labels, common.LabelKeyControllerInstanceID)
assert.Contains(t, wf.Labels, common.LabelKeyCreator)
assert.Equal(t, userEmailLabel, wf.Labels[common.LabelKeyCreatorEmail])
})
}
6 changes: 5 additions & 1 deletion server/workflowtemplate/workflow_template_server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,14 +163,16 @@ const wftStr3 = `{
}
}`

const userEmailLabel = "my-sub.at.your.org"

func getWorkflowTemplateServer() (workflowtemplatepkg.WorkflowTemplateServiceServer, context.Context) {
var unlabelledObj, wftObj1, wftObj2 v1alpha1.WorkflowTemplate
v1alpha1.MustUnmarshal(unlabelled, &unlabelledObj)
v1alpha1.MustUnmarshal(wftStr2, &wftObj1)
v1alpha1.MustUnmarshal(wftStr3, &wftObj2)
kubeClientSet := fake.NewSimpleClientset()
wfClientset := wftFake.NewSimpleClientset(&unlabelledObj, &wftObj1, &wftObj2)
ctx := context.WithValue(context.WithValue(context.WithValue(context.TODO(), auth.WfKey, wfClientset), auth.KubeKey, kubeClientSet), auth.ClaimsKey, &types.Claims{Claims: jwt.Claims{Subject: "my-sub"}})
ctx := context.WithValue(context.WithValue(context.WithValue(context.TODO(), auth.WfKey, wfClientset), auth.KubeKey, kubeClientSet), auth.ClaimsKey, &types.Claims{Claims: jwt.Claims{Subject: "my-sub"}, Email: "[email protected]"})
wftmplStore := NewWorkflowTemplateClientStore()
cwftmplStore := clusterworkflowtemplate.NewClusterWorkflowTemplateClientStore()
return NewWorkflowTemplateServer(instanceid.NewService("my-instanceid"), wftmplStore, cwftmplStore), ctx
Expand Down Expand Up @@ -206,6 +208,7 @@ func TestWorkflowTemplateServer_CreateWorkflowTemplate(t *testing.T) {
assert.NotNil(t, wftRsp)
assert.Contains(t, wftRsp.Labels, common.LabelKeyControllerInstanceID)
assert.Contains(t, wftRsp.Labels, common.LabelKeyCreator)
assert.Equal(t, userEmailLabel, wftRsp.Labels[common.LabelKeyCreatorEmail])
})
}

Expand Down Expand Up @@ -269,6 +272,7 @@ func TestWorkflowTemplateServer_UpdateWorkflowTemplate(t *testing.T) {
require.NoError(t, err)
assert.Contains(t, wftRsp.Labels, common.LabelKeyActor)
assert.Equal(t, string(creator.ActionUpdate), wftRsp.Labels[common.LabelKeyAction])
assert.Equal(t, userEmailLabel, wftRsp.Labels[common.LabelKeyActorEmail])
assert.Equal(t, "alpine:latest", wftRsp.Spec.Templates[0].Container.Image)
})
t.Run("Unlabelled", func(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion workflow/creator/creator.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ func UserActionLabel(ctx context.Context, action ActionType) map[string]string {
res[common.LabelKeyActor] = dnsFriendly(claims.Subject)
}
if claims.Email != "" {
res[common.LabelKeyActorEmail] = dnsFriendly(claims.Email)
res[common.LabelKeyActorEmail] = dnsFriendly(strings.Replace(claims.Email, "@", ".at.", 1))
}
if claims.PreferredUsername != "" {
res[common.LabelKeyActorPreferredUsername] = dnsFriendly(claims.PreferredUsername)
Expand Down