Skip to content

Commit

Permalink
Merge pull request #2021 from hankfreund/status_enum
Browse files Browse the repository at this point in the history
Compositions: Replace boolean for ResourceStatus.isHealthy with string enum.
  • Loading branch information
google-oss-prow[bot] authored Jun 17, 2024
2 parents 7695204 + 36e4f23 commit 9eef325
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 16 deletions.
21 changes: 14 additions & 7 deletions experiments/compositions/composition/api/v1alpha1/plan_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,14 +34,21 @@ type PlanSpec struct {
Stages map[string]Stage `json:"stages,omitempty"`
}

type HealthType string

const (
HEALTHY HealthType = "Healthy"
UNHEALTHY = "Unhealthy"
)

type ResourceStatus struct {
Group string `json:"group,omitempty"`
Version string `json:"version,omitempty"`
Kind string `json:"kind"`
Namespace string `json:"namespace,omitempty"`
Name string `json:"name,omitempty"`
Status string `json:"status,omitempty"`
IsHealthy bool `json:"isHealthy"`
Group string `json:"group,omitempty"`
Version string `json:"version,omitempty"`
Kind string `json:"kind"`
Namespace string `json:"namespace,omitempty"`
Name string `json:"name,omitempty"`
Status string `json:"status,omitempty"`
Health HealthType `json:"health"`
}

// StageStatus captures the status of a stage
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,8 @@ spec:
properties:
group:
type: string
isHealthy:
type: boolean
health:
type: string
kind:
type: string
name:
Expand All @@ -168,7 +168,7 @@ spec:
version:
type: string
required:
- isHealthy
- health
- kind
type: object
type: array
Expand All @@ -183,8 +183,8 @@ spec:
properties:
group:
type: string
isHealthy:
type: boolean
health:
type: string
kind:
type: string
name:
Expand All @@ -196,7 +196,7 @@ spec:
version:
type: string
required:
- isHealthy
- health
- kind
type: object
type: array
Expand Down
8 changes: 5 additions & 3 deletions experiments/compositions/composition/pkg/applier/applier.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ func (a *Applier) UpdatePruneStatus(status *compositionv1alpha1.PlanStatus) {
Namespace: resultObj.NameNamespace.Namespace,
Name: resultObj.NameNamespace.Name,
Status: "Pruned",
IsHealthy: true, // Is it ?
Health: compositionv1alpha1.HEALTHY, // Is it ?
}
if resultObj.Error != nil {
rs.Status = fmt.Sprintf("Prune Error: %s", resultObj.Error)
Expand Down Expand Up @@ -114,7 +114,7 @@ func (a *Applier) UpdateStageStatus(status *compositionv1alpha1.PlanStatus) {
Namespace: resultObj.NameNamespace.Namespace,
Name: resultObj.NameNamespace.Name,
Status: "",
IsHealthy: false,
Health: compositionv1alpha1.UNHEALTHY,
}
if resultObj.IsPruned {
rs.Status = "Unexpected Prune"
Expand All @@ -125,7 +125,9 @@ func (a *Applier) UpdateStageStatus(status *compositionv1alpha1.PlanStatus) {
applyCount++
rs.Status = resultObj.Message
}
rs.IsHealthy = resultObj.IsHealthy
if resultObj.IsHealthy {
rs.Health = compositionv1alpha1.HEALTHY
}
}
if status.Stages[a.stageName] == nil {
status.Stages[a.stageName] = &compositionv1alpha1.StageStatus{
Expand Down

0 comments on commit 9eef325

Please sign in to comment.