Skip to content
This repository was archived by the owner on May 24, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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: `<LABEL1>=<VALUE1>,<LABEL2>=<VALUE2>`
* `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: `<LABEL1>=<VALUE1>,<LABEL2>=<VALUE2>`
* `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
5 changes: 5 additions & 0 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ import (
// variables: namespace, labels
var dovecotLabels string
var dovecotDirectorLabels string
var dovecotDirectorContainerName string


var namespace string
var kubeconf *rest.Config
Expand All @@ -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")

Expand Down Expand Up @@ -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,
Expand Down
5 changes: 3 additions & 2 deletions docker/docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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