Skip to content

Commit

Permalink
feat: add isFailed for certificate
Browse files Browse the repository at this point in the history
  • Loading branch information
ckcd committed Feb 18, 2024
1 parent 22eb3d0 commit 9612558
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 5 deletions.
8 changes: 8 additions & 0 deletions pkg/apis/networking/v1alpha1/certificate_lifecycle.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,14 @@ func (c *Certificate) IsReady() bool {
cs.GetCondition(CertificateConditionReady).IsTrue()
}

// IsFailed returns true is the Certificate ready is false
// and the Certificate resource has been observed.
func (c *Certificate) IsFailed() bool {
cs := c.Status
return cs.ObservedGeneration == c.Generation &&
cs.GetCondition(CertificateConditionReady).IsFalse()
}

// GetCondition gets a specific condition of the Certificate status.
func (cs *CertificateStatus) GetCondition(t apis.ConditionType) *apis.Condition {
return certificateCondSet.Manage(cs).GetCondition(t)
Expand Down
14 changes: 9 additions & 5 deletions pkg/apis/networking/v1alpha1/certificate_lifecycle_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,12 +84,16 @@ func TestMarkNotReady(_ *testing.T) {
}

func TestMarkFailed(t *testing.T) {
c := &CertificateStatus{}
c.InitializeConditions()
apistest.CheckCondition(c, CertificateConditionReady, corev1.ConditionUnknown)
cs := &CertificateStatus{}
cs.InitializeConditions()
apistest.CheckCondition(cs, CertificateConditionReady, corev1.ConditionUnknown)

c.MarkFailed("failed", "failed")
apistest.CheckConditionFailed(c, CertificateConditionReady, t)
cs.MarkFailed("failed", "failed")
apistest.CheckConditionFailed(cs, CertificateConditionReady, t)
c := &Certificate{Status: *cs}
if !c.IsFailed() {
t.Error("IsFailed=false, want: true")
}
}

func TestMarkResourceNotOwned(t *testing.T) {
Expand Down

0 comments on commit 9612558

Please sign in to comment.