@@ -23,7 +23,9 @@ limitations under the License.
23
23
package cronjob
24
24
25
25
import (
26
+ "encoding/json"
26
27
"fmt"
28
+ "net/url"
27
29
28
30
batchv1beta1 "k8s.io/api/batch/v1beta1"
29
31
corev1 "k8s.io/api/core/v1"
@@ -190,6 +192,84 @@ func (t *TotallyABool) UnmarshalJSON(in []byte) error {
190
192
return nil
191
193
}
192
194
195
+ // +kubebuilder:validation:Type=string
196
+ // URL wraps url.URL.
197
+ // It has custom json marshal methods that enable it to be used in K8s CRDs
198
+ // such that the CRD resource will have the URL but operator code can can work with url.URL struct
199
+ type URL struct {
200
+ url.URL
201
+ }
202
+
203
+ func (u * URL ) MarshalJSON () ([]byte , error ) {
204
+ return []byte (fmt .Sprintf ("%q" , u .String ())), nil
205
+ }
206
+
207
+ func (u * URL ) UnmarshalJSON (b []byte ) error {
208
+ var ref string
209
+ if err := json .Unmarshal (b , & ref ); err != nil {
210
+ return err
211
+ }
212
+ if ref == "" {
213
+ * u = URL {}
214
+ return nil
215
+ }
216
+
217
+ r , err := url .Parse (ref )
218
+ if err != nil {
219
+ return err
220
+ } else if r != nil {
221
+ * u = URL {* r }
222
+ } else {
223
+ * u = URL {}
224
+ }
225
+ return nil
226
+ }
227
+
228
+ func (u * URL ) String () string {
229
+ if u == nil {
230
+ return ""
231
+ }
232
+ return u .URL .String ()
233
+ }
234
+
235
+ // +kubebuilder:validation:Type=string
236
+ // URL2 is an alias of url.URL.
237
+ // It has custom json marshal methods that enable it to be used in K8s CRDs
238
+ // such that the CRD resource will have the URL but operator code can can work with url.URL struct
239
+ type URL2 url.URL
240
+
241
+ func (u * URL2 ) MarshalJSON () ([]byte , error ) {
242
+ return []byte (fmt .Sprintf ("%q" , u .String ())), nil
243
+ }
244
+
245
+ func (u * URL2 ) UnmarshalJSON (b []byte ) error {
246
+ var ref string
247
+ if err := json .Unmarshal (b , & ref ); err != nil {
248
+ return err
249
+ }
250
+ if ref == "" {
251
+ * u = URL2 {}
252
+ return nil
253
+ }
254
+
255
+ r , err := url .Parse (ref )
256
+ if err != nil {
257
+ return err
258
+ } else if r != nil {
259
+ * u = * (* URL2 )(r )
260
+ } else {
261
+ * u = URL2 {}
262
+ }
263
+ return nil
264
+ }
265
+
266
+ func (u * URL2 ) String () string {
267
+ if u == nil {
268
+ return ""
269
+ }
270
+ return (* url .URL )(u ).String ()
271
+ }
272
+
193
273
// ConcurrencyPolicy describes how the job will be handled.
194
274
// Only one of the following concurrent policies may be specified.
195
275
// If none of the following policies is specified, the default one
@@ -226,6 +306,14 @@ type CronJobStatus struct {
226
306
// with microsecond precision.
227
307
// +optional
228
308
LastScheduleMicroTime * metav1.MicroTime `json:"lastScheduleMicroTime,omitempty"`
309
+
310
+ // LastActiveLogURL specifies the logging url for the last started job
311
+ // +optional
312
+ LastActiveLogURL * URL `json:"lastActiveLogURL,omitempty"`
313
+
314
+ // LastActiveLogURL2 specifies the logging url for the last started job
315
+ // +optional
316
+ LastActiveLogURL2 * URL2 `json:"lastActiveLogURL2,omitempty"`
229
317
}
230
318
231
319
// +kubebuilder:object:root=true
0 commit comments