Skip to content

Commit

Permalink
Use new Condition helper funcs
Browse files Browse the repository at this point in the history
Since we're now relying on the standardized metav1.Condition type
instead of our own implementation we should also make use of the helper
funcs provided by pkg/apis/meta and k8s api/meta.

Signed-off-by: Aurel Canciu <aurelcanciu@gmail.com>
  • Loading branch information
relu committed Nov 20, 2020
1 parent 5f61649 commit 85f75a0
Showing 1 changed file with 10 additions and 13 deletions.
23 changes: 10 additions & 13 deletions api/v1alpha1/imagerepository_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package v1alpha1

import (
corev1 "k8s.io/api/core/v1"
apimeta "k8s.io/apimachinery/pkg/api/meta"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

"github.com/fluxcd/pkg/apis/meta"
Expand Down Expand Up @@ -76,29 +77,25 @@ type ImageRepositoryStatus struct {

// SetImageRepositoryReadiness sets the ready condition with the given status, reason and message.
func SetImageRepositoryReadiness(ir ImageRepository, status metav1.ConditionStatus, reason, message string) ImageRepository {
ir.Status.Conditions = []metav1.Condition{
{
Type: meta.ReadyCondition,
Status: status,
LastTransitionTime: metav1.Now(),
Reason: reason,
Message: message,
},
}
ir.Status.ObservedGeneration = ir.ObjectMeta.Generation
meta.SetResourceCondition(&ir, meta.ReadyCondition, status, reason, message)
return ir
}

// GetLastTransitionTime returns the LastTransitionTime attribute of the ready conditon
func GetLastTransitionTime(ir ImageRepository) *metav1.Time {
for _, condition := range ir.Status.Conditions {
if condition.Type == meta.ReadyCondition {
return &condition.LastTransitionTime
}
if rc := apimeta.FindStatusCondition(ir.Status.Conditions, meta.ReadyCondition); rc != nil {
return &rc.LastTransitionTime
}

return nil
}

// GetStatusConditions returns a pointer to the Status.Conditions slice
func (in *ImageRepository) GetStatusConditions() *[]metav1.Condition {
return &in.Status.Conditions
}

// +kubebuilder:object:root=true
// +kubebuilder:subresource:status
// +kubebuilder:printcolumn:name="Last scan",type=string,JSONPath=`.status.lastScanTime`
Expand Down

0 comments on commit 85f75a0

Please sign in to comment.