Skip to content

Commit 8714dfd

Browse files
committed
qdrant cleanup
Signed-off-by: Masood <[email protected]>
1 parent 704ce96 commit 8714dfd

File tree

14 files changed

+94
-75
lines changed

14 files changed

+94
-75
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ require (
3838
k8s.io/klog/v2 v2.130.1
3939
kmodules.xyz/client-go v0.32.7
4040
kmodules.xyz/custom-resources v0.32.2
41-
kubedb.dev/apimachinery v0.58.3-0.20251024090116-419a58ac2212
41+
kubedb.dev/apimachinery v0.58.3-0.20251107091445-23f7968d860a
4242
sigs.k8s.io/controller-runtime v0.20.4
4343
xorm.io/xorm v1.3.9
4444
)

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -566,8 +566,8 @@ kmodules.xyz/monitoring-agent-api v0.32.1 h1:F0cm5NJWfgiANw3eiKkXXSXoClMBpAolMXE
566566
kmodules.xyz/monitoring-agent-api v0.32.1/go.mod h1:zgRKiJcuK7FOHy0Y1TsONRbJfgnPCs8t4Zh/6Afr+yU=
567567
kmodules.xyz/offshoot-api v0.32.0 h1:gogc5scSZe2JoXtZof72UGRl3Tit0kFaFRMkLLT1D8o=
568568
kmodules.xyz/offshoot-api v0.32.0/go.mod h1:tled7OxYZ3SkUJcrVFVVYyd+zXjsRSEm1R6Q3k4gcx0=
569-
kubedb.dev/apimachinery v0.58.3-0.20251024090116-419a58ac2212 h1:Ff2n3J78qmWqjPXa64Z0pOw5hPacmziMrrSE5KzYvq8=
570-
kubedb.dev/apimachinery v0.58.3-0.20251024090116-419a58ac2212/go.mod h1:cdAy0z4ED/iunIQprmaB4yCSxgBkFaT5fcOT/ogxl0Q=
569+
kubedb.dev/apimachinery v0.58.3-0.20251107091445-23f7968d860a h1:5Tn1I75UUjQi2QeUmILnq4bnRtJV6wxIADDlWubiUFk=
570+
kubedb.dev/apimachinery v0.58.3-0.20251107091445-23f7968d860a/go.mod h1:cdAy0z4ED/iunIQprmaB4yCSxgBkFaT5fcOT/ogxl0Q=
571571
kubeops.dev/operator-shard-manager v0.0.3 h1:Z2YOAfyQIjvHMwT4O56lR0l9z25s2tCVDO22u/XuYnw=
572572
kubeops.dev/operator-shard-manager v0.0.3/go.mod h1:2oRq5vnCaUxzE+qIiRuzB34PlqahiynE+sYqWu6AMIY=
573573
kubeops.dev/petset v0.0.12 h1:NSFEeuckBVm44f3cAL4HhcQWvnfOE4qgbfug7+FEyaY=

qdrant/kubedb_client_builder.go

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ import (
55
"fmt"
66

77
"github.com/qdrant/go-client/qdrant"
8-
core "k8s.io/api/core/v1"
98
"kubedb.dev/apimachinery/apis/kubedb"
109
api "kubedb.dev/apimachinery/apis/kubedb/v1alpha2"
1110
"sigs.k8s.io/controller-runtime/pkg/client"
@@ -29,36 +28,15 @@ func (o *KubeDBClientBuilder) WithContext(ctx context.Context) *KubeDBClientBuil
2928
return o
3029
}
3130

32-
func (o *KubeDBClientBuilder) GetQdrantAPIKey() string {
33-
db := o.db
34-
var secretName string
35-
if db.Spec.AuthSecret != nil {
36-
secretName = db.GetAuthSecretName()
37-
}
38-
39-
var secret core.Secret
40-
err := o.kc.Get(o.ctx, client.ObjectKey{Namespace: db.Namespace, Name: secretName}, &secret)
41-
if err != nil {
42-
return ""
43-
}
44-
45-
apiKey, ok := secret.Data[kubedb.QdrantAPIKey]
46-
if !ok {
47-
return ""
48-
}
49-
50-
return string(apiKey)
51-
}
52-
5331
func (o *KubeDBClientBuilder) GetQdrantClient() (*qdrant.Client, error) {
5432
if o.ctx == nil {
5533
o.ctx = context.Background()
5634
}
5735

5836
config := &qdrant.Config{
59-
Host: o.db.PrimaryServiceDNS(),
37+
Host: o.db.ServiceDNS(),
6038
Port: kubedb.QdrantGRPCPort,
61-
APIKey: o.GetQdrantAPIKey(),
39+
APIKey: o.db.GetAPIKey(o.ctx, o.kc),
6240
}
6341

6442
qdrantClient, err := qdrant.NewClient(config)

vendor/kubedb.dev/apimachinery/apis/catalog/v1alpha1/openapi_generated.go

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

vendor/kubedb.dev/apimachinery/apis/catalog/v1alpha1/qdrant_version_types.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,7 @@ type QdrantVersionSpec struct {
6767

6868
// QdrantSecurityContext is for the additional config for the DB container
6969
type QdrantSecurityContext struct {
70-
RunAsUser *int64 `json:"runAsUser,omitempty"`
71-
RunAsGroup *int64 `json:"runAsGroup,omitempty"`
70+
RunAsUser *int64 `json:"runAsUser,omitempty"`
7271
}
7372

7473
// QdrantVersionDatabase is the Qdrant Database image

vendor/kubedb.dev/apimachinery/apis/catalog/v1alpha1/zz_generated.deepcopy.go

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

vendor/kubedb.dev/apimachinery/apis/kubedb/constants.go

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2071,14 +2071,22 @@ const (
20712071

20722072
// =========================== Qdrant Constants ============================
20732073
const (
2074-
QdrantContainerName = "qdrant"
2075-
QdrantHTTPPortName = "http"
2076-
QdrantHTTPPort = 6333
2077-
QdrantGRPCPortName = "grpc"
2078-
QdrantGRPCPort = 6334
2079-
QdrantP2PPortName = "p2p"
2080-
QdrantP2PPort = 6335
2081-
QdrantConfigKey = "config.yaml"
2074+
QdrantContainerName = "qdrant"
2075+
2076+
QdrantHTTPPortName = "http"
2077+
QdrantHTTPPort = 6333
2078+
QdrantGRPCPortName = "grpc"
2079+
QdrantGRPCPort = 6334
2080+
QdrantP2PPortName = "p2p"
2081+
QdrantP2PPort = 6335
2082+
2083+
QdrantDataVolName = "data"
2084+
QdrantDataDir = "/qdrant/storage"
2085+
QdrantConfigVolName = "qdrant-config"
2086+
QdrantConfigDir = "/qdrant/config"
2087+
2088+
QdrantConfigFileName = "config.yaml"
2089+
20822090
QdrantAPIKey = "api-key"
20832091
QdrantReadOnlyAPIKey = "read-only-api-key"
20842092
)

vendor/kubedb.dev/apimachinery/apis/kubedb/v1alpha2/openapi_generated.go

Lines changed: 1 addition & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

vendor/kubedb.dev/apimachinery/apis/kubedb/v1alpha2/qdrant_helpers.go

Lines changed: 59 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -106,12 +106,18 @@ func (q *Qdrant) ServiceAccountName() string {
106106
return q.OffshootName()
107107
}
108108

109-
func (q *Qdrant) PrimaryServiceDNS() string {
109+
func (q *Qdrant) ServiceDNS() string {
110110
return fmt.Sprintf("%s.%s.svc", q.ServiceName(), q.Namespace)
111111
}
112112

113-
func (q *Qdrant) Address() string {
114-
return fmt.Sprintf("%v.%v.svc", q.Name, q.Namespace)
113+
func (q *Qdrant) GetPodAddress(i int) string {
114+
return fmt.Sprintf("%s-%d.%s.%s.svc:%d",
115+
q.OffshootName(),
116+
i,
117+
q.GoverningServiceName(),
118+
q.Namespace,
119+
kubedb.QdrantHTTPPort,
120+
)
115121
}
116122

117123
func (q *Qdrant) GetAuthSecretName() string {
@@ -121,6 +127,26 @@ func (q *Qdrant) GetAuthSecretName() string {
121127
return meta_util.NameWithSuffix(q.OffshootName(), "auth")
122128
}
123129

130+
func (q *Qdrant) GetAPIKey(ctx context.Context, kc client.Client) string {
131+
var secretName string
132+
if q.Spec.AuthSecret != nil {
133+
secretName = q.GetAuthSecretName()
134+
}
135+
136+
var secret core.Secret
137+
err := kc.Get(ctx, client.ObjectKey{Namespace: q.Namespace, Name: secretName}, &secret)
138+
if err != nil {
139+
return ""
140+
}
141+
142+
apiKey, ok := secret.Data[kubedb.QdrantAPIKey]
143+
if !ok {
144+
return ""
145+
}
146+
147+
return string(apiKey)
148+
}
149+
124150
func (q *Qdrant) ConfigSecretName() string {
125151
return meta_util.NameWithSuffix(q.OffshootName(), "config")
126152
}
@@ -161,6 +187,10 @@ func (q *Qdrant) SetDefaults(kc client.Client) {
161187
q.Spec.Replicas = pointer.Int32P(1)
162188
}
163189

190+
if q.Spec.Mode == "" {
191+
q.Spec.Mode = QdrantStandalone
192+
}
193+
164194
if q.Spec.DeletionPolicy == "" {
165195
q.Spec.DeletionPolicy = DeletionPolicyDelete
166196
}
@@ -169,6 +199,18 @@ func (q *Qdrant) SetDefaults(kc client.Client) {
169199
q.Spec.StorageType = StorageTypeDurable
170200
}
171201

202+
if q.Spec.AuthSecret == nil {
203+
q.Spec.AuthSecret = &SecretReference{}
204+
}
205+
206+
if q.Spec.AuthSecret.Kind == "" {
207+
q.Spec.AuthSecret.Kind = kubedb.ResourceKindSecret
208+
}
209+
210+
if q.Spec.PodTemplate == nil {
211+
q.Spec.PodTemplate = &ofst.PodTemplateSpec{}
212+
}
213+
172214
var qdVersion catalog.QdrantVersion
173215
err := kc.Get(context.TODO(), types.NamespacedName{
174216
Name: q.Spec.Version,
@@ -177,14 +219,16 @@ func (q *Qdrant) SetDefaults(kc client.Client) {
177219
return
178220
}
179221

180-
q.setDefaultContainerSecurityContext(&qdVersion, &q.Spec.PodTemplate)
222+
q.setDefaultContainerSecurityContext(&qdVersion, q.Spec.PodTemplate)
181223

182224
dbContainer := coreutil.GetContainerByName(q.Spec.PodTemplate.Spec.Containers, kubedb.QdrantContainerName)
183225
if dbContainer != nil && (dbContainer.Resources.Requests == nil || dbContainer.Resources.Limits == nil) {
184226
apis.SetDefaultResourceLimits(&dbContainer.Resources, kubedb.DefaultResources)
185227
}
186228

187229
q.SetHealthCheckerDefaults()
230+
231+
q.setDefaultContainerResourceLimits(q.Spec.PodTemplate)
188232
}
189233

190234
func (q *Qdrant) SetHealthCheckerDefaults() {
@@ -195,7 +239,7 @@ func (q *Qdrant) SetHealthCheckerDefaults() {
195239
q.Spec.HealthChecker.TimeoutSeconds = pointer.Int32P(10)
196240
}
197241
if q.Spec.HealthChecker.FailureThreshold == nil {
198-
q.Spec.HealthChecker.FailureThreshold = pointer.Int32P(3)
242+
q.Spec.HealthChecker.FailureThreshold = pointer.Int32P(1)
199243
}
200244
}
201245

@@ -240,7 +284,17 @@ func (q *Qdrant) assignDefaultContainerSecurityContext(qdVersion *catalog.Qdrant
240284
if rc.RunAsUser == nil {
241285
rc.RunAsUser = qdVersion.Spec.SecurityContext.RunAsUser
242286
}
287+
if rc.RunAsGroup == nil {
288+
rc.RunAsGroup = qdVersion.Spec.SecurityContext.RunAsUser
289+
}
243290
if rc.SeccompProfile == nil {
244291
rc.SeccompProfile = secomp.DefaultSeccompProfile()
245292
}
246293
}
294+
295+
func (q *Qdrant) setDefaultContainerResourceLimits(podTemplate *ofst.PodTemplateSpec) {
296+
dbContainer := coreutil.GetContainerByName(podTemplate.Spec.Containers, kubedb.QdrantContainerName)
297+
if dbContainer != nil && (dbContainer.Resources.Requests == nil && dbContainer.Resources.Limits == nil) {
298+
apis.SetDefaultResourceLimits(&dbContainer.Resources, kubedb.DefaultResources)
299+
}
300+
}

vendor/kubedb.dev/apimachinery/apis/kubedb/v1alpha2/qdrant_types.go

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,11 @@ const (
3131
)
3232

3333
// +kubebuilder:validation:Enum=Standalone;Distributed
34-
type QdrantClusterMode string
34+
type QdrantMode string
3535

3636
const (
37-
QdrantClusterModeStandalone QdrantClusterMode = "Standalone"
38-
QdrantClusterModeDistributed QdrantClusterMode = "Distributed"
37+
QdrantStandalone QdrantMode = "Standalone"
38+
QdrantDistributed QdrantMode = "Distributed"
3939
)
4040

4141
// Qdrant is the Schema for the Qdrant API
@@ -47,7 +47,6 @@ const (
4747
// +kubebuilder:object:root=true
4848
// +kubebuilder:subresource:status
4949
// +kubebuilder:resource:path=qdrants,singular=qdrant,shortName=qd,categories={datastore,kubedb,appscode,all}
50-
// +kubebuilder:printcolumn:name="Type",type="string",JSONPath=".apiVersion"
5150
// +kubebuilder:printcolumn:name="Version",type="string",JSONPath=".spec.version"
5251
// +kubebuilder:printcolumn:name="Status",type="string",JSONPath=".status.phase"
5352
// +kubebuilder:printcolumn:name="Age",type="date",JSONPath=".metadata.creationTimestamp"
@@ -64,13 +63,13 @@ type QdrantSpec struct {
6463
// Version of Qdrant to be deployed.
6564
Version string `json:"version"`
6665

67-
// Number of instances to deploy for an Qdrant database.
66+
// Number of instances to deploy for a Qdrant database.
6867
// +optional
6968
Replicas *int32 `json:"replicas,omitempty"`
7069

7170
// Qdrant cluster mode
7271
// +optional
73-
Mode *QdrantClusterMode `json:"mode,omitempty"`
72+
Mode QdrantMode `json:"mode,omitempty"`
7473

7574
// StorageType can be durable (default) or ephemeral
7675
StorageType StorageType `json:"storageType,omitempty"`
@@ -94,7 +93,7 @@ type QdrantSpec struct {
9493

9594
// PodTemplate is an optional configuration for pods used to expose database
9695
// +optional
97-
PodTemplate ofst.PodTemplateSpec `json:"podTemplate,omitempty"`
96+
PodTemplate *ofst.PodTemplateSpec `json:"podTemplate,omitempty"`
9897

9998
// ServiceTemplates is an optional configuration for services used to expose database
10099
// +optional

0 commit comments

Comments
 (0)