diff --git a/connect-inject/annotations.go b/connect-inject/annotations.go index 8158fc6f7f..3bcf4896ca 100644 --- a/connect-inject/annotations.go +++ b/connect-inject/annotations.go @@ -1,9 +1,9 @@ package connectinject const ( - // annotationStatus is the key of the annotation that is added to + // keyInjectStatus is the key of the annotation that is added to // a pod after an injection is done. - annotationStatus = "consul.hashicorp.com/connect-inject-status" + keyInjectStatus = "consul.hashicorp.com/connect-inject-status" // annotationInject is the key of the annotation that controls whether // injection is explicitly enabled or disabled for a pod. This should diff --git a/connect-inject/endpoints_controller.go b/connect-inject/endpoints_controller.go index c3f053cf52..59b20b09e7 100644 --- a/connect-inject/endpoints_controller.go +++ b/connect-inject/endpoints_controller.go @@ -607,7 +607,7 @@ func (r EndpointsController) requestsForRunningAgentPods(object client.Object) [ // hasBeenInjected checks the value of the status annotation and returns true if the Pod has been injected. func hasBeenInjected(pod corev1.Pod) bool { - if anno, ok := pod.Annotations[annotationStatus]; ok { + if anno, ok := pod.Annotations[keyInjectStatus]; ok { if anno == injected { return true } diff --git a/connect-inject/endpoints_controller_test.go b/connect-inject/endpoints_controller_test.go index 73c2aa02c1..f3bf5cf7c2 100644 --- a/connect-inject/endpoints_controller_test.go +++ b/connect-inject/endpoints_controller_test.go @@ -2503,8 +2503,8 @@ func createPod(name, ip string, inject bool) *corev1.Pod { }, } if inject { - pod.Labels[annotationStatus] = injected - pod.Annotations[annotationStatus] = injected + pod.Labels[keyInjectStatus] = injected + pod.Annotations[keyInjectStatus] = injected } return pod } diff --git a/connect-inject/handler.go b/connect-inject/handler.go index f82bf5fdae..cc1480f62f 100644 --- a/connect-inject/handler.go +++ b/connect-inject/handler.go @@ -228,7 +228,7 @@ func (h *Handler) Handle(_ context.Context, req admission.Request) admission.Res // pod.Annotations has already been initialized by h.defaultAnnotations() // and does not need to be checked for being a nil value. - pod.Annotations[annotationStatus] = injected + pod.Annotations[keyInjectStatus] = injected // Add annotations for metrics. if err = h.prometheusAnnotations(&pod); err != nil { @@ -239,7 +239,7 @@ func (h *Handler) Handle(_ context.Context, req admission.Request) admission.Res if pod.Labels == nil { pod.Labels = make(map[string]string) } - pod.Labels[annotationStatus] = injected + pod.Labels[keyInjectStatus] = injected // Consul-ENT only: Add the Consul destination namespace as an annotation to the pod. if h.EnableNamespaces { @@ -294,7 +294,7 @@ func (h *Handler) shouldInject(pod corev1.Pod, namespace string) (bool, error) { } // If we already injected then don't inject again - if pod.Annotations[annotationStatus] != "" { + if pod.Annotations[keyInjectStatus] != "" { return false, nil } diff --git a/connect-inject/handler_test.go b/connect-inject/handler_test.go index 8b104b11aa..b4a181da65 100644 --- a/connect-inject/handler_test.go +++ b/connect-inject/handler_test.go @@ -75,7 +75,7 @@ func TestHandlerHandle(t *testing.T) { Object: encodeRaw(t, &corev1.Pod{ ObjectMeta: metav1.ObjectMeta{ Annotations: map[string]string{ - annotationStatus: injected, + keyInjectStatus: injected, }, }, Spec: basicSpec, @@ -155,7 +155,7 @@ func TestHandlerHandle(t *testing.T) { }, { Operation: "add", - Path: "/metadata/annotations/" + escapeJSONPointer(annotationStatus), + Path: "/metadata/annotations/" + escapeJSONPointer(keyInjectStatus), }, { Operation: "add", @@ -240,7 +240,7 @@ func TestHandlerHandle(t *testing.T) { }, { Operation: "add", - Path: "/metadata/annotations/" + escapeJSONPointer(annotationStatus), + Path: "/metadata/annotations/" + escapeJSONPointer(keyInjectStatus), }, { Operation: "add", @@ -285,7 +285,7 @@ func TestHandlerHandle(t *testing.T) { }, { Operation: "add", - Path: "/metadata/annotations/" + escapeJSONPointer(annotationStatus), + Path: "/metadata/annotations/" + escapeJSONPointer(keyInjectStatus), }, { Operation: "add", @@ -334,7 +334,7 @@ func TestHandlerHandle(t *testing.T) { }, { Operation: "add", - Path: "/metadata/labels/" + escapeJSONPointer(annotationStatus), + Path: "/metadata/labels/" + escapeJSONPointer(keyInjectStatus), }, }, }, @@ -386,7 +386,7 @@ func TestHandlerHandle(t *testing.T) { }, { Operation: "add", - Path: "/metadata/annotations/" + escapeJSONPointer(annotationStatus), + Path: "/metadata/annotations/" + escapeJSONPointer(keyInjectStatus), }, { Operation: "add", @@ -406,7 +406,7 @@ func TestHandlerHandle(t *testing.T) { }, { Operation: "add", - Path: "/metadata/labels/" + escapeJSONPointer(annotationStatus), + Path: "/metadata/labels/" + escapeJSONPointer(keyInjectStatus), }, }, },