Skip to content

Commit 8bd0052

Browse files
committed
Add some feedback
1 parent 63218f3 commit 8bd0052

File tree

5 files changed

+23
-22
lines changed

5 files changed

+23
-22
lines changed

cmd/gateway/commands.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,7 @@ func createStaticModeCommand() *cobra.Command {
153153
PodIP: podIP,
154154
ServiceName: serviceName.value,
155155
Namespace: namespace,
156+
Name: podName,
156157
},
157158
HealthConfig: config.HealthConfig{
158159
Enabled: !disableHealth,

deploy/helm-chart/templates/rbac.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ rules:
3636
- create
3737
- patch
3838
- apiGroups:
39-
- "apps"
39+
- apps
4040
resources:
4141
- replicasets
4242
verbs:

internal/mode/static/config/config.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ type GatewayPodConfig struct {
4848
ServiceName string
4949
// Namespace is the namespace of this Pod.
5050
Namespace string
51+
// Name is the name of the Pod.
52+
Name string
5153
}
5254

5355
// MetricsConfig specifies the metrics config.

internal/mode/static/manager.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ func StartManager(cfg config.Config) error {
222222
Version: cfg.Version,
223223
PodNSName: types.NamespacedName{
224224
Namespace: cfg.GatewayPodConfig.Namespace,
225-
Name: cfg.LeaderElection.Identity,
225+
Name: cfg.GatewayPodConfig.Name,
226226
},
227227
})
228228
if err = mgr.Add(createTelemetryJob(cfg, dataCollector, nginxChecker.getReadyCh())); err != nil {

internal/mode/static/telemetry/collector.go

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -161,37 +161,35 @@ func collectGraphResourceCount(
161161

162162
func collectNGFReplicaCount(ctx context.Context, k8sClient client.Reader, podNSName types.NamespacedName) (int, error) {
163163
var pod v1.Pod
164-
if err := k8sClient.Get(ctx,
164+
if err := k8sClient.Get(
165+
ctx,
165166
types.NamespacedName{Namespace: podNSName.Namespace, Name: podNSName.Name},
166167
&pod,
167168
); err != nil {
168169
return 0, err
169170
}
170171

171172
podOwnerRefs := pod.GetOwnerReferences()
172-
if podOwnerRefs == nil {
173-
return 0, errors.New("could not get owner reference of NGF Pod")
174-
}
175173
if len(podOwnerRefs) != 1 {
176-
return 0, errors.New("multiple owner references of NGF Pod")
174+
return 0, fmt.Errorf("expected one owner reference of the NGF Pod, got %d", len(podOwnerRefs))
177175
}
178176

179-
switch kind := podOwnerRefs[0].Kind; kind {
180-
case "ReplicaSet":
181-
var replicaSet appsv1.ReplicaSet
182-
if err := k8sClient.Get(ctx,
183-
types.NamespacedName{Namespace: podNSName.Namespace, Name: podOwnerRefs[0].Name},
184-
&replicaSet,
185-
); err != nil {
186-
return 0, err
187-
}
177+
if podOwnerRefs[0].Kind != "ReplicaSet" {
178+
return 0, fmt.Errorf("expected pod owner reference to be ReplicaSet, got %s", podOwnerRefs[0].Kind)
179+
}
188180

189-
if replicaSet.Spec.Replicas == nil {
190-
return 0, errors.New("replica set replicas was nil")
191-
}
181+
var replicaSet appsv1.ReplicaSet
182+
if err := k8sClient.Get(
183+
ctx,
184+
types.NamespacedName{Namespace: podNSName.Namespace, Name: podOwnerRefs[0].Name},
185+
&replicaSet,
186+
); err != nil {
187+
return 0, err
188+
}
192189

193-
return int(*replicaSet.Spec.Replicas), nil
194-
default:
195-
return 0, fmt.Errorf("pod owner reference was not ReplicaSet, instead was %s", kind)
190+
if replicaSet.Spec.Replicas == nil {
191+
return 0, errors.New("replica set replicas was nil")
196192
}
193+
194+
return int(*replicaSet.Spec.Replicas), nil
197195
}

0 commit comments

Comments
 (0)