Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding support for Secrets #20

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
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
1 change: 0 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
*.swp
bin/
_dist/
.idea
golib
Expand Down
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,5 @@ FROM scratch

ENTRYPOINT ["/configmapcontroller"]

COPY bin/kubectl /kubectl
Copy link

@joekohlsdorf joekohlsdorf Apr 3, 2018

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you explain why it is necessary to ship the binary? Is using kubectl the only way to do this?

COPY ./build/configmapcontroller-linux-amd64 /configmapcontroller
15 changes: 10 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,23 +1,28 @@
# configmapcontroller

This controller watches for changes to `ConfigMap` objects and performs rolling upgrades on their associated deployments for apps which are not capable of watching the `ConfigMap` and updating dynamically.
This controller watches for changes to `ConfigMap` or `Secret` objects and performs rolling upgrades on their associated deployments,daemonsets or statefulsets for apps which are not capable of watching the `ConfigMap` and updating dynamically.

This is particularly useful if the `ConfigMap` is used to define environment variables - or your app cannot easily and reliably watch the `ConfigMap` and update itself on the fly.
This is particularly useful if the `ConfigMap` or `Secret` is used to define environment variables - or your app cannot easily and reliably watch the `ConfigMap` and update itself on the fly.

## How to use configmapcontroller

For a `Deployment` called `foo` have a `ConfigMap` called `foo`. Then add this annotation to your `Deployment`
For an object(DaemonSet, Deployment, StatefulSet) called `foo` have a `ConfigMap` called `foo`. Then add this annotation to your manifest:

```yaml
metadata:
annotations:
configmap.fabric8.io/update-on-change: "foo"
```

Then, providing `configmapcontroller` is running, whenever you edit the `ConfigMap` called `foo` the configmapcontroller will update the `Deployment` by adding the environment variable:
For configmaps use the annotation configmap.frabric8.io/update-on-change.

For secrets use the annotation secret.fabric8.io/update-on-change.

Then, providing `configmapcontroller` is running, whenever you edit the `ConfigMap` called `foo` the configmapcontroller will update the `Deployment`, `StatefulSet` or `DaemonSet` by labeling it and hence triggering a rolling update on the object provided that .spec.updateStrategy.type is set to `RollingUpdate`.

The label would be

```
FABRICB_FOO_REVISION=${configMapRevision}
```

This then triggers a rolling upgrade of your deployment's pods to use the new configuration.
Binary file added bin/kubectl
Binary file not shown.
18 changes: 1 addition & 17 deletions configmapcontroller.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,9 @@ import (
"syscall"
"time"

"github.com/fabric8io/configmapcontroller/client"
"github.com/fabric8io/configmapcontroller/controller"
"github.com/fabric8io/configmapcontroller/util"
"github.com/fabric8io/configmapcontroller/version"
"github.com/golang/glog"
oclient "github.com/openshift/origin/pkg/client"
"github.com/spf13/pflag"
"k8s.io/kubernetes/pkg/api"
kubectlutil "k8s.io/kubernetes/pkg/kubectl/cmd/util"
Expand Down Expand Up @@ -55,27 +52,14 @@ func main() {
glog.Fatalf("failed to create REST client config: %s", err)
}

var oc *oclient.Client
typeOfMaster, err := util.TypeOfMaster(kubeClient)
if err != nil {
glog.Fatalf("failed to create REST client config: %s", err)
}
if typeOfMaster == util.OpenShift {
oc, _, err = client.NewOpenShiftClient(restClientConfig)
if err != nil {
glog.Fatalf("failed to create REST client config: %s", err)
}
}

watchNamespaces := api.NamespaceAll
currentNamespace := os.Getenv("KUBERNETES_NAMESPACE")
if len(currentNamespace) > 0 {
watchNamespaces = currentNamespace
}
glog.Infof("Watching services in namespaces: `%s`", watchNamespaces)


c, err := controller.NewController(kubeClient, oc, restClientConfig, factory.JSONEncoder(), *resyncPeriod, watchNamespaces)
c, err := controller.NewController(kubeClient, restClientConfig, factory.JSONEncoder(), *resyncPeriod, watchNamespaces)
if err != nil {
glog.Fatalf("%s", err)
}
Expand Down
Loading