Skip to content

Commit

Permalink
Use checksum field for STS and svc reconciliation
Browse files Browse the repository at this point in the history
  • Loading branch information
nikita-vanyasin committed Dec 21, 2023
1 parent dcee3b0 commit 501003e
Show file tree
Hide file tree
Showing 6 changed files with 82 additions and 42 deletions.
12 changes: 12 additions & 0 deletions docs/api/ArangoMLExtension.V1Alpha1.md
Original file line number Diff line number Diff line change
Expand Up @@ -1221,6 +1221,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
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.

31 changes: 4 additions & 27 deletions pkg/util/compare/k8s/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,29 +21,13 @@
package k8s

import (
"crypto/sha256"
"encoding/json"
"fmt"

core "k8s.io/api/core/v1"

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

func GetKubernetesServiceSpecDiff(logger logging.Logger, spec, current core.ServiceSpec) (compare.Mode, error) {
specTmpl, err := compare.NewGenericChecksumTemplate[core.ServiceSpec, *core.ServiceSpec](&spec, checksumServiceSpec)
if err != nil {
return compare.SilentRotation, err
}

actualTmpl, err := compare.NewGenericChecksumTemplate[core.ServiceSpec, *core.ServiceSpec](&current, checksumServiceSpec)
if err != nil {
return compare.SilentRotation, err
}

mode, _, err := compare.P0[core.ServiceSpec](logger, compare.NewActionBuilderStub(), checksumServiceSpec, specTmpl, actualTmpl)
return mode, err
func ChecksumService(s *core.Service) (string, error) {
return checksumServiceSpec(&s.Spec)
}

func checksumServiceSpec(s *core.ServiceSpec) (string, error) {
Expand All @@ -53,12 +37,5 @@ func checksumServiceSpec(s *core.ServiceSpec) (string, error) {
"selector": s.Selector,
// add here more fields when needed
}

data, err := json.Marshal(parts)
if err != nil {
return "", err
}

checksum := fmt.Sprintf("%0x", sha256.Sum256(data))
return checksum, nil
return util.SHA256FromJSON(parts)
}
17 changes: 2 additions & 15 deletions pkg/util/compare/k8s/statefulset.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,24 +23,11 @@ package k8s
import (
apps "k8s.io/api/apps/v1"

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

func GetKubernetesStatefulSetSpecDiff(logger logging.Logger, spec, current apps.StatefulSetSpec) (compare.Mode, error) {
specTmpl, err := compare.NewGenericChecksumTemplate[apps.StatefulSetSpec, *apps.StatefulSetSpec](&spec, checksumStatefulSetSpec)
if err != nil {
return compare.SilentRotation, err
}

actualTmpl, err := compare.NewGenericChecksumTemplate[apps.StatefulSetSpec, *apps.StatefulSetSpec](&current, checksumStatefulSetSpec)
if err != nil {
return compare.SilentRotation, err
}

mode, _, err := compare.P0[apps.StatefulSetSpec](logger, compare.NewActionBuilderStub(), checksumStatefulSetSpec, specTmpl, actualTmpl)
return mode, err
func ChecksumStatefulSet(s *apps.StatefulSet) (string, error) {
return checksumStatefulSetSpec(&s.Spec)
}

func checksumStatefulSetSpec(s *apps.StatefulSetSpec) (string, error) {
Expand Down

0 comments on commit 501003e

Please sign in to comment.