Merge pull request #2089 from venkatbvc/gocylo_incremental_fix
Fix cyclomatic complexity in KSM files
This commit is contained in:
commit
31d6e8fc26
|
|
@ -55,7 +55,49 @@ var (
|
|||
|
||||
func hpaMetricFamilies(allowAnnotationsList, allowLabelsList []string) []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",
|
||||
"Information about this autoscaler.",
|
||||
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",
|
||||
"The generation observed by the HorizontalPodAutoscaler controller.",
|
||||
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",
|
||||
"Upper limit for the number of pods that can be set by the autoscaler; cannot be smaller than MinReplicas.",
|
||||
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",
|
||||
"Lower limit for the number of pods that can be set by the autoscaler, default 1.",
|
||||
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",
|
||||
"The metric specifications used by this autoscaler when calculating the desired replica count.",
|
||||
metric.Gauge,
|
||||
|
|
@ -182,8 +236,11 @@ func hpaMetricFamilies(allowAnnotationsList, allowLabelsList []string) []generat
|
|||
}
|
||||
return &metric.Family{Metrics: ms}
|
||||
}),
|
||||
),
|
||||
*generator.NewFamilyGeneratorWithStability(
|
||||
)
|
||||
}
|
||||
|
||||
func createHPAStatusTargetMetric() generator.FamilyGenerator {
|
||||
return *generator.NewFamilyGeneratorWithStability(
|
||||
"kube_horizontalpodautoscaler_status_target_metric",
|
||||
"The current metric status used by this autoscaler when calculating the desired replica count.",
|
||||
metric.Gauge,
|
||||
|
|
@ -238,8 +295,11 @@ func hpaMetricFamilies(allowAnnotationsList, allowLabelsList []string) []generat
|
|||
}
|
||||
return &metric.Family{Metrics: ms}
|
||||
}),
|
||||
),
|
||||
*generator.NewFamilyGeneratorWithStability(
|
||||
)
|
||||
}
|
||||
|
||||
func createHPAStatusCurrentReplicas() generator.FamilyGenerator {
|
||||
return *generator.NewFamilyGeneratorWithStability(
|
||||
"kube_horizontalpodautoscaler_status_current_replicas",
|
||||
"Current number of replicas of pods managed by this autoscaler.",
|
||||
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",
|
||||
"Desired number of replicas of pods managed by this autoscaler.",
|
||||
metric.Gauge,
|
||||
|
|
@ -270,8 +333,11 @@ func hpaMetricFamilies(allowAnnotationsList, allowLabelsList []string) []generat
|
|||
},
|
||||
}
|
||||
}),
|
||||
),
|
||||
*generator.NewFamilyGeneratorWithStability(
|
||||
)
|
||||
}
|
||||
|
||||
func createHPAAnnotations(allowAnnotationsList []string) generator.FamilyGenerator {
|
||||
return *generator.NewFamilyGeneratorWithStability(
|
||||
descHorizontalPodAutoscalerAnnotationsName,
|
||||
descHorizontalPodAutoscalerAnnotationsHelp,
|
||||
metric.Gauge,
|
||||
|
|
@ -289,8 +355,11 @@ func hpaMetricFamilies(allowAnnotationsList, allowLabelsList []string) []generat
|
|||
},
|
||||
}
|
||||
}),
|
||||
),
|
||||
*generator.NewFamilyGeneratorWithStability(
|
||||
)
|
||||
}
|
||||
|
||||
func createHPALabels(allowLabelsList []string) generator.FamilyGenerator {
|
||||
return *generator.NewFamilyGeneratorWithStability(
|
||||
descHorizontalPodAutoscalerLabelsName,
|
||||
descHorizontalPodAutoscalerLabelsHelp,
|
||||
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",
|
||||
"The condition of this autoscaler.",
|
||||
metric.Gauge,
|
||||
|
|
@ -333,33 +405,5 @@ func hpaMetricFamilies(allowAnnotationsList, allowLabelsList []string) []generat
|
|||
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)
|
||||
},
|
||||
}
|
||||
)
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue