func Merge(commonSpecs []v1.JaegerCommonSpec) *v1.JaegerCommonSpec {
	annotations := make(map[string]string)
	labels := make(map[string]string)
	var volumeMounts []corev1.VolumeMount
	var volumes []corev1.Volume
	resources := &corev1.ResourceRequirements{}
	var affinity *corev1.Affinity
	var tolerations []corev1.Toleration
	var securityContext *corev1.PodSecurityContext
	var serviceAccount string
	for _, commonSpec := range commonSpecs {
		for k, v := range commonSpec.Annotations {
			if _, ok := annotations[k]; !ok {
				annotations[k] = v
			}
		}
		for k, v := range commonSpec.Labels {
			if _, ok := labels[k]; !ok {
				labels[k] = v
			}
		}
		volumeMounts = append(volumeMounts, commonSpec.VolumeMounts...)
		volumes = append(volumes, commonSpec.Volumes...)
		MergeResources(resources, commonSpec.Resources)
		if affinity == nil {
			affinity = commonSpec.Affinity
		}
		tolerations = append(tolerations, commonSpec.Tolerations...)
		if securityContext == nil {
			securityContext = commonSpec.SecurityContext
		}
		if serviceAccount == "" {
			serviceAccount = commonSpec.ServiceAccount
		}
	}
	return &v1.JaegerCommonSpec{
		Annotations:     annotations,
		Labels:          labels,
		VolumeMounts:    RemoveDuplicatedVolumeMounts(volumeMounts),
		Volumes:         RemoveDuplicatedVolumes(volumes),
		Resources:       *resources,
		Affinity:        affinity,
		Tolerations:     tolerations,
		SecurityContext: securityContext,
		ServiceAccount:  serviceAccount,
	}
}
Merge returns a merged version of the list of JaegerCommonSpec instances with most specific first
package util
import (
	"crypto/rand"
	"encoding/base64"
	"fmt"
	"strconv"
	"strings"
	"github.com/spf13/viper"
	corev1 "k8s.io/api/core/v1"
	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
	v1 "github.com/jaegertracing/jaeger-operator/pkg/apis/jaegertracing/v1"
	"github.com/jaegertracing/jaeger-operator/pkg/version"
)
func RemoveDuplicatedVolumes(volumes []corev1.Volume) []corev1.Volume {
	var results []corev1.Volume
	existing := map[string]bool{}
	for _, volume := range volumes {
		if existing[volume.Name] {
			continue
		}
		results = append(results, volume)
		existing[volume.Name] = true
	}
	return results
}
func RemoveDuplicatedVolumeMounts(volumeMounts []corev1.VolumeMount) []corev1.VolumeMount {
	var results []corev1.VolumeMount
	existing := map[string]bool{}
	for _, volumeMount := range volumeMounts {
		if existing[volumeMount.Name] {
			continue
		}
		results = append(results, volumeMount)
		existing[volumeMount.Name] = true
	}
	return results
}
func RemoveDuplicatedImagePullSecrets(imagePullSecrets []corev1.LocalObjectReference) []corev1.LocalObjectReference {
	var results []corev1.LocalObjectReference
	existing := map[string]bool{}
	for _, imagePullSecret := range imagePullSecrets {
		if existing[imagePullSecret.Name] {
			continue
		}
		results = append(results, imagePullSecret)
		existing[imagePullSecret.Name] = true
	}
	return results
}