mirror of
https://github.com/stakater/Reloader.git
synced 2026-02-14 18:09:50 +00:00
Implement PR-1 review comments
This commit is contained in:
13
deployments/kubernetes/templates/chart/Chart.yaml.tmpl
Normal file
13
deployments/kubernetes/templates/chart/Chart.yaml.tmpl
Normal file
@@ -0,0 +1,13 @@
|
||||
# Generated from deployments/kubernetes/templates/chart/Chart.yaml.tmpl
|
||||
|
||||
apiVersion: v1
|
||||
name: reloader
|
||||
description: Reloader chart that runs on kubernetes
|
||||
version: {{ getenv "VERSION" }}
|
||||
keywords:
|
||||
- Reloader
|
||||
- kubernetes
|
||||
home: https://github.com/stakater/Reloader
|
||||
maintainers:
|
||||
- name: Stakater
|
||||
email: hello@stakater.com
|
||||
14
deployments/kubernetes/templates/chart/values.yaml.tmpl
Normal file
14
deployments/kubernetes/templates/chart/values.yaml.tmpl
Normal file
@@ -0,0 +1,14 @@
|
||||
# Generated from deployments/kubernetes/templates/chart/values.yaml.tmpl
|
||||
|
||||
kubernetes:
|
||||
host: https://kubernetes.default
|
||||
|
||||
reloader:
|
||||
labels:
|
||||
provider: stakater
|
||||
group: com.stakater.platform
|
||||
version: {{ getenv "VERSION" }}
|
||||
image:
|
||||
name: {{ getenv "DOCKER_IMAGE" }}
|
||||
tag: "{{ getenv "VERSION" }}"
|
||||
pullPolicy: IfNotPresent
|
||||
@@ -3,10 +3,13 @@ package controller
|
||||
import (
|
||||
"time"
|
||||
"math/rand"
|
||||
"testing"
|
||||
|
||||
"github.com/stakater/Reloader/pkg/kube"
|
||||
"github.com/sirupsen/logrus"
|
||||
"k8s.io/api/core/v1"
|
||||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||||
|
||||
)
|
||||
|
||||
var (
|
||||
@@ -24,9 +27,13 @@ func randSeq(n int) string {
|
||||
return string(b)
|
||||
}
|
||||
|
||||
// Creating a Controller for Updating Pod with Default Action without Resources so messages printed
|
||||
/*func TestControllerForUpdatePodShouldUpdateDefaultAction(t *testing.T) {
|
||||
controller, err := NewController(client, "configMaps", &v1.ConfigMap{})
|
||||
// Creating a Controller to do a rolling upgrade upon updating the configmap or secret
|
||||
func TestControllerForUpdatingConfigmapShouldUpdateDeployment(t *testing.T) {
|
||||
namespace := "test-reloader"
|
||||
createNamespace(t, namespace)
|
||||
defer deleteNamespace(t, namespace)
|
||||
|
||||
controller, err := NewController(client, "configMaps", namespace)
|
||||
if err != nil {
|
||||
logrus.Infof("Unable to create NewController error = %v", err)
|
||||
return
|
||||
@@ -35,7 +42,7 @@ func randSeq(n int) string {
|
||||
defer close(stop)
|
||||
go controller.Run(1, stop)
|
||||
time.Sleep(10 * time.Second)
|
||||
namespace := "test"
|
||||
|
||||
configmapName := configmapNamePrefix + "-withoutresources-update-" + randSeq(5)
|
||||
configmapClient := client.CoreV1().ConfigMaps(namespace)
|
||||
configmap := initConfigmap(namespace, configmapName)
|
||||
@@ -47,28 +54,25 @@ func randSeq(n int) string {
|
||||
time.Sleep(10 * time.Second)
|
||||
|
||||
logrus.Infof("Updating Configmap %q.\n", configmap.GetObjectMeta().GetName())
|
||||
retryErr := retry.RetryOnConflict(retry.DefaultRetry, func() error {
|
||||
configmap, err = configmapClient.Get(configmapName, metav1.GetOptions{})
|
||||
if err != nil {
|
||||
configmap, err = configmapClient.Get(configmapName, metav1.GetOptions{})
|
||||
if err != nil {
|
||||
|
||||
}
|
||||
configmap = updateConfigmap(namespace, configmapName)
|
||||
_, updateErr := configmapClient.Update(configmap)
|
||||
return updateErr
|
||||
})
|
||||
}
|
||||
configmap = updateConfigmap(namespace, configmapName)
|
||||
_, updateErr := configmapClient.Update(configmap)
|
||||
|
||||
|
||||
// TODO: Add functionality to verify reloader functionality here
|
||||
|
||||
if retryErr != nil {
|
||||
if updateErr != nil {
|
||||
controller.client.CoreV1().ConfigMaps(namespace).Delete(configmapName, &metav1.DeleteOptions{})
|
||||
panic(retryErr)
|
||||
panic(updateErr)
|
||||
}
|
||||
time.Sleep(10 * time.Second)
|
||||
logrus.Infof("Deleting Pod %q.\n", configmap.GetObjectMeta().GetName())
|
||||
logrus.Infof("Deleting Configmap %q.\n", configmap.GetObjectMeta().GetName())
|
||||
controller.client.CoreV1().ConfigMaps(namespace).Delete(configmapName, &metav1.DeleteOptions{})
|
||||
time.Sleep(15 * time.Second)
|
||||
}*/
|
||||
}
|
||||
|
||||
func initConfigmap(namespace string, configmapName string) *v1.ConfigMap {
|
||||
return &v1.ConfigMap{
|
||||
@@ -77,6 +81,21 @@ func initConfigmap(namespace string, configmapName string) *v1.ConfigMap {
|
||||
Namespace: namespace,
|
||||
Labels: map[string]string{"firstLabel": "temp"},
|
||||
},
|
||||
Data: map[string]string{"test.url":"www.google.com"},
|
||||
}
|
||||
}
|
||||
|
||||
func createNamespace(t *testing.T, namespace string) {
|
||||
_, err := client.CoreV1().Namespaces().Create(&v1.Namespace{ObjectMeta: metav1.ObjectMeta{Name: namespace}})
|
||||
if err != nil {
|
||||
t.Error("Failed to create namespace for testing", err)
|
||||
}
|
||||
}
|
||||
|
||||
func deleteNamespace(t *testing.T, namespace string) {
|
||||
err := client.CoreV1().Namespaces().Delete(namespace, &metav1.DeleteOptions{})
|
||||
if err != nil {
|
||||
t.Error("Failed to delete namespace that was created for testing", err)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -85,7 +104,8 @@ func updateConfigmap(namespace string, configmapName string) *v1.ConfigMap {
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Name: configmapName,
|
||||
Namespace: namespace,
|
||||
Labels: map[string]string{"firstLabel": "updated"},
|
||||
Labels: map[string]string{"firstLabel": "temp"},
|
||||
},
|
||||
Data: map[string]string{"test.url":"www.stakater.com"},
|
||||
}
|
||||
}
|
||||
|
||||
@@ -16,11 +16,13 @@ const (
|
||||
updateOnChangeAnnotation = "reloader.stakater.com/update-on-change"
|
||||
)
|
||||
|
||||
// Upgrader will upgrade the relevent deployment, deamonset and deamonset.
|
||||
type Upgrader struct{
|
||||
client kubernetes.Interface
|
||||
resourceType string
|
||||
}
|
||||
|
||||
// NewUpgrader Initializes the Upgrader
|
||||
func NewUpgrader(client kubernetes.Interface, resourceType string) (*Upgrader, error) {
|
||||
u := Upgrader{
|
||||
client: client,
|
||||
|
||||
Reference in New Issue
Block a user