Skip to content

Commit 0598e4b

Browse files
Tanner AltaresTanner Altares
Tanner Altares
authored and
Tanner Altares
committed
add support for rollback gating for loadtester
1 parent 1cca5a4 commit 0598e4b

File tree

1 file changed

+79
-0
lines changed

1 file changed

+79
-0
lines changed

pkg/loadtester/server.go

+79
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,85 @@ func ListenAndServe(port string, timeout time.Duration, logger *zap.SugaredLogge
109109
logger.Infof("%s gate closed", canaryName)
110110
})
111111

112+
mux.HandleFunc("/rollback/check", func(w http.ResponseWriter, r *http.Request) {
113+
body, err := ioutil.ReadAll(r.Body)
114+
if err != nil {
115+
logger.Error("reading the request body failed", zap.Error(err))
116+
w.WriteHeader(http.StatusBadRequest)
117+
return
118+
}
119+
defer r.Body.Close()
120+
121+
canary := &flaggerv1.CanaryWebhookPayload{}
122+
err = json.Unmarshal(body, canary)
123+
if err != nil {
124+
logger.Error("decoding the request body failed", zap.Error(err))
125+
w.WriteHeader(http.StatusBadRequest)
126+
return
127+
}
128+
129+
canaryName := fmt.Sprintf("rollback.%s.%s", canary.Name, canary.Namespace)
130+
approved := gate.isOpen(canaryName)
131+
if approved {
132+
w.WriteHeader(http.StatusOK)
133+
w.Write([]byte("Approved"))
134+
} else {
135+
w.WriteHeader(http.StatusForbidden)
136+
w.Write([]byte("Forbidden"))
137+
}
138+
139+
logger.Infof("%s rollback check: approved %v", canaryName, approved)
140+
})
141+
mux.HandleFunc("/rollback/open", func(w http.ResponseWriter, r *http.Request) {
142+
body, err := ioutil.ReadAll(r.Body)
143+
if err != nil {
144+
logger.Error("reading the request body failed", zap.Error(err))
145+
w.WriteHeader(http.StatusBadRequest)
146+
return
147+
}
148+
defer r.Body.Close()
149+
150+
canary := &flaggerv1.CanaryWebhookPayload{}
151+
err = json.Unmarshal(body, canary)
152+
if err != nil {
153+
logger.Error("decoding the request body failed", zap.Error(err))
154+
w.WriteHeader(http.StatusBadRequest)
155+
return
156+
}
157+
158+
canaryName := fmt.Sprintf("rollback.%s.%s", canary.Name, canary.Namespace)
159+
gate.open(canaryName)
160+
161+
w.WriteHeader(http.StatusAccepted)
162+
163+
logger.Infof("%s rollback opened", canaryName)
164+
})
165+
mux.HandleFunc("/rollback/close", func(w http.ResponseWriter, r *http.Request) {
166+
body, err := ioutil.ReadAll(r.Body)
167+
if err != nil {
168+
logger.Error("reading the request body failed", zap.Error(err))
169+
w.WriteHeader(http.StatusBadRequest)
170+
return
171+
}
172+
defer r.Body.Close()
173+
174+
canary := &flaggerv1.CanaryWebhookPayload{}
175+
err = json.Unmarshal(body, canary)
176+
if err != nil {
177+
logger.Error("decoding the request body failed", zap.Error(err))
178+
w.WriteHeader(http.StatusBadRequest)
179+
return
180+
}
181+
182+
183+
canaryName := fmt.Sprintf("rollback.%s.%s", canary.Name, canary.Namespace)
184+
gate.close(canaryName)
185+
186+
w.WriteHeader(http.StatusAccepted)
187+
188+
logger.Infof("%s rollback closed", canaryName)
189+
})
190+
112191
mux.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
113192
body, err := ioutil.ReadAll(r.Body)
114193
if err != nil {

0 commit comments

Comments
 (0)