From 0e142c41cfc5c4443daf934236cdc99d735d9e8b Mon Sep 17 00:00:00 2001 From: Simon Pasquier Date: Fri, 12 Jan 2024 15:14:38 +0100 Subject: [PATCH] chore: avoid issues with std.set* functions Functions like std.setMember() expect the input array to be sorted without duplicates. Signed-off-by: Simon Pasquier --- jsonnet/main.jsonnet | 6 +++--- jsonnet/utils/add-annotations.libsonnet | 4 ++-- jsonnet/utils/add-labels.libsonnet | 2 +- jsonnet/utils/remove-limits.libsonnet | 2 +- jsonnet/utils/set-terminationMessagePolicy.libsonnet | 4 ++-- manifests/0000_50_cluster-monitoring-operator_02-role.yaml | 2 +- 6 files changed, 10 insertions(+), 10 deletions(-) diff --git a/jsonnet/main.jsonnet b/jsonnet/main.jsonnet index 974d7a577b..5fa14e1523 100644 --- a/jsonnet/main.jsonnet +++ b/jsonnet/main.jsonnet @@ -140,7 +140,7 @@ local inCluster = $.controlPlane.mixin.grafanaDashboards + $.controlPlane.etcdMixin.grafanaDashboards, // Allow-listing dashboards that are going into the product. List needs to be sorted for std.setMember to work - local includeDashboards = [ + local includeDashboards = std.set([ 'cluster-total.json', 'etcd.json', 'k8s-resources-cluster.json', @@ -154,7 +154,7 @@ local inCluster = 'node-rsrc-use.json', 'pod-total.json', 'prometheus.json', - ], + ]), // This step is to delete row with titles 'Storage IO - Distribution(Containers)' // and 'Storage IO - Distribution' from 'k8s-resources-pod.json' dashboard since // Prometheus doesn't collect the per-container fs metrics @@ -163,7 +163,7 @@ local inCluster = }, local filterDashboard(dashboard, excludedRowTitles) = dashboard { rows: std.filter(function(row) !std.member(excludedRowTitles, row.title), dashboard.rows) }, dashboards: { - [k]: filterDashboard(allDashboards[k], if std.setMember(k, std.objectFields(filteredDashboards)) then filteredDashboards[k] else []) + [k]: filterDashboard(allDashboards[k], if std.setMember(k, std.set(std.objectFields(filteredDashboards))) then filteredDashboards[k] else []) for k in std.objectFields(allDashboards) if std.setMember(k, includeDashboards) }, diff --git a/jsonnet/utils/add-annotations.libsonnet b/jsonnet/utils/add-annotations.libsonnet index 8fd735c4bc..41f2a5b58d 100644 --- a/jsonnet/utils/add-annotations.libsonnet +++ b/jsonnet/utils/add-annotations.libsonnet @@ -29,14 +29,14 @@ 'target.workload.openshift.io/management': '{"effect": "PreferredDuringScheduling"}', }, local addAnnotation(o) = o { - [if std.setMember(o.kind, ['DaemonSet', 'Deployment', 'ReplicaSet']) then 'spec']+: { + [if std.setMember(o.kind, std.set(['DaemonSet', 'Deployment'])) then 'spec']+: { template+: { metadata+: { annotations+: annotation, }, }, }, - [if std.setMember(o.kind, ['Alertmanager', 'Prometheus', 'ThanosRuler']) then 'spec']+: + [if std.setMember(o.kind, std.set(['Alertmanager', 'Prometheus', 'ThanosRuler'])) then 'spec']+: { podMetadata+: { annotations+: annotation, diff --git a/jsonnet/utils/add-labels.libsonnet b/jsonnet/utils/add-labels.libsonnet index 671edd5427..1373a7bb97 100644 --- a/jsonnet/utils/add-labels.libsonnet +++ b/jsonnet/utils/add-labels.libsonnet @@ -2,7 +2,7 @@ local managedBy(o) = local name = o.metadata.name; // Some of the resources which are generated by jsonnet are moved under manifests/ and managed by CVO. - if o.kind == 'CustomResourceDefinition' || (o.kind == 'Role' && name == 'cluster-monitoring-operator-alert-customization') || (o.kind == 'Deployment' && name == 'cluster-monitoring-operator') || (o.kind == 'ClusterRole' && std.setMember(name, ['cluster-monitoring-operator-namespaced', 'cluster-monitoring-operator'])) then + if o.kind == 'CustomResourceDefinition' || (o.kind == 'Role' && name == 'cluster-monitoring-operator-alert-customization') || (o.kind == 'Deployment' && name == 'cluster-monitoring-operator') || (o.kind == 'ClusterRole' && std.setMember(name, std.set(['cluster-monitoring-operator-namespaced', 'cluster-monitoring-operator']))) then 'cluster-version-operator' else 'cluster-monitoring-operator', diff --git a/jsonnet/utils/remove-limits.libsonnet b/jsonnet/utils/remove-limits.libsonnet index 621e5ae1ea..61fd50aaf1 100644 --- a/jsonnet/utils/remove-limits.libsonnet +++ b/jsonnet/utils/remove-limits.libsonnet @@ -1,7 +1,7 @@ { removeLimits(o): { local removeLimit(o) = o { - [if std.setMember(o.kind, ['DaemonSet', 'Deployment', 'ReplicaSet']) then 'spec']+: { + [if std.setMember(o.kind, std.set(['DaemonSet', 'Deployment'])) then 'spec']+: { template+: { spec+: { containers: [ diff --git a/jsonnet/utils/set-terminationMessagePolicy.libsonnet b/jsonnet/utils/set-terminationMessagePolicy.libsonnet index 44467c53e3..97476917ea 100644 --- a/jsonnet/utils/set-terminationMessagePolicy.libsonnet +++ b/jsonnet/utils/set-terminationMessagePolicy.libsonnet @@ -1,7 +1,7 @@ { setTerminationMessagePolicy(o): o { local addTerminationMessagePolicy(o) = o { - [if std.setMember(o.kind, ['DaemonSet', 'Deployment', 'ReplicaSet']) then 'spec']+: { + [if std.setMember(o.kind, std.set(['DaemonSet', 'Deployment'])) then 'spec']+: { template+: { spec+: { containers: [ @@ -19,7 +19,7 @@ }, }, }, - [if std.setMember(o.kind, ['Alertmanager', 'Prometheus', 'ThanosRuler']) then 'spec']+: { + [if std.setMember(o.kind, std.set(['Alertmanager', 'Prometheus', 'ThanosRuler'])) then 'spec']+: { containers: [ c { terminationMessagePolicy: 'FallbackToLogsOnError', diff --git a/manifests/0000_50_cluster-monitoring-operator_02-role.yaml b/manifests/0000_50_cluster-monitoring-operator_02-role.yaml index 3540c307b3..cf765885c9 100644 --- a/manifests/0000_50_cluster-monitoring-operator_02-role.yaml +++ b/manifests/0000_50_cluster-monitoring-operator_02-role.yaml @@ -6,7 +6,7 @@ metadata: include.release.openshift.io/self-managed-high-availability: "true" include.release.openshift.io/single-node-developer: "true" labels: - app.kubernetes.io/managed-by: cluster-monitoring-operator + app.kubernetes.io/managed-by: cluster-version-operator app.kubernetes.io/part-of: openshift-monitoring name: cluster-monitoring-operator rules: