Skip to content

Commit

Permalink
Only assign UID if using the community image (#81)
Browse files Browse the repository at this point in the history
* Only assign UID if using the community image

Signed-off-by: Lucas Caparelli <[email protected]>

* Increase golintci timeout
  • Loading branch information
LCaparelli authored Jun 1, 2020
1 parent 2340c61 commit 7587f31
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
1 change: 1 addition & 0 deletions .github/workflows/nexus-operator-integration-checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ jobs:
with:
# Required: the version of golangci-lint is required and must be specified without patch version: we always use the latest patch version.
version: v1.27
args: --timeout=2m

unit_test:
name: Unit Tests
Expand Down
10 changes: 9 additions & 1 deletion pkg/controller/nexus/resource/deployment/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ func newDeployment(nexus *v1alpha1.Nexus) *appsv1.Deployment {
Template: corev1.PodTemplateSpec{
ObjectMeta: meta.DefaultObjectMeta(nexus),
Spec: corev1.PodSpec{
SecurityContext: &corev1.PodSecurityContext{FSGroup: &nexusUID, RunAsUser: &nexusUID, SupplementalGroups: []int64{nexusUID}},
Containers: []corev1.Container{
{
Name: nexusContainerName,
Expand Down Expand Up @@ -117,6 +116,7 @@ func newDeployment(nexus *v1alpha1.Nexus) *appsv1.Deployment {
addProbes(nexus, deployment)
applyJVMArgs(nexus, deployment)
addServiceAccount(nexus, deployment)
applySecurityContext(nexus, deployment)

return deployment
}
Expand Down Expand Up @@ -261,3 +261,11 @@ func addServiceAccount(nexus *v1alpha1.Nexus, deployment *appsv1.Deployment) {
deployment.Spec.Template.Spec.ServiceAccountName = nexus.Name
}
}

func applySecurityContext(nexus *v1alpha1.Nexus, deployment *appsv1.Deployment) {
var podSecContext *corev1.PodSecurityContext
if !nexus.Spec.UseRedHatImage {
podSecContext = &corev1.PodSecurityContext{FSGroup: &nexusUID, RunAsUser: &nexusUID, SupplementalGroups: []int64{nexusUID}}
}
deployment.Spec.Template.Spec.SecurityContext = podSecContext
}

0 comments on commit 7587f31

Please sign in to comment.