Skip to content

Commit

Permalink
Change "annotationStatus" key to "keyInjectStatus" as its used by lab…
Browse files Browse the repository at this point in the history
…els and annotations now. Commit 3986370 had a rebase issue from github UI which re-introduced cleanup controller, it was reverted and this is the correct commit.
  • Loading branch information
kschoche committed Apr 9, 2021
1 parent 3ebf05d commit 9be903f
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 15 deletions.
4 changes: 2 additions & 2 deletions connect-inject/annotations.go
Original file line number Diff line number Diff line change
@@ -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
Expand Down
2 changes: 1 addition & 1 deletion connect-inject/endpoints_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
4 changes: 2 additions & 2 deletions connect-inject/endpoints_controller_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
6 changes: 3 additions & 3 deletions connect-inject/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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 {
Expand Down Expand Up @@ -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
}

Expand Down
14 changes: 7 additions & 7 deletions connect-inject/handler_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -155,7 +155,7 @@ func TestHandlerHandle(t *testing.T) {
},
{
Operation: "add",
Path: "/metadata/annotations/" + escapeJSONPointer(annotationStatus),
Path: "/metadata/annotations/" + escapeJSONPointer(keyInjectStatus),
},
{
Operation: "add",
Expand Down Expand Up @@ -240,7 +240,7 @@ func TestHandlerHandle(t *testing.T) {
},
{
Operation: "add",
Path: "/metadata/annotations/" + escapeJSONPointer(annotationStatus),
Path: "/metadata/annotations/" + escapeJSONPointer(keyInjectStatus),
},
{
Operation: "add",
Expand Down Expand Up @@ -285,7 +285,7 @@ func TestHandlerHandle(t *testing.T) {
},
{
Operation: "add",
Path: "/metadata/annotations/" + escapeJSONPointer(annotationStatus),
Path: "/metadata/annotations/" + escapeJSONPointer(keyInjectStatus),
},
{
Operation: "add",
Expand Down Expand Up @@ -334,7 +334,7 @@ func TestHandlerHandle(t *testing.T) {
},
{
Operation: "add",
Path: "/metadata/labels/" + escapeJSONPointer(annotationStatus),
Path: "/metadata/labels/" + escapeJSONPointer(keyInjectStatus),
},
},
},
Expand Down Expand Up @@ -386,7 +386,7 @@ func TestHandlerHandle(t *testing.T) {
},
{
Operation: "add",
Path: "/metadata/annotations/" + escapeJSONPointer(annotationStatus),
Path: "/metadata/annotations/" + escapeJSONPointer(keyInjectStatus),
},
{
Operation: "add",
Expand All @@ -406,7 +406,7 @@ func TestHandlerHandle(t *testing.T) {
},
{
Operation: "add",
Path: "/metadata/labels/" + escapeJSONPointer(annotationStatus),
Path: "/metadata/labels/" + escapeJSONPointer(keyInjectStatus),
},
},
},
Expand Down

0 comments on commit 9be903f

Please sign in to comment.