fix xdsHost condition

This commit is contained in:
GLYASAI 2020-07-24 09:50:22 +08:00
parent fe4450de6f
commit 780b9b5202

View File

@ -158,12 +158,8 @@ func conversionServicePlugin(as *typesv1.AppService, dbmanager db.Manager) ([]v1
func createTCPDefaultPluginContainer(as *typesv1.AppService, pluginID string, envs []v1.EnvVar) v1.Container { func createTCPDefaultPluginContainer(as *typesv1.AppService, pluginID string, envs []v1.EnvVar) v1.Container {
envs = append(envs, v1.EnvVar{Name: "PLUGIN_ID", Value: pluginID}) envs = append(envs, v1.EnvVar{Name: "PLUGIN_ID", Value: pluginID})
_, xdsHostPort, apiHostPort := getXDSHostIPAndPort() xdsHost, xdsHostPort, apiHostPort := getXDSHostIPAndPort()
envs = append(envs, v1.EnvVar{Name: "XDS_HOST_IP", ValueFrom: &corev1.EnvVarSource{ envs = append(envs, xdsHostIPEnv(xdsHost))
FieldRef: &corev1.ObjectFieldSelector{
FieldPath: "status.hostIP",
},
}})
envs = append(envs, v1.EnvVar{Name: "API_HOST_PORT", Value: apiHostPort}) envs = append(envs, v1.EnvVar{Name: "API_HOST_PORT", Value: apiHostPort})
envs = append(envs, v1.EnvVar{Name: "XDS_HOST_PORT", Value: xdsHostPort}) envs = append(envs, v1.EnvVar{Name: "XDS_HOST_PORT", Value: xdsHostPort})
@ -177,12 +173,8 @@ func createTCPDefaultPluginContainer(as *typesv1.AppService, pluginID string, en
func createProbeMeshInitContainer(as *typesv1.AppService, pluginID, serviceAlias string, envs []v1.EnvVar) v1.Container { func createProbeMeshInitContainer(as *typesv1.AppService, pluginID, serviceAlias string, envs []v1.EnvVar) v1.Container {
envs = append(envs, v1.EnvVar{Name: "PLUGIN_ID", Value: pluginID}) envs = append(envs, v1.EnvVar{Name: "PLUGIN_ID", Value: pluginID})
_, xdsHostPort, apiHostPort := getXDSHostIPAndPort() xdsHost, xdsHostPort, apiHostPort := getXDSHostIPAndPort()
envs = append(envs, v1.EnvVar{Name: "XDS_HOST_IP", ValueFrom: &corev1.EnvVarSource{ envs = append(envs, xdsHostIPEnv(xdsHost))
FieldRef: &corev1.ObjectFieldSelector{
FieldPath: "status.hostIP",
},
}})
envs = append(envs, v1.EnvVar{Name: "API_HOST_PORT", Value: apiHostPort}) envs = append(envs, v1.EnvVar{Name: "API_HOST_PORT", Value: apiHostPort})
envs = append(envs, v1.EnvVar{Name: "XDS_HOST_PORT", Value: xdsHostPort}) envs = append(envs, v1.EnvVar{Name: "XDS_HOST_PORT", Value: xdsHostPort})
return v1.Container{ return v1.Container{
@ -340,15 +332,7 @@ func createPluginEnvs(pluginID, tenantID, serviceAlias string, mainEnvs []v1.Env
envs = append(envs, v1.EnvVar{Name: e.EnvName, Value: e.EnvValue}) envs = append(envs, v1.EnvVar{Name: e.EnvName, Value: e.EnvValue})
} }
xdsHost, xdsHostPort, apiHostPort := getXDSHostIPAndPort() xdsHost, xdsHostPort, apiHostPort := getXDSHostIPAndPort()
if xdsHost == "" { envs = append(envs, xdsHostIPEnv(xdsHost))
envs = append(envs, v1.EnvVar{Name: "XDS_HOST_IP", ValueFrom: &corev1.EnvVarSource{
FieldRef: &corev1.ObjectFieldSelector{
FieldPath: "status.hostIP",
},
}})
} else {
envs = append(envs, v1.EnvVar{Name: "XDS_HOST_IP", Value: xdsHost})
}
envs = append(envs, v1.EnvVar{Name: "API_HOST_PORT", Value: apiHostPort}) envs = append(envs, v1.EnvVar{Name: "API_HOST_PORT", Value: apiHostPort})
envs = append(envs, v1.EnvVar{Name: "XDS_HOST_PORT", Value: xdsHostPort}) envs = append(envs, v1.EnvVar{Name: "XDS_HOST_PORT", Value: xdsHostPort})
discoverURL := fmt.Sprintf( discoverURL := fmt.Sprintf(
@ -413,3 +397,14 @@ func createTCPUDPMeshRecources(as *typesv1.AppService) v1.ResourceRequirements {
return cpu return cpu
}()) }())
} }
func xdsHostIPEnv(xdsHost string) corev1.EnvVar {
if xdsHost == "" {
return v1.EnvVar{Name: "XDS_HOST_IP", ValueFrom: &corev1.EnvVarSource{
FieldRef: &corev1.ObjectFieldSelector{
FieldPath: "status.hostIP",
},
}}
}
return v1.EnvVar{Name: "XDS_HOST_IP", Value: xdsHost}
}