Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 11 additions & 7 deletions internal/store/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -271,12 +271,16 @@ func deploymentMetricFamilies(allowAnnotationsList, allowLabelsList []string) []
basemetrics.STABLE,
"",
wrapDeploymentFunc(func(d *v1.Deployment) *metric.Family {
ms := []*metric.Metric{}

if d.Spec.Replicas != nil {
ms = append(ms, &metric.Metric{
Value: float64(*d.Spec.Replicas),
})
}

return &metric.Family{
Metrics: []*metric.Metric{
{
Value: float64(*d.Spec.Replicas),
},
},
Metrics: ms,
}
}),
),
Expand All @@ -303,7 +307,7 @@ func deploymentMetricFamilies(allowAnnotationsList, allowLabelsList []string) []
basemetrics.STABLE,
"",
wrapDeploymentFunc(func(d *v1.Deployment) *metric.Family {
if d.Spec.Strategy.RollingUpdate == nil {
if d.Spec.Strategy.RollingUpdate == nil || d.Spec.Replicas == nil {
return &metric.Family{}
}

Expand All @@ -328,7 +332,7 @@ func deploymentMetricFamilies(allowAnnotationsList, allowLabelsList []string) []
basemetrics.STABLE,
"",
wrapDeploymentFunc(func(d *v1.Deployment) *metric.Family {
if d.Spec.Strategy.RollingUpdate == nil {
if d.Spec.Strategy.RollingUpdate == nil || d.Spec.Replicas == nil {
return &metric.Family{}
}

Expand Down
29 changes: 29 additions & 0 deletions internal/store/deployment_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,35 @@ func TestDeploymentStore(t *testing.T) {
kube_deployment_status_replicas_updated{deployment="deployment-without-owner",namespace="ns5"} 0
`,
},
{
Obj: &v1.Deployment{
ObjectMeta: metav1.ObjectMeta{
Name: "deployment-nil-replicas",
Namespace: "ns6",
},
Spec: v1.DeploymentSpec{
Strategy: v1.DeploymentStrategy{
RollingUpdate: &v1.RollingUpdateDeployment{
MaxUnavailable: &depl1MaxUnavailable,
MaxSurge: &depl1MaxSurge,
},
},
},
},
Want: `
# HELP kube_deployment_spec_replicas [STABLE] Number of desired pods for a deployment.
# TYPE kube_deployment_spec_replicas gauge
# HELP kube_deployment_spec_strategy_rollingupdate_max_unavailable [STABLE] Maximum number of unavailable replicas during a rolling update of a deployment.
# TYPE kube_deployment_spec_strategy_rollingupdate_max_unavailable gauge
# HELP kube_deployment_spec_strategy_rollingupdate_max_surge [STABLE] Maximum number of replicas that can be scheduled above the desired number of replicas during a rolling update of a deployment.
# TYPE kube_deployment_spec_strategy_rollingupdate_max_surge gauge
`,
MetricNames: []string{
"kube_deployment_spec_replicas",
"kube_deployment_spec_strategy_rollingupdate_max_unavailable",
"kube_deployment_spec_strategy_rollingupdate_max_surge",
},
},
}
for i, c := range cases {
c.Func = generator.ComposeMetricGenFuncs(deploymentMetricFamilies(c.AllowAnnotationsList, nil))
Expand Down