Skip to content

Commit

Permalink
[Feature] [ML] Extension Storage Condition (#1518)
Browse files Browse the repository at this point in the history
  • Loading branch information
ajanikow authored Dec 2, 2023
1 parent 4a8cbca commit 2a25820
Show file tree
Hide file tree
Showing 10 changed files with 246 additions and 14 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
- (Feature) (ML) Storage S3 sidecar implementation
- (Feature) TLS CA Secret Key
- (Refactoring) Extract Resource Helpers
- (Feature) (ML) Extension Storage Condition

## [1.2.35](https://github.com/arangodb/kube-arangodb/tree/1.2.35) (2023-11-06)
- (Maintenance) Update go-driver to v1.6.0, update IsNotFound() checks
Expand Down
8 changes: 8 additions & 0 deletions docs/api/ArangoMLExtension.V1Alpha1.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,14 @@ ArangoPipeDatabase define Database name to be used as MetadataService Backend in

Default Value: `arangopipe`

***

### .spec.storage

Type: `string` <sup>[\[ref\]](https://github.com/arangodb/kube-arangodb/blob/1.2.35/pkg/apis/ml/v1alpha1/extension_spec.go#L31)</sup>

Storage specify the ArangoMLStorage used within Extension

## Status

### .status.conditions
Expand Down
1 change: 1 addition & 0 deletions pkg/apis/ml/v1alpha1/extension_conditions.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ package v1alpha1
import api "github.com/arangodb/kube-arangodb/pkg/apis/deployment/v1"

const (
ExtensionStorageFoundCondition api.ConditionType = "StorageFound"
ExtensionDeploymentFoundCondition api.ConditionType = "DeploymentFound"
ExtensionMetadataServiceValidCondition api.ConditionType = "MetadataServiceValid"
LicenseValidCondition api.ConditionType = "LicenseValid"
Expand Down
12 changes: 12 additions & 0 deletions pkg/apis/ml/v1alpha1/extension_spec.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ type ArangoMLExtensionSpec struct {
// MetadataService keeps the MetadataService configuration
// +doc/immutable: This setting cannot be changed after the MetadataService has been created.
MetadataService *ArangoMLExtensionSpecMetadataService `json:"metadataService,omitempty"`

// Storage specify the ArangoMLStorage used within Extension
Storage *string `json:"storage,omitempty"`
}

func (a *ArangoMLExtensionSpec) GetMetadataService() *ArangoMLExtensionSpecMetadataService {
Expand All @@ -36,8 +39,17 @@ func (a *ArangoMLExtensionSpec) GetMetadataService() *ArangoMLExtensionSpecMetad
return a.MetadataService
}

func (a *ArangoMLExtensionSpec) GetStorage() *string {
if a == nil || a.Storage == nil {
return nil
}

return a.Storage
}

func (a *ArangoMLExtensionSpec) Validate() error {
return shared.WithErrors(shared.PrefixResourceErrors("spec",
shared.PrefixResourceErrors("metadataService", a.GetMetadataService().Validate()),
shared.PrefixResourceErrors("storage", shared.ValidateRequired(a.GetStorage(), shared.ValidateResourceName)),
))
}
5 changes: 5 additions & 0 deletions pkg/apis/ml/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 9 additions & 0 deletions pkg/apis/shared/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,3 +73,12 @@ func ValidateUID(uid types.UID) error {

return nil
}

// ValidateRequired validates if required resource is provided
func ValidateRequired[T any](in *T, validator func(T) error) error {
if in == nil {
return errors.Newf("resource should be not nil")
}

return validator(*in)
}
3 changes: 3 additions & 0 deletions pkg/crd/crds/ml-extension.schema.generated.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ v1alpha1:
type: string
type: object
type: object
storage:
description: Storage specify the ArangoMLStorage used within Extension
type: string
type: object
type: object
x-kubernetes-preserve-unknown-fields: true
37 changes: 37 additions & 0 deletions pkg/operatorV2/handle.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ type HandleP3Func[P1, P2, P3 interface{}] func(ctx context.Context, p1 P1, p2 P2

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

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

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)

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

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) {
isChanged := false
for _, h := range handler {
changed, err := h(ctx, p1, p2, p3, p4, p5)
if changed {
isChanged = true
}

if err != nil {
return isChanged, err
}
}

return isChanged, nil
}

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) {
changed, err := HandleP5[P1, P2, P3, P4, P5](ctx, p1, p2, p3, p4, p5, handler...)
if IsStop(err) {
return changed, nil
}

return changed, err
}

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) {
changed, err := HandleP5[P1, P2, P3, P4, P5](ctx, p1, p2, p3, p4, p5, handler...)
return WithCondition(conditions, condition, changed, err)
}

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) {
isChanged := false
for _, h := range handler {
Expand All @@ -209,3 +241,8 @@ func HandleP9WithStop[P1, P2, P3, P4, P5, P6, P7, P8, P9 interface{}](ctx contex

return changed, err
}

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) {
changed, err := HandleP9[P1, P2, P3, P4, P5, P6, P7, P8, P9](ctx, p1, p2, p3, p4, p5, p6, p7, p8, p9, handler...)
return WithCondition(conditions, condition, changed, err)
}
Loading

0 comments on commit 2a25820

Please sign in to comment.