Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Feature] [ML] Extension STS update propagation #1548

Merged
merged 6 commits into from
Dec 22, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions docs/api/ArangoMLExtension.V1Alpha1.md
Original file line number Diff line number Diff line change
Expand Up @@ -1427,6 +1427,18 @@ UID keeps the information about object UID

***

### .status.reconciliation.serviceChecksum

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

***

### .status.reconciliation.statefulSetChecksum

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

***

### .status.serviceAccount.cluster.binding.name

Type: `string` <sup>[\[ref\]](https://github.com/arangodb/kube-arangodb/blob/1.2.35/pkg/apis/shared/v1/object.go#L46)</sup>
Expand Down
6 changes: 3 additions & 3 deletions pkg/apis/deployment/v1/plan.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,9 @@ type Action struct {
MemberID string `json:"memberID,omitempty"`
// Group involved in this action
Group ServerGroup `json:"group,omitempty"`
// CreationTime is set the when the action is created.
// CreationTime is set when the action is created.
CreationTime meta.Time `json:"creationTime"`
// StartTime is set the when the action has been started, but needs to wait to be finished.
// StartTime is set when the action has been started, but needs to wait to be finished.
StartTime *meta.Time `json:"startTime,omitempty"`
// Reason for this action
Reason string `json:"reason,omitempty"`
Expand All @@ -98,7 +98,7 @@ type Action struct {
TaskID types.UID `json:"taskID,omitempty"`
// Architecture of the member involved in this action (if any)
Architecture ArangoDeploymentArchitectureType `json:"arch,omitempty"`
// Progress describes what is a status of the current action.
// Progress describes the status of the current action.
Progress string `json:"progress,omitempty"`
}

Expand Down
6 changes: 3 additions & 3 deletions pkg/apis/deployment/v2alpha1/plan.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,9 @@ type Action struct {
MemberID string `json:"memberID,omitempty"`
// Group involved in this action
Group ServerGroup `json:"group,omitempty"`
// CreationTime is set the when the action is created.
// CreationTime is set when the action is created.
CreationTime meta.Time `json:"creationTime"`
// StartTime is set the when the action has been started, but needs to wait to be finished.
// StartTime is set when the action has been started, but needs to wait to be finished.
StartTime *meta.Time `json:"startTime,omitempty"`
// Reason for this action
Reason string `json:"reason,omitempty"`
Expand All @@ -98,7 +98,7 @@ type Action struct {
TaskID types.UID `json:"taskID,omitempty"`
// Architecture of the member involved in this action (if any)
Architecture ArangoDeploymentArchitectureType `json:"arch,omitempty"`
// Progress describes what is a status of the current action.
// Progress describes the status of the current action.
Progress string `json:"progress,omitempty"`
}

Expand Down
5 changes: 4 additions & 1 deletion pkg/apis/ml/v1alpha1/extension_spec_deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,10 @@ func (s *ArangoMLExtensionSpecDeployment) Validate() error {
continue
}

if usedPorts.IndexOf(port) >= 0 {
duplicateCount := usedPorts.Count(func(i int32) bool {
return i == port
})
if duplicateCount > 0 {
errs = append(errs, shared.PrefixResourceErrors(prefix, errors.Newf("port %d already specified for other component", port)))
} else {
usedPorts.Append(port)
Expand Down
3 changes: 3 additions & 0 deletions pkg/apis/ml/v1alpha1/extension_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,7 @@ type ArangoMLExtensionStatus struct {

// ArangoDB keeps the information about local arangodb reference
ArangoDB *ArangoMLExtensionStatusArangoDBRef `json:"arangoDB,omitempty"`

// Reconciliation keeps the information about reconciliation process. For internal use.
Reconciliation *ArangoMLExtensionStatusReconciliation `json:"reconciliation"`
}
40 changes: 40 additions & 0 deletions pkg/apis/ml/v1alpha1/extension_status_reconciliation.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
//
// DISCLAIMER
//
// Copyright 2023 ArangoDB GmbH, Cologne, Germany
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// Copyright holder is ArangoDB GmbH, Cologne, Germany
//

package v1alpha1

type ArangoMLExtensionStatusReconciliation struct {
StatefulSetChecksum string `json:"statefulSetChecksum,omitempty"`
ServiceChecksum string `json:"serviceChecksum,omitempty"`
}

func (r *ArangoMLExtensionStatusReconciliation) GetStatefulSetChecksum() string {
if r == nil {
return ""
}
return r.StatefulSetChecksum
}

func (r *ArangoMLExtensionStatusReconciliation) GetServiceChecksum() string {
if r == nil {
return ""
}
return r.ServiceChecksum
}
21 changes: 21 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.

2 changes: 1 addition & 1 deletion pkg/util/compare/compare.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ func P2[T interface{}, P1, P2 interface{}](
}

if m, p, err := Evaluate(actionBuilder, evaluatorsFunc...); err != nil {
log.Err(err).Error("Error while getting diff")
log.Err(err).Error("Error while running evaluators")
return SkippedRotation, nil, err
} else {
mode = mode.And(m)
Expand Down
6 changes: 0 additions & 6 deletions pkg/util/compare/interfaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,7 @@ import (

type Template[T interface{}] interface {
GetTemplate() *T
SetTemplate(*T)

GetTemplateChecksum() string
SetTemplateChecksum(string)

GetChecksum() string
SetChecksum(string)
}

type Checksum[T interface{}] func(in *T) (string, error)
Expand Down
24 changes: 18 additions & 6 deletions pkg/util/helpers.go → pkg/util/compare/k8s/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,24 @@
// Copyright holder is ArangoDB GmbH, Cologne, Germany
//

package util
package k8s

// Ter implements a ternary operation: return cond ? a : b;
func Ter[T any](cond bool, a T, b T) T {
if cond {
return a
import (
core "k8s.io/api/core/v1"

"github.com/arangodb/kube-arangodb/pkg/util"
)

func ChecksumService(s *core.Service) (string, error) {
return checksumServiceSpec(&s.Spec)
}

func checksumServiceSpec(s *core.ServiceSpec) (string, error) {
parts := map[string]interface{}{
"type": s.Type,
"ports": s.Ports,
"selector": s.Selector,
// add here more fields when needed
}
return b
return util.SHA256FromJSON(parts)
}
43 changes: 43 additions & 0 deletions pkg/util/compare/k8s/statefulset.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
//
// DISCLAIMER
//
// Copyright 2023 ArangoDB GmbH, Cologne, Germany
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//
// Copyright holder is ArangoDB GmbH, Cologne, Germany
//

package k8s

import (
apps "k8s.io/api/apps/v1"

"github.com/arangodb/kube-arangodb/pkg/util"
)

func ChecksumStatefulSet(s *apps.StatefulSet) (string, error) {
return checksumStatefulSetSpec(&s.Spec)
}

func checksumStatefulSetSpec(s *apps.StatefulSetSpec) (string, error) {
parts := map[string]interface{}{
"replicas": s.Replicas,
"serviceName": s.ServiceName,
"minReadySeconds": s.MinReadySeconds,
"selector": s.Selector,
"template": s.Template,
// add here more fields when needed
}
return util.SHA256FromJSON(parts)
}
11 changes: 1 addition & 10 deletions pkg/util/list.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ package util

import "sort"

type List[T comparable] []T
type List[T any] []T

func (l List[T]) Filter(fn func(T) bool) List[T] {
if l == nil {
Expand Down Expand Up @@ -57,15 +57,6 @@ func (l List[T]) Sort(fn func(T, T) bool) List[T] {
return clone
}

func (l List[T]) IndexOf(item T) int {
for i, element := range l {
if element == item {
return i
}
}
return -1
}

func MapList[T, V comparable](in List[T], fn func(T) V) List[V] {
if in == nil {
return nil
Expand Down