From e6aa80d2c4d2a1ed61d87281fca662370bd403f9 Mon Sep 17 00:00:00 2001 From: shidao-ytt <43381136+shidao-ytt@users.noreply.github.com> Date: Wed, 10 Oct 2018 03:30:18 +0800 Subject: [PATCH] Add secret volume (#370) * add secret volume implement with config map Signed-off-by: xianwei.zw Signed-off-by: shidao-ytt * add request log for CreateContainerGroup --- providers/alicloud/eci.go | 30 +++++++++++++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/providers/alicloud/eci.go b/providers/alicloud/eci.go index 68056c8a2..921d66e98 100644 --- a/providers/alicloud/eci.go +++ b/providers/alicloud/eci.go @@ -214,11 +214,13 @@ func (p *ECIProvider) CreatePod(ctx context.Context, pod *v1.Pod) error { request.SecurityGroupId = p.secureGroup request.VSwitchId = p.vSwitch request.ContainerGroupName = ContainerGroupName + msg := fmt.Sprintf("CreateContainerGroup request %+v", request) + log.G(ctx).WithField("Method", "CreatePod").Info(msg) response, err := p.eciClient.CreateContainerGroup(request) if err != nil { return err } - msg := fmt.Sprintf("CreateContainerGroup successed. %s, %s, %s", response.RequestId, response.ContainerGroupId, ContainerGroupName) + msg = fmt.Sprintf("CreateContainerGroup successed. %s, %s, %s", response.RequestId, response.ContainerGroupId, ContainerGroupName) log.G(ctx).WithField("Method", "CreatePod").Info(msg) return nil } @@ -652,6 +654,32 @@ func (p *ECIProvider) getVolumes(pod *v1.Pod) ([]eci.Volume, error) { continue } + if v.Secret != nil { + ConfigFileToPaths := make([]eci.ConfigFileToPath, 0) + secret, err := p.resourceManager.GetSecret(v.Secret.SecretName, pod.Namespace) + if v.Secret.Optional != nil && !*v.Secret.Optional && k8serr.IsNotFound(err) { + return nil, fmt.Errorf("Secret %s is required by Pod %s and does not exist", v.Secret.SecretName, pod.Name) + } + if secret == nil { + continue + } + for k, v := range secret.Data { + var b bytes.Buffer + enc := base64.NewEncoder(base64.StdEncoding, &b) + enc.Write(v) + ConfigFileToPaths = append(ConfigFileToPaths, eci.ConfigFileToPath{Path: k, Content: b.String()}) + } + + if len(ConfigFileToPaths) != 0 { + volumes = append(volumes, eci.Volume{ + Type: eci.VOL_TYPE_CONFIGFILEVOLUME, + Name: v.Name, + ConfigFileVolumeConfigFileToPaths: ConfigFileToPaths, + }) + } + continue + } + // If we've made it this far we have found a volume type that isn't supported return nil, fmt.Errorf("Pod %s requires volume %s which is of an unsupported type\n", pod.Name, v.Name) }