This is an automated email from the ASF dual-hosted git repository.
kichan pushed a commit to branch master
in repository
https://gitbox.apache.org/repos/asf/trafficserver-ingress-controller.git
The following commit(s) were added to refs/heads/master by this push:
new 8ee930f Resolves conflicting configmaps (#39)
8ee930f is described below
commit 8ee930fbca41ecebb588895d056b58e7d056b04a
Author: Rishabh Chhabra <[email protected]>
AuthorDate: Mon Aug 10 16:31:04 2020 -0500
Resolves conflicting configmaps (#39)
* Resolves conflicting configmaps
* Removes extraneous file
* Modifies readme to add annotation instructions
---
README.md | 4 +-
charts/ats-ingress/templates/ats-configmap.yaml | 1 +
k8s/configmaps/ats-configmap.yaml | 2 +
watcher/handlerConfigmap.go | 10 +++++
watcher/handlerConfigmap_test.go | 20 ++++++++++
watcher/watcher_test.go | 49 +++++++++++++++++++++++++
6 files changed, 84 insertions(+), 2 deletions(-)
diff --git a/README.md b/README.md
index a680c73..e1a8ae7 100644
--- a/README.md
+++ b/README.md
@@ -134,8 +134,8 @@ When both steps _above_ have executed at least once, ATS
proxying will have star
Below is an example of configuring Apache Traffic Server [_reloadable_
configurations](https://docs.trafficserver.apache.org/en/8.0.x/admin-guide/files/records.config.en.html#reloadable)
using [kubernetes
configmap](https://kubernetes.io/docs/tasks/configure-pod-container/configure-pod-configmap/)
resource:
-- `$ kubectl apply -f k8s/configmaps/`
- - create a ConfigMap resource in `trafficserver-test` if not already exist
+- `$ kubectl apply -f k8s/configmaps/ats-configmap.yaml`
+ - create a ConfigMap resource in `trafficserver-test` with the annotation
`"ats-configmap":"true"` if not already exist
- configure 3 _reloadable_ ATS configurations:
1. `proxy.config.output.logfile.rolling_enabled: "1"`
2. `proxy.config.output.logfile.rolling_interval_sec: "3000"`
diff --git a/charts/ats-ingress/templates/ats-configmap.yaml
b/charts/ats-ingress/templates/ats-configmap.yaml
index cf825da..425da11 100644
--- a/charts/ats-ingress/templates/ats-configmap.yaml
+++ b/charts/ats-ingress/templates/ats-configmap.yaml
@@ -22,6 +22,7 @@ metadata:
"helm.sh/hook": post-install
"helm.sh/hook-weight": "0"
"helm.sh/hook-delete-policy": before-hook-creation
+ "ats-configmap": "true"
data:
# reloadable data only
proxy.config.log.logfile_dir: {{ .Values.ats.log.dir | quote }}
\ No newline at end of file
diff --git a/k8s/configmaps/ats-configmap.yaml
b/k8s/configmaps/ats-configmap.yaml
index 7d66ddd..79078ff 100644
--- a/k8s/configmaps/ats-configmap.yaml
+++ b/k8s/configmaps/ats-configmap.yaml
@@ -26,6 +26,8 @@ kind: ConfigMap
metadata:
namespace: trafficserver-test
name: ats
+ annotations:
+ "ats-configmap" : "true"
data:
# reloadable data only
proxy.config.output.logfile.rolling_enabled: "1"
diff --git a/watcher/handlerConfigmap.go b/watcher/handlerConfigmap.go
index 84bccd1..0283c0d 100644
--- a/watcher/handlerConfigmap.go
+++ b/watcher/handlerConfigmap.go
@@ -41,6 +41,16 @@ func (c *CMHandler) update(newObj interface{}) {
log.Println("In ConfigMapHandler Update; cannot cast to
*v1.ConfigMap")
return
}
+
+ annotations := cm.GetAnnotations()
+ if val, ok := annotations["ats-configmap"]; ok {
+ if val != "true" {
+ return
+ }
+ } else {
+ return
+ }
+
for currKey, currVal := range cm.Data {
msg, err := c.Ep.ATSManager.ConfigSet(currKey, currVal) //
update ATS
if err != nil {
diff --git a/watcher/handlerConfigmap_test.go b/watcher/handlerConfigmap_test.go
index f952fc5..37ac248 100644
--- a/watcher/handlerConfigmap_test.go
+++ b/watcher/handlerConfigmap_test.go
@@ -59,6 +59,23 @@ func TestAdd_BasicConfigMap(t *testing.T) {
}
+func TestShouldNotAdd_BasicConfigMap(t *testing.T) {
+ cmHandler := createExampleCMHandler()
+ exampleConfigMap := createExampleConfigMap()
+
+ exampleConfigMap.Annotations = map[string]string{
+ "ats-configmap": "false",
+ }
+
+ cmHandler.Add(&exampleConfigMap)
+
+ rEnabled, err :=
cmHandler.Ep.ATSManager.ConfigGet("proxy.config.output.logfile.rolling_enabled")
+
+ if err == nil {
+ t.Errorf("Should not have executed. Instead gives %s", rEnabled)
+ }
+}
+
func TestUpdate_BasicConfigMap(t *testing.T) {
cmHandler := createExampleCMHandler()
exampleConfigMap := createExampleConfigMap()
@@ -97,6 +114,9 @@ func createExampleConfigMap() v1.ConfigMap {
ObjectMeta: meta_v1.ObjectMeta{
Name: "testsvc",
Namespace: "trafficserver-test-2",
+ Annotations: map[string]string{
+ "ats-configmap": "true",
+ },
},
Data: map[string]string{
"proxy.config.output.logfile.rolling_enabled": "1",
diff --git a/watcher/watcher_test.go b/watcher/watcher_test.go
index e4ae13c..9bd8dfc 100644
--- a/watcher/watcher_test.go
+++ b/watcher/watcher_test.go
@@ -240,6 +240,9 @@ func TestInNamespacesWatchFor_Add(t *testing.T) {
ObjectMeta: meta_v1.ObjectMeta{
Name: "testsvc",
Namespace: "trafficserver",
+ Annotations: map[string]string{
+ "ats-configmap": "true",
+ },
},
Data: map[string]string{
"proxy.config.output.logfile.rolling_enabled": "1",
@@ -292,6 +295,9 @@ func TestInNamespacesWatchFor_Update(t *testing.T) {
ObjectMeta: meta_v1.ObjectMeta{
Name: "testsvc",
Namespace: "trafficserver",
+ Annotations: map[string]string{
+ "ats-configmap": "true",
+ },
},
Data: map[string]string{
"proxy.config.output.logfile.rolling_enabled": "1",
@@ -305,6 +311,9 @@ func TestInNamespacesWatchFor_Update(t *testing.T) {
ObjectMeta: meta_v1.ObjectMeta{
Name: "testsvc",
Namespace: "trafficserver",
+ Annotations: map[string]string{
+ "ats-configmap": "true",
+ },
},
Data: map[string]string{
"proxy.config.output.logfile.rolling_enabled": "1",
@@ -357,6 +366,9 @@ func TestInNamespacesWatchFor_ShouldNotAdd(t *testing.T) {
ObjectMeta: meta_v1.ObjectMeta{
Name: "testsvc",
Namespace: "trafficserver",
+ Annotations: map[string]string{
+ "ats-configmap": "true",
+ },
},
Data: map[string]string{
"proxy.config.output.logfile.rolling_enabled": "1",
@@ -402,6 +414,43 @@ func TestInNamespacesWatchFor_ShouldNotAdd(t *testing.T) {
} else if !reflect.DeepEqual(threshold, "2") {
t.Errorf("returned \n%s, but expected \n%s", threshold, "2")
}
+
+ w.Cs.CoreV1().ConfigMaps("trafficserver-2").Create(&v1.ConfigMap{
+ ObjectMeta: meta_v1.ObjectMeta{
+ Name: "testsvc",
+ Namespace: "trafficserver",
+ },
+ Data: map[string]string{
+ "proxy.config.output.logfile.rolling_enabled": "1",
+ "proxy.config.output.logfile.rolling_interval_sec":
"3000",
+ "proxy.config.restart.active_client_threshold": "4",
+ },
+ })
+ time.Sleep(100 * time.Millisecond)
+
+ rEnabled, err =
cmHandler.Ep.ATSManager.ConfigGet("proxy.config.output.logfile.rolling_enabled")
+
+ if err != nil {
+ t.Error(err)
+ } else if !reflect.DeepEqual(rEnabled, "1") {
+ t.Errorf("returned \n%s, but expected \n%s", rEnabled, "1")
+ }
+
+ rInterval, err =
cmHandler.Ep.ATSManager.ConfigGet("proxy.config.output.logfile.rolling_interval_sec")
+
+ if err != nil {
+ t.Error(err)
+ } else if !reflect.DeepEqual(rInterval, "4000") {
+ t.Errorf("returned \n%s, but expected \n%s", rInterval, "4000")
+ }
+
+ threshold, err =
cmHandler.Ep.ATSManager.ConfigGet("proxy.config.restart.active_client_threshold")
+
+ if err != nil {
+ t.Error(err)
+ } else if !reflect.DeepEqual(threshold, "2") {
+ t.Errorf("returned \n%s, but expected \n%s", threshold, "2")
+ }
}
func getTestWatcher() (Watcher, *framework.FakeControllerSource) {