Skip to content

Commit

Permalink
Implement PR-1 review comments
Browse files Browse the repository at this point in the history
  • Loading branch information
faizanahmad055 committed Jul 13, 2018
1 parent c35bb74 commit 82bd2b5
Show file tree
Hide file tree
Showing 8 changed files with 62 additions and 11 deletions.
2 changes: 1 addition & 1 deletion .version
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1.0.0
0.0.1
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ We would like to watch if some change happens in `ConfigMap` and `Secret` object

## Solution

Reloader can watch any changes in `ConfigMap` and `Secret` objects and then performs rolling upgrades on their associated `Deployments`, `Deamonsets` and `Statefulsets` and updating these dynamically.
Reloader can watch any changes in `ConfigMap` and `Secret` objects and update or recreate Pods for their associated `Deployments`, `Deamonsets` and `Statefulsets`. In this way Pods can get the latest changes in `ConfigMap` or `Secret` objects.

**NOTE:** This controller has been inspired from [configmapController](https://github.com/fabric8io/configmapcontroller)

Expand Down
2 changes: 1 addition & 1 deletion deployments/kubernetes/chart/reloader/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
apiVersion: v1
name: reloader
description: Reloader chart that runs on kubernetes
version: 1.0.0
version: 0.0.1
keywords:
- Reloader
- kubernetes
Expand Down
4 changes: 2 additions & 2 deletions deployments/kubernetes/chart/reloader/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ reloader:
labels:
provider: stakater
group: com.stakater.platform
version: 1.0.0
version: 0.0.1
image:
name: stakater/reloader
tag: "1.0.0"
tag: "0.0.1"
pullPolicy: IfNotPresent
55 changes: 53 additions & 2 deletions internal/pkg/controller/controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,14 @@ import (
"github.com/sirupsen/logrus"
"github.com/stakater/Reloader/pkg/kube"
"k8s.io/api/core/v1"
"k8s.io/api/extensions/v1beta1"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

var (
client, err = kube.GetClient()
client, _ = kube.GetClient()
configmapNamePrefix = "testconfigmap-reloader"
secretNamePrefix = "testsecret-reloader"
secretNamePrefix = "testsecret-reloader"
letters = []rune("abcdefghijklmnopqrstuvwxyz")
)

Expand Down Expand Up @@ -48,10 +49,12 @@ func TestControllerForUpdatingConfigmapShouldUpdateDeployment(t *testing.T) {
configmap := initConfigmap(namespace, configmapName)
configmap, err = configmapClient.Create(configmap)
if err != nil {
logrus.Infof("Error detected %s.\n", err)
panic(err)
}
logrus.Infof("Created Configmap %q.\n", configmap.GetObjectMeta().GetName())
time.Sleep(10 * time.Second)
createDeployement(configmapName, namespace)

logrus.Infof("Updating Configmap %q.\n", configmap.GetObjectMeta().GetName())
configmap, err = configmapClient.Get(configmapName, metav1.GetOptions{})
Expand All @@ -77,6 +80,17 @@ func TestControllerForUpdatingConfigmapShouldUpdateDeployment(t *testing.T) {
time.Sleep(15 * time.Second)
}

func createDeployement(deploymentName string, namespace string) {
deploymentClient := client.Extensions().Deployments(namespace)
deployment := initDeployment(namespace, deploymentName)
deployment, error := deploymentClient.Create(deployment)
if error != nil {
panic(error)
}
//time.Sleep(10 * time.Second)
logrus.Infof("Created Deployment %q.\n", deployment.GetObjectMeta().GetName())
}

func TestControllerForUpdatingSecretShouldUpdateDeployment(t *testing.T) {
namespace := "test-reloader-secrets"
createNamespace(t, namespace)
Expand Down Expand Up @@ -137,6 +151,43 @@ func initConfigmap(namespace string, configmapName string) *v1.ConfigMap {
}
}

func initDeployment(namespace string, deploymentName string) *v1beta1.Deployment {
replicaset := int32(1)
return &v1beta1.Deployment{
ObjectMeta: metav1.ObjectMeta{
Name: deploymentName,
Namespace: namespace,
Labels: map[string]string{"firstLabel": "temp"},
Annotations: map[string]string{"reloader.stakater.com/update-on-change": deploymentName},
},
Spec: v1beta1.DeploymentSpec{
Replicas: &replicaset,
Strategy: v1beta1.DeploymentStrategy{
Type: v1beta1.RollingUpdateDeploymentStrategyType,
},
Template: v1.PodTemplateSpec{
ObjectMeta: metav1.ObjectMeta{
Labels: map[string]string{"secondLabel": "temp"},
},
Spec: v1.PodSpec{
Containers: []v1.Container{
v1.Container{
Image: "tutum/hello-world",
Name: deploymentName,
Env: []v1.EnvVar{
v1.EnvVar{
Name: "BUCKET_NAME",
Value: "test",
},
},
},
},
},
},
},
}
}

func initSecret(namespace string, secretName string) *v1.Secret {
return &v1.Secret{
ObjectMeta: metav1.ObjectMeta{
Expand Down
4 changes: 2 additions & 2 deletions internal/pkg/upgrader/upgrader.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ func rollingUpgradeDeployments(oldObj interface{}, client kubernetes.Interface)
configMapName := oldObj.(*v1.ConfigMap).Name
configMapVersion := convertConfigMapToToken(oldObj.(*v1.ConfigMap))

deployments, err := client.Apps().Deployments(ns).List(meta_v1.ListOptions{})
deployments, err := client.ExtensionsV1beta1().Deployments(ns).List(meta_v1.ListOptions{})
if err != nil {
return errors.Wrap(err, "failed to list deployments")
}
Expand All @@ -79,7 +79,7 @@ func rollingUpgradeDeployments(oldObj interface{}, client kubernetes.Interface)
updateContainers(containers, annotationValue, configMapVersion)

// update the deployment
_, err := client.Apps().Deployments(ns).Update(&d)
_, err := client.ExtensionsV1beta1().Deployments(ns).Update(&d)
if err != nil {
return errors.Wrap(err, "update deployment failed")
}
Expand Down
2 changes: 1 addition & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,4 @@ func main() {
os.Exit(1)
}
os.Exit(0)
}
}
2 changes: 1 addition & 1 deletion pkg/kube/resourcemapper.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ import (
// ResourceMap are resources from where changes are going to be detected
var ResourceMap = map[string]runtime.Object{
"configMaps": &v1.ConfigMap{},
"secrets": &v1.Secret{},
"secrets": &v1.Secret{},
}

0 comments on commit 82bd2b5

Please sign in to comment.