1
0
mirror of https://github.com/coreos/prometheus-operator.git synced 2026-02-05 15:46:31 +01:00

Chore: rename internal/util package to sortutil (#7719)

* rename internal/util -> internal/sortutil
This commit is contained in:
M Viswanath Sai
2025-07-22 14:40:33 +05:30
committed by GitHub
parent 2f4bf6aea1
commit baf40889d1
8 changed files with 21 additions and 21 deletions

View File

@@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
package util
package sortutil
import (
"cmp"

View File

@@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
package util
package sortutil
import (
"testing"

View File

@@ -34,7 +34,7 @@ import (
"k8s.io/apimachinery/pkg/types"
"k8s.io/utils/ptr"
"github.com/prometheus-operator/prometheus-operator/internal/util"
sortutil "github.com/prometheus-operator/prometheus-operator/internal/sortutil"
"github.com/prometheus-operator/prometheus-operator/pkg/alertmanager/validation"
monitoringv1 "github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring/v1"
monitoringv1alpha1 "github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring/v1alpha1"
@@ -344,7 +344,7 @@ func (cb *ConfigBuilder) InitializeFromRawConfiguration(b []byte) error {
// AddAlertmanagerConfigs adds AlertmanagerConfig objects to the current configuration.
func (cb *ConfigBuilder) AddAlertmanagerConfigs(ctx context.Context, amConfigs map[string]*monitoringv1alpha1.AlertmanagerConfig) error {
subRoutes := make([]*route, 0, len(amConfigs))
for _, amConfigIdentifier := range util.SortedKeys(amConfigs) {
for _, amConfigIdentifier := range sortutil.SortedKeys(amConfigs) {
crKey := types.NamespacedName{
Name: amConfigs[amConfigIdentifier].Name,
Namespace: amConfigs[amConfigIdentifier].Namespace,

View File

@@ -35,7 +35,7 @@ import (
corev1 "k8s.io/client-go/kubernetes/typed/core/v1"
"k8s.io/client-go/tools/cache"
"github.com/prometheus-operator/prometheus-operator/internal/util"
sortutil "github.com/prometheus-operator/prometheus-operator/internal/sortutil"
"github.com/prometheus-operator/prometheus-operator/pkg/k8sutil"
)
@@ -211,7 +211,7 @@ func TweakByLabel(options *metav1.ListOptions, label string, filter FilterType,
default:
panic(fmt.Sprintf("unsupported filter: %q", filter))
}
selectors := []string{fmt.Sprintf("%s %s (%s)", label, op, strings.Join(util.SortedKeys(valueSet), ","))}
selectors := []string{fmt.Sprintf("%s %s (%s)", label, op, strings.Join(sortutil.SortedKeys(valueSet), ","))}
if options.LabelSelector != "" {
selectors = append(selectors, options.LabelSelector)

View File

@@ -24,7 +24,7 @@ import (
"k8s.io/client-go/kubernetes"
corev1 "k8s.io/client-go/kubernetes/typed/core/v1"
"github.com/prometheus-operator/prometheus-operator/internal/util"
sortutil "github.com/prometheus-operator/prometheus-operator/internal/sortutil"
"github.com/prometheus-operator/prometheus-operator/pkg/k8sutil"
)
@@ -63,7 +63,7 @@ func (s *ShardedSecret) shard() []*v1.Secret {
secretSize := 0
currentSecret := s.newSecretAt(currentIndex)
for _, key := range util.SortedKeys(s.data) {
for _, key := range sortutil.SortedKeys(s.data) {
v := s.data[key]
vSize := len(key) + len(v)
if secretSize+vSize > MaxSecretDataSizeBytes {

View File

@@ -35,7 +35,7 @@ import (
"k8s.io/apimachinery/pkg/util/intstr"
"k8s.io/utils/ptr"
"github.com/prometheus-operator/prometheus-operator/internal/util"
sortutil "github.com/prometheus-operator/prometheus-operator/internal/sortutil"
monitoringv1 "github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring/v1"
monitoringv1alpha1 "github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring/v1alpha1"
"github.com/prometheus-operator/prometheus-operator/pkg/assets"
@@ -487,7 +487,7 @@ func (cg *ConfigGenerator) addNativeHistogramConfig(cfg yaml.MapSlice, nhc monit
func stringMapToMapSlice[V any](m map[string]V) yaml.MapSlice {
res := yaml.MapSlice{}
for _, k := range util.SortedKeys(m) {
for _, k := range sortutil.SortedKeys(m) {
res = append(res, yaml.MapItem{Key: k, Value: m[k]})
}
@@ -1370,7 +1370,7 @@ func (cg *ConfigGenerator) generatePodMonitorConfig(
// If roleSelector is set, we don't need to add the service labels to the relabeling rules.
if ptr.Deref(m.Spec.SelectorMechanism, monitoringv1.SelectorMechanismRelabel) == monitoringv1.SelectorMechanismRelabel {
for _, k := range util.SortedKeys(m.Spec.Selector.MatchLabels) {
for _, k := range sortutil.SortedKeys(m.Spec.Selector.MatchLabels) {
relabelings = append(relabelings, yaml.MapSlice{
{Key: "action", Value: "keep"},
{Key: "source_labels", Value: []string{"__meta_kubernetes_pod_label_" + sanitizeLabelName(k), "__meta_kubernetes_pod_labelpresent_" + sanitizeLabelName(k)}},
@@ -1661,7 +1661,7 @@ func (cg *ConfigGenerator) generateProbeConfig(
// Generate kubernetes_sd_config section for the ingress resources.
// Filter targets by ingresses selected by the monitor.
// Exact label matches.
for _, k := range util.SortedKeys(m.Spec.Targets.Ingress.Selector.MatchLabels) {
for _, k := range sortutil.SortedKeys(m.Spec.Targets.Ingress.Selector.MatchLabels) {
relabelings = append(relabelings, yaml.MapSlice{
{Key: "action", Value: "keep"},
{Key: "source_labels", Value: []string{"__meta_kubernetes_ingress_label_" + sanitizeLabelName(k), "__meta_kubernetes_ingress_labelpresent_" + sanitizeLabelName(k)}},
@@ -1871,7 +1871,7 @@ func (cg *ConfigGenerator) generateServiceMonitorConfig(
// Exact label matches.
// If roleSelector is set, we don't need to add the service labels to the relabeling rules.
if ptr.Deref(m.Spec.SelectorMechanism, monitoringv1.SelectorMechanismRelabel) == monitoringv1.SelectorMechanismRelabel {
for _, k := range util.SortedKeys(m.Spec.Selector.MatchLabels) {
for _, k := range sortutil.SortedKeys(m.Spec.Selector.MatchLabels) {
relabelings = append(relabelings, yaml.MapSlice{
{Key: "action", Value: "keep"},
{Key: "source_labels", Value: []string{"__meta_kubernetes_service_label_" + sanitizeLabelName(k), "__meta_kubernetes_service_labelpresent_" + sanitizeLabelName(k)}},
@@ -2943,7 +2943,7 @@ func (cg *ConfigGenerator) appendServiceMonitorConfigs(
store *assets.StoreBuilder,
shards int32) []yaml.MapSlice {
for _, identifier := range util.SortedKeys(serviceMonitors) {
for _, identifier := range sortutil.SortedKeys(serviceMonitors) {
for i, ep := range serviceMonitors[identifier].Spec.Endpoints {
slices = append(slices,
cg.WithKeyVals("service_monitor", identifier).generateServiceMonitorConfig(
@@ -2966,7 +2966,7 @@ func (cg *ConfigGenerator) appendPodMonitorConfigs(
store *assets.StoreBuilder,
shards int32) []yaml.MapSlice {
for _, identifier := range util.SortedKeys(podMonitors) {
for _, identifier := range sortutil.SortedKeys(podMonitors) {
for i, ep := range podMonitors[identifier].Spec.PodMetricsEndpoints {
slices = append(slices,
cg.WithKeyVals("pod_monitor", identifier).generatePodMonitorConfig(
@@ -2989,7 +2989,7 @@ func (cg *ConfigGenerator) appendProbeConfigs(
store *assets.StoreBuilder,
shards int32) []yaml.MapSlice {
for _, identifier := range util.SortedKeys(probes) {
for _, identifier := range sortutil.SortedKeys(probes) {
slices = append(slices,
cg.WithKeyVals("probe", identifier).generateProbeConfig(
probes[identifier],
@@ -3105,7 +3105,7 @@ func (cg *ConfigGenerator) appendScrapeConfigs(
store *assets.StoreBuilder,
shards int32) ([]yaml.MapSlice, error) {
for _, identifier := range util.SortedKeys(scrapeConfigs) {
for _, identifier := range sortutil.SortedKeys(scrapeConfigs) {
cfgGenerator := cg.WithKeyVals("scrapeconfig", identifier)
scrapeConfig, err := cfgGenerator.generateScrapeConfig(scrapeConfigs[identifier], store.ForNamespace(scrapeConfigs[identifier].GetNamespace()), shards)

View File

@@ -23,7 +23,7 @@ import (
v1 "k8s.io/api/core/v1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"github.com/prometheus-operator/prometheus-operator/internal/util"
sortutil "github.com/prometheus-operator/prometheus-operator/internal/sortutil"
"github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring"
monitoringv1 "github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring/v1"
namespacelabeler "github.com/prometheus-operator/prometheus-operator/pkg/namespacelabeler"
@@ -200,7 +200,7 @@ func makeRulesConfigMaps(p *monitoringv1.Prometheus, ruleFiles map[string]string
// To make bin packing algorithm deterministic, sort ruleFiles filenames and
// iterate over filenames instead of ruleFiles map (not deterministic).
for _, filename := range util.SortedKeys(ruleFiles) {
for _, filename := range sortutil.SortedKeys(ruleFiles) {
// If rule file doesn't fit into current bucket, create new bucket.
if bucketSize(buckets[currBucketIndex])+len(ruleFiles[filename]) > operator.MaxConfigMapDataSize {
buckets = append(buckets, map[string]string{})

View File

@@ -24,7 +24,7 @@ import (
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/utils/ptr"
"github.com/prometheus-operator/prometheus-operator/internal/util"
sortutil "github.com/prometheus-operator/prometheus-operator/internal/sortutil"
"github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring"
monitoringv1 "github.com/prometheus-operator/prometheus-operator/pkg/apis/monitoring/v1"
namespacelabeler "github.com/prometheus-operator/prometheus-operator/pkg/namespacelabeler"
@@ -202,7 +202,7 @@ func makeRulesConfigMaps(t *monitoringv1.ThanosRuler, ruleFiles map[string]strin
// To make bin packing algorithm deterministic, sort ruleFiles filenames and
// iterate over filenames instead of ruleFiles map (not deterministic).
for _, filename := range util.SortedKeys(ruleFiles) {
for _, filename := range sortutil.SortedKeys(ruleFiles) {
// If rule file doesn't fit into current bucket, create new bucket.
if bucketSize(buckets[currBucketIndex])+len(ruleFiles[filename]) > operator.MaxConfigMapDataSize {
buckets = append(buckets, map[string]string{})