[AliCloud] Add init container (#382)
* clean up eci sdk code remove unnecessary code * add init containers support
This commit is contained in:
@@ -178,7 +178,8 @@ func (p *ECIProvider) CreatePod(ctx context.Context, pod *v1.Pod) error {
|
||||
request.RestartPolicy = string(pod.Spec.RestartPolicy)
|
||||
|
||||
// get containers
|
||||
containers, err := p.getContainers(pod)
|
||||
containers, err := p.getContainers(pod, false)
|
||||
initContainers, err := p.getContainers(pod, true)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
@@ -197,6 +198,7 @@ func (p *ECIProvider) CreatePod(ctx context.Context, pod *v1.Pod) error {
|
||||
|
||||
// assign all the things
|
||||
request.Containers = containers
|
||||
request.InitContainers = initContainers
|
||||
request.Volumes = volumes
|
||||
request.ImageRegistryCredentials = creds
|
||||
CreationTimestamp := pod.CreationTimestamp.UTC().Format(podTagTimeFormat)
|
||||
@@ -539,9 +541,13 @@ func readDockerConfigJSONSecret(secret *v1.Secret, ips []eci.ImageRegistryCreden
|
||||
return ips, err
|
||||
}
|
||||
|
||||
func (p *ECIProvider) getContainers(pod *v1.Pod) ([]eci.CreateContainer, error) {
|
||||
containers := make([]eci.CreateContainer, 0, len(pod.Spec.Containers))
|
||||
for _, container := range pod.Spec.Containers {
|
||||
func (p *ECIProvider) getContainers(pod *v1.Pod, init bool) ([]eci.CreateContainer, error) {
|
||||
podContainers := pod.Spec.Containers
|
||||
if init {
|
||||
podContainers = pod.Spec.InitContainers
|
||||
}
|
||||
containers := make([]eci.CreateContainer, 0, len(podContainers))
|
||||
for _, container := range podContainers {
|
||||
c := eci.CreateContainer{
|
||||
Name: container.Name,
|
||||
Image: container.Image,
|
||||
@@ -646,9 +652,9 @@ func (p *ECIProvider) getVolumes(pod *v1.Pod) ([]eci.Volume, error) {
|
||||
|
||||
if len(ConfigFileToPaths) != 0 {
|
||||
volumes = append(volumes, eci.Volume{
|
||||
Type: eci.VOL_TYPE_CONFIGFILEVOLUME,
|
||||
Name: v.Name,
|
||||
ConfigFileVolumeConfigFileToPaths: ConfigFileToPaths,
|
||||
Type: eci.VOL_TYPE_CONFIGFILEVOLUME,
|
||||
Name: v.Name,
|
||||
ConfigFileToPaths: ConfigFileToPaths,
|
||||
})
|
||||
}
|
||||
continue
|
||||
@@ -672,9 +678,9 @@ func (p *ECIProvider) getVolumes(pod *v1.Pod) ([]eci.Volume, error) {
|
||||
|
||||
if len(ConfigFileToPaths) != 0 {
|
||||
volumes = append(volumes, eci.Volume{
|
||||
Type: eci.VOL_TYPE_CONFIGFILEVOLUME,
|
||||
Name: v.Name,
|
||||
ConfigFileVolumeConfigFileToPaths: ConfigFileToPaths,
|
||||
Type: eci.VOL_TYPE_CONFIGFILEVOLUME,
|
||||
Name: v.Name,
|
||||
ConfigFileToPaths: ConfigFileToPaths,
|
||||
})
|
||||
}
|
||||
continue
|
||||
|
||||
@@ -77,6 +77,7 @@ func (client *Client) CreateContainerGroupWithCallback(request *CreateContainerG
|
||||
type CreateContainerGroupRequest struct {
|
||||
*requests.RpcRequest
|
||||
Containers []CreateContainer `position:"Query" name:"Container" type:"Repeated"`
|
||||
InitContainers []CreateContainer `position:"Query" name:"InitContainer" type:"Repeated"`
|
||||
ResourceOwnerId requests.Integer `position:"Query" name:"ResourceOwnerId"`
|
||||
SecurityGroupId string `position:"Query" name:"SecurityGroupId"`
|
||||
ImageRegistryCredentials []ImageRegistryCredential `position:"Query" name:"ImageRegistryCredential" type:"Repeated"`
|
||||
@@ -92,17 +93,17 @@ type CreateContainerGroupRequest struct {
|
||||
}
|
||||
|
||||
type CreateContainer struct {
|
||||
Name string `position:"Query" name:"Name"`
|
||||
Image string `position:"Query" name:"Image"`
|
||||
Memory requests.Float `position:"Query" name:"Memory"`
|
||||
Cpu requests.Float `position:"Query" name:"Cpu"`
|
||||
WorkingDir string `position:"Query" name:"WorkingDir"`
|
||||
ImagePullPolicy string `position:"Query" name:"ImagePullPolicy"`
|
||||
Commands []string `position:"Query" name:"Command" type:"Repeated"`
|
||||
Args []string `position:"Query" name:"Arg" type:"Repeated"`
|
||||
VolumeMounts []VolumeMount `position:"Query" name:"VolumeMount" type:"Repeated"`
|
||||
Ports []ContainerPort `position:"Query" name:"Port" type:"Repeated"`
|
||||
EnvironmentVars []EnvironmentVar `position:"Query" name:"EnvironmentVar" type:"Repeated"`
|
||||
Name string `name:"Name"`
|
||||
Image string `name:"Image"`
|
||||
Memory requests.Float `name:"Memory"`
|
||||
Cpu requests.Float `name:"Cpu"`
|
||||
WorkingDir string `name:"WorkingDir"`
|
||||
ImagePullPolicy string `name:"ImagePullPolicy"`
|
||||
Commands []string `name:"Command" type:"Repeated"`
|
||||
Args []string `name:"Arg" type:"Repeated"`
|
||||
VolumeMounts []VolumeMount `name:"VolumeMount" type:"Repeated"`
|
||||
Ports []ContainerPort `name:"Port" type:"Repeated"`
|
||||
EnvironmentVars []EnvironmentVar `name:"EnvironmentVar" type:"Repeated"`
|
||||
}
|
||||
|
||||
// CreateContainerGroupImageRegistryCredential is a repeated param struct in CreateContainerGroupRequest
|
||||
@@ -115,8 +116,8 @@ type ImageRegistryCredential struct {
|
||||
// CreateContainerGroupResponse is the response struct for api CreateContainerGroup
|
||||
type CreateContainerGroupResponse struct {
|
||||
*responses.BaseResponse
|
||||
RequestId string `json:"RequestId" xml:"RequestId"`
|
||||
ContainerGroupId string `json:"ContainerGroupId" xml:"ContainerGroupId"`
|
||||
RequestId string
|
||||
ContainerGroupId string
|
||||
}
|
||||
|
||||
// CreateCreateContainerGroupRequest creates a request to invoke CreateContainerGroup API
|
||||
|
||||
@@ -17,6 +17,6 @@ package eci
|
||||
|
||||
// ConfigFileVolumeConfigFileToPath is a nested struct in eci response
|
||||
type ConfigFileToPath struct {
|
||||
Content string `json:"Content" xml:"Content" position:"Query" name:"Content"`
|
||||
Path string `json:"Path" xml:"Path" position:"Query" name:"Path"`
|
||||
Content string `name:"Content"`
|
||||
Path string `name:"Path"`
|
||||
}
|
||||
|
||||
@@ -17,18 +17,18 @@ package eci
|
||||
|
||||
// Container is a nested struct in eci response
|
||||
type Container struct {
|
||||
Name string `json:"Name" xml:"Name" position:"Query" name:"Name"`
|
||||
Image string `json:"Image" xml:"Image" position:"Query" name:"Image"`
|
||||
Memory float64 `json:"Memory" xml:"Memory" position:"Query" name:"Memory"`
|
||||
Cpu float64 `json:"Cpu" xml:"Cpu" position:"Query" name:"Cpu" `
|
||||
Name string `json:"Name" xml:"Name" `
|
||||
Image string `json:"Image" xml:"Image"`
|
||||
Memory float64 `json:"Memory" xml:"Memory"`
|
||||
Cpu float64 `json:"Cpu" xml:"Cpu"`
|
||||
RestartCount int `json:"RestartCount" xml:"RestartCount"`
|
||||
WorkingDir string `json:"WorkingDir" xml:"WorkingDir" position:"Query" name:"WorkingDir"`
|
||||
ImagePullPolicy string `json:"ImagePullPolicy" xml:"ImagePullPolicy" position:"Query" name:"ImagePullPolicy"`
|
||||
Commands []string `json:"Commands" xml:"Commands" position:"Query" name:"Command" type:"Repeated"`
|
||||
Args []string `json:"Args" xml:"Args" position:"Query" name:"Arg" type:"Repeated"`
|
||||
WorkingDir string `json:"WorkingDir" xml:"WorkingDir"`
|
||||
ImagePullPolicy string `json:"ImagePullPolicy" xml:"ImagePullPolicy"`
|
||||
Commands []string `json:"Commands" xml:"Commands"`
|
||||
Args []string `json:"Args" xml:"Args"`
|
||||
PreviousState ContainerState `json:"PreviousState" xml:"PreviousState"`
|
||||
CurrentState ContainerState `json:"CurrentState" xml:"CurrentState"`
|
||||
VolumeMounts []VolumeMount `json:"VolumeMounts" xml:"VolumeMounts" position:"Query" name:"VolumeMount" type:"Repeated"`
|
||||
Ports []ContainerPort `json:"Ports" xml:"Ports" position:"Query" name:"Port" type:"Repeated"`
|
||||
EnvironmentVars []EnvironmentVar `json:"EnvironmentVars" xml:"EnvironmentVars" position:"Query" name:"EnvironmentVar" type:"Repeated"`
|
||||
VolumeMounts []VolumeMount `json:"VolumeMounts" xml:"VolumeMounts"`
|
||||
Ports []ContainerPort `json:"Ports" xml:"Ports"`
|
||||
EnvironmentVars []EnvironmentVar `json:"EnvironmentVars" xml:"EnvironmentVars"`
|
||||
}
|
||||
|
||||
@@ -21,6 +21,6 @@ import (
|
||||
|
||||
// ContainerPort is a nested struct in eci response
|
||||
type ContainerPort struct {
|
||||
Port requests.Integer `json:"Port" xml:"Port" position:"Query" name:"Port"`
|
||||
Protocol string `json:"Protocol" xml:"Protocol" position:"Query" name:"Protocol"`
|
||||
Port requests.Integer `name:"Port"`
|
||||
Protocol string `name:"Protocol"`
|
||||
}
|
||||
|
||||
@@ -17,6 +17,6 @@ package eci
|
||||
|
||||
// EnvironmentVar is a nested struct in eci response
|
||||
type EnvironmentVar struct {
|
||||
Key string `json:"Key" xml:"Key" position:"Query" name:"Key"`
|
||||
Value string `json:"Value" xml:"Value" position:"Query" name:"Value"`
|
||||
Key string `name:"Key"`
|
||||
Value string `name:"Value"`
|
||||
}
|
||||
|
||||
@@ -17,6 +17,6 @@ package eci
|
||||
|
||||
// Label is a nested struct in eci response
|
||||
type Tag struct {
|
||||
Key string `json:"Key" xml:"Key" position:"Query" name:"Key"`
|
||||
Value string `json:"Value" xml:"Value" position:"Query" name:"Value"`
|
||||
Key string `name:"Key"`
|
||||
Value string `name:"Value"`
|
||||
}
|
||||
|
||||
@@ -25,11 +25,11 @@ const (
|
||||
)
|
||||
|
||||
type Volume struct {
|
||||
Type string `json:"Type" xml:"Type" position:"Query" name:"Type"`
|
||||
Name string `json:"Name" xml:"Name" position:"Query" name:"Name"`
|
||||
NfsVolumePath string `json:"NfsVolumePath" xml:"NfsVolumePath" position:"Query" name:"NFSVolume.Path"`
|
||||
NfsVolumeServer string `json:"NfsVolumeServer" xml:"NfsVolumeServer" position:"Query" name:"NFSVolume.Server"`
|
||||
NfsVolumeReadOnly requests.Boolean `json:"NfsVolumeReadOnly" xml:"NfsVolumeReadOnly" position:"Query" name:"NFSVolume.ReadOnly"`
|
||||
EmptyDirVolumeEnable requests.Boolean `json:"EmptyDirVolumeEnable" xml:"EmptyDirVolumeEnable" position:"Query" name:"EmptyDirVolume.Enable"`
|
||||
ConfigFileVolumeConfigFileToPaths []ConfigFileToPath `json:"ConfigFileVolumeConfigFileToPaths" xml:"ConfigFileVolume" position:"Query" name:"ConfigFileVolume.ConfigFileToPath" type:"Repeated"`
|
||||
Type string `name:"Type"`
|
||||
Name string `name:"Name"`
|
||||
NfsVolumePath string `name:"NFSVolume.Path"`
|
||||
NfsVolumeServer string `name:"NFSVolume.Server"`
|
||||
NfsVolumeReadOnly requests.Boolean `name:"NFSVolume.ReadOnly"`
|
||||
EmptyDirVolumeEnable requests.Boolean `name:"EmptyDirVolume.Enable"`
|
||||
ConfigFileToPaths []ConfigFileToPath `name:"ConfigFileVolume.ConfigFileToPath" type:"Repeated"`
|
||||
}
|
||||
|
||||
@@ -19,7 +19,7 @@ import "github.com/aliyun/alibaba-cloud-sdk-go/sdk/requests"
|
||||
|
||||
// VolumeMount is a nested struct in eci response
|
||||
type VolumeMount struct {
|
||||
MountPath string `json:"MountPath" xml:"MountPath" position:"Query" name:"MountPath"`
|
||||
ReadOnly requests.Boolean `json:"ReadOnly" xml:"ReadOnly" position:"Query" name:"ReadOnly"`
|
||||
Name string `json:"Name" xml:"Name" position:"Query" name:"Name"`
|
||||
MountPath string `name:"MountPath"`
|
||||
ReadOnly requests.Boolean `name:"ReadOnly"`
|
||||
Name string `name:"Name"`
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user