Skip to content

Commit

Permalink
Feature Enabling and Disabling of jaeger-agent
Browse files Browse the repository at this point in the history
Due to deprecation of the jaeger agent, and the fact that jaeger can
accept the traces directly via OTEL SDK. I don't know if this change is
too simple and will introduce side effects. So please help me

Signed-off-by: Magnus Jensen <[email protected]>
  • Loading branch information
Mactherobot committed Oct 4, 2024
1 parent 043c224 commit 54ccfaa
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 0 deletions.
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
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
56 changes: 56 additions & 0 deletions pkg/deployment/agent_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,37 @@ 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 TestNewAgentNotDefined(t *testing.T) {
jaeger := v1.Jaeger{}

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

func TestDefaultAgentImage(t *testing.T) {
viper.Set("jaeger-agent-image", "org/custom-agent-image")
defer reset()

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 +88,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 +100,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 +124,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 +149,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 +186,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 +199,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 +223,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 +294,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 +324,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 +342,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 +355,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 +368,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 +380,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 +393,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 +415,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 +426,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 +453,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 +479,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

0 comments on commit 54ccfaa

Please sign in to comment.