@@ -34,10 +34,22 @@ var (
34
34
ErrAnnotation = errors .New ("a required annotation was missing" )
35
35
)
36
36
37
- // ConvertStatusCondition translates from Kubernetes status conditions to API ones.
38
- func ConvertStatusCondition (in * unikornv1.Condition ) openapi.ResourceProvisioningStatus {
37
+ // convertStatusCondition translates from Kubernetes status conditions to API ones.
38
+ func convertStatusCondition (in any ) openapi.ResourceProvisioningStatus {
39
+ // Not a resource with status conditions, consider it provisioned.
40
+ reader , ok := in .(unikornv1.StatusConditionReader )
41
+ if ! ok {
42
+ return openapi .ResourceProvisioningStatusProvisioned
43
+ }
44
+
45
+ // No condition yet, it's unknown.
46
+ condition , err := reader .StatusConditionRead (unikornv1 .ConditionAvailable )
47
+ if err != nil {
48
+ return openapi .ResourceProvisioningStatusUnknown
49
+ }
50
+
39
51
//nolint:exhaustive
40
- switch in .Reason {
52
+ switch condition .Reason {
41
53
case unikornv1 .ConditionReasonProvisioning :
42
54
return openapi .ResourceProvisioningStatusProvisioning
43
55
case unikornv1 .ConditionReasonProvisioned :
@@ -46,21 +58,47 @@ func ConvertStatusCondition(in *unikornv1.Condition) openapi.ResourceProvisionin
46
58
return openapi .ResourceProvisioningStatusError
47
59
case unikornv1 .ConditionReasonDeprovisioning :
48
60
return openapi .ResourceProvisioningStatusDeprovisioning
49
- default :
50
- return openapi .ResourceProvisioningStatusUnknown
51
61
}
62
+
63
+ return openapi .ResourceProvisioningStatusUnknown
64
+ }
65
+
66
+ // convertHealthCondition translates from Kubernetes heath conditions to API ones.
67
+ func convertHealthCondition (in any ) openapi.ResourceHealthStatus {
68
+ // Not a resource with status conditions, consider it healthy.
69
+ reader , ok := in .(unikornv1.StatusConditionReader )
70
+ if ! ok {
71
+ return openapi .ResourceHealthStatusHealthy
72
+ }
73
+
74
+ // No condition yet, it's unknown.
75
+ condition , err := reader .StatusConditionRead (unikornv1 .ConditionHealthy )
76
+ if err != nil {
77
+ return openapi .ResourceHealthStatusUnknown
78
+ }
79
+
80
+ //nolint:exhaustive
81
+ switch condition .Reason {
82
+ case unikornv1 .ConditionReasonHealthy :
83
+ return openapi .ResourceHealthStatusHealthy
84
+ case unikornv1 .ConditionReasonDegraded :
85
+ return openapi .ResourceHealthStatusDegraded
86
+ }
87
+
88
+ return openapi .ResourceHealthStatusUnknown
52
89
}
53
90
54
91
// ResourceReadMetadata extracts generic metadata from a resource for GET APIs.
55
- func ResourceReadMetadata (in metav1.Object , tags unikornv1.TagList , status openapi. ResourceProvisioningStatus ) openapi.ResourceReadMetadata {
92
+ func ResourceReadMetadata (in metav1.Object , tags unikornv1.TagList ) openapi.ResourceReadMetadata {
56
93
labels := in .GetLabels ()
57
94
annotations := in .GetAnnotations ()
58
95
59
96
out := openapi.ResourceReadMetadata {
60
97
Id : in .GetName (),
61
98
Name : labels [constants .NameLabel ],
62
99
CreationTime : in .GetCreationTimestamp ().Time ,
63
- ProvisioningStatus : status ,
100
+ ProvisioningStatus : convertStatusCondition (in ),
101
+ HealthStatus : convertHealthCondition (in ),
64
102
}
65
103
66
104
if v , ok := annotations [constants .DescriptionAnnotation ]; ok {
@@ -95,10 +133,10 @@ func ResourceReadMetadata(in metav1.Object, tags unikornv1.TagList, status opena
95
133
96
134
// OrganizationScopedResourceReadMetadata extracts organization scoped metdata from a resource
97
135
// for GET APIS.
98
- func OrganizationScopedResourceReadMetadata (in metav1.Object , tags unikornv1.TagList , status openapi. ResourceProvisioningStatus ) openapi.OrganizationScopedResourceReadMetadata {
136
+ func OrganizationScopedResourceReadMetadata (in metav1.Object , tags unikornv1.TagList ) openapi.OrganizationScopedResourceReadMetadata {
99
137
labels := in .GetLabels ()
100
138
101
- temp := ResourceReadMetadata (in , tags , status )
139
+ temp := ResourceReadMetadata (in , tags )
102
140
103
141
out := openapi.OrganizationScopedResourceReadMetadata {
104
142
Id : temp .Id ,
@@ -109,6 +147,7 @@ func OrganizationScopedResourceReadMetadata(in metav1.Object, tags unikornv1.Tag
109
147
ModifiedBy : temp .ModifiedBy ,
110
148
ModifiedTime : temp .ModifiedTime ,
111
149
ProvisioningStatus : temp .ProvisioningStatus ,
150
+ HealthStatus : temp .HealthStatus ,
112
151
Tags : temp .Tags ,
113
152
OrganizationId : labels [constants .OrganizationLabel ],
114
153
}
@@ -118,10 +157,10 @@ func OrganizationScopedResourceReadMetadata(in metav1.Object, tags unikornv1.Tag
118
157
119
158
// ProjectScopedResourceReadMetadata extracts project scoped metdata from a resource for
120
159
// GET APIs.
121
- func ProjectScopedResourceReadMetadata (in metav1.Object , tags unikornv1.TagList , status openapi. ResourceProvisioningStatus ) openapi.ProjectScopedResourceReadMetadata {
160
+ func ProjectScopedResourceReadMetadata (in metav1.Object , tags unikornv1.TagList ) openapi.ProjectScopedResourceReadMetadata {
122
161
labels := in .GetLabels ()
123
162
124
- temp := OrganizationScopedResourceReadMetadata (in , tags , status )
163
+ temp := OrganizationScopedResourceReadMetadata (in , tags )
125
164
126
165
out := openapi.ProjectScopedResourceReadMetadata {
127
166
Id : temp .Id ,
@@ -132,6 +171,7 @@ func ProjectScopedResourceReadMetadata(in metav1.Object, tags unikornv1.TagList,
132
171
ModifiedBy : temp .ModifiedBy ,
133
172
ModifiedTime : temp .ModifiedTime ,
134
173
ProvisioningStatus : temp .ProvisioningStatus ,
174
+ HealthStatus : temp .HealthStatus ,
135
175
Tags : temp .Tags ,
136
176
OrganizationId : temp .OrganizationId ,
137
177
ProjectId : labels [constants .ProjectLabel ],
0 commit comments