Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature Enabling and Disabling of jaeger-agent #2697

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions apis/v1/jaeger_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -514,6 +514,9 @@ type JaegerIngesterSpec struct {

// JaegerAgentSpec defines the options to be used when deploying the agent
type JaegerAgentSpec struct {
// +optional
Enabled *bool `json:"enabled,omitempty"`

// Strategy can be either 'DaemonSet' or 'Sidecar' (default)
// +optional
Strategy string `json:"strategy,omitempty"`
Expand Down
2 changes: 2 additions & 0 deletions bundle/manifests/jaegertracing.io_jaegers.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -933,6 +933,8 @@ spec:
type: object
dnsPolicy:
type: string
enabled:
type: boolean
hostNetwork:
type: boolean
image:
Expand Down
2 changes: 2 additions & 0 deletions config/crd/bases/jaegertracing.io_jaegers.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -930,6 +930,8 @@ spec:
type: object
dnsPolicy:
type: string
enabled:
type: boolean
hostNetwork:
type: boolean
image:
Expand Down
132 changes: 132 additions & 0 deletions config/manifests/bases/jaeger-operator.clusterserviceversion.yaml-e

Large diffs are not rendered by default.

9 changes: 9 additions & 0 deletions pkg/deployment/agent.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,15 @@ func NewAgent(jaeger *v1.Jaeger) *Agent {

// Get returns a Agent pod
func (a *Agent) Get() *appsv1.DaemonSet {
// Check if the agent is enabled
if a.jaeger.Spec.Agent.Enabled != nil && !*a.jaeger.Spec.Agent.Enabled {
a.jaeger.Logger().V(-1).Info(
"agent not enabled",
"enabled", a.jaeger.Spec.Agent.Enabled,
)
return nil
}

if !strings.EqualFold(a.jaeger.Spec.Agent.Strategy, "daemonset") {
a.jaeger.Logger().V(-1).Info(
"skipping agent daemonset",
Expand Down
58 changes: 58 additions & 0 deletions pkg/deployment/agent_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,25 @@ func reset() {
func TestNewAgent(t *testing.T) {
jaeger := v1.NewJaeger(types.NamespacedName{Name: "my-instance"})
jaeger.Spec.Agent.Strategy = "daemonset"
enabled := true
jaeger.Spec.Agent.Enabled = &enabled

d := NewAgent(jaeger).Get()
assert.Empty(t, jaeger.Spec.Agent.Image)
assert.Contains(t, d.Spec.Template.Spec.Containers[0].Image, "jaeger-agent")
}

func TestNewAgentDisabled(t *testing.T) {
jaeger := v1.NewJaeger(types.NamespacedName{Name: "my-instance"})
jaeger.Spec.Agent.Enabled = new(bool)

d := NewAgent(jaeger).Get()
assert.Nil(t, d)
}

func TestNewAgentNotDefinedWithStrategy(t *testing.T) {
jaeger := v1.NewJaeger(types.NamespacedName{Name: "my-instance"})
jaeger.Spec.Agent.Strategy = "daemonset"

d := NewAgent(jaeger).Get()
assert.Empty(t, jaeger.Spec.Agent.Image)
Expand All @@ -47,6 +66,8 @@ func TestDefaultAgentImage(t *testing.T) {

jaeger := v1.NewJaeger(types.NamespacedName{Name: "my-instance"})
jaeger.Spec.Agent.Strategy = "daemonset"
enabled := true
jaeger.Spec.Agent.Enabled = &enabled

d := NewAgent(jaeger).Get()
assert.Empty(t, jaeger.Spec.Agent.Image)
Expand All @@ -69,6 +90,9 @@ func TestGetSidecarDeployment(t *testing.T) {
func TestGetDaemonSetDeployment(t *testing.T) {
jaeger := v1.NewJaeger(types.NamespacedName{Name: "my-instance"})
jaeger.Spec.Agent.Strategy = "daemonset"
enabled := true
jaeger.Spec.Agent.Enabled = &enabled

agent := NewAgent(jaeger)

ds := agent.Get()
Expand All @@ -78,6 +102,8 @@ func TestGetDaemonSetDeployment(t *testing.T) {
func TestDaemonSetAgentAnnotations(t *testing.T) {
jaeger := v1.NewJaeger(types.NamespacedName{Name: "my-instance"})
jaeger.Spec.Agent.Strategy = "daemonset"
enabled := true
jaeger.Spec.Agent.Enabled = &enabled
jaeger.Spec.Annotations = map[string]string{
"name": "operator",
"hello": "jaeger",
Expand All @@ -100,6 +126,8 @@ func TestDaemonSetAgentAnnotations(t *testing.T) {
func TestDaemonSetAgentLabels(t *testing.T) {
jaeger := v1.NewJaeger(types.NamespacedName{Name: "my-instance"})
jaeger.Spec.Agent.Strategy = "daemonset"
enabled := true
jaeger.Spec.Agent.Enabled = &enabled
jaeger.Spec.Labels = map[string]string{
"name": "operator",
"hello": "jaeger",
Expand All @@ -123,6 +151,8 @@ func TestDaemonSetAgentLabels(t *testing.T) {
func TestDaemonSetAgentResources(t *testing.T) {
jaeger := v1.NewJaeger(types.NamespacedName{Name: "my-instance"})
jaeger.Spec.Agent.Strategy = "daemonset"
enabled := true
jaeger.Spec.Agent.Enabled = &enabled
jaeger.Spec.Resources = corev1.ResourceRequirements{
Limits: corev1.ResourceList{
corev1.ResourceLimitsCPU: *resource.NewQuantity(1024, resource.BinarySI),
Expand Down Expand Up @@ -158,6 +188,8 @@ func TestDaemonSetAgentResources(t *testing.T) {
func TestAgentLabels(t *testing.T) {
jaeger := v1.NewJaeger(types.NamespacedName{Name: "my-instance"})
jaeger.Spec.Agent.Strategy = "daemonset"
enabled := true
jaeger.Spec.Agent.Enabled = &enabled
a := NewAgent(jaeger)
dep := a.Get()
assert.Equal(t, "jaeger-operator", dep.Spec.Template.Labels["app.kubernetes.io/managed-by"])
Expand All @@ -169,6 +201,8 @@ func TestAgentLabels(t *testing.T) {
func TestAgentOrderOfArguments(t *testing.T) {
jaeger := v1.NewJaeger(types.NamespacedName{Name: "my-instance"})
jaeger.Spec.Agent.Strategy = "daemonset"
enabled := true
jaeger.Spec.Agent.Enabled = &enabled
jaeger.Spec.Agent.Options = v1.NewOptions(map[string]interface{}{
"b-option": "b-value",
"a-option": "a-value",
Expand All @@ -191,6 +225,8 @@ func TestAgentOrderOfArguments(t *testing.T) {
func TestAgentCustomReporterPort(t *testing.T) {
jaeger := v1.NewJaeger(types.NamespacedName{Name: "my-instance"})
jaeger.Spec.Agent.Strategy = "daemonset"
enabled := true
jaeger.Spec.Agent.Enabled = &enabled
jaeger.Spec.Agent.Options = v1.NewOptions(map[string]interface{}{
"reporter.grpc.host-port": "collector:5000",
})
Expand Down Expand Up @@ -260,6 +296,8 @@ func TestAgentArgumentsOpenshiftTLS(t *testing.T) {
Namespace: "test",
})
jaeger.Spec.Agent.Strategy = "daemonset"
enabled := true
jaeger.Spec.Agent.Enabled = &enabled
jaeger.Spec.Agent.Options = tt.options

a := NewAgent(jaeger)
Expand Down Expand Up @@ -288,6 +326,8 @@ func TestAgentImagePullSecrets(t *testing.T) {
jaeger := v1.NewJaeger(types.NamespacedName{Name: "TestAllInOneImagePullSecrets"})
const pullSecret = "mysecret"
jaeger.Spec.Agent.Strategy = "daemonset"
enabled := true
jaeger.Spec.Agent.Enabled = &enabled
jaeger.Spec.Agent.ImagePullSecrets = []corev1.LocalObjectReference{
{
Name: pullSecret,
Expand All @@ -304,6 +344,8 @@ func TestAgentImagePullPolicy(t *testing.T) {
jaeger := v1.NewJaeger(types.NamespacedName{Name: "TestAgentImagePullPolicy"})
const pullPolicy = corev1.PullPolicy("Always")
jaeger.Spec.Agent.Strategy = "daemonset"
enabled := true
jaeger.Spec.Agent.Enabled = &enabled
jaeger.Spec.ImagePullPolicy = corev1.PullPolicy("Always")

agent := NewAgent(jaeger)
Expand All @@ -315,6 +357,8 @@ func TestAgentImagePullPolicy(t *testing.T) {
func TestAgentServiceLinks(t *testing.T) {
jaeger := v1.NewJaeger(types.NamespacedName{Name: "my-instance"})
jaeger.Spec.Agent.Strategy = "daemonset"
enabled := true
jaeger.Spec.Agent.Enabled = &enabled
a := NewAgent(jaeger)
dep := a.Get()
falseVar := false
Expand All @@ -326,6 +370,8 @@ func TestAgentHostNetwork(t *testing.T) {
trueVar := true
jaeger := v1.NewJaeger(types.NamespacedName{Name: "my-instance"})
jaeger.Spec.Agent.Strategy = "daemonset"
enabled := true
jaeger.Spec.Agent.Enabled = &enabled
jaeger.Spec.Agent.HostNetwork = &trueVar
a := NewAgent(jaeger)
dep := a.Get()
Expand All @@ -336,6 +382,8 @@ func TestAgentDNSPolicyWithHostNetwork(t *testing.T) {
trueVar := true
jaeger := v1.NewJaeger(types.NamespacedName{Name: "my-instance"})
jaeger.Spec.Agent.Strategy = "daemonset"
enabled := true
jaeger.Spec.Agent.Enabled = &enabled
jaeger.Spec.Agent.HostNetwork = &trueVar
a := NewAgent(jaeger)
dep := a.Get()
Expand All @@ -347,6 +395,8 @@ func TestAgentPriorityClassName(t *testing.T) {
priorityClassName := "test-class"
jaeger := v1.NewJaeger(types.NamespacedName{Name: "my-instance"})
jaeger.Spec.Agent.Strategy = "daemonset"
enabled := true
jaeger.Spec.Agent.Enabled = &enabled
jaeger.Spec.Agent.PriorityClassName = priorityClassName
a := NewAgent(jaeger)
dep := a.Get()
Expand All @@ -367,6 +417,8 @@ func TestAgentLivenessProbe(t *testing.T) {
}
jaeger := v1.NewJaeger(types.NamespacedName{Name: "my-instance"})
jaeger.Spec.Agent.Strategy = "daemonset"
enabled := true
jaeger.Spec.Agent.Enabled = &enabled
jaeger.Spec.Agent.LivenessProbe = livenessProbe
a := NewAgent(jaeger)
dep := a.Get()
Expand All @@ -376,6 +428,8 @@ func TestAgentLivenessProbe(t *testing.T) {
func TestAgentEmptyEmptyLivenessProbe(t *testing.T) {
jaeger := v1.NewJaeger(types.NamespacedName{Name: "my-instance"})
jaeger.Spec.Agent.Strategy = "daemonset"
enabled := true
jaeger.Spec.Agent.Enabled = &enabled
a := NewAgent(jaeger)
dep := a.Get()
assert.Equal(t, &corev1.Probe{
Expand All @@ -401,6 +455,8 @@ func TestAgentContainerSecurityContext(t *testing.T) {
}
jaeger := v1.NewJaeger(types.NamespacedName{Name: "my-instance"})
jaeger.Spec.Agent.Strategy = "daemonset"
enabled := true
jaeger.Spec.Agent.Enabled = &enabled
jaeger.Spec.Agent.ContainerSecurityContext = &securityContextVar

a := NewAgent(jaeger)
Expand All @@ -425,6 +481,8 @@ func TestAgentContainerSecurityContextOverride(t *testing.T) {
}
jaeger := v1.NewJaeger(types.NamespacedName{Name: "my-instance"})
jaeger.Spec.Agent.Strategy = "daemonset"
enabled := true
jaeger.Spec.Agent.Enabled = &enabled
jaeger.Spec.ContainerSecurityContext = &securityContextVar
jaeger.Spec.Agent.ContainerSecurityContext = &overrideSecurityContextVar

Expand Down
2 changes: 2 additions & 0 deletions pkg/strategy/all_in_one_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ func TestCreateAllInOneDeploymentWithDaemonSetAgent(t *testing.T) {

j := v1.NewJaeger(types.NamespacedName{Name: name})
j.Spec.Agent.Strategy = "DaemonSet"
enabled := true
j.Spec.Agent.Enabled = &enabled

c := newAllInOneStrategy(context.Background(), j)
assertDeploymentsAndServicesForAllInOne(t, j, c, true, false, false)
Expand Down
2 changes: 2 additions & 0 deletions pkg/strategy/production_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ func TestCreateProductionDeploymentWithDaemonSetAgent(t *testing.T) {

j := v1.NewJaeger(types.NamespacedName{Name: name})
j.Spec.Agent.Strategy = "DaemonSet"
enabled := true
j.Spec.Agent.Enabled = &enabled

c := newProductionStrategy(context.Background(), j)
assertDeploymentsAndServicesForProduction(t, j, c, true, false, false)
Expand Down
2 changes: 2 additions & 0 deletions pkg/strategy/streaming_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ func TestCreateStreamingDeploymentWithDaemonSetAgent(t *testing.T) {

j := v1.NewJaeger(types.NamespacedName{Name: name})
j.Spec.Agent.Strategy = "DaemonSet"
enabled := true
j.Spec.Agent.Enabled = &enabled

c := newStreamingStrategy(context.Background(), j)
assertDeploymentsAndServicesForStreaming(t, j, c, true, false, false)
Expand Down
16 changes: 16 additions & 0 deletions tests/e2e/sidecar/sidecar-deployment/08-disable-agent.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Create another Jaeger instance with the agent disabled
apiVersion: jaegertracing.io/v1
kind: Jaeger
metadata:
name: agent-as-sidecar3
spec:
agent:
enabled: false
strategy: allinone
allInOne:
options:
log-level: "debug"
memory.max-traces: 10000
ingress:
enabled: true
security: "none"
4 changes: 4 additions & 0 deletions tests/e2e/sidecar/sidecar-deployment/08-errors.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: agent-as-sidecar-3
29 changes: 17 additions & 12 deletions tests/e2e/sidecar/sidecar-deployment/README.md
Original file line number Diff line number Diff line change
@@ -1,22 +1,27 @@
# Sidecar - Deployment

## What is this test case testing?

Test the deployment of the Jaeger agent as as sidecar annotating a deployment.

[From the Jaeger documentation](https://www.jaegertracing.io/docs/latest/operator/#auto-injecting-jaeger-agent-sidecars):

> The operator can inject Jaeger Agent sidecars in Deployment workloads,
provided that the deployment or its namespace has the annotation
`sidecar.jaegertracing.io/inject` with a suitable value. The values can be either
"true" (as string), or the Jaeger instance name, as returned by `kubectl get
> provided that the deployment or its namespace has the annotation
> `sidecar.jaegertracing.io/inject` with a suitable value. The values can be either
> "true" (as string), or the Jaeger instance name, as returned by `kubectl get
jaegers`. When "true" is used, there should be exactly one Jaeger instance for
the same namespace as the deployment, otherwise, the operator can’t figure out
automatically which Jaeger instance to use. A specific Jaeger instance name on
a deployment has a higher precedence than true applied on its namespace.
> the same namespace as the deployment, otherwise, the operator can’t figure out
> automatically which Jaeger instance to use. A specific Jaeger instance name on
> a deployment has a higher precedence than true applied on its namespace.

This test works in the following way:
* Create a Jaeger instance
* Inject the Jaeger agent as a sidecard for a deployment
* Create a second Jaeger instance
* Remove the first Jaeger instance (now, the deployment will use the second Jaeger instance)
* Check there were no errors
* Check the sidecar is removed when the annotation is removed

- Create a Jaeger instance
- Inject the Jaeger agent as a sidecard for a deployment
- Create a second Jaeger instance
- Remove the first Jaeger instance (now, the deployment will use the second Jaeger instance)
- Check there were no errors
- Check the sidecar is removed when the annotation is removed
- Create a third Jaeger instance with the agent disabled
- Check that the sidecar is not created for the third Jaeger instance
Loading