func BuildEtcdManifest(c *EtcdCluster) *v1.Pod {

	pod := &v1.Pod{}
	pod.APIVersion = "v1"
	pod.Kind = "Pod"
	pod.Name = c.PodName
	pod.Namespace = "kube-system"
	pod.Labels = map[string]string{"k8s-app": c.PodName}
	pod.Spec.HostNetwork = true

	// dereference our resource requests if they exist
	// cpu
	var cpuRequest resource.Quantity
	if c.CPURequest != nil {
		cpuRequest = *c.CPURequest
	}

	// memory
	var memoryRequest resource.Quantity
	if c.MemoryRequest != nil {
		memoryRequest = *c.MemoryRequest
	}

	{
		container := v1.Container{
			Name:  "etcd-container",
			Image: c.ImageSource,
			Resources: v1.ResourceRequirements{
				Requests: v1.ResourceList{
					v1.ResourceCPU:    cpuRequest,
					v1.ResourceMemory: memoryRequest,
				},
			},
			Command: exec.WithTee("/usr/local/bin/etcd", []string{}, "/var/log/etcd.log"),
		}
		// build the environment variables for etcd service
		container.Env = buildEtcdEnvironmentOptions(c)

		container.LivenessProbe = &v1.Probe{
			InitialDelaySeconds: 15,
			TimeoutSeconds:      15,
		}
		// ensure we have the correct probe schema
		if c.isTLS() {
			container.LivenessProbe.TCPSocket = &v1.TCPSocketAction{
				Host: "127.0.0.1",
				Port: intstr.FromInt(c.ClientPort),
			}
		} else {
			container.LivenessProbe.HTTPGet = &v1.HTTPGetAction{
				Host:   "127.0.0.1",
				Port:   intstr.FromInt(c.ClientPort),
				Path:   "/health",
				Scheme: v1.URISchemeHTTP,
			}
		}
		container.Ports = append(container.Ports, v1.ContainerPort{
			Name:          "serverport",
			ContainerPort: int32(c.PeerPort),
			HostPort:      int32(c.PeerPort),
		})
		container.Ports = append(container.Ports, v1.ContainerPort{
			Name:          "clientport",
			ContainerPort: int32(c.ClientPort),
			HostPort:      int32(c.ClientPort),
		})
		container.VolumeMounts = append(container.VolumeMounts, v1.VolumeMount{
			Name:      "varetcdata",
			MountPath: "/var/etcd/" + c.DataDirName,
			ReadOnly:  false,
		})
		container.VolumeMounts = append(container.VolumeMounts, v1.VolumeMount{
			Name:      "varlogetcd",
			MountPath: "/var/log/etcd.log",
			ReadOnly:  false,
		})
		container.VolumeMounts = append(container.VolumeMounts, v1.VolumeMount{
			Name:      "hosts",
			MountPath: "/etc/hosts",
			ReadOnly:  true,
		})
		// add the host path mount to the pod spec
		pod.Spec.Volumes = append(pod.Spec.Volumes, v1.Volume{
			Name: "varetcdata",
			VolumeSource: v1.VolumeSource{
				HostPath: &v1.HostPathVolumeSource{
					Path: c.VolumeMountPath + "/var/etcd/" + c.DataDirName,
				},
			},
		})
		pod.Spec.Volumes = append(pod.Spec.Volumes, v1.Volume{
			Name: "varlogetcd",
			VolumeSource: v1.VolumeSource{
				HostPath: &v1.HostPathVolumeSource{
					Path: c.LogFile,
				},
			},
		})
		pod.Spec.Volumes = append(pod.Spec.Volumes, v1.Volume{
			Name: "hosts",
			VolumeSource: v1.VolumeSource{
				HostPath: &v1.HostPathVolumeSource{
					Path: "/etc/hosts",
				},
			},
		})
		// @check if tls is enabled and mount the directory. It might be worth considering
		// if we you use our own directory in /srv i.e /srv/etcd rather than the default /src/kubernetes
		if c.isTLS() {
			for _, dirname := range buildCertificateDirectories(c) {
				normalized := strings.Replace(dirname, "/", "", -1)
				pod.Spec.Volumes = append(pod.Spec.Volumes, v1.Volume{
					Name: normalized,
					VolumeSource: v1.VolumeSource{
						HostPath: &v1.HostPathVolumeSource{
							Path: dirname,
						},
					},
				})
				container.VolumeMounts = append(container.VolumeMounts, v1.VolumeMount{
					Name:      normalized,
					MountPath: dirname,
					ReadOnly:  true,
				})
			}
		}

		pod.Spec.Containers = append(pod.Spec.Containers, container)
	}

	if c.BackupStore != "" && c.BackupImage != "" {
		backupContainer := buildEtcdBackupManagerContainer(c)
		pod.Spec.Containers = append(pod.Spec.Containers, *backupContainer)
	}

	kubemanifest.MarkPodAsCritical(pod)
	kubemanifest.MarkPodAsClusterCritical(pod)

	return pod
}
// BuildEtcdManifest creates the pod spec, based on the etcd cluster
BuildEtcdManifest creates the pod spec, based on the etcd cluster
// BuildEtcdManifest creates the pod spec based on the etcd cluster
func BuildEtcdManifest(c *EtcdCluster) *v1.Pod {
	pod := &v1.Pod{}
	pod.APIVersion = "v1"
	pod.Kind = "Pod"
	pod.Name = c.PodName
	pod.Namespace = "kube-system"
	pod.Labels = map[string]string{"k8s-app": c.PodName}
	pod.Spec.HostNetwork = true
	var cpuRequest resource.Quantity
	if c.CPURequest != nil {
		cpuRequest = *c.CPURequest
	}
	var memoryRequest resource.Quantity
	if c.MemoryRequest != nil {
		memoryRequest = *c.MemoryRequest
	}
	{
		container := v1.Container{
			Name:  "etcd-container",
			Image: c.ImageSource,
			Resources: v1.ResourceRequirements{
				Requests: v1.ResourceList{
					v1.ResourceCPU:    cpuRequest,
					v1.ResourceMemory: memoryRequest,
				},
			},
			Command: exec.WithTee("/usr/local/bin/etcd", []string{}, "/var/log/etcd.log"),
		}
		container.Env = buildEtcdEnvironmentOptions(c)
		container.LivenessProbe = &v1.Probe{
			InitialDelaySeconds: 15,
			TimeoutSeconds:      15,
		}
		if c.isTLS() {
			container.LivenessProbe.TCPSocket = &v1.TCPSocketAction{
				Host: "127.0.0.1",
				Port: intstr.FromInt(c.ClientPort),
			}
		} else {
			container.LivenessProbe.HTTPGet = &v1.HTTPGetAction{
				Host:   "127.0.0.1",
				Port:   intstr.FromInt(c.ClientPort),
				Path:   "/health",
				Scheme: v1.URISchemeHTTP,
			}
		}
		container.Ports = append(container.Ports, v1.ContainerPort{
			Name:          "serverport",
			ContainerPort: int32(c.PeerPort),
			HostPort:      int32(c.PeerPort),
		})
		container.Ports = append(container.Ports, v1.ContainerPort{
			Name:          "clientport",
			ContainerPort: int32(c.ClientPort),
			HostPort:      int32(c.ClientPort),
		})
		container.VolumeMounts = append(container.VolumeMounts, v1.VolumeMount{
			Name:      "varetcdata",
			MountPath: "/var/etcd/" + c.DataDirName,
			ReadOnly:  false,
		})
		container.VolumeMounts = append(container.VolumeMounts, v1.VolumeMount{
			Name:      "varlogetcd",
			MountPath: "/var/log/etcd.log",
			ReadOnly:  false,
		})
		container.VolumeMounts = append(container.VolumeMounts, v1.VolumeMount{
			Name:      "hosts",
			MountPath: "/etc/hosts",
			ReadOnly:  true,
		})
		pod.Spec.Volumes = append(pod.Spec.Volumes, v1.Volume{
			Name: "varetcdata",
			VolumeSource: v1.VolumeSource{
				HostPath: &v1.HostPathVolumeSource{
					Path: c.VolumeMountPath + "/var/etcd/" + c.DataDirName,
				},
			},
		})
		pod.Spec.Volumes = append(pod.Spec.Volumes, v1.Volume{
			Name: "varlogetcd",
			VolumeSource: v1.VolumeSource{
				HostPath: &v1.HostPathVolumeSource{
					Path: c.LogFile,
				},
			},
		})
		pod.Spec.Volumes = append(pod.Spec.Volumes, v1.Volume{
			Name: "hosts",
			VolumeSource: v1.VolumeSource{
				HostPath: &v1.HostPathVolumeSource{
					Path: "/etc/hosts",
				},
			},
		})
		if c.isTLS() {
			for _, dirname := range buildCertificateDirectories(c) {
				normalized := strings.Replace(dirname, "/", "", -1)
				pod.Spec.Volumes = append(pod.Spec.Volumes, v1.Volume{
					Name: normalized,
					VolumeSource: v1.VolumeSource{
						HostPath: &v1.HostPathVolumeSource{
							Path: dirname,
						},
					},
				})
				container.VolumeMounts = append(container.VolumeMounts, v1.VolumeMount{
					Name:      normalized,
					MountPath: dirname,
					ReadOnly:  true,
				})
			}
		}
		pod.Spec.Containers = append(pod.Spec.Containers, container)
	}
	if c.BackupStore != "" && c.BackupImage != "" {
		backupContainer := buildEtcdBackupManagerContainer(c)
		pod.Spec.Containers = append(pod.Spec.Containers, *backupContainer)
	}
	kubemanifest.MarkPodAsCritical(pod)
	kubemanifest.MarkPodAsClusterCritical(pod)
	return pod
}
func BuildEtcdManifest ( c * EtcdCluster ) * v1 . Pod { pod := & v1 . Pod { } pod . APIVersion = " " pod . Kind = " " pod . Name = c . PodName pod . Namespace = " " pod . Labels = map [ string ] string { " " : c . PodName } pod . Spec . HostNetwork = true var cpuRequest resource . Quantity if c . CPURequest != nil { cpuRequest = * c . CPURequest } var memoryRequest resource . Quantity if c . MemoryRequest != nil { memoryRequest = * c . MemoryRequest } { container := v1 . Container { Name : " " , Image : c . ImageSource , Resources : v1 . ResourceRequirements { Requests : v1 . ResourceList { v1 . ResourceCPU : cpuRequest , v1 . ResourceMemory : memoryRequest , } , } , Command : exec . WithTee ( " " , [ ] string { } , " " ) , } container . Env = buildEtcdEnvironmentOptions ( c ) container . LivenessProbe = & v1 . Probe { InitialDelaySeconds : 15 , TimeoutSeconds : 15 , } if c . isTLS ( ) { container . LivenessProbe . TCPSocket = & v1 . TCPSocketAction { Host : " " , Port : intstr . FromInt ( c . ClientPort ) , } } else { container . LivenessProbe . HTTPGet = & v1 . HTTPGetAction { Host : " " , Port : intstr . FromInt ( c . ClientPort ) , Path : " " , Scheme : v1 . URISchemeHTTP , } } container . Ports = append ( container . Ports , v1 . ContainerPort { Name : " " , ContainerPort : int32 ( c . PeerPort ) , HostPort : int32 ( c . PeerPort ) , } ) container . Ports = append ( container . Ports , v1 . ContainerPort { Name : " " , ContainerPort : int32 ( c . ClientPort ) , HostPort : int32 ( c . ClientPort ) , } ) container . VolumeMounts = append ( container . VolumeMounts , v1 . VolumeMount { Name : " " , MountPath : " " + c . DataDirName , ReadOnly : false , } ) container . VolumeMounts = append ( container . VolumeMounts , v1 . VolumeMount { Name : " " , MountPath : " " , ReadOnly : false , } ) container . VolumeMounts = append ( container . VolumeMounts , v1 . VolumeMount { Name : " " , MountPath : " " , ReadOnly : true , } ) pod . Spec . Volumes = append ( pod . Spec . Volumes , v1 . Volume { Name : " " , VolumeSource : v1 . VolumeSource { HostPath : & v1 . HostPathVolumeSource { Path : c . VolumeMountPath + " " + c . DataDirName , } , } , } ) pod . Spec . Volumes = append ( pod . Spec . Volumes , v1 . Volume { Name : " " , VolumeSource : v1 . VolumeSource { HostPath : & v1 . HostPathVolumeSource { Path : c . LogFile , } , } , } ) pod . Spec . Volumes = append ( pod . Spec . Volumes , v1 . Volume { Name : " " , VolumeSource : v1 . VolumeSource { HostPath : & v1 . HostPathVolumeSource { Path : " " , } , } , } ) if c . isTLS ( ) { for _ , dirname := range buildCertificateDirectories ( c ) { normalized := strings . Replace ( dirname , " " , " " , - 1 ) pod . Spec . Volumes = append ( pod . Spec . Volumes , v1 . Volume { Name : normalized , VolumeSource : v1 . VolumeSource { HostPath : & v1 . HostPathVolumeSource { Path : dirname , } , } , } ) container . VolumeMounts = append ( container . VolumeMounts , v1 . VolumeMount { Name : normalized , MountPath : dirname , ReadOnly : true , } ) } } pod . Spec . Containers = append ( pod . Spec . Containers , container ) } if c . BackupStore != " " && c . BackupImage != " " { backupContainer := buildEtcdBackupManagerContainer ( c ) pod . Spec . Containers = append ( pod . Spec . Containers , * backupContainer ) } kubemanifest . MarkPodAsCritical ( pod ) kubemanifest . MarkPodAsClusterCritical ( pod ) return pod }
BuildEtcdManifest creates the pod spec, based on the etcd cluster
BuildEtcdManifest creates the pod spec based on the etcd cluster
// dereference our resource requests if they exist // cpu // memory // build the environment variables for etcd service // ensure we have the correct probe schema // add the host path mount to the pod spec // @check if tls is enabled and mount the directory. It might be worth considering // if we you use our own directory in /srv i.e /srv/etcd rather than the default /src/kubernetes