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