Skip to content
This repository was archived by the owner on May 24, 2025. It is now read-only.

Commit 7a08f3c

Browse files
authored
Merge pull request #4 from Bobonium/main
add config option to set container name in case multiple containers exist in dovecot-director pod
2 parents 53ef356 + 409ee47 commit 7a08f3c

File tree

3 files changed

+11
-4
lines changed

3 files changed

+11
-4
lines changed

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,10 @@ If you don't run it inside a k8s cluster it tries to load the kubeconfig in the
1313
If it does not exist you need to specify the absolute path with command flag "-c".
1414

1515
Environment variables needed for successful execution:
16-
* `DOVECOT_DIRECTOR_LABELS`(string): All labels given to dovecot director for conclusive identification of dovecot director pods in the following format: `<LABEL1>=<VALUE1>,<LABEL2>=<VALUE2>`
17-
* `DOVECOT_LABELS`(string): All labels given to dovecot for conclusive identification of dovecot pods, same format as in `DOVECOT_DIRECTOR_LABELS`
1816
* `DOVECOT_NAMESPACE`(string): Namespace name which must contain both dovecot director and dovecot pods
17+
* `DOVECOT_LABELS`(string): All labels given to dovecot for conclusive identification of dovecot pods, same format as in `DOVECOT_DIRECTOR_LABELS`
18+
* `DOVECOT_DIRECTOR_LABELS`(string): All labels given to dovecot director for conclusive identification of dovecot director pods in the following format: `<LABEL1>=<VALUE1>,<LABEL2>=<VALUE2>`
19+
* `DOVECOT_DIRECTOR_CONTAINER_NAME` (string) (optional): Container Name of dovecot-director in Pod. Defaults to first Container in Pod if not set.
1920

2021
### Used Library
2122
https://github.com/kubernetes/client-go

cmd/main.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ import (
2222
// variables: namespace, labels
2323
var dovecotLabels string
2424
var dovecotDirectorLabels string
25+
var dovecotDirectorContainerName string
26+
2527

2628
var namespace string
2729
var kubeconf *rest.Config
@@ -38,6 +40,8 @@ func main() {
3840
panic(err.Error())
3941
}
4042
dovecotDirectorLabels = os.Getenv("DOVECOT_DIRECTOR_LABELS")
43+
dovecotDirectorContainerName = os.Getenv("DOVECOT_DIRECTOR_CONTAINER_NAME")
44+
4145
dovecotLabels = os.Getenv("DOVECOT_LABELS")
4246
namespace = os.Getenv("DOVECOT_NAMESPACE")
4347

@@ -68,6 +72,7 @@ func ExecuteCommand(command string, podname string, namespace string, clientset
6872
req := clientset.CoreV1().RESTClient().Post().Resource("pods").Name(podname).Namespace(namespace).SubResource("exec")
6973
// THE FOLLOWING EXPECTS THE POD TO HAVE ONLY ONE CONTAINER IN WHICH THE COMMAND IS GOING TO BE EXECUTED
7074
option := &v1.PodExecOptions{
75+
Container: dovecotDirectorContainerName,
7176
Command: cmd,
7277
Stdin: false,
7378
Stdout: true,

docker/docker-compose.yaml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ services:
88
volumes:
99
- ~/.kube/.config:/root/.kube/config
1010
environment:
11-
- DOVECOT_DIRECTOR_LABELS=app.kubernetes.io/instance=test,app.kubernetes.io/name=dovecot-director
12-
- DOVECOT_LABELS=app.kubernetes.io/instance=test,app.kubernetes.io/name=dovecot
1311
- DOVECOT_NAMESPACE=mail
12+
- DOVECOT_LABELS=app.kubernetes.io/instance=test,app.kubernetes.io/name=dovecot
13+
- DOVECOT_DIRECTOR_LABELS=app.kubernetes.io/instance=test,app.kubernetes.io/name=dovecot-director
14+
- DOVECOT_DIRECTOR_CONTAINER_NAME=dovecot-director

0 commit comments

Comments
 (0)