Skip to content

Commit 960dc94

Browse files
authored
refactor(operator): prometheus operand (#629)
1 parent 62e2e1c commit 960dc94

File tree

18 files changed

+388
-168
lines changed

18 files changed

+388
-168
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.1.0/).
1818
### Fixed
1919
- Fixed a bug where the scheduler would not re-try updating podgroup status after failure
2020
- Fixed a bug where ray workloads gang scheduling would ignore `minReplicas` if autoscaling was not set
21+
- KAI Config wrong statuses when prometheus operand is enabled
2122

2223
## [v0.9.1] - 20250-09-15
2324

pkg/apis/kai/v1/config_types.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ const (
3737
Available ConditionReason = "available"
3838
Reconciled ConditionReason = "reconciled"
3939
DependenciesFulfilled ConditionReason = "dependencies_fulfilled"
40+
DependenciesMissing ConditionReason = "dependencies_missing"
4041
PrometheusConnected ConditionReason = "prometheus_connected"
4142
PrometheusConnectionFailed ConditionReason = "prometheus_connection_failed"
4243
)

pkg/operator/controller/status_reconciler/status_reconciler.go

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ func (r *StatusReconciler) ReconcileStatus(ctx context.Context, object objectWit
4848
if err := r.reconcileCondition(ctx, object, r.getAvailableCondition(ctx, object.GetGeneration())); err != nil {
4949
return err
5050
}
51-
return r.reconcileCondition(ctx, object, r.getDependenciesFulfilledCondition(object.GetGeneration()))
51+
return r.reconcileCondition(ctx, object, r.getDependenciesFulfilledCondition(ctx, object))
5252
}
5353

5454
func (r *StatusReconciler) reconcileCondition(ctx context.Context, object objectWithConditions, condition metav1.Condition) error {
@@ -155,13 +155,36 @@ func (r *StatusReconciler) getAvailableCondition(ctx context.Context, gen int64)
155155
}
156156
}
157157

158-
func (r *StatusReconciler) getDependenciesFulfilledCondition(gen int64) metav1.Condition {
158+
func (r *StatusReconciler) getDependenciesFulfilledCondition(ctx context.Context, object objectWithConditions) metav1.Condition {
159+
missingDependencies, err := r.deployable.HasMissingDependencies(ctx, r.Client, object.GetInternalObject())
160+
if err != nil {
161+
return metav1.Condition{
162+
Type: string(kaiv1.ConditionDependenciesFulfilled),
163+
Status: metav1.ConditionFalse,
164+
Reason: string(kaiv1.DependenciesMissing),
165+
Message: err.Error(),
166+
ObservedGeneration: object.GetGeneration(),
167+
LastTransitionTime: metav1.Now(),
168+
}
169+
}
170+
171+
if len(missingDependencies) > 0 {
172+
return metav1.Condition{
173+
Type: string(kaiv1.ConditionDependenciesFulfilled),
174+
Status: metav1.ConditionFalse,
175+
Reason: string(kaiv1.DependenciesMissing),
176+
Message: missingDependencies,
177+
ObservedGeneration: object.GetGeneration(),
178+
LastTransitionTime: metav1.Now(),
179+
}
180+
}
181+
159182
return metav1.Condition{
160183
Type: string(kaiv1.ConditionDependenciesFulfilled),
161184
Status: metav1.ConditionTrue,
162185
Reason: string(kaiv1.DependenciesFulfilled),
163186
Message: "Dependencies are fulfilled",
164-
ObservedGeneration: gen,
187+
ObservedGeneration: object.GetGeneration(),
165188
LastTransitionTime: metav1.Now(),
166189
}
167190
}

pkg/operator/controller/status_reconciler/status_reconciler_test.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,14 @@ func (f *fakeDeployable) IsAvailable(ctx context.Context, runtimeClient client.R
188188
return f.isAvailable, nil
189189
}
190190

191+
func (f *fakeDeployable) Monitor(ctx context.Context, runtimeReader client.Reader, kaiConfig *kaiv1.Config) error {
192+
return nil
193+
}
194+
195+
func (f *fakeDeployable) HasMissingDependencies(ctx context.Context, readerClient client.Reader, obj client.Object) (string, error) {
196+
return "", nil
197+
}
198+
191199
func (f *fakeDeployable) Name() string {
192200
return "fakeDeployable"
193201
}

pkg/operator/operands/admission/admission.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,3 +81,7 @@ func (a *Admission) Name() string {
8181
func (a *Admission) Monitor(ctx context.Context, runtimeReader client.Reader, kaiConfig *kaiv1.Config) error {
8282
return nil
8383
}
84+
85+
func (a *Admission) HasMissingDependencies(context.Context, client.Reader, *kaiv1.Config) (string, error) {
86+
return "", nil
87+
}

pkg/operator/operands/binder/binder.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,3 +66,7 @@ func (b *Binder) Name() string {
6666
func (b *Binder) Monitor(ctx context.Context, runtimeReader client.Reader, kaiConfig *kaiv1.Config) error {
6767
return nil
6868
}
69+
70+
func (b *Binder) HasMissingDependencies(context.Context, client.Reader, *kaiv1.Config) (string, error) {
71+
return "", nil
72+
}

pkg/operator/operands/deployable/deployable.go

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,15 +66,15 @@ func (d *DeployableOperands) Deploy(
6666
Controller: ptr.To(true),
6767
}
6868

69-
if createObjectsInCluster(ctx, runtimeClient, reconcilerAsOwnerReference, objectsToCreate) != nil {
69+
if err := createObjectsInCluster(ctx, runtimeClient, reconcilerAsOwnerReference, objectsToCreate); err != nil {
7070
return err
7171
}
7272

73-
if deleteObjectsInCluster(ctx, runtimeClient, objectsToDelete) != nil {
73+
if err := deleteObjectsInCluster(ctx, runtimeClient, objectsToDelete); err != nil {
7474
return err
7575
}
7676

77-
if updateObjectsInCluster(ctx, runtimeClient, reconcilerAsOwnerReference, objectsToUpdate) != nil {
77+
if err := updateObjectsInCluster(ctx, runtimeClient, reconcilerAsOwnerReference, objectsToUpdate); err != nil {
7878
return err
7979
}
8080
return nil
@@ -301,3 +301,26 @@ func (d *DeployableOperands) Monitor(ctx context.Context, runtimeReader client.R
301301
}
302302
return nil
303303
}
304+
305+
func (d *DeployableOperands) HasMissingDependencies(ctx context.Context, readerClient client.Reader, object client.Object) (string, error) {
306+
var missingDependencies string
307+
var err error
308+
309+
kaiConfig, checkForKAIConfig := object.(*kaiv1.Config)
310+
if !checkForKAIConfig {
311+
return "", nil
312+
}
313+
314+
for _, operand := range d.operands {
315+
// Assuming each operand has a HasDependencies method
316+
missing, e := operand.HasMissingDependencies(ctx, readerClient, kaiConfig)
317+
if e != nil {
318+
err = errors.Join(err, e)
319+
}
320+
if len(missing) > 0 {
321+
missingDependencies = missingDependencies + fmt.Sprintf("\n%s is missing %s", operand.Name(), missing)
322+
}
323+
}
324+
325+
return missingDependencies, err
326+
}

0 commit comments

Comments
 (0)