Skip to content
This repository has been archived by the owner on Mar 28, 2020. It is now read-only.

Commit

Permalink
Merge pull request #1949 from hasbro17/haseeb/change-default-pod-UID
Browse files Browse the repository at this point in the history
*: make SecurityContext configurable via PodPolicy
  • Loading branch information
hasbro17 authored Apr 12, 2018
2 parents daba74a + fe90844 commit 73f1141
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 8 deletions.
4 changes: 4 additions & 0 deletions pkg/apis/etcd/v1beta2/cluster.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,10 @@ type PodPolicy struct {
// busybox:latest uses uclibc which contains a bug that sometimes prevents name resolution
// More info: https://github.com/docker-library/busybox/issues/27
BusyboxImage string `json:"busyboxImage,omitempty"`

// SecurityContext specifies the security context for the entire pod
// More info: https://kubernetes.io/docs/tasks/configure-pod-container/security-context
SecurityContext *v1.PodSecurityContext `json:"securityContext,omitempty"`
}

// TODO: move this to initializer
Expand Down
9 changes: 9 additions & 0 deletions pkg/apis/etcd/v1beta2/zz_generated.deepcopy.go

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

16 changes: 8 additions & 8 deletions pkg/util/k8sutil/k8sutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -350,9 +350,6 @@ func newEtcdPod(m *etcdutil.Member, initialCluster []string, clusterName, state,
}})
}

runAsNonRoot := true
podUID := int64(9000)
fsGroup := podUID
pod := &v1.Pod{
ObjectMeta: metav1.ObjectMeta{
Name: m.Name,
Expand Down Expand Up @@ -383,17 +380,20 @@ func newEtcdPod(m *etcdutil.Member, initialCluster []string, clusterName, state,
Hostname: m.Name,
Subdomain: clusterName,
AutomountServiceAccountToken: func(b bool) *bool { return &b }(false),
SecurityContext: &v1.PodSecurityContext{
RunAsUser: &podUID,
RunAsNonRoot: &runAsNonRoot,
FSGroup: &fsGroup,
},
SecurityContext: podSecurityContext(cs.Pod),
},
}
SetEtcdVersion(pod, cs.Version)
return pod
}

func podSecurityContext(podPolicy *api.PodPolicy) *v1.PodSecurityContext {
if podPolicy == nil {
return nil
}
return podPolicy.SecurityContext
}

func NewEtcdPod(m *etcdutil.Member, initialCluster []string, clusterName, state, token string, cs api.ClusterSpec, owner metav1.OwnerReference) *v1.Pod {
pod := newEtcdPod(m, initialCluster, clusterName, state, token, cs)
applyPodPolicy(clusterName, pod, cs.Pod)
Expand Down

0 comments on commit 73f1141

Please sign in to comment.