func ApplyEtcdTLSOptions(e *v1alpha1.EtcdCluster, app *tAppV1.TApp) {
	if e.Spec.Secure == nil || e.Spec.Secure.TLS == nil {
		// TODO: remove volume
		return
	}

	tlsConfig := e.Spec.Secure.TLS

	// append tls volume and mount
	var volumes []corev1.Volume
	var volumeMounts []corev1.VolumeMount

	// using external cert
	if tlsConfig.ExternalCerts != nil && tlsConfig.ExternalCerts.ServerSecret != "" {
		volumes = append(volumes, corev1.Volume{
			Name: constants.EtcdServerTLSVolumeName,
			VolumeSource: corev1.VolumeSource{
				Secret: &corev1.SecretVolumeSource{
					SecretName: tlsConfig.ExternalCerts.ServerSecret,
				},
			},
		})
		volumeMounts = append(volumeMounts, corev1.VolumeMount{
			Name:      constants.EtcdServerTLSVolumeName,
			MountPath: constants.EtcdServerTLSMountPath,
		})
	}
	if tlsConfig.ExternalCerts != nil && tlsConfig.ExternalCerts.PeerSecret != "" {
		volumes = append(volumes, corev1.Volume{
			Name: constants.EtcdPeerTLSVolumeName,
			VolumeSource: corev1.VolumeSource{
				Secret: &corev1.SecretVolumeSource{
					SecretName: tlsConfig.ExternalCerts.PeerSecret,
				},
			},
		})
		volumeMounts = append(volumeMounts, corev1.VolumeMount{
			Name:      constants.EtcdPeerTLSVolumeName,
			MountPath: constants.EtcdPeerTLSMountPath,
		})
	}
	if tlsConfig.ExternalCerts != nil && tlsConfig.ExternalCerts.ClientSecret != "" {
		volumes = append(volumes, corev1.Volume{
			Name: constants.EtcdClientTLSVolumeName,
			VolumeSource: corev1.VolumeSource{
				Secret: &corev1.SecretVolumeSource{
					SecretName: tlsConfig.ExternalCerts.ClientSecret,
				},
			},
		})
		volumeMounts = append(volumeMounts, corev1.VolumeMount{
			Name:      constants.EtcdClientTLSVolumeName,
			MountPath: constants.EtcdClientTLSMountPath,
		})
	}

	// using auto generate cert
	if tlsConfig.AutoTLSCert != nil && tlsConfig.AutoTLSCert.AutoGenerateServerCert {
		volumes = append(volumes, corev1.Volume{
			Name: constants.EtcdServerTLSVolumeName,
			VolumeSource: corev1.VolumeSource{
				Secret: &corev1.SecretVolumeSource{
					SecretName: secure.NameForEtcdCertSecret(e.Name, secure.EtcdServerCert),
				},
			},
		})
		volumeMounts = append(volumeMounts, corev1.VolumeMount{
			Name:      constants.EtcdServerTLSVolumeName,
			MountPath: constants.EtcdServerTLSMountPath,
		})
	}
	if tlsConfig.AutoTLSCert != nil && tlsConfig.AutoTLSCert.AutoGeneratePeerCert {
		volumes = append(volumes, corev1.Volume{
			Name: constants.EtcdPeerTLSVolumeName,
			VolumeSource: corev1.VolumeSource{
				Secret: &corev1.SecretVolumeSource{
					SecretName: secure.NameForEtcdCertSecret(e.Name, secure.EtcdPeerCert),
				},
			},
		})
		volumeMounts = append(volumeMounts, corev1.VolumeMount{
			Name:      constants.EtcdPeerTLSVolumeName,
			MountPath: constants.EtcdPeerTLSMountPath,
		})
	}
	if tlsConfig.AutoTLSCert != nil && tlsConfig.AutoTLSCert.AutoGenerateClientCert {
		volumes = append(volumes, corev1.Volume{
			Name: constants.EtcdClientTLSVolumeName,
			VolumeSource: corev1.VolumeSource{
				Secret: &corev1.SecretVolumeSource{
					SecretName: secure.NameForEtcdCertSecret(e.Name, secure.EtcdClientCert),
				},
			},
		})
		volumeMounts = append(volumeMounts, corev1.VolumeMount{
			Name:      constants.EtcdClientTLSVolumeName,
			MountPath: constants.EtcdClientTLSMountPath,
		})
	}

	for k, tp := range app.Spec.TemplatePool {
		tp.Spec.Volumes = append(tp.Spec.Volumes, volumes...)
		app.Spec.TemplatePool[k] = tp
	}

	for i := range app.Spec.TemplatePool {
		app.Spec.TemplatePool[i].Spec.Containers[0].VolumeMounts = append(app.Spec.TemplatePool[i].Spec.Containers[0].VolumeMounts, volumeMounts...)
	}
}
// ApplyEtcdTLSOptions set the etcd tls option args for TApp
ApplyEtcdTLSOptions set the etcd tls option args for TApp
// ApplyEtcdTLSOptions set the etcd tls option args for TApp
func ApplyEtcdTLSOptions(e *v1alpha1.EtcdCluster, app *tAppV1.TApp) {
	if e.Spec.Secure == nil || e.Spec.Secure.TLS == nil {
		return
	}
	tlsConfig := e.Spec.Secure.TLS
	var volumes []corev1.Volume
	var volumeMounts []corev1.VolumeMount
	if tlsConfig.ExternalCerts != nil && tlsConfig.ExternalCerts.ServerSecret != "" {
		volumes = append(volumes, corev1.Volume{
			Name: constants.EtcdServerTLSVolumeName,
			VolumeSource: corev1.VolumeSource{
				Secret: &corev1.SecretVolumeSource{
					SecretName: tlsConfig.ExternalCerts.ServerSecret,
				},
			},
		})
		volumeMounts = append(volumeMounts, corev1.VolumeMount{
			Name:      constants.EtcdServerTLSVolumeName,
			MountPath: constants.EtcdServerTLSMountPath,
		})
	}
	if tlsConfig.ExternalCerts != nil && tlsConfig.ExternalCerts.PeerSecret != "" {
		volumes = append(volumes, corev1.Volume{
			Name: constants.EtcdPeerTLSVolumeName,
			VolumeSource: corev1.VolumeSource{
				Secret: &corev1.SecretVolumeSource{
					SecretName: tlsConfig.ExternalCerts.PeerSecret,
				},
			},
		})
		volumeMounts = append(volumeMounts, corev1.VolumeMount{
			Name:      constants.EtcdPeerTLSVolumeName,
			MountPath: constants.EtcdPeerTLSMountPath,
		})
	}
	if tlsConfig.ExternalCerts != nil && tlsConfig.ExternalCerts.ClientSecret != "" {
		volumes = append(volumes, corev1.Volume{
			Name: constants.EtcdClientTLSVolumeName,
			VolumeSource: corev1.VolumeSource{
				Secret: &corev1.SecretVolumeSource{
					SecretName: tlsConfig.ExternalCerts.ClientSecret,
				},
			},
		})
		volumeMounts = append(volumeMounts, corev1.VolumeMount{
			Name:      constants.EtcdClientTLSVolumeName,
			MountPath: constants.EtcdClientTLSMountPath,
		})
	}
	if tlsConfig.AutoTLSCert != nil && tlsConfig.AutoTLSCert.AutoGenerateServerCert {
		volumes = append(volumes, corev1.Volume{
			Name: constants.EtcdServerTLSVolumeName,
			VolumeSource: corev1.VolumeSource{
				Secret: &corev1.SecretVolumeSource{
					SecretName: secure.NameForEtcdCertSecret(e.Name, secure.EtcdServerCert),
				},
			},
		})
		volumeMounts = append(volumeMounts, corev1.VolumeMount{
			Name:      constants.EtcdServerTLSVolumeName,
			MountPath: constants.EtcdServerTLSMountPath,
		})
	}
	if tlsConfig.AutoTLSCert != nil && tlsConfig.AutoTLSCert.AutoGeneratePeerCert {
		volumes = append(volumes, corev1.Volume{
			Name: constants.EtcdPeerTLSVolumeName,
			VolumeSource: corev1.VolumeSource{
				Secret: &corev1.SecretVolumeSource{
					SecretName: secure.NameForEtcdCertSecret(e.Name, secure.EtcdPeerCert),
				},
			},
		})
		volumeMounts = append(volumeMounts, corev1.VolumeMount{
			Name:      constants.EtcdPeerTLSVolumeName,
			MountPath: constants.EtcdPeerTLSMountPath,
		})
	}
	if tlsConfig.AutoTLSCert != nil && tlsConfig.AutoTLSCert.AutoGenerateClientCert {
		volumes = append(volumes, corev1.Volume{
			Name: constants.EtcdClientTLSVolumeName,
			VolumeSource: corev1.VolumeSource{
				Secret: &corev1.SecretVolumeSource{
					SecretName: secure.NameForEtcdCertSecret(e.Name, secure.EtcdClientCert),
				},
			},
		})
		volumeMounts = append(volumeMounts, corev1.VolumeMount{
			Name:      constants.EtcdClientTLSVolumeName,
			MountPath: constants.EtcdClientTLSMountPath,
		})
	}
	for k, tp := range app.Spec.TemplatePool {
		tp.Spec.Volumes = append(tp.Spec.Volumes, volumes...)
		app.Spec.TemplatePool[k] = tp
	}
	for i := range app.Spec.TemplatePool {
		app.Spec.TemplatePool[i].Spec.Containers[0].VolumeMounts = append(app.Spec.TemplatePool[i].Spec.Containers[0].VolumeMounts, volumeMounts...)
	}
}
func ApplyEtcdTLSOptions ( e * v1alpha1 . EtcdCluster , app * tAppV1 . TApp ) { if e . Spec . Secure == nil || e . Spec . Secure . TLS == nil { return } tlsConfig := e . Spec . Secure . TLS var volumes [ ] corev1 . Volume var volumeMounts [ ] corev1 . VolumeMount if tlsConfig . ExternalCerts != nil && tlsConfig . ExternalCerts . ServerSecret != " " { volumes = append ( volumes , corev1 . Volume { Name : constants . EtcdServerTLSVolumeName , VolumeSource : corev1 . VolumeSource { Secret : & corev1 . SecretVolumeSource { SecretName : tlsConfig . ExternalCerts . ServerSecret , } , } , } ) volumeMounts = append ( volumeMounts , corev1 . VolumeMount { Name : constants . EtcdServerTLSVolumeName , MountPath : constants . EtcdServerTLSMountPath , } ) } if tlsConfig . ExternalCerts != nil && tlsConfig . ExternalCerts . PeerSecret != " " { volumes = append ( volumes , corev1 . Volume { Name : constants . EtcdPeerTLSVolumeName , VolumeSource : corev1 . VolumeSource { Secret : & corev1 . SecretVolumeSource { SecretName : tlsConfig . ExternalCerts . PeerSecret , } , } , } ) volumeMounts = append ( volumeMounts , corev1 . VolumeMount { Name : constants . EtcdPeerTLSVolumeName , MountPath : constants . EtcdPeerTLSMountPath , } ) } if tlsConfig . ExternalCerts != nil && tlsConfig . ExternalCerts . ClientSecret != " " { volumes = append ( volumes , corev1 . Volume { Name : constants . EtcdClientTLSVolumeName , VolumeSource : corev1 . VolumeSource { Secret : & corev1 . SecretVolumeSource { SecretName : tlsConfig . ExternalCerts . ClientSecret , } , } , } ) volumeMounts = append ( volumeMounts , corev1 . VolumeMount { Name : constants . EtcdClientTLSVolumeName , MountPath : constants . EtcdClientTLSMountPath , } ) } if tlsConfig . AutoTLSCert != nil && tlsConfig . AutoTLSCert . AutoGenerateServerCert { volumes = append ( volumes , corev1 . Volume { Name : constants . EtcdServerTLSVolumeName , VolumeSource : corev1 . VolumeSource { Secret : & corev1 . SecretVolumeSource { SecretName : secure . NameForEtcdCertSecret ( e . Name , secure . EtcdServerCert ) , } , } , } ) volumeMounts = append ( volumeMounts , corev1 . VolumeMount { Name : constants . EtcdServerTLSVolumeName , MountPath : constants . EtcdServerTLSMountPath , } ) } if tlsConfig . AutoTLSCert != nil && tlsConfig . AutoTLSCert . AutoGeneratePeerCert { volumes = append ( volumes , corev1 . Volume { Name : constants . EtcdPeerTLSVolumeName , VolumeSource : corev1 . VolumeSource { Secret : & corev1 . SecretVolumeSource { SecretName : secure . NameForEtcdCertSecret ( e . Name , secure . EtcdPeerCert ) , } , } , } ) volumeMounts = append ( volumeMounts , corev1 . VolumeMount { Name : constants . EtcdPeerTLSVolumeName , MountPath : constants . EtcdPeerTLSMountPath , } ) } if tlsConfig . AutoTLSCert != nil && tlsConfig . AutoTLSCert . AutoGenerateClientCert { volumes = append ( volumes , corev1 . Volume { Name : constants . EtcdClientTLSVolumeName , VolumeSource : corev1 . VolumeSource { Secret : & corev1 . SecretVolumeSource { SecretName : secure . NameForEtcdCertSecret ( e . Name , secure . EtcdClientCert ) , } , } , } ) volumeMounts = append ( volumeMounts , corev1 . VolumeMount { Name : constants . EtcdClientTLSVolumeName , MountPath : constants . EtcdClientTLSMountPath , } ) } for k , tp := range app . Spec . TemplatePool { tp . Spec . Volumes = append ( tp . Spec . Volumes , volumes ... ) app . Spec . TemplatePool [ k ] = tp } for i := range app . Spec . TemplatePool { app . Spec . TemplatePool [ i ] . Spec . Containers [ 0 ] . VolumeMounts = append ( app . Spec . TemplatePool [ i ] . Spec . Containers [ 0 ] . VolumeMounts , volumeMounts ... ) } }
ApplyEtcdTLSOptions set the etcd tls option args for TApp
ApplyEtcdTLSOptions set the etcd tls option args for TApp
// TODO: remove volume // append tls volume and mount // using external cert // using auto generate cert