Skip to content

Commit 2c646f9

Browse files
committed
Improve AutoOpsAgentPolicy Status Reporting
1 parent e569059 commit 2c646f9

File tree

12 files changed

+797
-15
lines changed

12 files changed

+797
-15
lines changed

config/crds/v1/all-crds.yaml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2547,10 +2547,27 @@ spec:
25472547
type: object
25482548
status:
25492549
properties:
2550+
details:
2551+
additionalProperties:
2552+
properties:
2553+
error:
2554+
type: string
2555+
message:
2556+
type: string
2557+
phase:
2558+
type: string
2559+
required:
2560+
- phase
2561+
type: object
2562+
description: Details contains lightweight per-resource details.
2563+
type: object
25502564
errors:
25512565
description: Errors is the number of resources that are in an error
25522566
state.
25532567
type: integer
2568+
message:
2569+
description: Message is a human-readable summary of the status.
2570+
type: string
25542571
observedGeneration:
25552572
description: ObservedGeneration is the most recent generation observed
25562573
for this AutoOpsAgentPolicy.
@@ -2563,9 +2580,17 @@ spec:
25632580
description: Ready is the number of resources that are in a ready
25642581
state.
25652582
type: integer
2583+
readyCount:
2584+
description: ReadyCount is a human readable string of ready monitored
2585+
resources vs all monitored resources, Ready/Resources.
2586+
type: string
25662587
resources:
25672588
description: Resources is the number of resources that match the ResourceSelector.
25682589
type: integer
2590+
skipped:
2591+
description: Skipped is the number of resources that are skipped from
2592+
monitoring due to rbac permissions.
2593+
type: integer
25692594
required:
25702595
- errors
25712596
- ready

config/crds/v1/resources/autoops.k8s.elastic.co_autoopsagentpolicies.yaml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8696,10 +8696,27 @@ spec:
86968696
type: object
86978697
status:
86988698
properties:
8699+
details:
8700+
additionalProperties:
8701+
properties:
8702+
error:
8703+
type: string
8704+
message:
8705+
type: string
8706+
phase:
8707+
type: string
8708+
required:
8709+
- phase
8710+
type: object
8711+
description: Details contains lightweight per-resource details.
8712+
type: object
86998713
errors:
87008714
description: Errors is the number of resources that are in an error
87018715
state.
87028716
type: integer
8717+
message:
8718+
description: Message is a human-readable summary of the status.
8719+
type: string
87038720
observedGeneration:
87048721
description: ObservedGeneration is the most recent generation observed
87058722
for this AutoOpsAgentPolicy.
@@ -8712,9 +8729,17 @@ spec:
87128729
description: Ready is the number of resources that are in a ready
87138730
state.
87148731
type: integer
8732+
readyCount:
8733+
description: ReadyCount is a human readable string of ready monitored
8734+
resources vs all monitored resources, Ready/Resources.
8735+
type: string
87158736
resources:
87168737
description: Resources is the number of resources that match the ResourceSelector.
87178738
type: integer
8739+
skipped:
8740+
description: Skipped is the number of resources that are skipped from
8741+
monitoring due to rbac permissions.
8742+
type: integer
87188743
required:
87198744
- errors
87208745
- ready

deploy/eck-operator/charts/eck-operator-crds/templates/all-crds.yaml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2568,10 +2568,27 @@ spec:
25682568
type: object
25692569
status:
25702570
properties:
2571+
details:
2572+
additionalProperties:
2573+
properties:
2574+
error:
2575+
type: string
2576+
message:
2577+
type: string
2578+
phase:
2579+
type: string
2580+
required:
2581+
- phase
2582+
type: object
2583+
description: Details contains lightweight per-resource details.
2584+
type: object
25712585
errors:
25722586
description: Errors is the number of resources that are in an error
25732587
state.
25742588
type: integer
2589+
message:
2590+
description: Message is a human-readable summary of the status.
2591+
type: string
25752592
observedGeneration:
25762593
description: ObservedGeneration is the most recent generation observed
25772594
for this AutoOpsAgentPolicy.
@@ -2584,9 +2601,17 @@ spec:
25842601
description: Ready is the number of resources that are in a ready
25852602
state.
25862603
type: integer
2604+
readyCount:
2605+
description: ReadyCount is a human readable string of ready monitored
2606+
resources vs all monitored resources, Ready/Resources.
2607+
type: string
25872608
resources:
25882609
description: Resources is the number of resources that match the ResourceSelector.
25892610
type: integer
2611+
skipped:
2612+
description: Skipped is the number of resources that are skipped from
2613+
monitoring due to rbac permissions.
2614+
type: integer
25902615
required:
25912616
- errors
25922617
- ready

docs/reference/api-reference/main.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,19 @@ AutoOpsRef defines a reference to a secret containing connection details for Aut
319319

320320

321321

322+
323+
### ResourcePhase (string) [#resourcephase]
324+
325+
326+
327+
:::{admonition} Appears In:
328+
* [AutoOpsResourceStatus](#autoopsresourcestatus)
329+
330+
:::
331+
332+
333+
334+
322335
% TODO add function to crd-ref-docs return anchor used in links docs-v3 does not seem to produce valid markdown anchors
323336
## autoscaling.k8s.elastic.co/v1alpha1 [#autoscalingk8selasticcov1alpha1]
324337

pkg/apis/autoops/v1alpha1/autoopsagentpolicy_types.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,10 +100,27 @@ type AutoOpsAgentPolicyStatus struct {
100100
Ready int `json:"ready"`
101101
// Errors is the number of resources that are in an error state.
102102
Errors int `json:"errors"`
103+
// Skipped is the number of resources that are skipped from monitoring due to rbac permissions.
104+
Skipped int `json:"skipped,omitempty"`
105+
// ReadyCount is a human readable string of ready monitored resources vs all monitored resources, Ready/Resources.
106+
ReadyCount string `json:"readyCount,omitempty"`
107+
103108
// Phase is the phase of the AutoOpsAgentPolicy.
104109
Phase PolicyPhase `json:"phase,omitempty"`
105110
// ObservedGeneration is the most recent generation observed for this AutoOpsAgentPolicy.
106111
ObservedGeneration int64 `json:"observedGeneration,omitempty"`
112+
113+
// Message is a human-readable summary of the status.
114+
Message string `json:"message,omitempty"`
115+
116+
// Details contains lightweight per-resource details.
117+
Details map[string]AutoOpsResourceStatus `json:"details,omitempty"`
118+
}
119+
120+
type AutoOpsResourceStatus struct {
121+
Phase ResourcePhase `json:"phase"`
122+
Message string `json:"message,omitempty"` // Only set for non-ready states
123+
Error string `json:"error,omitempty"` // Only set for error states
107124
}
108125

109126
// PolicyPhase represents the current lifecycle phase of an AutoOpsAgentPolicy.
@@ -157,3 +174,10 @@ func (p PolicyPhase) Priority() int {
157174
func (p *AutoOpsAgentPolicy) IsMarkedForDeletion() bool {
158175
return !p.DeletionTimestamp.IsZero()
159176
}
177+
178+
type ResourcePhase string
179+
180+
const (
181+
ErrorResourcePhase ResourcePhase = "Error"
182+
SkippedResourcePhase ResourcePhase = "Skipped"
183+
)

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

Lines changed: 23 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/controller/autoops/controller.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ func (r *AgentPolicyReconciler) Reconcile(ctx context.Context, request reconcile
166166
}
167167

168168
results := r.doReconcile(ctx, policy, state)
169-
state.CalculateFinalPhase(results.IsReconciled())
169+
state.Finalize(results.IsReconciled())
170170

171171
result, err := r.updateStatusFromState(ctx, state)
172172
results = results.WithResult(result).WithError(err)

pkg/controller/autoops/reconcile.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ func (r *AgentPolicyReconciler) internalReconcile(
116116
accessAllowed, err := isAutoOpsAssociationAllowed(ctx, r.accessReviewer, &policy, &es, r.recorder)
117117
if err != nil {
118118
log.Error(err, "while checking access for Elasticsearch cluster", "es_namespace", es.Namespace, "es_name", es.Name)
119-
state.UpdateWithPhase(autoopsv1alpha1.ErrorPhase)
119+
state.ResourceRBACError(es)
120120
results.WithError(err)
121121
continue
122122
}
@@ -168,7 +168,7 @@ func (r *AgentPolicyReconciler) internalReconcile(
168168
if es.Spec.HTTP.TLS.Enabled() {
169169
if err := r.reconcileAutoOpsESCASecret(ctx, policy, es); err != nil {
170170
log.Error(err, "while reconciling AutoOps ES CA secret")
171-
state.MarkResourceError()
171+
state.ResourceError(es, "Failed to create AutoOps ES CA secret", err)
172172
results.WithError(err)
173173
continue
174174
}
@@ -177,39 +177,39 @@ func (r *AgentPolicyReconciler) internalReconcile(
177177
apiKeySecret, err := r.reconcileAutoOpsESAPIKey(ctx, policy, es)
178178
if err != nil {
179179
log.Error(err, "while reconciling AutoOps ES API key")
180-
state.MarkResourceError()
180+
state.ResourceError(es, "Failed to create AutoOps ES API key", err)
181181
results.WithError(err)
182182
continue
183183
}
184184

185185
configMap, err := ReconcileAutoOpsESConfigMap(ctx, r.Client, policy, es)
186186
if err != nil {
187187
log.Error(err, "while reconciling AutoOps ES config map")
188-
state.MarkResourceError()
188+
state.ResourceError(es, "Failed to create AutoOps ES config map", err)
189189
results.WithError(err)
190190
continue
191191
}
192192

193193
configHash, err := buildConfigHash(ctx, *configMap, *apiKeySecret, r.Client, policy)
194194
if err != nil {
195195
log.Error(err, "while building config hash")
196-
state.MarkResourceError()
196+
state.ResourceError(es, "Failed to prepare AutoOps agent deployment", err)
197197
results.WithError(err)
198198
continue
199199
}
200200

201201
deploymentParams, err := r.buildDeployment(configHash, policy, es)
202202
if err != nil {
203203
log.Error(err, "while getting deployment params")
204-
state.MarkResourceError()
204+
state.ResourceError(es, "Failed to build AutoOps agent deployment", err)
205205
results.WithError(err)
206206
continue
207207
}
208208

209209
reconciledDeployment, err := deployment.Reconcile(ctx, r.Client, deploymentParams, &policy)
210210
if err != nil {
211211
log.Error(err, "while reconciling deployment")
212-
state.MarkResourceError()
212+
state.ResourceError(es, "Failed to reconcile AutoOps agent deployment", err)
213213
results.WithError(err)
214214
continue
215215
}

0 commit comments

Comments
 (0)