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

Adding support for OpenShift securityContext #706

Open
wants to merge 1 commit 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
5 changes: 5 additions & 0 deletions api/v1beta1/common_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,11 @@ type PodOptions struct {
// +optional
InitContainers []corev1.Container `json:"initContainers,omitempty"`

// Removes the fsGroup securityContext from
// the StatefulSet for compatibility with OpenShift.
// +optional
Openshift bool `json:"openshift,omitempty"`

// ImagePullSecrets to apply to the pod.
// These are for init/sidecarContainers in addition to the imagePullSecret defined for the
// solr image.
Expand Down
4 changes: 4 additions & 0 deletions config/crd/bases/solr.apache.org_solrclouds.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4943,6 +4943,10 @@ spec:
type: string
description: Node Selector to be added for the StatefulSet.
type: object
openshift:
description: Removes the fsGroup securityContext from the
StatefulSet for compatibility with OpenShift.
type: boolean
podSecurityContext:
description: PodSecurityContext is the security context for
the pod.
Expand Down
4 changes: 4 additions & 0 deletions config/crd/bases/solr.apache.org_solrprometheusexporters.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2955,6 +2955,10 @@ spec:
type: string
description: Node Selector to be added for the StatefulSet.
type: object
openshift:
description: Removes the fsGroup securityContext from the
StatefulSet for compatibility with OpenShift.
type: boolean
podSecurityContext:
description: PodSecurityContext is the security context for
the pod.
Expand Down
19 changes: 10 additions & 9 deletions controllers/util/solr_util.go
Original file line number Diff line number Diff line change
Expand Up @@ -543,19 +543,20 @@ func GenerateStatefulSet(solrCloud *solr.SolrCloud, solrCloudStatus *solr.SolrCl

Spec: corev1.PodSpec{
TerminationGracePeriodSeconds: &terminationGracePeriod,
SecurityContext: &corev1.PodSecurityContext{
FSGroup: &defaultFSGroup,
},
Volumes: solrVolumes,
InitContainers: initContainers,
HostAliases: hostAliases,
Containers: containers,
ReadinessGates: podReadinessGates,
SecurityContext: &corev1.PodSecurityContext{},
Volumes: solrVolumes,
InitContainers: initContainers,
HostAliases: hostAliases,
Containers: containers,
ReadinessGates: podReadinessGates,
},
},
VolumeClaimTemplates: pvcs,
},
}
if customPodOptions.Openshift != true {
stateful.Spec.Template.Spec.SecurityContext.FSGroup = &defaultFSGroup
}
if solrCloud.UsesHeadlessService() {
stateful.Spec.Template.Spec.Subdomain = solrCloud.HeadlessServiceName()
}
Expand Down Expand Up @@ -592,7 +593,7 @@ func GenerateStatefulSet(solrCloud *solr.SolrCloud, solrCloudStatus *solr.SolrCl

if customPodOptions.PodSecurityContext != nil {
stateful.Spec.Template.Spec.SecurityContext = customPodOptions.PodSecurityContext
if stateful.Spec.Template.Spec.SecurityContext.FSGroup == nil {
if stateful.Spec.Template.Spec.SecurityContext.FSGroup == nil && customPodOptions.Openshift != true {
stateful.Spec.Template.Spec.SecurityContext.FSGroup = &defaultFSGroup
}
}
Expand Down
8 changes: 8 additions & 0 deletions helm/solr-operator/crds/crds.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5192,6 +5192,10 @@ spec:
type: string
description: Node Selector to be added for the StatefulSet.
type: object
openshift:
description: Removes the fsGroup securityContext from the
StatefulSet for compatibility with OpenShift.
type: boolean
podSecurityContext:
description: PodSecurityContext is the security context for
the pod.
Expand Down Expand Up @@ -20022,6 +20026,10 @@ spec:
type: string
description: Node Selector to be added for the StatefulSet.
type: object
openshift:
description: Removes the fsGroup securityContext from the
StatefulSet for compatibility with OpenShift.
type: boolean
podSecurityContext:
description: PodSecurityContext is the security context for
the pod.
Expand Down