MCPcopy Index your code
hub / github.com/cloudnative-pg/cloudnative-pg / updateClusterLabels

Function updateClusterLabels

pkg/reconciler/instance/metadata.go:133–161  ·  view source on GitHub ↗

updateClusterLabels checks if there are labels in the cluster that are not present in the pods, and if so applies them. We do not support the case of removed labels from the cluster resource. Returns true if the instance needed updating

(
	ctx context.Context,
	cluster *apiv1.Cluster,
	instance *corev1.Pod,
)

Source from the content-addressed store, hash-verified

131//
132// Returns true if the instance needed updating
133func updateClusterLabels(
134 ctx context.Context,
135 cluster *apiv1.Cluster,
136 instance *corev1.Pod,
137) bool {
138 contextLogger := log.FromContext(ctx)
139
140 if instance.Labels == nil {
141 instance.Labels = make(map[string]string)
142 }
143
144 // if all the required labels are already set and with the correct value,
145 // there's nothing more to do
146 if utils.IsLabelSubset(instance.Labels, cluster.Labels, cluster.GetFixedInheritedLabels(),
147 configuration.Current) {
148 contextLogger.Trace(
149 "Skipping cluster label reconciliation, because they are already present on pod",
150 "pod", instance.Name,
151 "podLabels", instance.Labels,
152 "clusterLabels", cluster.Labels,
153 )
154 return false
155 }
156
157 // otherwise, we add the modified/new labels to the pod
158 contextLogger.Info("Updating cluster labels on pod", "pod", instance.Name)
159 utils.InheritLabels(&instance.ObjectMeta, cluster.Labels, cluster.GetFixedInheritedLabels(), configuration.Current)
160 return true
161}
162
163// Make sure that primary and replicas are correctly labelled as such
164//

Callers 2

ReconcileMetadataFunction · 0.85
metadata_test.goFile · 0.85

Calls 5

IsLabelSubsetFunction · 0.92
InheritLabelsFunction · 0.92
TraceMethod · 0.80
InfoMethod · 0.80

Tested by

no test coverage detected