Skip to content

Commit

Permalink
Increased timeout for docker pull to 2 minutes and made value configu…
Browse files Browse the repository at this point in the history
…rable
  • Loading branch information
torresdal committed Aug 23, 2019
1 parent cac1a28 commit 4ae4984
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion cmd/azure-keyvault-secrets-webhook/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ type azureKeyVaultConfig struct {
aadPodBindingLabel string
cloudConfigHostPath string
cloudConfigContainerPath string
dockerPullTimeout int
}

var config azureKeyVaultConfig
Expand Down Expand Up @@ -287,7 +288,7 @@ func getContainerCmd(container corev1.Container, creds string) ([]string, error)
}

func getDockerImage(container corev1.Container, creds string) (*dockertypes.ImageInspect, error) {
timeout := 30 * time.Second
timeout := time.Duration(config.dockerPullTimeout) * time.Second
ctx, cancel := context.WithTimeout(context.Background(), timeout)
defer cancel()

Expand All @@ -312,6 +313,10 @@ func getDockerImage(container corev1.Container, creds string) (*dockertypes.Imag
return nil, fmt.Errorf("failed to pull docker image '%s', error: %+v", imageName, err)
}

if ctx.Err() != nil {
return nil, ctx.Err()
}

imgPullOutput, err := ioutil.ReadAll(imgReader)
log.Debugf("docker pull image output: %s", imgPullOutput)
// io.Copy(os.Stdout, imgReader)
Expand All @@ -325,6 +330,10 @@ func getDockerImage(container corev1.Container, creds string) (*dockertypes.Imag
return nil, fmt.Errorf("failed to inspect docker image '%s', error: %+v", imageName, err)
}

if ctx.Err() != nil {
return nil, ctx.Err()
}

return &inspect, nil
}

Expand Down Expand Up @@ -511,6 +520,7 @@ func mutatePodSpec(pod *corev1.Pod) error {

func initConfig() {
viper.SetDefault("azurekeyvault_env_image", "spvest/azure-keyvault-env:latest")
viper.SetDefault("custom_docker_pull_timeout", 120)
viper.AutomaticEnv()
}

Expand Down Expand Up @@ -543,6 +553,7 @@ func main() {
customAuth: viper.GetBool("CUSTOM_AUTH"),
customAuthAutoInject: viper.GetBool("CUSTOM_AUTH_INJECT"),
credentialsSecretName: viper.GetString("CUSTOM_AUTH_INJECT_SECRET_NAME"),
dockerPullTimeout: viper.GetInt("CUSTOM_DOCKER_PULL_TIMEOUT"),
cloudConfigHostPath: "/etc/kubernetes/azure.json",
cloudConfigContainerPath: "/azure-keyvault/azure.json",
}
Expand Down

0 comments on commit 4ae4984

Please sign in to comment.