Skip to content

Commit

Permalink
Added configuration for the sidecar agent's securityContext
Browse files Browse the repository at this point in the history
Signed-off-by: chgl <chgl@users.noreply.github.com>
  • Loading branch information
chgl committed Sep 25, 2020
1 parent 01f738a commit f6ee9c8
Show file tree
Hide file tree
Showing 6 changed files with 80 additions and 3 deletions.
50 changes: 50 additions & 0 deletions deploy/crds/jaegertracing.io_jaegers_crd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -662,6 +662,56 @@ spec:
type: object
serviceAccount:
type: string
sidecarSecurityContext:
properties:
allowPrivilegeEscalation:
type: boolean
capabilities:
properties:
add:
items:
type: string
type: array
drop:
items:
type: string
type: array
type: object
privileged:
type: boolean
procMount:
type: string
readOnlyRootFilesystem:
type: boolean
runAsGroup:
format: int64
type: integer
runAsNonRoot:
type: boolean
runAsUser:
format: int64
type: integer
seLinuxOptions:
properties:
level:
type: string
role:
type: string
type:
type: string
user:
type: string
type: object
windowsOptions:
properties:
gmsaCredentialSpec:
type: string
gmsaCredentialSpecName:
type: string
runAsUserName:
type: string
type: object
type: object
strategy:
type: string
tolerations:
Expand Down
3 changes: 3 additions & 0 deletions pkg/apis/jaegertracing/v1/jaeger_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -383,6 +383,9 @@ type JaegerAgentSpec struct {

// +optional
Config FreeForm `json:"config,omitempty"`

// +optional
SidecarSecurityContext *v1.SecurityContext `json:"sidecarSecurityContext,omitempty"`
}

// JaegerStorageSpec defines the common storage options to be used for the query and collector
Expand Down
5 changes: 5 additions & 0 deletions pkg/apis/jaegertracing/v1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion pkg/apis/jaegertracing/v1/zz_generated.openapi.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions pkg/inject/sidecar.go
Original file line number Diff line number Diff line change
Expand Up @@ -274,8 +274,9 @@ func container(jaeger *v1.Jaeger, dep *appsv1.Deployment) corev1.Container {
Name: "admin-http",
},
},
Resources: commonSpec.Resources,
VolumeMounts: volumesAndMountsSpec.VolumeMounts,
Resources: commonSpec.Resources,
SecurityContext: jaeger.Spec.Agent.SidecarSecurityContext,
VolumeMounts: volumesAndMountsSpec.VolumeMounts,
}
}

Expand Down
13 changes: 13 additions & 0 deletions pkg/inject/sidecar_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -850,3 +850,16 @@ func TestInjectSidecarOnOpenShift(t *testing.T) {
assert.Len(t, dep.Spec.Template.Spec.Containers[1].VolumeMounts, 2)
assert.Len(t, dep.Spec.Template.Spec.Volumes, 2)
}

func TestSidecarWithSecurityContext(t *testing.T) {
var user, group int64 = 111, 222
expectedSecurityContext := &corev1.SecurityContext{RunAsUser: &user, RunAsGroup: &group}

jaeger := v1.NewJaeger(types.NamespacedName{Name: "TestSidecarWithSecurityContext"})
jaeger.Spec.Agent.SidecarSecurityContext = expectedSecurityContext

dep := dep(map[string]string{}, map[string]string{})
dep = Sidecar(jaeger, dep)
assert.Len(t, dep.Spec.Template.Spec.Containers, 2)
assert.Equal(t, dep.Spec.Template.Spec.Containers[1].SecurityContext, expectedSecurityContext)
}

0 comments on commit f6ee9c8

Please sign in to comment.