func CopyPodTemplates()

in controllers/util/common.go [411:526]


func CopyPodTemplates(from, to *corev1.PodTemplateSpec, basePath string, logger logr.Logger) (requireUpdate bool) {
	if basePath == "" {
		logger = logger.WithValues("kind", "pod")
	}
	if !DeepEqualWithNils(to.Labels, from.Labels) {
		requireUpdate = true
		logger.Info("Update required because field changed", "field", basePath+"Labels", "from", to.Labels, "to", from.Labels)
		to.Labels = from.Labels
	}

	if !DeepEqualWithNils(to.Annotations, from.Annotations) {
		requireUpdate = true
		logger.Info("Update required because field changed", "field", basePath+"Annotations", "from", to.Annotations, "to", from.Annotations)
		to.Annotations = from.Annotations
	}

	requireUpdate = CopyPodContainers(&from.Spec.Containers, &to.Spec.Containers, basePath+"Spec.Containers", logger) || requireUpdate

	requireUpdate = CopyPodContainers(&from.Spec.InitContainers, &to.Spec.InitContainers, basePath+"Spec.InitContainers", logger) || requireUpdate

	requireUpdate = CopyPodVolumes(&from.Spec.Volumes, &to.Spec.Volumes, basePath+"Spec.Volumes", logger) || requireUpdate

	if !DeepEqualWithNils(to.Spec.HostAliases, from.Spec.HostAliases) {
		hostAliasUpdate := false
		if to.Spec.HostAliases == nil {
			hostAliasUpdate = true
			to.Spec.HostAliases = from.Spec.HostAliases
		} else {
			// Do not remove aliases that are no longer used.
			// This is in case Solr is scaling down and we want to keep the old addresses for future use.
			for _, fromAlias := range from.Spec.HostAliases {
				found := false
				for i, toAlias := range to.Spec.HostAliases {
					if fromAlias.Hostnames[0] == toAlias.Hostnames[0] {
						found = true
						if !DeepEqualWithNils(toAlias, fromAlias) {
							hostAliasUpdate = true
							to.Spec.HostAliases[i] = fromAlias
							break
						}
					}
				}
				if !found {
					hostAliasUpdate = true
					to.Spec.HostAliases = append(to.Spec.HostAliases, fromAlias)
				}
			}
		}
		if hostAliasUpdate {
			requireUpdate = true
			logger.Info("Update required because field changed", "field", basePath+"Spec.HostAliases", "from", to.Spec.HostAliases, "to", from.Spec.HostAliases)
		}
	}

	if !DeepEqualWithNils(to.Spec.ImagePullSecrets, from.Spec.ImagePullSecrets) {
		requireUpdate = true
		logger.Info("Update required because field changed", "field", basePath+"Spec.ImagePullSecrets", "from", to.Spec.ImagePullSecrets, "to", from.Spec.ImagePullSecrets)
		to.Spec.ImagePullSecrets = from.Spec.ImagePullSecrets
	}

	if !DeepEqualWithNils(to.Spec.Affinity, from.Spec.Affinity) {
		requireUpdate = true
		logger.Info("Update required because field changed", "field", basePath+"Spec.Affinity", "from", to.Spec.Affinity, "to", from.Spec.Affinity)
		to.Spec.Affinity = from.Spec.Affinity
	}

	if !DeepEqualWithNils(to.Spec.SecurityContext, from.Spec.SecurityContext) {
		requireUpdate = true
		logger.Info("Update required because field changed", "field", basePath+"Spec.SecurityContext", "from", to.Spec.SecurityContext, "to", from.Spec.SecurityContext)
		to.Spec.SecurityContext = from.Spec.SecurityContext
	}

	if !DeepEqualWithNils(to.Spec.NodeSelector, from.Spec.NodeSelector) {
		requireUpdate = true
		logger.Info("Update required because field changed", "field", basePath+"Spec.NodeSelector", "from", to.Spec.NodeSelector, "to", from.Spec.NodeSelector)
		to.Spec.NodeSelector = from.Spec.NodeSelector
	}

	if !DeepEqualWithNils(to.Spec.Tolerations, from.Spec.Tolerations) {
		requireUpdate = true
		logger.Info("Update required because field changed", "field", basePath+"Spec.Tolerations", "from", to.Spec.Tolerations, "to", from.Spec.Tolerations)
		to.Spec.Tolerations = from.Spec.Tolerations
	}

	if !DeepEqualWithNils(to.Spec.PriorityClassName, from.Spec.PriorityClassName) {
		requireUpdate = true
		logger.Info("Update required because field changed", "field", basePath+"Spec.PriorityClassName", "from", to.Spec.PriorityClassName, "to", from.Spec.PriorityClassName)
		to.Spec.PriorityClassName = from.Spec.PriorityClassName
	}

	if !DeepEqualWithNils(to.Spec.TerminationGracePeriodSeconds, from.Spec.TerminationGracePeriodSeconds) {
		requireUpdate = true
		logger.Info("Update required because field changed", "field", basePath+"Spec.TerminationGracePeriodSeconds", "from", to.Spec.TerminationGracePeriodSeconds, "to", from.Spec.TerminationGracePeriodSeconds)
		to.Spec.TerminationGracePeriodSeconds = from.Spec.TerminationGracePeriodSeconds
	}

	if !DeepEqualWithNils(to.Spec.ServiceAccountName, from.Spec.ServiceAccountName) {
		requireUpdate = true
		logger.Info("Update required because field changed", "field", basePath+"Spec.ServiceAccountName", "from", to.Spec.ServiceAccountName, "to", from.Spec.ServiceAccountName)
		to.Spec.ServiceAccountName = from.Spec.ServiceAccountName
	}

	if !DeepEqualWithNils(to.Spec.TopologySpreadConstraints, from.Spec.TopologySpreadConstraints) {
		requireUpdate = true
		logger.Info("Update required because field changed", "field", basePath+"Spec.TopologySpreadConstraints", "from", to.Spec.TopologySpreadConstraints, "to", from.Spec.TopologySpreadConstraints)
		to.Spec.TopologySpreadConstraints = from.Spec.TopologySpreadConstraints
	}

	if !DeepEqualWithNils(to.Spec.ReadinessGates, from.Spec.ReadinessGates) {
		requireUpdate = true
		logger.Info("Update required because field changed", "field", basePath+"Spec.ReadinessGates", "from", to.Spec.ReadinessGates, "to", from.Spec.ReadinessGates)
		to.Spec.ReadinessGates = from.Spec.ReadinessGates
	}

	return requireUpdate
}