@@ -39,40 +39,49 @@ describe('workflow-helper', () => {
39
39
describe ( 'composePodLogsStreamHandler' , ( ) => {
40
40
it ( 'returns the stream from the default handler if there is no errors.' , async ( ) => {
41
41
const defaultStream = new PassThrough ( ) ;
42
- const defaultHandler = jest . fn ( ( _podName : string , _namespace ?: string ) =>
42
+ const defaultHandler = jest . fn ( ( _podName : string , _createdAt : string , _namespace ?: string ) =>
43
43
Promise . resolve ( defaultStream ) ,
44
44
) ;
45
- const stream = await composePodLogsStreamHandler ( defaultHandler ) ( 'podName' , 'namespace' ) ;
46
- expect ( defaultHandler ) . toBeCalledWith ( 'podName' , 'namespace' ) ;
45
+ const stream = await composePodLogsStreamHandler ( defaultHandler ) (
46
+ 'podName' ,
47
+ '2024-08-13' ,
48
+ 'namespace' ,
49
+ ) ;
50
+ expect ( defaultHandler ) . toBeCalledWith ( 'podName' , '2024-08-13' , 'namespace' ) ;
47
51
expect ( stream ) . toBe ( defaultStream ) ;
48
52
} ) ;
49
53
50
54
it ( 'returns the stream from the fallback handler if there is any error.' , async ( ) => {
51
55
const fallbackStream = new PassThrough ( ) ;
52
- const defaultHandler = jest . fn ( ( _podName : string , _namespace ?: string ) =>
56
+ const defaultHandler = jest . fn ( ( _podName : string , _createdAt : string , _namespace ?: string ) =>
53
57
Promise . reject ( 'unknown error' ) ,
54
58
) ;
55
- const fallbackHandler = jest . fn ( ( _podName : string , _namespace ?: string ) =>
59
+ const fallbackHandler = jest . fn ( ( _podName : string , _createdAt : string , _namespace ?: string ) =>
56
60
Promise . resolve ( fallbackStream ) ,
57
61
) ;
58
62
const stream = await composePodLogsStreamHandler ( defaultHandler , fallbackHandler ) (
59
63
'podName' ,
64
+ '2024-08-13' ,
60
65
'namespace' ,
61
66
) ;
62
- expect ( defaultHandler ) . toBeCalledWith ( 'podName' , 'namespace' ) ;
63
- expect ( fallbackHandler ) . toBeCalledWith ( 'podName' , 'namespace' ) ;
67
+ expect ( defaultHandler ) . toBeCalledWith ( 'podName' , '2024-08-13' , ' namespace') ;
68
+ expect ( fallbackHandler ) . toBeCalledWith ( 'podName' , '2024-08-13' , ' namespace') ;
64
69
expect ( stream ) . toBe ( fallbackStream ) ;
65
70
} ) ;
66
71
67
72
it ( 'throws error if both handler and fallback fails.' , async ( ) => {
68
- const defaultHandler = jest . fn ( ( _podName : string , _namespace ?: string ) =>
73
+ const defaultHandler = jest . fn ( ( _podName : string , _createdAt : string , _namespace ?: string ) =>
69
74
Promise . reject ( 'unknown error for default' ) ,
70
75
) ;
71
- const fallbackHandler = jest . fn ( ( _podName : string , _namespace ?: string ) =>
76
+ const fallbackHandler = jest . fn ( ( _podName : string , _createdAt : string , _namespace ?: string ) =>
72
77
Promise . reject ( 'unknown error for fallback' ) ,
73
78
) ;
74
79
await expect (
75
- composePodLogsStreamHandler ( defaultHandler , fallbackHandler ) ( 'podName' , 'namespace' ) ,
80
+ composePodLogsStreamHandler ( defaultHandler , fallbackHandler ) (
81
+ 'podName' ,
82
+ '2024-08-13' ,
83
+ 'namespace' ,
84
+ ) ,
76
85
) . rejects . toEqual ( 'unknown error for fallback' ) ;
77
86
} ) ;
78
87
} ) ;
@@ -82,7 +91,7 @@ describe('workflow-helper', () => {
82
91
const mockedGetPodLogs : jest . Mock = getPodLogs as any ;
83
92
mockedGetPodLogs . mockResolvedValueOnce ( 'pod logs' ) ;
84
93
85
- const stream = await getPodLogsStreamFromK8s ( 'podName' , 'namespace' ) ;
94
+ const stream = await getPodLogsStreamFromK8s ( 'podName' , '' , ' namespace') ;
86
95
expect ( mockedGetPodLogs ) . toBeCalledWith ( 'podName' , 'namespace' , 'main' ) ;
87
96
expect ( stream . read ( ) . toString ( ) ) . toBe ( 'pod logs' ) ;
88
97
} ) ;
@@ -101,24 +110,34 @@ describe('workflow-helper', () => {
101
110
client,
102
111
key : 'folder/key' ,
103
112
} ;
104
- const createRequest = jest . fn ( ( _podName : string , _namespace ?: string ) =>
113
+ const createRequest = jest . fn ( ( _podName : string , _createdAt : string , _namespace ?: string ) =>
105
114
Promise . resolve ( configs ) ,
106
115
) ;
107
- const stream = await toGetPodLogsStream ( createRequest ) ( 'podName' , 'namespace' ) ;
116
+ const stream = await toGetPodLogsStream ( createRequest ) ( 'podName' , '2024-08-13' , ' namespace') ;
108
117
expect ( mockedClientGetObject ) . toBeCalledWith ( 'bucket' , 'folder/key' ) ;
109
118
} ) ;
110
119
} ) ;
111
120
112
121
describe ( 'createPodLogsMinioRequestConfig' , ( ) => {
113
122
it ( 'returns a MinioRequestConfig factory with the provided minioClientOptions, bucket, and prefix.' , async ( ) => {
114
123
const mockedClient : jest . Mock = MinioClient as any ;
115
- const requestFunc = await createPodLogsMinioRequestConfig ( minioConfig , 'bucket' , 'prefix' ) ;
116
- const request = await requestFunc ( 'workflow-name-abc' , 'namespace' ) ;
124
+ const requestFunc = await createPodLogsMinioRequestConfig (
125
+ minioConfig ,
126
+ 'bucket' ,
127
+ 'artifacts/{{workflow.name}}/{{workflow.creationTimestamp.Y}}/{{workflow.creationTimestamp.m}}/{{workflow.creationTimestamp.d}}/{{pod.name}}' ,
128
+ ) ;
129
+ const request = await requestFunc (
130
+ 'workflow-name-system-container-impl-foo' ,
131
+ '2024-08-13' ,
132
+ 'namespace' ,
133
+ ) ;
117
134
118
135
expect ( mockedClient ) . toBeCalledWith ( minioConfig ) ;
119
136
expect ( request . client ) . toBeInstanceOf ( MinioClient ) ;
120
137
expect ( request . bucket ) . toBe ( 'bucket' ) ;
121
- expect ( request . key ) . toBe ( 'prefix/workflow-name/workflow-name-abc/main.log' ) ;
138
+ expect ( request . key ) . toBe (
139
+ 'artifacts/workflow-name/2024/08/13/workflow-name-system-container-impl-foo/main.log' ,
140
+ ) ;
122
141
} ) ;
123
142
} ) ;
124
143
@@ -128,31 +147,28 @@ describe('workflow-helper', () => {
128
147
apiVersion : 'argoproj.io/v1alpha1' ,
129
148
kind : 'Workflow' ,
130
149
status : {
150
+ artifactRepositoryRef : {
151
+ artifactRepository : {
152
+ archiveLogs : true ,
153
+ s3 : {
154
+ accessKeySecret : { key : 'accessKey' , name : 'accessKeyName' } ,
155
+ bucket : 'bucket' ,
156
+ endpoint : 'minio-service.kubeflow' ,
157
+ insecure : true ,
158
+ key :
159
+ 'prefix/workflow-name/workflow-name-system-container-impl-abc/some-artifact.csv' ,
160
+ secretKeySecret : { key : 'secretKey' , name : 'secretKeyName' } ,
161
+ } ,
162
+ } ,
163
+ } ,
131
164
nodes : {
132
165
'workflow-name-abc' : {
133
166
outputs : {
134
167
artifacts : [
135
168
{
136
- name : 'some-artifact.csv' ,
137
- s3 : {
138
- accessKeySecret : { key : 'accessKey' , name : 'accessKeyName' } ,
139
- bucket : 'bucket' ,
140
- endpoint : 'minio-service.kubeflow' ,
141
- insecure : true ,
142
- key : 'prefix/workflow-name/workflow-name-abc/some-artifact.csv' ,
143
- secretKeySecret : { key : 'secretKey' , name : 'secretKeyName' } ,
144
- } ,
145
- } ,
146
- {
147
- archiveLogs : true ,
148
- name : 'main.log' ,
169
+ name : 'main-logs' ,
149
170
s3 : {
150
- accessKeySecret : { key : 'accessKey' , name : 'accessKeyName' } ,
151
- bucket : 'bucket' ,
152
- endpoint : 'minio-service.kubeflow' ,
153
- insecure : true ,
154
- key : 'prefix/workflow-name/workflow-name-abc/main.log' ,
155
- secretKeySecret : { key : 'secretKey' , name : 'secretKeyName' } ,
171
+ key : 'prefix/workflow-name/workflow-name-system-container-impl-abc/main.log' ,
156
172
} ,
157
173
} ,
158
174
] ,
@@ -174,7 +190,10 @@ describe('workflow-helper', () => {
174
190
mockedClientGetObject . mockResolvedValueOnce ( objStream ) ;
175
191
objStream . end ( 'some fake logs.' ) ;
176
192
177
- const stream = await getPodLogsStreamFromWorkflow ( 'workflow-name-abc' ) ;
193
+ const stream = await getPodLogsStreamFromWorkflow (
194
+ 'workflow-name-system-container-impl-abc' ,
195
+ '2024-07-09' ,
196
+ ) ;
178
197
179
198
expect ( mockedGetArgoWorkflow ) . toBeCalledWith ( 'workflow-name' ) ;
180
199
@@ -193,7 +212,7 @@ describe('workflow-helper', () => {
193
212
expect ( mockedClientGetObject ) . toBeCalledTimes ( 1 ) ;
194
213
expect ( mockedClientGetObject ) . toBeCalledWith (
195
214
'bucket' ,
196
- 'prefix/workflow-name/workflow-name-abc/main.log' ,
215
+ 'prefix/workflow-name/workflow-name-system-container-impl- abc/main.log' ,
197
216
) ;
198
217
} ) ;
199
218
} ) ;
0 commit comments