Merge pull request #2089 from venkatbvc/gocylo_incremental_fix

Fix cyclomatic complexity in KSM files
This commit is contained in:
Kubernetes Prow Robot 2023-06-05 08:37:29 -07:00 committed by GitHub
commit 31d6e8fc26
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 323 additions and 279 deletions

View File

@ -55,7 +55,49 @@ var (
func hpaMetricFamilies(allowAnnotationsList, allowLabelsList []string) []generator.FamilyGenerator { func hpaMetricFamilies(allowAnnotationsList, allowLabelsList []string) []generator.FamilyGenerator {
return []generator.FamilyGenerator{ return []generator.FamilyGenerator{
*generator.NewFamilyGeneratorWithStability( createHPAInfo(),
createHPAMetaDataGeneration(),
createHPASpecMaxReplicas(),
createHPASpecMinReplicas(),
createHPASpecTargetMetric(),
createHPAStatusTargetMetric(),
createHPAStatusCurrentReplicas(),
createHPAStatusDesiredReplicas(),
createHPAAnnotations(allowAnnotationsList),
createHPALabels(allowLabelsList),
createHPAStatusCondition(),
}
}
func wrapHPAFunc(f func(*autoscaling.HorizontalPodAutoscaler) *metric.Family) func(interface{}) *metric.Family {
return func(obj interface{}) *metric.Family {
hpa := obj.(*autoscaling.HorizontalPodAutoscaler)
metricFamily := f(hpa)
for _, m := range metricFamily.Metrics {
m.LabelKeys, m.LabelValues = mergeKeyValues(descHorizontalPodAutoscalerLabelsDefaultLabels, []string{hpa.Namespace, hpa.Name}, m.LabelKeys, m.LabelValues)
}
return metricFamily
}
}
func createHPAListWatch(kubeClient clientset.Interface, ns string, fieldSelector string) cache.ListerWatcher {
return &cache.ListWatch{
ListFunc: func(opts metav1.ListOptions) (runtime.Object, error) {
opts.FieldSelector = fieldSelector
return kubeClient.AutoscalingV2().HorizontalPodAutoscalers(ns).List(context.TODO(), opts)
},
WatchFunc: func(opts metav1.ListOptions) (watch.Interface, error) {
opts.FieldSelector = fieldSelector
return kubeClient.AutoscalingV2().HorizontalPodAutoscalers(ns).Watch(context.TODO(), opts)
},
}
}
func createHPAInfo() generator.FamilyGenerator {
return *generator.NewFamilyGeneratorWithStability(
"kube_horizontalpodautoscaler_info", "kube_horizontalpodautoscaler_info",
"Information about this autoscaler.", "Information about this autoscaler.",
metric.Gauge, metric.Gauge,
@ -78,8 +120,11 @@ func hpaMetricFamilies(allowAnnotationsList, allowLabelsList []string) []generat
}, },
} }
}), }),
), )
*generator.NewFamilyGeneratorWithStability( }
func createHPAMetaDataGeneration() generator.FamilyGenerator {
return *generator.NewFamilyGeneratorWithStability(
"kube_horizontalpodautoscaler_metadata_generation", "kube_horizontalpodautoscaler_metadata_generation",
"The generation observed by the HorizontalPodAutoscaler controller.", "The generation observed by the HorizontalPodAutoscaler controller.",
metric.Gauge, metric.Gauge,
@ -94,8 +139,11 @@ func hpaMetricFamilies(allowAnnotationsList, allowLabelsList []string) []generat
}, },
} }
}), }),
), )
*generator.NewFamilyGeneratorWithStability( }
func createHPASpecMaxReplicas() generator.FamilyGenerator {
return *generator.NewFamilyGeneratorWithStability(
"kube_horizontalpodautoscaler_spec_max_replicas", "kube_horizontalpodautoscaler_spec_max_replicas",
"Upper limit for the number of pods that can be set by the autoscaler; cannot be smaller than MinReplicas.", "Upper limit for the number of pods that can be set by the autoscaler; cannot be smaller than MinReplicas.",
metric.Gauge, metric.Gauge,
@ -110,8 +158,11 @@ func hpaMetricFamilies(allowAnnotationsList, allowLabelsList []string) []generat
}, },
} }
}), }),
), )
*generator.NewFamilyGeneratorWithStability( }
func createHPASpecMinReplicas() generator.FamilyGenerator {
return *generator.NewFamilyGeneratorWithStability(
"kube_horizontalpodautoscaler_spec_min_replicas", "kube_horizontalpodautoscaler_spec_min_replicas",
"Lower limit for the number of pods that can be set by the autoscaler, default 1.", "Lower limit for the number of pods that can be set by the autoscaler, default 1.",
metric.Gauge, metric.Gauge,
@ -126,8 +177,11 @@ func hpaMetricFamilies(allowAnnotationsList, allowLabelsList []string) []generat
}, },
} }
}), }),
), )
*generator.NewFamilyGeneratorWithStability( }
func createHPASpecTargetMetric() generator.FamilyGenerator {
return *generator.NewFamilyGeneratorWithStability(
"kube_horizontalpodautoscaler_spec_target_metric", "kube_horizontalpodautoscaler_spec_target_metric",
"The metric specifications used by this autoscaler when calculating the desired replica count.", "The metric specifications used by this autoscaler when calculating the desired replica count.",
metric.Gauge, metric.Gauge,
@ -182,8 +236,11 @@ func hpaMetricFamilies(allowAnnotationsList, allowLabelsList []string) []generat
} }
return &metric.Family{Metrics: ms} return &metric.Family{Metrics: ms}
}), }),
), )
*generator.NewFamilyGeneratorWithStability( }
func createHPAStatusTargetMetric() generator.FamilyGenerator {
return *generator.NewFamilyGeneratorWithStability(
"kube_horizontalpodautoscaler_status_target_metric", "kube_horizontalpodautoscaler_status_target_metric",
"The current metric status used by this autoscaler when calculating the desired replica count.", "The current metric status used by this autoscaler when calculating the desired replica count.",
metric.Gauge, metric.Gauge,
@ -238,8 +295,11 @@ func hpaMetricFamilies(allowAnnotationsList, allowLabelsList []string) []generat
} }
return &metric.Family{Metrics: ms} return &metric.Family{Metrics: ms}
}), }),
), )
*generator.NewFamilyGeneratorWithStability( }
func createHPAStatusCurrentReplicas() generator.FamilyGenerator {
return *generator.NewFamilyGeneratorWithStability(
"kube_horizontalpodautoscaler_status_current_replicas", "kube_horizontalpodautoscaler_status_current_replicas",
"Current number of replicas of pods managed by this autoscaler.", "Current number of replicas of pods managed by this autoscaler.",
metric.Gauge, metric.Gauge,
@ -254,8 +314,11 @@ func hpaMetricFamilies(allowAnnotationsList, allowLabelsList []string) []generat
}, },
} }
}), }),
), )
*generator.NewFamilyGeneratorWithStability( }
func createHPAStatusDesiredReplicas() generator.FamilyGenerator {
return *generator.NewFamilyGeneratorWithStability(
"kube_horizontalpodautoscaler_status_desired_replicas", "kube_horizontalpodautoscaler_status_desired_replicas",
"Desired number of replicas of pods managed by this autoscaler.", "Desired number of replicas of pods managed by this autoscaler.",
metric.Gauge, metric.Gauge,
@ -270,8 +333,11 @@ func hpaMetricFamilies(allowAnnotationsList, allowLabelsList []string) []generat
}, },
} }
}), }),
), )
*generator.NewFamilyGeneratorWithStability( }
func createHPAAnnotations(allowAnnotationsList []string) generator.FamilyGenerator {
return *generator.NewFamilyGeneratorWithStability(
descHorizontalPodAutoscalerAnnotationsName, descHorizontalPodAutoscalerAnnotationsName,
descHorizontalPodAutoscalerAnnotationsHelp, descHorizontalPodAutoscalerAnnotationsHelp,
metric.Gauge, metric.Gauge,
@ -289,8 +355,11 @@ func hpaMetricFamilies(allowAnnotationsList, allowLabelsList []string) []generat
}, },
} }
}), }),
), )
*generator.NewFamilyGeneratorWithStability( }
func createHPALabels(allowLabelsList []string) generator.FamilyGenerator {
return *generator.NewFamilyGeneratorWithStability(
descHorizontalPodAutoscalerLabelsName, descHorizontalPodAutoscalerLabelsName,
descHorizontalPodAutoscalerLabelsHelp, descHorizontalPodAutoscalerLabelsHelp,
metric.Gauge, metric.Gauge,
@ -308,8 +377,11 @@ func hpaMetricFamilies(allowAnnotationsList, allowLabelsList []string) []generat
}, },
} }
}), }),
), )
*generator.NewFamilyGeneratorWithStability( }
func createHPAStatusCondition() generator.FamilyGenerator {
return *generator.NewFamilyGeneratorWithStability(
"kube_horizontalpodautoscaler_status_condition", "kube_horizontalpodautoscaler_status_condition",
"The condition of this autoscaler.", "The condition of this autoscaler.",
metric.Gauge, metric.Gauge,
@ -333,33 +405,5 @@ func hpaMetricFamilies(allowAnnotationsList, allowLabelsList []string) []generat
Metrics: ms, Metrics: ms,
} }
}), }),
), )
}
}
func wrapHPAFunc(f func(*autoscaling.HorizontalPodAutoscaler) *metric.Family) func(interface{}) *metric.Family {
return func(obj interface{}) *metric.Family {
hpa := obj.(*autoscaling.HorizontalPodAutoscaler)
metricFamily := f(hpa)
for _, m := range metricFamily.Metrics {
m.LabelKeys, m.LabelValues = mergeKeyValues(descHorizontalPodAutoscalerLabelsDefaultLabels, []string{hpa.Namespace, hpa.Name}, m.LabelKeys, m.LabelValues)
}
return metricFamily
}
}
func createHPAListWatch(kubeClient clientset.Interface, ns string, fieldSelector string) cache.ListerWatcher {
return &cache.ListWatch{
ListFunc: func(opts metav1.ListOptions) (runtime.Object, error) {
opts.FieldSelector = fieldSelector
return kubeClient.AutoscalingV2().HorizontalPodAutoscalers(ns).List(context.TODO(), opts)
},
WatchFunc: func(opts metav1.ListOptions) (watch.Interface, error) {
opts.FieldSelector = fieldSelector
return kubeClient.AutoscalingV2().HorizontalPodAutoscalers(ns).Watch(context.TODO(), opts)
},
}
} }