MCPcopy Create free account
hub / github.com/cloudnative-pg/cloudnative-pg / updateOperatorLabels

Function updateOperatorLabels

pkg/reconciler/instance/metadata.go:224–248  ·  view source on GitHub ↗

updateOperatorLabels ensures that the instances are labelled as instances, and have the correct instance name Returns true if the instance needed updating

(
	ctx context.Context,
	instance *corev1.Pod,
)

Source from the content-addressed store, hash-verified

222//
223// Returns true if the instance needed updating
224func updateOperatorLabels(
225 ctx context.Context,
226 instance *corev1.Pod,
227) bool {
228 contextLogger := log.FromContext(ctx)
229
230 if instance.Labels == nil {
231 instance.Labels = make(map[string]string)
232 }
233
234 var modified bool
235 if instance.Labels[utils.InstanceNameLabelName] != instance.Name {
236 contextLogger.Info("Setting instance label name", "pod", instance.Name)
237 instance.Labels[utils.InstanceNameLabelName] = instance.Name
238 modified = true
239 }
240
241 if instance.Labels[utils.PodRoleLabelName] != string(utils.PodRoleInstance) {
242 contextLogger.Info("Setting pod role label name", "pod", instance.Name)
243 instance.Labels[utils.PodRoleLabelName] = string(utils.PodRoleInstance)
244 modified = true
245 }
246
247 return modified
248}

Callers 2

ReconcileMetadataFunction · 0.85
metadata_test.goFile · 0.85

Calls 1

InfoMethod · 0.80

Tested by

no test coverage detected