Skip to content

Commit

Permalink
make a nonsense changege
Browse files Browse the repository at this point in the history
Signed-off-by: Pavol Loffay <p.loffay@gmail.com>
  • Loading branch information
pavolloffay committed Oct 27, 2021
1 parent b1600a1 commit 70b3577
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 22 deletions.
2 changes: 1 addition & 1 deletion docs/otelcol_cr_spec.md
Original file line number Diff line number Diff line change
Expand Up @@ -78,4 +78,4 @@ spec:
// +optional Toleration to schedule OpenTelemetry Collector pods.
// This is only relevant to daemonsets, statefulsets and deployments
tolerations: []
```
```
4 changes: 2 additions & 2 deletions pkg/sidecar/annotation.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,8 @@ const (
Annotation = "sidecar.opentelemetry.io/inject"
)

// annotationValue returns the effective annotation value, based on the annotations from the pod and namespace.
func annotationValue(ns corev1.Namespace, pod corev1.Pod) string {
// AnnotationValue returns the effective annotation value, based on the annotations from the pod and namespace.
func AnnotationValue(ns corev1.Namespace, pod corev1.Pod) string {
// is the pod annotated with instructions to inject sidecars? is the namespace annotated?
// if any of those is true, a sidecar might be desired.
podAnnValue := pod.Annotations[Annotation]
Expand Down
2 changes: 1 addition & 1 deletion pkg/sidecar/annotation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ func TestEffectiveAnnotationValue(t *testing.T) {
} {
t.Run(tt.desc, func(t *testing.T) {
// test
annValue := annotationValue(tt.ns, tt.pod)
annValue := AnnotationValue(tt.ns, tt.pod)

// verify
assert.Equal(t, tt.expected, annValue)
Expand Down
18 changes: 9 additions & 9 deletions pkg/sidecar/pod.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.

// Package sidecar contains operations related to sidecar manipulation (add, update, remove).
// Package sidecar contains operations related to sidecar manipulation (Add, update, remove).
package sidecar

import (
Expand All @@ -31,9 +31,9 @@ const (
label = "sidecar.opentelemetry.io/injected"
)

// add a new sidecar container to the given pod, based on the given OpenTelemetryCollector.
func add(cfg config.Config, logger logr.Logger, otelcol v1alpha1.OpenTelemetryCollector, pod corev1.Pod) (corev1.Pod, error) {
// add the container
// Add a new sidecar container to the given pod, based on the given OpenTelemetryCollector.
func Add(cfg config.Config, logger logr.Logger, otelcol v1alpha1.OpenTelemetryCollector, pod corev1.Pod) (corev1.Pod, error) {
// Add the container
volumes := collector.Volumes(cfg, otelcol)
container := collector.Container(cfg, logger, otelcol)
pod.Spec.Containers = append(pod.Spec.Containers, container)
Expand All @@ -47,9 +47,9 @@ func add(cfg config.Config, logger logr.Logger, otelcol v1alpha1.OpenTelemetryCo
return pod, nil
}

// remove the sidecar container from the given pod.
func remove(pod corev1.Pod) (corev1.Pod, error) {
if !existsIn(pod) {
// Remove the sidecar container from the given pod.
func Remove(pod corev1.Pod) (corev1.Pod, error) {
if !ExistsIn(pod) {
return pod, nil
}

Expand All @@ -63,8 +63,8 @@ func remove(pod corev1.Pod) (corev1.Pod, error) {
return pod, nil
}

// existsIn checks whether a sidecar container exists in the given pod.
func existsIn(pod corev1.Pod) bool {
// ExistsIn checks whether a sidecar container exists in the given pod.
func ExistsIn(pod corev1.Pod) bool {
for _, container := range pod.Spec.Containers {
if container.Name == naming.Container() {
return true
Expand Down
10 changes: 5 additions & 5 deletions pkg/sidecar/pod_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ func TestAddSidecarWhenNoSidecarExists(t *testing.T) {
cfg := config.New(config.WithCollectorImage("some-default-image"))

// test
changed, err := add(cfg, logger, otelcol, pod)
changed, err := Add(cfg, logger, otelcol, pod)

// verify
assert.NoError(t, err)
Expand All @@ -74,7 +74,7 @@ func TestAddSidecarWhenOneExistsAlready(t *testing.T) {
cfg := config.New(config.WithCollectorImage("some-default-image"))

// test
changed, err := add(cfg, logger, otelcol, pod)
changed, err := Add(cfg, logger, otelcol, pod)

// verify
assert.NoError(t, err)
Expand All @@ -94,7 +94,7 @@ func TestRemoveSidecar(t *testing.T) {
}

// test
changed, err := remove(pod)
changed, err := Remove(pod)

// verify
assert.NoError(t, err)
Expand All @@ -112,7 +112,7 @@ func TestRemoveNonExistingSidecar(t *testing.T) {
}

// test
changed, err := remove(pod)
changed, err := Remove(pod)

// verify
assert.NoError(t, err)
Expand Down Expand Up @@ -141,7 +141,7 @@ func TestExistsIn(t *testing.T) {
}},
} {
t.Run(tt.desc, func(t *testing.T) {
assert.Equal(t, tt.expected, existsIn(tt.pod))
assert.Equal(t, tt.expected, ExistsIn(tt.pod))
})
}
}
8 changes: 4 additions & 4 deletions pkg/sidecar/podmutator.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ func (p *sidecarPodMutator) Mutate(ctx context.Context, ns corev1.Namespace, pod
logger := p.logger.WithValues("namespace", pod.Namespace, "name", pod.Name)

// if no annotations are found at all, just return the same pod
annValue := annotationValue(ns, pod)
annValue := AnnotationValue(ns, pod)
if len(annValue) == 0 {
logger.V(1).Info("annotation not present in deployment, skipping sidecar injection")
return pod, nil
Expand All @@ -64,13 +64,13 @@ func (p *sidecarPodMutator) Mutate(ctx context.Context, ns corev1.Namespace, pod
// is the annotation value 'false'? if so, we need a pod without the sidecar (ie, remove if exists)
if strings.EqualFold(annValue, "false") {
logger.V(1).Info("pod explicitly refuses sidecar injection, attempting to remove sidecar if it exists")
return remove(pod)
return Remove(pod)
}

// from this point and on, a sidecar is wanted

// check whether there's a sidecar already -- return the same pod if that's the case.
if existsIn(pod) {
if ExistsIn(pod) {
logger.V(1).Info("pod already has sidecar in it, skipping injection")
return pod, nil
}
Expand All @@ -91,7 +91,7 @@ func (p *sidecarPodMutator) Mutate(ctx context.Context, ns corev1.Namespace, pod
// once it's been determined that a sidecar is desired, none exists yet, and we know which instance it should talk to,
// we should add the sidecar.
logger.V(1).Info("injecting sidecar into pod", "otelcol-namespace", otelcol.Namespace, "otelcol-name", otelcol.Name)
return add(p.config, p.logger, otelcol, pod)
return Add(p.config, p.logger, otelcol, pod)
}

func (p *sidecarPodMutator) getCollectorInstance(ctx context.Context, ns corev1.Namespace, ann string) (v1alpha1.OpenTelemetryCollector, error) {
Expand Down

0 comments on commit 70b3577

Please sign in to comment.