@@ -28,6 +28,8 @@ import (
28
28
"github.com/nxadm/tail"
29
29
30
30
"sigs.k8s.io/kwok/kustomize/crd"
31
+ "sigs.k8s.io/kwok/kustomize/metrics/resource"
32
+ "sigs.k8s.io/kwok/kustomize/metrics/usage"
31
33
nodefast "sigs.k8s.io/kwok/kustomize/stage/node/fast"
32
34
nodeheartbeat "sigs.k8s.io/kwok/kustomize/stage/node/heartbeat"
33
35
nodeheartbeatwithlease "sigs.k8s.io/kwok/kustomize/stage/node/heartbeat-with-lease"
@@ -210,8 +212,16 @@ func (c *Cluster) Save(ctx context.Context) error {
210
212
}
211
213
212
214
if ! slices .Contains (conf .Options .EnableCRDs , v1alpha1 .MetricKind ) {
213
- stages := config.FilterWithTypeFromContext [* internalversion.Metric ](ctx )
214
- objs = appendIntoInternalObjects (objs , stages ... )
215
+ metrics := config.FilterWithTypeFromContext [* internalversion.Metric ](ctx )
216
+ if len (metrics ) != 0 {
217
+ objs = appendIntoInternalObjects (objs , metrics ... )
218
+ } else if c .conf .Options .EnableMetricsServer {
219
+ m , err := config.UnmarshalWithType [* internalversion.Metric , string ](resource .DefaultMetricsResource )
220
+ if err != nil {
221
+ return err
222
+ }
223
+ objs = appendIntoInternalObjects (objs , m )
224
+ }
215
225
}
216
226
217
227
if ! slices .Contains (conf .Options .EnableCRDs , v1alpha1 .ResourceUsageKind ) {
@@ -220,8 +230,16 @@ func (c *Cluster) Save(ctx context.Context) error {
220
230
}
221
231
222
232
if ! slices .Contains (conf .Options .EnableCRDs , v1alpha1 .ClusterResourceUsageKind ) {
223
- stages := config.FilterWithTypeFromContext [* internalversion.ClusterResourceUsage ](ctx )
224
- objs = appendIntoInternalObjects (objs , stages ... )
233
+ cru := config.FilterWithTypeFromContext [* internalversion.ClusterResourceUsage ](ctx )
234
+ if len (cru ) != 0 {
235
+ objs = appendIntoInternalObjects (objs , cru ... )
236
+ } else if c .conf .Options .EnableMetricsServer {
237
+ m , err := config.UnmarshalWithType [* internalversion.ClusterResourceUsage , string ](usage .DefaultUsageFromAnnotation )
238
+ if err != nil {
239
+ return err
240
+ }
241
+ objs = appendIntoInternalObjects (objs , m )
242
+ }
225
243
}
226
244
227
245
if ! slices .Contains (conf .Options .EnableCRDs , v1alpha1 .AttachKind ) {
0 commit comments