Skip to content

Commit

Permalink
Merge pull request #23 from stakater/global-namespaces
Browse files Browse the repository at this point in the history
make konfigurator configurable to watch all namespaces
  • Loading branch information
kahootali authored Jan 11, 2019
2 parents 284e1bc + 04de664 commit da64b49
Show file tree
Hide file tree
Showing 7 changed files with 50 additions and 24 deletions.
5 changes: 3 additions & 2 deletions Jenkinsfile
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
#!/usr/bin/groovy
@Library('github.com/stakater/fabric8-pipeline-library@v2.9.8')
@Library('github.com/stakater/fabric8-pipeline-library@v2.10.3')

def dummy

goBuildAndRelease {
toolsImage = "stakater/pipeline-tools:1.13.0"
toolsImage = "stakater/pipeline-tools:1.13.2"
chartRepositoryURL = 'https://stakater.github.io/stakater-charts'
}
29 changes: 18 additions & 11 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,12 @@ A kubernetes operator that can dynamically generate app configuration when kuber

## Deploying to Kubernetes

Deploying Konfigurator is a 2 step procedure:
Deploying Konfigurator requires:

1. Deploy CRD to your cluster
2. Deploy Konfigurator operator
1. Deploying CRD to your cluster
2. Deploying Konfigurator operator

So first apply the CRD manifest by running the following command:

```bash
kubectl apply -f https://raw.githubusercontent.com/stakater/Konfigurator/master/deploy/crd.yaml
```

Once the CRD is installed, you can deploy the operator on your kubernetes cluster via any of the following methods.
You can deploy the CRD and operator on your kubernetes cluster via any of the following methods.

### Vanilla Manifests

Expand All @@ -43,7 +37,12 @@ You can apply vanilla manifests by running the following command
kubectl apply -f https://raw.githubusercontent.com/stakater/Konfigurator/master/deployments/kubernetes/konfigurator.yaml
```

By default Konfigurator gets deployed in the default namespace and manages its custom resources in that namespace.
Konfigurator by default looks for **KonfiguratorTemplate** only in the namespace where it is deployed, but it can be managed to work globally, you would have to change the `WATCH_NAMESPACE` environment variable to "" in the above manifest. e.g. change `WWATCH_NAMESPACE` section to:

```yaml
- name: WATCH_NAMESPACE
value: ""
```
### Helm Charts
Expand All @@ -59,6 +58,14 @@ helm install stakater/konfigurator

Once Konfigurator is running, you can start creating resources supported by it. For details about its custom resources, look [here](https://github.com/stakater/Konfigurator/tree/master/docs/konfigurator-template.md).

To make Konfigurator work globally, you would have to change the `WATCH_NAMESPACE` environment variable to "" in values.yaml. e.g. change `WWATCH_NAMESPACE` section to:

```yaml
env:
- name: WATCH_NAMESPACE
value: ""
```
## Help
**Got a question?**
Expand Down
15 changes: 10 additions & 5 deletions cmd/Konfigurator/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@ package main

import (
"context"
"os"
"runtime"

sdk "github.com/operator-framework/operator-sdk/pkg/sdk"
"github.com/operator-framework/operator-sdk/pkg/util/k8sutil"
sdkVersion "github.com/operator-framework/operator-sdk/version"
kContext "github.com/stakater/Konfigurator/pkg/context"
stub "github.com/stakater/Konfigurator/pkg/stub"
Expand Down Expand Up @@ -36,14 +36,19 @@ func main() {
}

func watchKonfiguratorTemplate() {
namespace, err := k8sutil.GetWatchNamespace()
if err != nil {
logrus.Fatalf("Failed to get watch namespace: %v", err)
}
namespace := getWatchNamespace()

watch("konfigurator.stakater.com/v1alpha1", "KonfiguratorTemplate", namespace, 15)
}

func getWatchNamespace() string {
namespace := os.Getenv("WATCH_NAMESPACE")
if namespace == "" {
logrus.Infof("WATCH_NAMESPACE is empty")
}
return namespace
}

func watchPods() {
watch("v1", "Pod", "", 0)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,7 @@ spec:
command:
- Konfigurator
env:
- name: WATCH_NAMESPACE
valueFrom:
fieldRef:
fieldPath: metadata.namespace
- name: OPERATOR_NAME
value: "{{ template "konfigurator.name" . }}"
{{ toYaml .Values.konfigurator.env | indent 12 }}
serviceAccountName: {{ template "konfigurator.name" . }}
6 changes: 6 additions & 0 deletions deployments/kubernetes/chart/konfigurator/templates/rbac.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,12 @@ rules:
- secrets
verbs:
- "*"
- apiGroups:
- "*"
resources:
- konfiguratortemplates
verbs:
- "*"
---

kind: ClusterRoleBinding
Expand Down
7 changes: 6 additions & 1 deletion deployments/kubernetes/chart/konfigurator/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,9 @@ konfigurator:
image:
name: stakater/konfigurator
tag: "0.0.11"
pullPolicy: IfNotPresent
pullPolicy: IfNotPresent
env:
- name: WATCH_NAMESPACE
valueFrom:
fieldRef:
fieldPath: metadata.namespace
7 changes: 6 additions & 1 deletion deployments/kubernetes/templates/chart/values.yaml.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,9 @@ konfigurator:
image:
name: {{ getenv "DOCKER_IMAGE" }}
tag: "{{ getenv "VERSION" }}"
pullPolicy: IfNotPresent
pullPolicy: IfNotPresent
env:
- name: WATCH_NAMESPACE
valueFrom:
fieldRef:
fieldPath: metadata.namespace

0 comments on commit da64b49

Please sign in to comment.