Skip to content

Commit

Permalink
avoid potential nil pointer
Browse files Browse the repository at this point in the history
  • Loading branch information
usernameisnull committed Jun 25, 2024
1 parent f07d0af commit e4f7929
Showing 1 changed file with 26 additions and 25 deletions.
51 changes: 26 additions & 25 deletions pkg/resources/statefulsets/minio-statefulset.go
Original file line number Diff line number Diff line change
Expand Up @@ -423,34 +423,35 @@ func poolContainerSecurityContext(pool *miniov2.Pool) *corev1.SecurityContext {
var runAsUser int64 = 1000
var runAsGroup int64 = 1000
poolSCSet := false

// Values from pool.SecurityContext ONLY if provided
if pool.SecurityContext != nil {
if pool.SecurityContext.RunAsNonRoot != nil {
runAsNonRoot = *pool.SecurityContext.RunAsNonRoot
poolSCSet = true
}
if pool.SecurityContext.RunAsUser != nil {
runAsUser = *pool.SecurityContext.RunAsUser
poolSCSet = true
}
if pool.SecurityContext.RunAsGroup != nil {
runAsGroup = *pool.SecurityContext.RunAsGroup
poolSCSet = true
}
if poolSCSet {
// Only set values if one of above is set otherwise let it empty
containerSecurityContext = corev1.SecurityContext{
RunAsNonRoot: &runAsNonRoot,
RunAsUser: &runAsUser,
RunAsGroup: &runAsGroup,
if pool != nil {
// Values from pool.SecurityContext ONLY if provided
if pool.SecurityContext != nil {
if pool.SecurityContext.RunAsNonRoot != nil {
runAsNonRoot = *pool.SecurityContext.RunAsNonRoot
poolSCSet = true
}
if pool.SecurityContext.RunAsUser != nil {
runAsUser = *pool.SecurityContext.RunAsUser
poolSCSet = true
}
if pool.SecurityContext.RunAsGroup != nil {
runAsGroup = *pool.SecurityContext.RunAsGroup
poolSCSet = true
}
if poolSCSet {
// Only set values if one of above is set otherwise let it empty
containerSecurityContext = corev1.SecurityContext{
RunAsNonRoot: &runAsNonRoot,
RunAsUser: &runAsUser,
RunAsGroup: &runAsGroup,
}
}
}
}

// Values from pool.ContainerSecurityContext if provided
if pool != nil && pool.ContainerSecurityContext != nil {
containerSecurityContext = *pool.ContainerSecurityContext
// Values from pool.ContainerSecurityContext if provided
if pool.ContainerSecurityContext != nil {
containerSecurityContext = *pool.ContainerSecurityContext
}
}
return &containerSecurityContext
}
Expand Down

0 comments on commit e4f7929

Please sign in to comment.