Skip to content

Commit a6267b2

Browse files
authored
Remove GetQdrantClusterCrdForHash helper (#116)
The helper is moved to the operator codebase, given that is only used by the operator internally to detect if pods needs to be restart on QdrantCluster update.
1 parent b146ff7 commit a6267b2

File tree

2 files changed

+0
-95
lines changed

2 files changed

+0
-95
lines changed

api/v1/qdrantcluster_types.go

Lines changed: 0 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -31,49 +31,6 @@ const (
3131
RecreateNodeAnnotationKey = "operator.qdrant.com/recreate-node"
3232
)
3333

34-
// GetQdrantClusterCrdForHash creates a QdrantCluster for the use of creating a hash for the provided QdrantCluster,
35-
// It uses a subset only, so it ignores e.g. majority of the the status and some fields from the spec.
36-
func GetQdrantClusterCrdForHash(qc QdrantCluster) QdrantCluster {
37-
// Only include the items to be inspected (basically the spec and a single annot)
38-
result := QdrantCluster{
39-
ObjectMeta: metav1.ObjectMeta{
40-
Annotations: map[string]string{},
41-
},
42-
}
43-
// Add the restartAt annot if needed
44-
if annots := qc.GetAnnotations(); annots != nil {
45-
if val, found := annots[RestartedAtAnnotationKey]; found {
46-
result.Annotations[RestartedAtAnnotationKey] = val
47-
}
48-
}
49-
cloned := qc.Spec.DeepCopy()
50-
// Version is a special case, we can upgrade via an upgade-path,
51-
// so we should take care of the version in status instead
52-
if v := qc.Status.Version; v != "" {
53-
cloned.Version = v
54-
}
55-
// Remove all fields (aka set a fixed value) which shouldn't restart the pod
56-
// The list is sorted alphabetically, for easier maintainability
57-
cloned.ClusterManager = nil
58-
cloned.Ingress = nil
59-
cloned.Pauses = nil
60-
cloned.Resources.Storage = ""
61-
cloned.RestartAllPodsConcurrently = false
62-
cloned.Service = nil
63-
cloned.ServicePerNode = nil
64-
cloned.Size = 1
65-
if v := cloned.StatefulSet; v != nil {
66-
v.Annotations = nil
67-
}
68-
cloned.StartupDelaySeconds = nil
69-
cloned.StorageClassNames = nil
70-
cloned.Suspend = false
71-
// Set Spec for result
72-
result.Spec = *cloned
73-
// Return result
74-
return result
75-
}
76-
7734
type GPUType string
7835

7936
//goland:noinspection GoUnusedConst

api/v1/qdrantcluster_types_test.go

Lines changed: 0 additions & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,8 @@
11
package v1
22

33
import (
4-
"crypto/sha256"
5-
"encoding/json"
6-
"fmt"
74
"testing"
85

9-
"github.com/stretchr/testify/assert"
106
"github.com/stretchr/testify/require"
117
)
128

@@ -21,51 +17,3 @@ func TestValidate(t *testing.T) {
2117
require.Error(t, err)
2218
require.ErrorContains(t, err, "Spec.Resources.CPU error: quantities must match the regular expression '^([+-]?[0-9.]+)([eEinumkKMGTP]*[-+]?[0-9]*)$'")
2319
}
24-
25-
func TestGetQdrantClusterCrdForHash(t *testing.T) {
26-
qc := QdrantCluster{}
27-
hash, err := getQdrantClusterCrdHash(qc)
28-
require.NoError(t, err)
29-
assert.Equal(t, "523a8cb", hash)
30-
31-
falseVal := false
32-
qc.Spec.ServicePerNode = &falseVal
33-
hash, err = getQdrantClusterCrdHash(qc)
34-
require.NoError(t, err)
35-
assert.Equal(t, "523a8cb", hash)
36-
37-
trueVal := true
38-
qc.Spec.ServicePerNode = &trueVal
39-
hash, err = getQdrantClusterCrdHash(qc)
40-
require.NoError(t, err)
41-
assert.Equal(t, "523a8cb", hash)
42-
}
43-
44-
// getQdrantClusterCrdHash created a hash for the provided QdrantCluster,
45-
// however a subset only, see GetQdrantClusterCrdForHash for details.
46-
func getQdrantClusterCrdHash(qc QdrantCluster) (string, error) {
47-
inspect := GetQdrantClusterCrdForHash(qc)
48-
// Get the hash, so we can diff later
49-
hash, err := getHash(inspect)
50-
if err != nil {
51-
return "", fmt.Errorf("failed to get hash for QdrantCluster: %w", err)
52-
}
53-
return hash, err
54-
}
55-
56-
// Get hash of provided value.
57-
// Returns the first 7 characters of the hash (like GitHub).
58-
func getHash(v any) (string, error) {
59-
json, err := json.Marshal(v)
60-
if err != nil {
61-
return "", fmt.Errorf("marshal failed: %w", err)
62-
}
63-
// Initialize hash
64-
hash := sha256.New()
65-
// add the serialized content
66-
hash.Write(json)
67-
// close hash
68-
sum := hash.Sum(nil)
69-
// Return first 7 characters
70-
return fmt.Sprintf("%x", sum)[:7], nil
71-
}

0 commit comments

Comments
 (0)