8000 MLCronJob embedded fields (#1520) · arangodb/kube-arangodb@d74e1db · GitHub
[go: up one dir, main page]

Skip to content

Commit d74e1db

Browse files
MLCronJob embedded fields (#1520)
Co-authored-by: Nikita Vaniasin <nikita.vanyasin@gmail.com>
1 parent 2b063dc commit d74e1db

File tree

7 files changed

+2966
-7
lines changed

7 files changed

+2966
-7
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -797,7 +797,7 @@ check-community:
797797
_check: sync-crds
798798
@$(MAKE) fmt yamlfmt license-verify linter run-unit-tests bin vulncheck-optional
799799

800-
generate: generate-internal generate-proto fmt
800+
generate: generate-internal generate-proto fmt yamlfmt
801801

802802
generate-internal:
803803
ROOT=$(ROOT) go test --count=1 "$(REPOPATH)/internal/..."

docs/api/ArangoMLCronJob.V1Alpha1.md

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,27 @@
22

33
## Spec
44

5+
### .spec
6+
7+
Type: `batch.CronJobSpec` <sup>[\[ref\]](https://github.com/arangodb/kube-arangodb/blob/1.2.35/pkg/apis/ml/v1alpha1/cronjob_spec.go#L32)</sup>
8+
9+
Links:
10+
* [Kubernetes Documentation](https://godoc.org/k8s.io/api/batch/v1beta1#CronJobSpec)
11+
512
## Status
613

14+
### .status
15+
16+
Type: `batch.CronJobStatus` <sup>[\[ref\]](https://github.com/arangodb/kube-arangodb/blob/1.2.35/pkg/apis/ml/v1alpha1/cronjob_status.go#L36)</sup>
17+
18+
Links:
19+
* [Kubernetes Documentation](https://godoc.org/k8s.io/api/batch/v1beta1#CronJobStatus)
20+
21+
***
22+
723
### .status.conditions
824

9-
Type: `api.Conditions` <sup>[\[ref\]](https://github.com/arangodb/kube-arangodb/blob/1.2.35/pkg/apis/ml/v1alpha1/cronjob_status.go#L28)</sup>
25+
Type: `api.Conditions` <sup>[\[ref\]](https://github.com/arangodb/kube-arangodb/blob/1.2.35/pkg/apis/ml/v1alpha1/cronjob_status.go#L32)</sup>
1026

1127
Conditions specific to the entire cron job
1228

internal/docs_parser_test.go

Lines changed: 39 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -184,6 +184,20 @@ func iterateOverObjectDirect(t *testing.T, fields map[string]*ast.Field, name st
184184
}
185185
}
186186

187+
// inline and anonymous field (embedded)
188+
if inline && n == "" {
189+
if doc != nil {
190+
if t, ok := extractType(doc); ok {
191+
info := typeInfo{
192+
path: fmt.Sprintf("%s.%s", path, name),
193+
typ: t[0],
194+
}
195+
r[info] = doc
196+
continue
197+
}
198+
}
199+
}
200+
187201
if inline {
188202
for k, v := range iterateOverObjectDirect(t, fields, name, f.Type, path) {
189203
if v == nil {
@@ -301,9 +315,32 @@ func parseSourceFiles(t *testing.T, root string, fset *token.FileSet, path strin
301315
if nt != nil {
302316
require.NotEmpty(t, nt.Name)
303317

304- for _, name := range x.Names {
305-
r[fmt.Sprintf("%s.%s.%s", k, nt.Name, name)] = x
318+
if len(x.Names) > 0 {
319+
for _, name := range x.Names {
320+
r[fmt.Sprintf("%s.%s.%s", k, nt.Name, name)] = x
321+
}
322+
} else {
323+
// If x.Names is empty, it's an anonymous field
324+
if len(x.Names) == 0 {
325+
// first check if it's a pointer to a struct
326+
typeName, ok := x.Type.(*ast.StarExpr)
327+
if ok {
328+
ident, ok := typeName.X.(*ast.SelectorExpr)
329+
if ok {
330+
fieldName := ident.Sel.Name
331+
r[fmt.Sprintf("%s.%s.%s", k, nt.Name, fieldName)] = x
332+
}
333+
} else {
334+
// if it's not a pointer
335+
ident, ok := x.Type.(*ast.SelectorExpr)
336+
if ok {
337+
fieldName := ident.Sel.Name
338+
r[fmt.Sprintf("%s.%s.%s", k, nt.Name, fieldName)] = x
339+
}
340+
}
341+
}
306342
}
343+
307344
}
308345
}
309346

pkg/apis/ml/v1alpha1/cronjob_spec.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,16 @@
2020

2121
package v1alpha1
2222

23-
import "github.com/arangodb/kube-arangodb/pkg/apis/shared"
23+
import (
24+
batchApi "k8s.io/api/batch/v1beta1"
25+
26+
"github.com/arangodb/kube-arangodb/pkg/apis/shared"
27+
)
2428

2529
type ArangoMLCronJobSpec struct {
30+
// +doc/type: batch.CronJobSpec
31+
// +doc/link: Kubernetes Documentation|https://godoc.org/k8s.io/api/batch/v1beta1#CronJobSpec
32+
*batchApi.CronJobSpec `json:",inline"`
2633
}
2734

2835
func (a *ArangoMLCronJobSpec) Validate() error {

pkg/apis/ml/v1alpha1/cronjob_status.go

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,18 @@
2020

2121
package v1alpha1
2222

23-
import api "github.com/arangodb/kube-arangodb/pkg/apis/deployment/v1"
23+
import (
24+
batchApi "k8s.io/api/batch/v1beta1"
25+
26+
api "github.com/arangodb/kube-arangodb/pkg/apis/deployment/v1"
27+
)
2428

2529
type ArangoMLCronJobStatus struct {
2630
// Conditions specific to the entire cron job
2731
// +doc/type: api.Conditions
2832
Conditions api.ConditionList `json:"conditions,omitempty"`
33+
34+
// +doc/type: batch.CronJobStatus
35+
// +doc/link: Kubernetes Documentation|https://godoc.org/k8s.io/api/batch/v1beta1#CronJobStatus
36+
batchApi.CronJobStatus `json:",inline"`
2937
}

pkg/apis/ml/v1alpha1/zz_generated.deepcopy.go

Lines changed: 8 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)
0