diff --git a/README.md b/README.md index c2515e7..141107f 100644 --- a/README.md +++ b/README.md @@ -13,9 +13,10 @@ If you don't run it inside a k8s cluster it tries to load the kubeconfig in the If it does not exist you need to specify the absolute path with command flag "-c". Environment variables needed for successful execution: -* `DOVECOT_DIRECTOR_LABELS`(string): All labels given to dovecot director for conclusive identification of dovecot director pods in the following format: `=,=` -* `DOVECOT_LABELS`(string): All labels given to dovecot for conclusive identification of dovecot pods, same format as in `DOVECOT_DIRECTOR_LABELS` * `DOVECOT_NAMESPACE`(string): Namespace name which must contain both dovecot director and dovecot pods +* `DOVECOT_LABELS`(string): All labels given to dovecot for conclusive identification of dovecot pods, same format as in `DOVECOT_DIRECTOR_LABELS` +* `DOVECOT_DIRECTOR_LABELS`(string): All labels given to dovecot director for conclusive identification of dovecot director pods in the following format: `=,=` +* `DOVECOT_DIRECTOR_CONTAINER_NAME` (string) (optional): Container Name of dovecot-director in Pod. Defaults to first Container in Pod if not set. ### Used Library https://github.com/kubernetes/client-go diff --git a/cmd/main.go b/cmd/main.go index f3f77b4..1c29029 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -22,6 +22,8 @@ import ( // variables: namespace, labels var dovecotLabels string var dovecotDirectorLabels string +var dovecotDirectorContainerName string + var namespace string var kubeconf *rest.Config @@ -38,6 +40,8 @@ func main() { panic(err.Error()) } dovecotDirectorLabels = os.Getenv("DOVECOT_DIRECTOR_LABELS") + dovecotDirectorContainerName = os.Getenv("DOVECOT_DIRECTOR_CONTAINER_NAME") + dovecotLabels = os.Getenv("DOVECOT_LABELS") namespace = os.Getenv("DOVECOT_NAMESPACE") @@ -68,6 +72,7 @@ func ExecuteCommand(command string, podname string, namespace string, clientset req := clientset.CoreV1().RESTClient().Post().Resource("pods").Name(podname).Namespace(namespace).SubResource("exec") // THE FOLLOWING EXPECTS THE POD TO HAVE ONLY ONE CONTAINER IN WHICH THE COMMAND IS GOING TO BE EXECUTED option := &v1.PodExecOptions{ + Container: dovecotDirectorContainerName, Command: cmd, Stdin: false, Stdout: true, diff --git a/docker/docker-compose.yaml b/docker/docker-compose.yaml index 1a3e171..3eaccbc 100644 --- a/docker/docker-compose.yaml +++ b/docker/docker-compose.yaml @@ -8,6 +8,7 @@ services: volumes: - ~/.kube/.config:/root/.kube/config environment: - - DOVECOT_DIRECTOR_LABELS=app.kubernetes.io/instance=test,app.kubernetes.io/name=dovecot-director - - DOVECOT_LABELS=app.kubernetes.io/instance=test,app.kubernetes.io/name=dovecot - DOVECOT_NAMESPACE=mail + - DOVECOT_LABELS=app.kubernetes.io/instance=test,app.kubernetes.io/name=dovecot + - DOVECOT_DIRECTOR_LABELS=app.kubernetes.io/instance=test,app.kubernetes.io/name=dovecot-director + - DOVECOT_DIRECTOR_CONTAINER_NAME=dovecot-director