|
| 1 | +// Copyright 2019 HAProxy Technologies LLC |
| 2 | +// |
| 3 | +// Licensed under the Apache License, Version 2.0 (the "License"); |
| 4 | +// you may not use this file except in compliance with the License. |
| 5 | +// You may obtain a copy of the License at |
| 6 | +// |
| 7 | +// http://www.apache.org/licenses/LICENSE-2.0 |
| 8 | +// |
| 9 | +// Unless required by applicable law or agreed to in writing, software |
| 10 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +// See the License for the specific language governing permissions and |
| 13 | +// limitations under the License. |
| 14 | + |
| 15 | +package timeoutserver |
| 16 | + |
| 17 | +import ( |
| 18 | + "github.com/haproxytech/kubernetes-ingress/pkg/k8s" |
| 19 | + "github.com/haproxytech/kubernetes-ingress/pkg/store" |
| 20 | + networkingv1 "k8s.io/api/networking/v1" |
| 21 | +) |
| 22 | + |
| 23 | +func (suite *TimeoutServerSuite) TestTimeoutServerConfigMap() { |
| 24 | + // name := suite.T().Name() |
| 25 | + // testController := suite.TestControllers[name] |
| 26 | + |
| 27 | + suite.StartController() |
| 28 | + cm := suite.setupTest() |
| 29 | + |
| 30 | + /////////////////////////////////////// |
| 31 | + // timeout server setup in: |
| 32 | + // - configmap only |
| 33 | + cm.Status = store.MODIFIED |
| 34 | + cm.Annotations["timeout-server"] = "77000" |
| 35 | + svc := newAppSvc() |
| 36 | + ing := newAppIngress() |
| 37 | + events := []k8s.SyncDataEvent{ |
| 38 | + {SyncType: k8s.CONFIGMAP, Namespace: configMapNamespace, Name: configMapName, Data: cm}, |
| 39 | + {SyncType: k8s.SERVICE, Namespace: appNs, Name: serviceName, Data: svc}, |
| 40 | + {SyncType: k8s.INGRESS, Namespace: appNs, Name: ingressName, Data: ing}, |
| 41 | + } |
| 42 | + suite.fixture(events...) |
| 43 | + // Expected occurrences of "timeout server 77000" |
| 44 | + // 1- defaults |
| 45 | + // 2- backend haproxy-controller_default-local-service_http |
| 46 | + // 3- backend appNs_appSvcName_https |
| 47 | + suite.ExpectHaproxyConfigContains("timeout server 77000", 3) |
| 48 | + |
| 49 | + suite.StopController() |
| 50 | +} |
| 51 | + |
| 52 | +func (suite *TimeoutServerSuite) TestTimeoutServerService() { |
| 53 | + // name := suite.T().Name() |
| 54 | + // testController := suite.TestControllers[name] |
| 55 | + |
| 56 | + suite.StartController() |
| 57 | + cm := suite.setupTest() |
| 58 | + |
| 59 | + /////////////////////////////////////// |
| 60 | + // timeout server setup in: |
| 61 | + // - configmap (77000) |
| 62 | + // - ingress (76000) |
| 63 | + // - app svc (75000) (appNs_appSvcName_https) |
| 64 | + cm.Status = store.MODIFIED |
| 65 | + cm.Annotations["timeout-server"] = "77000" |
| 66 | + ing := newAppIngress() |
| 67 | + ing.Annotations["timeout-server"] = "76000" |
| 68 | + svc := newAppSvc() |
| 69 | + svc.Annotations["timeout-server"] = "75000" |
| 70 | + |
| 71 | + events := []k8s.SyncDataEvent{ |
| 72 | + {SyncType: k8s.CONFIGMAP, Namespace: configMapNamespace, Name: configMapName, Data: cm}, |
| 73 | + {SyncType: k8s.SERVICE, Namespace: appNs, Name: serviceName, Data: svc}, |
| 74 | + {SyncType: k8s.INGRESS, Namespace: appNs, Name: ingressName, Data: ing}, |
| 75 | + } |
| 76 | + suite.fixture(events...) |
| 77 | + // Expected occurrences of "timeout server 77000": #2 |
| 78 | + // 1- defaults |
| 79 | + // 2- backend haproxy-controller_default-local-service_http |
| 80 | + // Expected occurrences of "timeout server 75000": #1 (from service) |
| 81 | + // 1- backend appNs_appSvcName_https |
| 82 | + // Expected occurrences of "timeout server 76000": #0 (from ingress) |
| 83 | + suite.ExpectHaproxyConfigContains("timeout server 77000", 2) |
| 84 | + suite.ExpectHaproxyConfigContains("timeout server 75000", 1) |
| 85 | + suite.ExpectHaproxyConfigContains("timeout server 76000", 0) |
| 86 | + |
| 87 | + suite.StopController() |
| 88 | +} |
| 89 | + |
| 90 | +func (suite *TimeoutServerSuite) TestTimeoutServerIngress() { |
| 91 | + // name := suite.T().Name() |
| 92 | + // testController := suite.TestControllers[name] |
| 93 | + |
| 94 | + suite.StartController() |
| 95 | + cm := suite.setupTest() |
| 96 | + |
| 97 | + /////////////////////////////////////// |
| 98 | + // timeout server setup in: |
| 99 | + // - configmap (77000) |
| 100 | + // - ingress (76000) |
| 101 | + cm.Status = store.MODIFIED |
| 102 | + cm.Annotations["timeout-server"] = "77000" |
| 103 | + ing := newAppIngress() |
| 104 | + ing.Annotations["timeout-server"] = "76000" |
| 105 | + svc := newAppSvc() |
| 106 | + |
| 107 | + events := []k8s.SyncDataEvent{ |
| 108 | + {SyncType: k8s.CONFIGMAP, Namespace: configMapNamespace, Name: configMapName, Data: cm}, |
| 109 | + {SyncType: k8s.SERVICE, Namespace: appNs, Name: serviceName, Data: svc}, |
| 110 | + {SyncType: k8s.INGRESS, Namespace: appNs, Name: ingressName, Data: ing}, |
| 111 | + } |
| 112 | + suite.fixture(events...) |
| 113 | + // Expected occurrences of "timeout server 77000": #2 |
| 114 | + // 1- defaults |
| 115 | + // 2- backend haproxy-controller_default-local-service_http |
| 116 | + // Expected occurrences of "timeout server 75000": #0 (from service) |
| 117 | + // Expected occurrences of "timeout server 76000": #1 (from ingress) |
| 118 | + // 1- backend appNs_appSvcName_https |
| 119 | + suite.ExpectHaproxyConfigContains("timeout server 77000", 2) |
| 120 | + suite.ExpectHaproxyConfigContains("timeout server 75000", 0) |
| 121 | + suite.ExpectHaproxyConfigContains("timeout server 76000", 1) |
| 122 | + |
| 123 | + suite.StopController() |
| 124 | +} |
| 125 | + |
| 126 | +func newAppSvc() *store.Service { |
| 127 | + return &store.Service{ |
| 128 | + Annotations: map[string]string{}, |
| 129 | + Name: serviceName, |
| 130 | + Namespace: appNs, |
| 131 | + Ports: []store.ServicePort{ |
| 132 | + { |
| 133 | + Name: "https", |
| 134 | + Protocol: "TCP", |
| 135 | + Port: 443, |
| 136 | + Status: store.ADDED, |
| 137 | + }, |
| 138 | + }, |
| 139 | + Status: store.ADDED, |
| 140 | + } |
| 141 | +} |
| 142 | + |
| 143 | +func newAppIngress() *store.Ingress { |
| 144 | + return &store.Ingress{ |
| 145 | + IngressCore: store.IngressCore{ |
| 146 | + APIVersion: store.NETWORKINGV1, |
| 147 | + Name: ingressName, |
| 148 | + Namespace: appNs, |
| 149 | + Annotations: map[string]string{}, |
| 150 | + Rules: map[string]*store.IngressRule{ |
| 151 | + "": { |
| 152 | + Paths: map[string]*store.IngressPath{ |
| 153 | + string(networkingv1.PathTypePrefix) + "-/": { |
| 154 | + Path: "/", |
| 155 | + PathTypeMatch: string(networkingv1.PathTypePrefix), |
| 156 | + SvcNamespace: appNs, |
| 157 | + SvcPortString: "https", |
| 158 | + SvcName: serviceName, |
| 159 | + }, |
| 160 | + }, |
| 161 | + }, |
| 162 | + }, |
| 163 | + }, |
| 164 | + Status: store.ADDED, |
| 165 | + } |
| 166 | +} |
0 commit comments