Skip to content

Commit 3c8db43

Browse files
author
Arvind Thirumurugan
committed
address minor comments
Signed-off-by: Arvind Thirumurugan <arvindth@microsoft.com>
1 parent f3ea6d5 commit 3c8db43

File tree

6 files changed

+46
-25
lines changed

6 files changed

+46
-25
lines changed

approval-controller-metric-collector/README.md

Lines changed: 42 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ This solution introduces three new CRDs that work together with KubeFleet's nati
3232
3. **ClusterStagedWorkloadTracker** (cluster-scoped)
3333
- Defines which workloads to monitor for a ClusterStagedUpdateRun
3434
- The name must match the ClusterStagedUpdateRun name
35-
- Specifies namespace, workload name, and expected health status
35+
- Specifies workload's name, namespace and expected health status
3636
- Used by approval-request-controller to determine if stage is ready for approval
3737

3838
4. **StagedWorkloadTracker** (namespaced)
@@ -49,7 +49,7 @@ This solution introduces three new CRDs that work together with KubeFleet's nati
4949
- The ApprovalRequest enters "Pending" state, waiting for approval
5050

5151
2. **Metric Collector Deployment**
52-
- Approval-request-controller watches the CAR
52+
- Approval-request-controller watches the `ClusterApprovalRequest`, `ApprovalRequest` objects
5353
- Creates a `MetricCollector` resource on the hub (cluster-scoped)
5454
- Creates a `ClusterResourceOverride` with per-cluster customization rules
5555
- Each cluster gets a unique `reportNamespace`: `fleet-member-<cluster-name>`
@@ -127,6 +127,8 @@ cd approval-controller-metric-collector/approval-request-controller
127127
kubectl config use-context kind-hub
128128

129129
# Register member clusters with the hub
130+
# This creates MemberCluster resources for kind-cluster-1, kind-cluster-2, and kind-cluster-3
131+
# Each MemberCluster resource contains the API endpoint and credentials for the member cluster
130132
kubectl apply -f ./examples/membercluster/
131133

132134
# Verify clusters are registered
@@ -151,7 +153,12 @@ Create the prometheus namespace and deploy Prometheus for metrics collection:
151153
# Create prometheus namespace
152154
kubectl create ns prometheus
153155

154-
# Deploy Prometheus (ConfigMap, Deployment, Service, RBAC)
156+
# Deploy Prometheus (ConfigMap, Deployment, Service, RBAC, and CRP)
157+
# - ConfigMap: Contains Prometheus scrape configuration
158+
# - Deployment: Runs Prometheus server
159+
# - Service: Exposes Prometheus on port 9090
160+
# - RBAC: ServiceAccount, ClusterRole, and ClusterRoleBinding for pod discovery
161+
# - CRP: ClusterResourcePlacement to propagate Prometheus to all member clusters
155162
kubectl apply -f ./examples/prometheus/
156163
```
157164

@@ -165,7 +172,9 @@ Create the test namespace and deploy the sample application:
165172
# Create test namespace
166173
kubectl create ns test-ns
167174

168-
# Deploy sample metric app (this will be propagated to member clusters)
175+
# Deploy sample metric app
176+
# This creates a Deployment with a simple Go app that exposes a /metrics endpoint
177+
# The app reports workload_health=1.0 (healthy) by default
169178
kubectl apply -f ./examples/sample-metric-app/
170179
```
171180

@@ -193,15 +202,19 @@ Apply the appropriate workload tracker based on which type of staged update you'
193202

194203
```bash
195204
# Apply ClusterStagedWorkloadTracker
196-
# Important: The name must match your ClusterStagedUpdateRun name
205+
# This defines which workloads to monitor for the staged rollout
206+
# The name "example-cluster-staged-run" must match the ClusterStagedUpdateRun name
207+
# Tracks: sample-metric-app in test-ns namespace
197208
kubectl apply -f ./examples/workloadtracker/clusterstagedworkloadtracker.yaml
198209
```
199210

200211
#### For Namespace-Scoped Updates (StagedUpdateRun):
201212

202213
```bash
203214
# Apply StagedWorkloadTracker
204-
# Important: The name and namespace must match your StagedUpdateRun name and namespace
215+
# This defines which workloads to monitor for the namespace-scoped staged rollout
216+
# The name "example-staged-run" and namespace "test-ns" must match the StagedUpdateRun
217+
# Tracks: sample-metric-app in test-ns namespace
205218
kubectl apply -f ./examples/workloadtracker/stagedworkloadtracker.yaml
206219
```
207220

@@ -243,9 +256,13 @@ cd ../approval-request-controller
243256
kubectl config use-context kind-hub
244257

245258
# Apply ClusterStagedUpdateStrategy
259+
# Defines the stages for the rollout: staging (cluster-1) -> prod (cluster-2, cluster-3)
260+
# Each stage requires approval before proceeding
246261
kubectl apply -f ./examples/updateRun/example-csus.yaml
247262

248-
# Apply ClusterResourcePlacement
263+
# Apply ClusterResourcePlacement for sample-metric-app
264+
# This is the resource that will be updated across stages
265+
# Selects the sample-metric-app deployment in test-ns namespace
249266
kubectl apply -f ./examples/updateRun/example-crp.yaml
250267

251268
# Verify CRP is created
@@ -261,6 +278,9 @@ prometheus-crp 1 True 1 True 1
261278

262279
```bash
263280
# Apply ClusterStagedUpdateRun to start the staged rollout
281+
# This creates the actual update run that progresses through the defined stages
282+
# Name: example-cluster-staged-run (must match ClusterStagedWorkloadTracker)
283+
# References the ClusterResourcePlacement (example-crp) and ClusterStagedUpdateStrategy
264284
kubectl apply -f ./examples/updateRun/example-csur.yaml
265285

266286
# Check the staged update run status
@@ -286,6 +306,9 @@ kubectl config use-context kind-hub
286306

287307
``` bash
288308
# Apply namespace-scoped ClusterResourcePlacement
309+
# This CRP is configured to only place resources in the test-ns namespace
310+
# This resource is needed because we cannot propagate Namespace which is a
311+
# cluster-scoped resource via RP
289312
kubectl apply -f ./examples/updateRun/example-ns-only-crp.yaml
290313

291314
kubectl get crp -A
@@ -295,15 +318,18 @@ Output:
295318
```bash
296319
NAME GEN SCHEDULED SCHEDULED-GEN AVAILABLE AVAILABLE-GEN AGE
297320
ns-only-crp 1 True 1 True 1 5s
298-
proemetheus-crp 1 True 1 True 1 2m34s
321+
prometheus-crp 1 True 1 True 1 2m34s
299322
```
300323

301324
```bash
302-
# Apply StagedUpdateStrategy
325+
# Apply StagedUpdateStrategy (namespace-scoped)
326+
# Defines the stages: staging (cluster-1) -> prod (cluster-2, cluster-3)
327+
# Each stage requires approval before proceeding
303328
kubectl apply -f ./examples/updateRun/example-sus.yaml
304329

305-
```bash
306-
# Apply ResourcePlacement
330+
# Apply ResourcePlacement (namespace-scoped)
331+
# This is the namespace-scoped version that works with the test-ns namespace
332+
# References the ns-only-crp ClusterResourcePlacement
307333
kubectl apply -f ./examples/updateRun/example-rp.yaml
308334

309335
# Verify RP is created
@@ -317,7 +343,11 @@ test-ns example-rp 1 True 1
317343
```
318344

319345
```bash
320-
# Apply StagedUpdateRun to start the staged rollout
346+
# Apply StagedUpdateRun to start the staged rollout (namespace-scoped)
347+
# This creates the actual update run that progresses through the defined stages
348+
# Name: example-staged-run (must match StagedWorkloadTracker)
349+
# Namespace: test-ns (must match StagedWorkloadTracker namespace)
350+
# References the ResourcePlacement (example-rp)
321351
kubectl apply -f ./examples/updateRun/example-sur.yaml
322352

323353
# Check the staged update run status
@@ -389,13 +419,6 @@ fleet-member-kind-cluster-1 mc-example-staged-run-staging 1 27s
389419
```
390420

391421
The approval controller will automatically approve stages when the metric collectors report that workloads are healthy.
392-
1. Builds the `metric-collector:latest` image
393-
2. Builds the `metric-app:local` image
394-
3. Loads both images into each kind cluster
395-
4. Creates hub token secret with proper RBAC
396-
5. Installs the metric-collector via Helm
397-
398-
The `metric-app:local` image is pre-loaded so it's available when you propagate the sample-metric-app deployment from hub to member clusters.
399422

400423
## Verification
401424

approval-controller-metric-collector/approval-request-controller/apis/metric/v1alpha1/metriccollector_types.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ type MetricCollectorSpec struct {
6464
ReportNamespace string `json:"reportNamespace"`
6565
}
6666

67-
// MetricsEndpointSpec defines how to access the metrics endpoint.ctor.
67+
// MetricCollectorStatus defines the observed state of MetricCollector.
6868
type MetricCollectorStatus struct {
6969
// Conditions is an array of current observed conditions.
7070
// +optional

approval-controller-metric-collector/approval-request-controller/cmd/approvalrequestcontroller/main.go

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,11 +53,9 @@ func init() {
5353
func main() {
5454
var metricsAddr string
5555
var probeAddr string
56-
var logLevel int
5756

5857
flag.StringVar(&metricsAddr, "metrics-bind-address", ":8080", "The address the metric endpoint binds to.")
5958
flag.StringVar(&probeAddr, "health-probe-bind-address", ":8081", "The address the probe endpoint binds to.")
60-
flag.IntVar(&logLevel, "v", 2, "Log level (0-10)")
6159

6260
opts := zap.Options{
6361
Development: true,
@@ -67,7 +65,7 @@ func main() {
6765

6866
ctrl.SetLogger(zap.New(zap.UseFlagOptions(&opts)))
6967

70-
klog.InfoS("Starting ApprovalRequest Controller", "logLevel", logLevel)
68+
klog.InfoS("Starting ApprovalRequest Controller")
7169

7270
config := ctrl.GetConfigOrDie()
7371

approval-controller-metric-collector/approval-request-controller/examples/prometheus/prometheus-crp.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
apiVersion: placement.kubernetes-fleet.io/v1beta1
22
kind: ClusterResourcePlacement
33
metadata:
4-
name: proemetheus-crp
4+
name: prometheus-crp
55
spec:
66
resourceSelectors:
77
- group: ""

approval-controller-metric-collector/metric-collector/cmd/metriccollector/metric-app/main.go renamed to approval-controller-metric-collector/metric-collector/cmd/metric-app/main.go

File renamed without changes.

approval-controller-metric-collector/metric-collector/docker/metric-app.Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ RUN go mod init metric-app && \
88
go get github.com/prometheus/client_golang/prometheus/promhttp@latest
99

1010
# Copy source code
11-
COPY metric-collector/cmd/metriccollector/metric-app/ ./
11+
COPY metric-collector/cmd/metric-app/ ./
1212

1313
# Build the application
1414
RUN CGO_ENABLED=0 GOOS=linux go build -a -installsuffix cgo -o metric-app main.go

0 commit comments

Comments
 (0)