Skip to content

Commit 501003e

Browse files
Use checksum field for STS and svc reconciliation
1 parent dcee3b0 commit 501003e

File tree

6 files changed

+82
-42
lines changed

6 files changed

+82
-42
lines changed

docs/api/ArangoMLExtension.V1Alpha1.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1221,6 +1221,18 @@ UID keeps the information about object UID
12211221

12221222
***
12231223

1224+
### .status.reconciliation.serviceChecksum
1225+
1226+
Type: `string` <sup>[\[ref\]](https://github.com/arangodb/kube-arangodb/blob/1.2.35/pkg/apis/ml/v1alpha1/extension_status_reconciliation.go#L25)</sup>
1227+
1228+
***
1229+
1230+
### .status.reconciliation.statefulSetChecksum
1231+
1232+
Type: `string` <sup>[\[ref\]](https://github.com/arangodb/kube-arangodb/blob/1.2.35/pkg/apis/ml/v1alpha1/extension_status_reconciliation.go#L24)</sup>
1233+
1234+
***
1235+
12241236
### .status.serviceAccount.cluster.binding.name
12251237

12261238
Type: `string` <sup>[\[ref\]](https://github.com/arangodb/kube-arangodb/blob/1.2.35/pkg/apis/shared/v1/object.go#L46)</sup>

pkg/apis/ml/v1alpha1/extension_status.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,7 @@ type ArangoMLExtensionStatus struct {
3838

3939
// ArangoDB keeps the information about local arangodb reference
4040
ArangoDB *ArangoMLExtensionStatusArangoDBRef `json:"arangoDB,omitempty"`
41+
42+
// Reconciliation keeps the information about reconciliation process. For internal use.
43+
Reconciliation *ArangoMLExtensionStatusReconciliation `json:"reconciliation"`
4144
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
//
2+
// DISCLAIMER
3+
//
4+
// Copyright 2023 ArangoDB GmbH, Cologne, Germany
5+
//
6+
// Licensed under the Apache License, Version 2.0 (the "License");
7+
// you may not use this file except in compliance with the License.
8+
// You may obtain a copy of the License at
9+
//
10+
// http://www.apache.org/licenses/LICENSE-2.0
11+
//
12+
// Unless required by applicable law or agreed to in writing, software
13+
// distributed under the License is distributed on an "AS IS" BASIS,
14+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
// See the License for the specific language governing permissions and
16+
// limitations under the License.
17+
//
18+
// Copyright holder is ArangoDB GmbH, Cologne, Germany
19+
//
20+
21+
package v1alpha1
22+
23+
type ArangoMLExtensionStatusReconciliation struct {
24+
StatefulSetChecksum string `json:"statefulSetChecksum,omitempty"`
25+
ServiceChecksum string `json:"serviceChecksum,omitempty"`
26+
}
27+
28+
func (r *ArangoMLExtensionStatusReconciliation) GetStatefulSetChecksum() string {
29+
if r == nil {
30+
return ""
31+
}
32+
return r.StatefulSetChecksum
33+
}
34+
35+
func (r *ArangoMLExtensionStatusReconciliation) GetServiceChecksum() string {
36+
if r == nil {
37+
return ""
38+
}
39+
return r.ServiceChecksum
40+
}

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

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

pkg/util/compare/k8s/service.go

Lines changed: 4 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -21,29 +21,13 @@
2121
package k8s
2222

2323
import (
24-
"crypto/sha256"
25-
"encoding/json"
26-
"fmt"
27-
2824
core "k8s.io/api/core/v1"
2925

30-
"github.com/arangodb/kube-arangodb/pkg/logging"
31-
"github.com/arangodb/kube-arangodb/pkg/util/compare"
26+
"github.com/arangodb/kube-arangodb/pkg/util"
3227
)
3328

34-
func GetKubernetesServiceSpecDiff(logger logging.Logger, spec, current core.ServiceSpec) (compare.Mode, error) {
35-
specTmpl, err := compare.NewGenericChecksumTemplate[core.ServiceSpec, *core.ServiceSpec](&spec, checksumServiceSpec)
36-
if err != nil {
37-
return compare.SilentRotation, err
38-
}
39-
40-
actualTmpl, err := compare.NewGenericChecksumTemplate[core.ServiceSpec, *core.ServiceSpec](&current, checksumServiceSpec)
41-
if err != nil {
42-
return compare.SilentRotation, err
43-
}
44-
45-
mode, _, err := compare.P0[core.ServiceSpec](logger, compare.NewActionBuilderStub(), checksumServiceSpec, specTmpl, actualTmpl)
46-
return mode, err
29+
func ChecksumService(s *core.Service) (string, error) {
30+
return checksumServiceSpec(&s.Spec)
4731
}
4832

4933
func checksumServiceSpec(s *core.ServiceSpec) (string, error) {
@@ -53,12 +37,5 @@ func checksumServiceSpec(s *core.ServiceSpec) (string, error) {
5337
"selector": s.Selector,
5438
// add here more fields when needed
5539
}
56-
57-
data, err := json.Marshal(parts)
58-
if err != nil {
59-
return "", err
60-
}
61-
62-
checksum := fmt.Sprintf("%0x", sha256.Sum256(data))
63-
return checksum, nil
40+
return util.SHA256FromJSON(parts)
6441
}

pkg/util/compare/k8s/statefulset.go

Lines changed: 2 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -23,24 +23,11 @@ package k8s
2323
import (
2424
apps "k8s.io/api/apps/v1"
2525

26-
"github.com/arangodb/kube-arangodb/pkg/logging"
2726
"github.com/arangodb/kube-arangodb/pkg/util"
28-
"github.com/arangodb/kube-arangodb/pkg/util/compare"
2927
)
3028

31-
func GetKubernetesStatefulSetSpecDiff(logger logging.Logger, spec, current apps.StatefulSetSpec) (compare.Mode, error) {
32-
specTmpl, err := compare.NewGenericChecksumTemplate[apps.StatefulSetSpec, *apps.StatefulSetSpec](&spec, checksumStatefulSetSpec)
33-
if err != nil {
34-
return compare.SilentRotation, err
35-
}
36-
37-
actualTmpl, err := compare.NewGenericChecksumTemplate[apps.StatefulSetSpec, *apps.StatefulSetSpec](&current, checksumStatefulSetSpec)
38-
if err != nil {
39-
return compare.SilentRotation, err
40-
}
41-
42-
mode, _, err := compare.P0[apps.StatefulSetSpec](logger, compare.NewActionBuilderStub(), checksumStatefulSetSpec, specTmpl, actualTmpl)
43-
return mode, err
29+
func ChecksumStatefulSet(s *apps.StatefulSet) (string, error) {
30+
return checksumStatefulSetSpec(&s.Spec)
4431
}
4532

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

0 commit comments

Comments
 (0)