Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use conditions helper in reconciler (kstatus compat) #282

Merged
merged 3 commits into from
Nov 22, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 11 additions & 6 deletions api/v1beta1/alert_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,21 @@ type Alert struct {
}

// GetStatusConditions returns a pointer to the Status.Conditions slice
// Deprecated: use GetConditions instead.
func (in *Alert) GetStatusConditions() *[]metav1.Condition {
return &in.Status.Conditions
}

// GetConditions returns the status conditions of the object.
func (in *Alert) GetConditions() []metav1.Condition {
return in.Status.Conditions
}

// SetConditions sets the status conditions on the object.
func (in *Alert) SetConditions(conditions []metav1.Condition) {
in.Status.Conditions = conditions
}

// +kubebuilder:object:root=true

// AlertList contains a list of Alert
Expand All @@ -101,9 +112,3 @@ type AlertList struct {
func init() {
SchemeBuilder.Register(&Alert{}, &AlertList{})
}

func SetAlertReadiness(alert Alert, status metav1.ConditionStatus, reason, message string) Alert {
meta.SetResourceCondition(&alert, meta.ReadyCondition, status, reason, message)
alert.Status.ObservedGeneration = alert.Generation
return alert
}
4 changes: 4 additions & 0 deletions api/v1beta1/condition_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,10 @@ const (
// InitializedReason represents the fact that a given resource has been initialized.
InitializedReason string = "Initialized"

// ValidationFailedReason represents the fact that some part of the spec of a given resource
// couldn't be validated.
ValidationFailedReason string = "ValidationFailed"

// TokenNotFound represents the fact that receiver token can't be found.
TokenNotFoundReason string = "TokenNotFound"
)
22 changes: 16 additions & 6 deletions api/v1beta1/provider_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,11 @@ type ProviderSpec struct {
// a PEM-encoded CA certificate (`caFile`)
// +optional
CertSecretRef *meta.LocalObjectReference `json:"certSecretRef,omitempty"`

// This flag tells the controller to suspend subsequent events handling.
// Defaults to false.
// +optional
Suspend bool `json:"suspend,omitempty"`
}

const (
Expand Down Expand Up @@ -112,10 +117,21 @@ type Provider struct {
}

// GetStatusConditions returns a pointer to the Status.Conditions slice
// Deprecated: use GetConditions instead.
func (in *Provider) GetStatusConditions() *[]metav1.Condition {
return &in.Status.Conditions
}

// GetConditions returns the status conditions of the object.
func (in *Provider) GetConditions() []metav1.Condition {
return in.Status.Conditions
}

// SetConditions sets the status conditions on the object.
func (in *Provider) SetConditions(conditions []metav1.Condition) {
in.Status.Conditions = conditions
}

// +kubebuilder:object:root=true

// ProviderList contains a list of Provider
Expand All @@ -128,9 +144,3 @@ type ProviderList struct {
func init() {
SchemeBuilder.Register(&Provider{}, &ProviderList{})
}

func SetProviderReadiness(provider Provider, status metav1.ConditionStatus, reason, message string) Provider {
meta.SetResourceCondition(&provider, meta.ReadyCondition, status, reason, message)
provider.Status.ObservedGeneration = provider.Generation
return provider
}
22 changes: 10 additions & 12 deletions api/v1beta1/receiver_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,22 +80,20 @@ const (
ACRReceiver string = "acr"
)

func ReceiverReady(receiver Receiver, reason, message, url string) Receiver {
meta.SetResourceCondition(&receiver, meta.ReadyCondition, metav1.ConditionTrue, reason, message)
receiver.Status.ObservedGeneration = receiver.Generation
receiver.Status.URL = url
return receiver
// GetStatusConditions returns a pointer to the Status.Conditions slice
// Deprecated: use GetConditions instead.
func (in *Receiver) GetStatusConditions() *[]metav1.Condition {
return &in.Status.Conditions
}

func ReceiverNotReady(receiver Receiver, reason, message string) Receiver {
meta.SetResourceCondition(&receiver, meta.ReadyCondition, metav1.ConditionFalse, reason, message)
receiver.Status.ObservedGeneration = receiver.Generation
return receiver
// GetConditions returns the status conditions of the object.
func (in *Receiver) GetConditions() []metav1.Condition {
return in.Status.Conditions
}

// GetStatusConditions returns a pointer to the Status.Conditions slice
func (in *Receiver) GetStatusConditions() *[]metav1.Condition {
return &in.Status.Conditions
// SetConditions sets the status conditions on the object.
func (in *Receiver) SetConditions(conditions []metav1.Condition) {
in.Status.Conditions = conditions
}

// +genclient
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,9 @@ spec:
required:
- name
type: object
suspend:
description: This flag tells the controller to suspend subsequent events handling. Defaults to false.
type: boolean
type:
description: Type of provider
enum:
Expand Down
Loading