Skip to content

Commit

Permalink
feat: add status attribute to the MonitoringStack CRD (#143)
Browse files Browse the repository at this point in the history
This adds conditions to the MonitorinStackStatus type and
updates the controller logic so that the conditions are updated
based on the Prometheus status conditions during the reconciliation.
  • Loading branch information
tremes authored Jul 20, 2022
1 parent 37c777e commit bcda150
Show file tree
Hide file tree
Showing 9 changed files with 691 additions and 16 deletions.
62 changes: 62 additions & 0 deletions deploy/crds/common/monitoring.rhobs_monitoringstacks.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -854,6 +854,68 @@ spec:
description: MonitoringStackStatus defines the observed state of MonitoringStack.
It should always be reconstructable from the state of the cluster and/or
outside world.
properties:
conditions:
description: Conditions provide status information about the MonitoringStack
items:
properties:
lastTransitionTime:
description: lastTransitionTime is the last time the condition
transitioned from one status to another. This should be when
the underlying condition changed. If that is not known, then
using the time when the API field changed is acceptable.
format: date-time
type: string
message:
description: message is a human readable message indicating
details about the transition. This may be an empty string.
maxLength: 32768
type: string
observedGeneration:
description: observedGeneration represents the .metadata.generation
that the condition was set based upon. For instance, if .metadata.generation
is currently 12, but the .status.conditions[x].observedGeneration
is 9, the condition is out of date with respect to the current
state of the instance.
format: int64
minimum: 0
type: integer
reason:
description: reason contains a programmatic identifier indicating
the reason for the condition's last transition. Producers
of specific condition types may define expected values and
meanings for this field, and whether the values are considered
a guaranteed API. The value should be a CamelCase string.
This field may not be empty.
maxLength: 1024
minLength: 1
pattern: ^[A-Za-z]([A-Za-z0-9_,:]*[A-Za-z0-9_])?$
type: string
status:
description: status of the condition
enum:
- "True"
- "False"
- Unknown
- Degraded
type: string
type:
description: type of condition in CamelCase or in foo.example.com/CamelCase.
The regex it matches is (dns1123SubdomainFmt/)?(qualifiedNameFmt)
maxLength: 316
pattern: ^([a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*/)?(([A-Za-z0-9][-A-Za-z0-9_.]*)?[A-Za-z0-9])$
type: string
required:
- lastTransitionTime
- message
- reason
- status
- type
type: object
type: array
x-kubernetes-list-type: atomic
required:
- conditions
type: object
type: object
served: true
Expand Down
98 changes: 97 additions & 1 deletion docs/api.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ MonitoringStack is the Schema for the monitoringstacks API
</td>
<td>false</td>
</tr><tr>
<td><b>status</b></td>
<td><b><a href="#monitoringstackstatus">status</a></b></td>
<td>object</td>
<td>
MonitoringStackStatus defines the observed state of MonitoringStack. It should always be reconstructable from the state of the cluster and/or outside world.<br/>
Expand Down Expand Up @@ -1785,6 +1785,102 @@ Define resources requests and limits for Monitoring Stack Pods.
</tr></tbody>
</table>


### MonitoringStack.status
<sup><sup>[↩ Parent](#monitoringstack)</sup></sup>



MonitoringStackStatus defines the observed state of MonitoringStack. It should always be reconstructable from the state of the cluster and/or outside world.

<table>
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th>Description</th>
<th>Required</th>
</tr>
</thead>
<tbody><tr>
<td><b><a href="#monitoringstackstatusconditionsindex">conditions</a></b></td>
<td>[]object</td>
<td>
Conditions provide status information about the MonitoringStack<br/>
</td>
<td>true</td>
</tr></tbody>
</table>


### MonitoringStack.status.conditions[index]
<sup><sup>[↩ Parent](#monitoringstackstatus)</sup></sup>





<table>
<thead>
<tr>
<th>Name</th>
<th>Type</th>
<th>Description</th>
<th>Required</th>
</tr>
</thead>
<tbody><tr>
<td><b>lastTransitionTime</b></td>
<td>string</td>
<td>
lastTransitionTime is the last time the condition transitioned from one status to another. This should be when the underlying condition changed. If that is not known, then using the time when the API field changed is acceptable.<br/>
<br/>
<i>Format</i>: date-time<br/>
</td>
<td>true</td>
</tr><tr>
<td><b>message</b></td>
<td>string</td>
<td>
message is a human readable message indicating details about the transition. This may be an empty string.<br/>
</td>
<td>true</td>
</tr><tr>
<td><b>reason</b></td>
<td>string</td>
<td>
reason contains a programmatic identifier indicating the reason for the condition's last transition. Producers of specific condition types may define expected values and meanings for this field, and whether the values are considered a guaranteed API. The value should be a CamelCase string. This field may not be empty.<br/>
</td>
<td>true</td>
</tr><tr>
<td><b>status</b></td>
<td>enum</td>
<td>
status of the condition<br/>
<br/>
<i>Enum</i>: True, False, Unknown, Degraded<br/>
</td>
<td>true</td>
</tr><tr>
<td><b>type</b></td>
<td>string</td>
<td>
type of condition in CamelCase or in foo.example.com/CamelCase. The regex it matches is (dns1123SubdomainFmt/)?(qualifiedNameFmt)<br/>
</td>
<td>true</td>
</tr><tr>
<td><b>observedGeneration</b></td>
<td>integer</td>
<td>
observedGeneration represents the .metadata.generation that the condition was set based upon. For instance, if .metadata.generation is currently 12, but the .status.conditions[x].observedGeneration is 9, the condition is out of date with respect to the current state of the instance.<br/>
<br/>
<i>Format</i>: int64<br/>
<i>Minimum</i>: 0<br/>
</td>
<td>false</td>
</tr></tbody>
</table>

## ThanosQuerier
<sup><sup>[↩ Parent](#monitoringrhobsv1alpha1 )</sup></sup>

Expand Down
71 changes: 69 additions & 2 deletions pkg/apis/monitoring/v1alpha1/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,75 @@ type MonitoringStackSpec struct {
// MonitoringStackStatus defines the observed state of MonitoringStack.
// It should always be reconstructable from the state of the cluster and/or outside world.
type MonitoringStackStatus struct {
// TODO(sthaha): INSERT ADDITIONAL STATUS FIELDS -- observed state of prometheus
// ??
// Conditions provide status information about the MonitoringStack
// +listType=atomic
Conditions []Condition `json:"conditions"`
}

type ConditionStatus string

// +required
// +kubebuilder:validation:Required
// +kubebuilder:validation:Pattern=`^([a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*/)?(([A-Za-z0-9][-A-Za-z0-9_.]*)?[A-Za-z0-9])$`
// +kubebuilder:validation:MaxLength=316
type ConditionType string

const (
ConditionTrue ConditionStatus = "True"
ConditionDegraded ConditionStatus = "Degraded"
ConditionFalse ConditionStatus = "False"
ConditionUnknown ConditionStatus = "Unknown"

ReconciledCondition ConditionType = "Reconciled"
AvailableCondition ConditionType = "Available"
)

type Condition struct {
// type of condition in CamelCase or in foo.example.com/CamelCase.
// The regex it matches is (dns1123SubdomainFmt/)?(qualifiedNameFmt)
Type ConditionType `json:"type"`
// observedGeneration represents the .metadata.generation that the condition was set based upon.
// For instance, if .metadata.generation is currently 12, but the .status.conditions[x].observedGeneration is 9, the condition is out of date
// with respect to the current state of the instance.
// +optional
// +kubebuilder:validation:Minimum=0
ObservedGeneration int64 `json:"observedGeneration,omitempty"`
// lastTransitionTime is the last time the condition transitioned from one status to another.
// This should be when the underlying condition changed. If that is not known, then using the time when the API field changed is acceptable.
// +required
// +kubebuilder:validation:Required
// +kubebuilder:validation:Type=string
// +kubebuilder:validation:Format=date-time
LastTransitionTime metav1.Time `json:"lastTransitionTime"`
// reason contains a programmatic identifier indicating the reason for the condition's last transition.
// Producers of specific condition types may define expected values and meanings for this field,
// and whether the values are considered a guaranteed API.
// The value should be a CamelCase string.
// This field may not be empty.
// +required
// +kubebuilder:validation:Required
// +kubebuilder:validation:MaxLength=1024
// +kubebuilder:validation:MinLength=1
// +kubebuilder:validation:Pattern=`^[A-Za-z]([A-Za-z0-9_,:]*[A-Za-z0-9_])?$`
Reason string `json:"reason"`
// message is a human readable message indicating details about the transition.
// This may be an empty string.
// +required
// +kubebuilder:validation:Required
// +kubebuilder:validation:MaxLength=32768
Message string `json:"message"`
// status of the condition
// +required
// +kubebuilder:validation:Required
// +kubebuilder:validation:Enum=True;False;Unknown;Degraded
Status ConditionStatus `json:"status"`
}

func (c Condition) Equal(n Condition) bool {
if c.Reason == n.Reason && c.Status == n.Status && c.Message == n.Message && c.ObservedGeneration == n.ObservedGeneration {
return true
}
return false
}

type PrometheusConfig struct {
Expand Down
25 changes: 24 additions & 1 deletion pkg/apis/monitoring/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit bcda150

Please sign in to comment.