refactoring

This commit is contained in:
Andrei Pohilko
2023-08-03 18:05:33 +01:00
parent 0b354331d5
commit d46d7ab1da

View File

@@ -84,6 +84,23 @@ func EnhanceStatus(res *v12.Carp, err error) *v12.CarpStatus {
c.Status = Healthy c.Status = Healthy
c.Reason = "Exists" //since there is no condition to check here, we can set reason as exists. c.Reason = "Exists" //since there is no condition to check here, we can set reason as exists.
} else if s.Phase == "" && len(s.Conditions) > 0 { } else if s.Phase == "" && len(s.Conditions) > 0 {
applyCustomConditions(&s, &c)
} else if s.Phase == "Pending" {
c.Status = Progressing
c.Reason = string(s.Phase)
} else if s.Phase == "" {
c.Status = Healthy
c.Reason = "Exists"
} else {
log.Warnf("Unhandled status: %v", s)
c.Reason = string(s.Phase)
}
s.Conditions = append(s.Conditions, c)
return &s
}
func applyCustomConditions(s *v12.CarpStatus, c *v12.CarpCondition) {
for _, cond := range s.Conditions { for _, cond := range s.Conditions {
if cond.Type == "Progressing" { // https://kubernetes.io/docs/concepts/workloads/controllers/deployment/ if cond.Type == "Progressing" { // https://kubernetes.io/docs/concepts/workloads/controllers/deployment/
if cond.Status == "False" { if cond.Status == "False" {
@@ -121,19 +138,6 @@ func EnhanceStatus(res *v12.Carp, err error) *v12.CarpStatus {
c.Message = cond.Message c.Message = cond.Message
} }
} }
} else if s.Phase == "Pending" {
c.Status = Progressing
c.Reason = string(s.Phase)
} else if s.Phase == "" {
c.Status = Healthy
c.Reason = "Exists"
} else {
log.Warnf("Unhandled status: %v", s)
c.Reason = string(s.Phase)
}
s.Conditions = append(s.Conditions, c)
return &s
} }
func (h *KubeHandler) Describe(c *gin.Context) { func (h *KubeHandler) Describe(c *gin.Context) {