Skip to content

Commit 8dac379

Browse files
author
Arvind Thirumurugan
committed
add MetricCollectorReport CRD
Signed-off-by: Arvind Thirumurugan <[email protected]>
1 parent be151ba commit 8dac379

File tree

9 files changed

+526
-53
lines changed

9 files changed

+526
-53
lines changed
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
/*
2+
Copyright 2025 The KubeFleet Authors.
3+
4+
Licensed under the Apache License, Version 2.0 (the "License");
5+
you may not use this file except in compliance with the License.
6+
You may obtain a copy of the License at
7+
8+
http://www.apache.org/licenses/LICENSE-2.0
9+
10+
Unless required by applicable law or agreed to in writing, software
11+
distributed under the License is distributed on an "AS IS" BASIS,
12+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
See the License for the specific language governing permissions and
14+
limitations under the License.
15+
*/
16+
17+
package v1beta1
18+
19+
import (
20+
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
21+
)
22+
23+
// +genclient
24+
// +kubebuilder:object:root=true
25+
// +kubebuilder:resource:scope="Namespaced",shortName=mcr,categories={fleet,fleet-metrics}
26+
// +kubebuilder:storageversion
27+
// +kubebuilder:printcolumn:JSONPath=`.workloadsMonitored`,name="Workloads",type=integer
28+
// +kubebuilder:printcolumn:JSONPath=`.lastCollectionTime`,name="Last-Collection",type=date
29+
// +kubebuilder:printcolumn:JSONPath=`.metadata.creationTimestamp`,name="Age",type=date
30+
31+
// MetricCollectorReport is created by the MetricCollector controller on the hub cluster
32+
// in the fleet-member-{clusterName} namespace to report collected metrics from a member cluster.
33+
// The controller watches MetricCollector objects on the member cluster, collects metrics,
34+
// and syncs the status to the hub as MetricCollectorReport objects.
35+
//
36+
// Controller workflow:
37+
// 1. MetricCollector reconciles and collects metrics on member cluster
38+
// 2. Metrics include clusterName from workload_health labels
39+
// 3. Controller creates/updates MetricCollectorReport in fleet-member-{clusterName} namespace on hub
40+
// 4. Report name matches MetricCollector name for easy lookup
41+
//
42+
// Namespace: fleet-member-{clusterName} (extracted from CollectedMetrics[0].ClusterName)
43+
// Name: Same as MetricCollector name
44+
// All metrics in CollectedMetrics are guaranteed to have the same ClusterName.
45+
type MetricCollectorReport struct {
46+
metav1.TypeMeta `json:",inline"`
47+
metav1.ObjectMeta `json:"metadata,omitempty"`
48+
49+
// Conditions copied from the MetricCollector status.
50+
// +optional
51+
Conditions []metav1.Condition `json:"conditions,omitempty"`
52+
53+
// ObservedGeneration is the generation most recently observed from the MetricCollector.
54+
// +optional
55+
ObservedGeneration int64 `json:"observedGeneration,omitempty"`
56+
57+
// WorkloadsMonitored is the count of workloads being monitored.
58+
// +optional
59+
WorkloadsMonitored int32 `json:"workloadsMonitored,omitempty"`
60+
61+
// LastCollectionTime is when metrics were last collected on the member cluster.
62+
// +optional
63+
LastCollectionTime *metav1.Time `json:"lastCollectionTime,omitempty"`
64+
65+
// CollectedMetrics contains the most recent metrics from each workload.
66+
// All metrics are guaranteed to have the same ClusterName since they're collected from one member cluster.
67+
// +optional
68+
CollectedMetrics []WorkloadMetrics `json:"collectedMetrics,omitempty"`
69+
70+
// LastReportTime is when this report was last synced to the hub.
71+
// +optional
72+
LastReportTime *metav1.Time `json:"lastReportTime,omitempty"`
73+
}
74+
75+
// +kubebuilder:object:root=true
76+
77+
// MetricCollectorReportList contains a list of MetricCollectorReport.
78+
type MetricCollectorReportList struct {
79+
metav1.TypeMeta `json:",inline"`
80+
metav1.ListMeta `json:"metadata,omitempty"`
81+
Items []MetricCollectorReport `json:"items"`
82+
}
83+
84+
func init() {
85+
SchemeBuilder.Register(&MetricCollectorReport{}, &MetricCollectorReportList{})
86+
}

apis/placement/v1beta1/zz_generated.deepcopy.go

Lines changed: 78 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cmd/memberagent/main.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -467,7 +467,8 @@ func Start(ctx context.Context, hubCfg, memberConfig *rest.Config, hubOpts, memb
467467

468468
// Set up the MetricCollector controller.
469469
mcReconciler := &metriccollector.Reconciler{
470-
Client: memberMgr.GetClient(),
470+
MemberClient: memberMgr.GetClient(),
471+
HubClient: hubMgr.GetClient(),
471472
}
472473
if err := mcReconciler.SetupWithManager(memberMgr); err != nil {
473474
klog.ErrorS(err, "Failed to set up MetricCollector controller with the controller manager")

cmd/metric-app/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ func main() {
1414
if clusterName == "" {
1515
clusterName = "unknown"
1616
}
17-
17+
1818
workloadName := os.Getenv("WORKLOAD_NAME")
1919
if workloadName == "" {
2020
workloadName = "unknown"
Lines changed: 176 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,176 @@
1+
---
2+
apiVersion: apiextensions.k8s.io/v1
3+
kind: CustomResourceDefinition
4+
metadata:
5+
annotations:
6+
controller-gen.kubebuilder.io/version: v0.16.0
7+
name: metriccollectorreports.placement.kubernetes-fleet.io
8+
spec:
9+
group: placement.kubernetes-fleet.io
10+
names:
11+
categories:
12+
- fleet
13+
- fleet-metrics
14+
kind: MetricCollectorReport
15+
listKind: MetricCollectorReportList
16+
plural: metriccollectorreports
17+
shortNames:
18+
- mcr
19+
singular: metriccollectorreport
20+
scope: Namespaced
21+
versions:
22+
- additionalPrinterColumns:
23+
- jsonPath: .workloadsMonitored
24+
name: Workloads
25+
type: integer
26+
- jsonPath: .lastCollectionTime
27+
name: Last-Collection
28+
type: date
29+
- jsonPath: .metadata.creationTimestamp
30+
name: Age
31+
type: date
32+
name: v1beta1
33+
schema:
34+
openAPIV3Schema:
35+
description: |-
36+
MetricCollectorReport is created by the MetricCollector controller on the hub cluster
37+
in the fleet-member-{clusterName} namespace to report collected metrics from a member cluster.
38+
The controller watches MetricCollector objects on the member cluster, collects metrics,
39+
and syncs the status to the hub as MetricCollectorReport objects.
40+
41+
Controller workflow:
42+
1. MetricCollector reconciles and collects metrics on member cluster
43+
2. Metrics include clusterName from workload_health labels
44+
3. Controller creates/updates MetricCollectorReport in fleet-member-{clusterName} namespace on hub
45+
4. Report name matches MetricCollector name for easy lookup
46+
47+
Namespace: fleet-member-{clusterName} (extracted from CollectedMetrics[0].ClusterName)
48+
Name: Same as MetricCollector name
49+
All metrics in CollectedMetrics are guaranteed to have the same ClusterName.
50+
properties:
51+
apiVersion:
52+
description: |-
53+
APIVersion defines the versioned schema of this representation of an object.
54+
Servers should convert recognized schemas to the latest internal value, and
55+
may reject unrecognized values.
56+
More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources
57+
type: string
58+
collectedMetrics:
59+
description: |-
60+
CollectedMetrics contains the most recent metrics from each workload.
61+
All metrics are guaranteed to have the same ClusterName since they're collected from one member cluster.
62+
items:
63+
description: WorkloadMetrics represents metrics collected from a single
64+
workload pod.
65+
properties:
66+
clusterName:
67+
description: ClusterName from the workload_health metric label.
68+
type: string
69+
health:
70+
description: Health indicates if the workload is healthy (true=healthy,
71+
false=unhealthy).
72+
type: boolean
73+
namespace:
74+
description: Namespace is the namespace of the pod.
75+
type: string
76+
workloadName:
77+
description: WorkloadName from the workload_health metric label
78+
(typically the deployment name).
79+
type: string
80+
required:
81+
- clusterName
82+
- health
83+
- namespace
84+
- workloadName
85+
type: object
86+
type: array
87+
conditions:
88+
description: Conditions copied from the MetricCollector status.
89+
items:
90+
description: Condition contains details for one aspect of the current
91+
state of this API Resource.
92+
properties:
93+
lastTransitionTime:
94+
description: |-
95+
lastTransitionTime is the last time the condition transitioned from one status to another.
96+
This should be when the underlying condition changed. If that is not known, then using the time when the API field changed is acceptable.
97+
format: date-time
98+
type: string
99+
message:
100+
description: |-
101+
message is a human readable message indicating details about the transition.
102+
This may be an empty string.
103+
maxLength: 32768
104+
type: string
105+
observedGeneration:
106+
description: |-
107+
observedGeneration represents the .metadata.generation that the condition was set based upon.
108+
For instance, if .metadata.generation is currently 12, but the .status.conditions[x].observedGeneration is 9, the condition is out of date
109+
with respect to the current state of the instance.
110+
format: int64
111+
minimum: 0
112+
type: integer
113+
reason:
114+
description: |-
115+
reason contains a programmatic identifier indicating the reason for the condition's last transition.
116+
Producers of specific condition types may define expected values and meanings for this field,
117+
and whether the values are considered a guaranteed API.
118+
The value should be a CamelCase string.
119+
This field may not be empty.
120+
maxLength: 1024
121+
minLength: 1
122+
pattern: ^[A-Za-z]([A-Za-z0-9_,:]*[A-Za-z0-9_])?$
123+
type: string
124+
status:
125+
description: status of the condition, one of True, False, Unknown.
126+
enum:
127+
- "True"
128+
- "False"
129+
- Unknown
130+
type: string
131+
type:
132+
description: type of condition in CamelCase or in foo.example.com/CamelCase.
133+
maxLength: 316
134+
pattern: ^([a-z0-9]([-a-z0-9]*[a-z0-9])?(\.[a-z0-9]([-a-z0-9]*[a-z0-9])?)*/)?(([A-Za-z0-9][-A-Za-z0-9_.]*)?[A-Za-z0-9])$
135+
type: string
136+
required:
137+
- lastTransitionTime
138+
- message
139+
- reason
140+
- status
141+
- type
142+
type: object
143+
type: array
144+
kind:
145+
description: |-
146+
Kind is a string value representing the REST resource this object represents.
147+
Servers may infer this from the endpoint the client submits requests to.
148+
Cannot be updated.
149+
In CamelCase.
150+
More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds
151+
type: string
152+
lastCollectionTime:
153+
description: LastCollectionTime is when metrics were last collected on
154+
the member cluster.
155+
format: date-time
156+
type: string
157+
lastReportTime:
158+
description: LastReportTime is when this report was last synced to the
159+
hub.
160+
format: date-time
161+
type: string
162+
metadata:
163+
type: object
164+
observedGeneration:
165+
description: ObservedGeneration is the generation most recently observed
166+
from the MetricCollector.
167+
format: int64
168+
type: integer
169+
workloadsMonitored:
170+
description: WorkloadsMonitored is the count of workloads being monitored.
171+
format: int32
172+
type: integer
173+
type: object
174+
served: true
175+
storage: true
176+
subresources: {}

0 commit comments

Comments
 (0)