Skip to content

Commit 8332af2

Browse files
committed
NE 484: Use ingress-operator subcommand instead of hello-openshift for canary server
1 parent 9497871 commit 8332af2

16 files changed

Lines changed: 251 additions & 110 deletions

File tree

assets/canary/daemonset.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ spec:
88
template:
99
spec:
1010
containers:
11-
- name: hello-openshift-canary
12-
# Image is set at runtime
11+
- name: serve-healthcheck-canary
12+
# Image and command are set at runtime
1313
imagePullPolicy: IfNotPresent
1414
terminationMessagePolicy: FallbackToLogsOnError
1515
ports:

cmd/ingress-operator/main.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ func main() {
1414
var rootCmd = &cobra.Command{Use: "ingress-operator"}
1515
rootCmd.AddCommand(NewStartCommand())
1616
rootCmd.AddCommand(NewRenderCommand())
17+
rootCmd.AddCommand(NewServeHealthCheckCommand())
1718

1819
if err := rootCmd.Execute(); err != nil {
1920
log.Error(err, "error")
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
package main
2+
3+
import (
4+
"fmt"
5+
"net"
6+
"net/http"
7+
"os"
8+
"strconv"
9+
10+
"github.com/spf13/cobra"
11+
12+
canarycontroller "github.com/openshift/cluster-ingress-operator/pkg/operator/controller/canary"
13+
)
14+
15+
func healthCheckHandler(w http.ResponseWriter, r *http.Request) {
16+
response := os.Getenv("RESPONSE")
17+
if len(response) == 0 {
18+
response = canarycontroller.CanaryHealthcheckResponse
19+
}
20+
21+
// Echo back the port the request was received on
22+
// via a "request-port" header.
23+
addr := r.Context().Value(http.LocalAddrContextKey).(net.Addr)
24+
if tcpAddr, ok := addr.(*net.TCPAddr); ok {
25+
w.Header().Set("x-request-port", strconv.Itoa(tcpAddr.Port))
26+
}
27+
28+
_, err := fmt.Fprintln(w, response)
29+
if err == nil {
30+
fmt.Println("Serving canary healthcheck request")
31+
} else {
32+
fmt.Printf("Could not serve canary healthcheck: %v\n", err)
33+
}
34+
}
35+
36+
func listenAndServe(port string) {
37+
fmt.Printf("serving on %s\n", port)
38+
err := http.ListenAndServe(":"+port, nil)
39+
if err != nil {
40+
panic("ListenAndServe: " + err.Error())
41+
}
42+
}
43+
44+
func NewServeHealthCheckCommand() *cobra.Command {
45+
var command = &cobra.Command{
46+
Use: canarycontroller.CanaryHealthcheckCommand,
47+
Short: "Certify canary server health by echoing a response",
48+
Long: canarycontroller.CanaryHealthcheckCommand + ` echoes a response when queried, thus certifying health of the canary service.`,
49+
Run: func(cmd *cobra.Command, args []string) {
50+
serveHealthCheck()
51+
},
52+
}
53+
54+
return command
55+
}
56+
57+
func serveHealthCheck() {
58+
http.HandleFunc("/", healthCheckHandler)
59+
port := os.Getenv("PORT")
60+
if len(port) == 0 {
61+
port = "8080"
62+
}
63+
go listenAndServe(port)
64+
65+
port = os.Getenv("SECOND_PORT")
66+
if len(port) == 0 {
67+
port = "8888"
68+
}
69+
go listenAndServe(port)
70+
71+
select {}
72+
}

cmd/ingress-operator/start.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,7 @@ type StartOptions struct {
4545
// IngressControllerImage is the pullspec of the ingress controller image to
4646
// be managed.
4747
IngressControllerImage string
48-
// CanaryImage is the pullspec of the canary tester server image to
49-
// be managed.
48+
// CanaryImage is the pullspec of the ingress operator image
5049
CanaryImage string
5150
// ReleaseVersion is the cluster version which the operator will converge to.
5251
ReleaseVersion string

manifests/02-deployment.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ spec:
6363
- name: IMAGE
6464
value: openshift/origin-haproxy-router:v4.0
6565
- name: CANARY_IMAGE
66-
value: quay.io/openshift/origin-hello-openshift:latest
66+
value: openshift/origin-cluster-ingress-operator:latest
6767
resources:
6868
requests:
6969
cpu: 10m

manifests/image-references

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,3 @@ spec:
1414
from:
1515
kind: DockerImage
1616
name: "quay.io/openshift/origin-kube-rbac-proxy:latest"
17-
- name: hello-openshift
18-
from:
19-
kind: DockerImage
20-
name: "quay.io/openshift/origin-hello-openshift:latest"

pkg/manifests/bindata.go

Lines changed: 12 additions & 12 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

pkg/operator/config/config.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ type Config struct {
1212
// IngressControllerImage is the ingress controller image to manage.
1313
IngressControllerImage string
1414

15-
// CanaryImage is the ingress canary image to manage.
15+
// CanaryImage is the ingress operator image, which runs a canary command.
1616
CanaryImage string
1717

1818
Stop chan struct{}

pkg/operator/controller/canary/controller.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,12 @@ const (
5252
// Canary route rotation is enabled when the canary route rotation annotation has
5353
// a value of "true" (disabled otherwise).
5454
CanaryRouteRotationAnnotation = "ingress.operator.openshift.io/rotate-canary-route"
55+
56+
// CanaryHealthcheckCommand is a parameter to pass to the ingress-operator to call
57+
// into the handler for the canary daemonset health check
58+
CanaryHealthcheckCommand = "serve-healthcheck"
59+
// CanaryHealthcheckResponse is the message that signals a successful health check
60+
CanaryHealthcheckResponse = "Healthcheck requested"
5561
)
5662

5763
var (

pkg/operator/controller/canary/daemonset.go

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,7 @@ func desiredCanaryDaemonSet(canaryImage string) *appsv1.DaemonSet {
9494
daemonset.Spec.Template.Labels = controller.CanaryDaemonSetPodSelector(canaryControllerName).MatchLabels
9595

9696
daemonset.Spec.Template.Spec.Containers[0].Image = canaryImage
97+
daemonset.Spec.Template.Spec.Containers[0].Command = []string{"ingress-operator", CanaryHealthcheckCommand}
9798

9899
return daemonset
99100
}
@@ -104,11 +105,20 @@ func canaryDaemonSetChanged(current, expected *appsv1.DaemonSet) (bool, *appsv1.
104105
changed := false
105106
updated := current.DeepCopy()
106107

107-
// Update the canary daemonset when the canary server image changes
108-
if len(current.Spec.Template.Spec.Containers) > 0 && len(expected.Spec.Template.Spec.Containers) > 0 &&
109-
current.Spec.Template.Spec.Containers[0].Image != expected.Spec.Template.Spec.Containers[0].Image {
110-
updated.Spec.Template.Spec.Containers[0].Image = expected.Spec.Template.Spec.Containers[0].Image
111-
changed = true
108+
// Update the canary daemonset when the canary server image, command, or container name changes
109+
if len(current.Spec.Template.Spec.Containers) > 0 && len(expected.Spec.Template.Spec.Containers) > 0 {
110+
if current.Spec.Template.Spec.Containers[0].Image != expected.Spec.Template.Spec.Containers[0].Image {
111+
updated.Spec.Template.Spec.Containers[0].Image = expected.Spec.Template.Spec.Containers[0].Image
112+
changed = true
113+
}
114+
if !cmp.Equal(current.Spec.Template.Spec.Containers[0].Command, expected.Spec.Template.Spec.Containers[0].Command) {
115+
updated.Spec.Template.Spec.Containers[0].Command = expected.Spec.Template.Spec.Containers[0].Command
116+
changed = true
117+
}
118+
if current.Spec.Template.Spec.Containers[0].Name != expected.Spec.Template.Spec.Containers[0].Name {
119+
updated.Spec.Template.Spec.Containers[0].Name = expected.Spec.Template.Spec.Containers[0].Name
120+
changed = true
121+
}
112122
}
113123

114124
if !cmp.Equal(current.Spec.Template.Spec.NodeSelector, expected.Spec.Template.Spec.NodeSelector, cmpopts.EquateEmpty()) {

0 commit comments

Comments
 (0)