mirror of
https://github.com/stakater/Reloader.git
synced 2026-02-14 09:59:50 +00:00
Implement PR-1 review comments
This commit is contained in:
@@ -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)
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
@@ -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")
|
||||
)
|
||||
|
||||
@@ -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{})
|
||||
@@ -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)
|
||||
@@ -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{
|
||||
|
||||
@@ -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")
|
||||
}
|
||||
@@ -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")
|
||||
}
|
||||
|
||||
@@ -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{},
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user