Skip to content

Commit 2a25820

Browse files
authored
[Feature] [ML] Extension Storage Condition (#1518)
1 parent 4a8cbca commit 2a25820

File tree

10 files changed

+246
-14
lines changed

10 files changed

+246
-14
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
- (Feature) (ML) Storage S3 sidecar implementation
2727
- (Feature) TLS CA Secret Key
2828
- (Refactoring) Extract Resource Helpers
29+
- (Feature) (ML) Extension Storage Condition
2930

3031
## [1.2.35](https://github.com/arangodb/kube-arangodb/tree/1.2.35) (2023-11-06)
3132
- (Maintenance) Update go-driver to v1.6.0, update IsNotFound() checks

docs/api/ArangoMLExtension.V1Alpha1.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,14 @@ ArangoPipeDatabase define Database name to be used as MetadataService Backend in
2020

2121
Default Value: `arangopipe`
2222

23+
***
24+
25+
### .spec.storage
26+
27+
Type: `string` <sup>[\[ref\]](https://github.com/arangodb/kube-arangodb/blob/1.2.35/pkg/apis/ml/v1alpha1/extension_spec.go#L31)</sup>
28+
29+
Storage specify the ArangoMLStorage used within Extension
30+
2331
## Status
2432

2533
### .status.conditions

pkg/apis/ml/v1alpha1/extension_conditions.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ package v1alpha1
2323
import api "github.com/arangodb/kube-arangodb/pkg/apis/deployment/v1"
2424

2525
const (
26+
ExtensionStorageFoundCondition api.ConditionType = "StorageFound"
2627
ExtensionDeploymentFoundCondition api.ConditionType = "DeploymentFound"
2728
ExtensionMetadataServiceValidCondition api.ConditionType = "MetadataServiceValid"
2829
LicenseValidCondition api.ConditionType = "LicenseValid"

pkg/apis/ml/v1alpha1/extension_spec.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ type ArangoMLExtensionSpec struct {
2626
// MetadataService keeps the MetadataService configuration
2727
// +doc/immutable: This setting cannot be changed after the MetadataService has been created.
2828
MetadataService *ArangoMLExtensionSpecMetadataService `json:"metadataService,omitempty"`
29+
30+
// Storage specify the ArangoMLStorage used within Extension
31+
Storage *string `json:"storage,omitempty"`
2932
}
3033

3134
func (a *ArangoMLExtensionSpec) GetMetadataService() *ArangoMLExtensionSpecMetadataService {
@@ -36,8 +39,17 @@ func (a *ArangoMLExtensionSpec) GetMetadataService() *ArangoMLExtensionSpecMetad
3639
return a.MetadataService
3740
}
3841

42+
func (a *ArangoMLExtensionSpec) GetStorage() *string {
43+
if a == nil || a.Storage == nil {
44+
return nil
45+
}
46+
47+
return a.Storage
48+
}
49+
3950
func (a *ArangoMLExtensionSpec) Validate() error {
4051
return shared.WithErrors(shared.PrefixResourceErrors("spec",
4152
shared.PrefixResourceErrors("metadataService", a.GetMetadataService().Validate()),
53+
shared.PrefixResourceErrors("storage", shared.ValidateRequired(a.GetStorage(), shared.ValidateResourceName)),
4254
))
4355
}

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

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/apis/shared/validate.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,3 +73,12 @@ func ValidateUID(uid types.UID) error {
7373

7474
return nil
7575
}
76+
77+
// ValidateRequired validates if required resource is provided
78+
func ValidateRequired[T any](in *T, validator func(T) error) error {
79+
if in == nil {
80+
return errors.Newf("resource should be not nil")
81+
}
82+
83+
return validator(*in)
84+
}

pkg/crd/crds/ml-extension.schema.generated.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,9 @@ v1alpha1:
1717
type: string
1818
type: object
1919
type: object
20+
storage:
21+
description: Storage specify the ArangoMLStorage used within Extension
22+
type: string
2023
type: object
2124
type: object
2225
x-kubernetes-preserve-unknown-fields: true

pkg/operatorV2/handle.go

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,8 @@ type HandleP3Func[P1, P2, P3 interface{}] func(ctx context.Context, p1 P1, p2 P2
5757

5858
type HandleP4Func[P1, P2, P3, P4 interface{}] func(ctx context.Context, p1 P1, p2 P2, p3 P3, p4 P4) (bool, error)
5959

60+
type HandleP5Func[P1, P2, P3, P4, P5 interface{}] func(ctx context.Context, p1 P1, p2 P2, p3 P3, p4 P4, p5 P5) (bool, error)
61+
6062
type HandleP9Func[P1, P2, P3, P4, P5, P6, P7, P8, P9 interface{}] func(ctx context.Context, p1 P1, p2 P2, p3 P3, p4 P4, p5 P5, p6 P6, p7 P7, p8 P8, p9 P9) (bool, error)
6163

6264
func HandleP0(ctx context.Context, handler ...HandleP0Func) (bool, error) {
@@ -185,6 +187,36 @@ func HandleP4WithCondition[P1, P2, P3, P4 interface{}](ctx context.Context, cond
185187
return WithCondition(conditions, condition, changed, err)
186188
}
187189

190+
func HandleP5[P1, P2, P3, P4, P5 interface{}](ctx context.Context, p1 P1, p2 P2, p3 P3, p4 P4, p5 P5, handler ...HandleP5Func[P1, P2, P3, P4, P5]) (bool, error) {
191+
isChanged := false
192+
for _, h := range handler {
193+
changed, err := h(ctx, p1, p2, p3, p4, p5)
194+
if changed {
195+
isChanged = true
196+
}
197+
198+
if err != nil {
199+
return isChanged, err
200+
}
201+
}
202+
203+
return isChanged, nil
204+
}
205+
206+
func HandleP5WithStop[P1, P2, P3, P4, P5 interface{}](ctx context.Context, p1 P1, p2 P2, p3 P3, p4 P4, p5 P5, handler ...HandleP5Func[P1, P2, P3, P4, P5]) (bool, error) {
207+
changed, err := HandleP5[P1, P2, P3, P4, P5](ctx, p1, p2, p3, p4, p5, handler...)
208+
if IsStop(err) {
209+
return changed, nil
210+
}
211+
212+
return changed, err
213+
}
214+
215+
func HandleP5WithCondition[P1, P2, P3, P4, P5 interface{}](ctx context.Context, conditions *api.ConditionList, condition api.ConditionType, p1 P1, p2 P2, p3 P3, p4 P4, p5 P5, handler ...HandleP5Func[P1, P2, P3, P4, P5]) (bool, error) {
216+
changed, err := HandleP5[P1, P2, P3, P4, P5](ctx, p1, p2, p3, p4, p5, handler...)
217+
return WithCondition(conditions, condition, changed, err)
218+
}
219+
188220
func HandleP9[P1, P2, P3, P4, P5, P6, P7, P8, P9 interface{}](ctx context.Context, p1 P1, p2 P2, p3 P3, p4 P4, p5 P5, p6 P6, p7 P7, p8 P8, p9 P9, handler ...HandleP9Func[P1, P2, P3, P4, P5, P6, P7, P8, P9]) (bool, error) {
189221
isChanged := false
190222
for _, h := range handler {
@@ -209,3 +241,8 @@ func HandleP9WithStop[P1, P2, P3, P4, P5, P6, P7, P8, P9 interface{}](ctx contex
209241

210242
return changed, err
211243
}
244+
245+
func HandleP9WithCondition[P1, P2, P3, P4, P5, P6, P7, P8, P9 interface{}](ctx context.Context, conditions *api.ConditionList, condition api.ConditionType, p1 P1, p2 P2, p3 P3, p4 P4, p5 P5, p6 P6, p7 P7, p8 P8, p9 P9, handler ...HandleP9Func[P1, P2, P3, P4, P5, P6, P7, P8, P9]) (bool, error) {
246+
changed, err := HandleP9[P1, P2, P3, P4, P5, P6, P7, P8, P9](ctx, p1, p2, p3, p4, p5, p6, p7, p8, p9, handler...)
247+
return WithCondition(conditions, condition, changed, err)
248+
}

0 commit comments

Comments
 (0)