Skip to content
Merged
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
22 changes: 12 additions & 10 deletions pkg/cmd/server/bootstrappolicy/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,12 @@ const (
BuilderServiceAccountName = "builder"
DeployerServiceAccountName = "deployer"

InfraBuildControllerServiceAccountName = "build-controller"
InfraReplicationControllerServiceAccountName = "replication-controller"
InfraDeploymentControllerServiceAccountName = "deployment-controller"
InfraJobControllerServiceAccountName = "job-controller"
InfraHPAControllerServiceAccountName = "hpa-controller"
InfraBuildControllerServiceAccountName = "build-controller"
InfraReplicationControllerServiceAccountName = "replication-controller"
InfraDeploymentControllerServiceAccountName = "deployment-controller"
InfraJobControllerServiceAccountName = "job-controller"
InfraHPAControllerServiceAccountName = "hpa-controller"
InfraPersistentVolumeControllerServiceAccountName = "pv-controller"

MasterUnqualifiedUsername = "openshift-master"
RouterUnqualifiedUsername = "openshift-router"
Expand Down Expand Up @@ -64,11 +65,12 @@ const (
BasicUserRoleName = "basic-user"
StatusCheckerRoleName = "cluster-status"

BuildControllerRoleName = "system:build-controller"
ReplicationControllerRoleName = "system:replication-controller"
DeploymentControllerRoleName = "system:deployment-controller"
JobControllerRoleName = "system:job-controller"
HPAControllerRoleName = "system:hpa-controller"
BuildControllerRoleName = "system:build-controller"
ReplicationControllerRoleName = "system:replication-controller"
DeploymentControllerRoleName = "system:deployment-controller"
JobControllerRoleName = "system:job-controller"
HPAControllerRoleName = "system:hpa-controller"
PersistentVolumeControllerRoleName = "system:pv-controller"

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you need to define this role in bootstrappolicy/policy.go (see JobControllerRoleName definition as an example). Include all API calls, verbs and objects the persistent volume controller's client will need to be permitted to do.


ImagePullerRoleName = "system:image-puller"
ImageBuilderRoleName = "system:image-builder"
Expand Down
52 changes: 52 additions & 0 deletions pkg/cmd/server/bootstrappolicy/policy.go
Original file line number Diff line number Diff line change
Expand Up @@ -416,6 +416,58 @@ func GetBootstrapClusterRoles() []authorizationapi.ClusterRole {
},
},
},
{
ObjectMeta: kapi.ObjectMeta{
Name: PersistentVolumeControllerRoleName,
},
Rules: []authorizationapi.PolicyRule{
// PersistentVolumeBinder.volumeController.ListWatch
{
Verbs: sets.NewString("list", "watch"),
Resources: sets.NewString("persistentvolumes"),
},
// PersistentVolumeBinder.syncVolume()
{
Verbs: sets.NewString("get", "update", "create", "delete"),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

when would the controller create a PV?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The provisioning pieces (which were declined for 3.1) will require Create and Delete of PVs.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

does deleting a PV come from the recycler? if so, move that to the recycler section

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I arranged them this way just to avoid duplication.

Both the binder and recycler require Get/Update. Recycler requires Create/Delete. They are all in one here, since it's the same account.

Resources: sets.NewString("persistentvolumes"),
},
// PersistentVolumeBinder.syncVolume()
{
Verbs: sets.NewString("update"),
Resources: sets.NewString("persistentvolumes/status"),
},
// PersistentVolumeBinder.claimController.ListWatch
{
Verbs: sets.NewString("list", "watch"),
Resources: sets.NewString("persistentvolumeclaims"),
},
// PersistentVolumeBinder.syncClaim()
{
Verbs: sets.NewString("get", "update"),
Resources: sets.NewString("persistentvolumeclaims"),
},
// PersistentVolumeBinder.syncClaim()
{
Verbs: sets.NewString("update"),
Resources: sets.NewString("persistentvolumeclaims/status"),
},
// PersistentVolumeRecycler.reclaimVolume() -> handleRecycle()
{
Verbs: sets.NewString("list", "watch"),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

recyclerClient has GetPod, but not ListPods

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add "get" here, just because the recyclerClient potentially makes use of it

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added

Resources: sets.NewString("pods"),
},
// PersistentVolumeRecycler.reclaimVolume() -> handleRecycle()
{
Verbs: sets.NewString("get", "create", "delete"),

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

per the other comment, added "get" here, which follows where "get" lives in the other defined policies.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[merge]

On Wed, Nov 4, 2015 at 3:10 PM, Mark Turansky [email protected]
wrote:

In pkg/cmd/server/bootstrappolicy/policy.go
#5465 (comment):

  •               Verbs:     sets.NewString("get", "update"),
    
  •               Resources: sets.NewString("persistentvolumeclaims"),
    
  •           },
    
  •           // PersistentVolumeBinder.syncClaim()
    
  •           {
    
  •               Verbs:     sets.NewString("update"),
    
  •               Resources: sets.NewString("persistentvolumeclaims/status"),
    
  •           },
    
  •           // PersistentVolumeRecycler.reclaimVolume() -> handleRecycle()
    
  •           {
    
  •               Verbs:     sets.NewString("list", "watch"),
    
  •               Resources: sets.NewString("pods"),
    
  •           },
    
  •           // PersistentVolumeRecycler.reclaimVolume() -> handleRecycle()
    
  •           {
    
  •               Verbs:     sets.NewString("get", "create", "delete"),
    

per the other comment, added "get" here, which follows where "get" lives
in the other defined policies.

—
Reply to this email directly or view it on GitHub
https://github.com/openshift/origin/pull/5465/files#r43932540.

Resources: sets.NewString("pods"),
},
// PersistentVolumeRecycler.reclaimVolume() -> handleRecycle()
{
Verbs: sets.NewString("create", "update", "patch"),
Resources: sets.NewString("events"),
},
},
},
{
ObjectMeta: kapi.ObjectMeta{
Name: HPAControllerRoleName,
Expand Down
4 changes: 2 additions & 2 deletions pkg/cmd/server/kubernetes/master.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func (c *MasterConfig) RunPersistentVolumeClaimBinder() {
binder.Run()
}

func (c *MasterConfig) RunPersistentVolumeClaimRecycler(recyclerImageName string) {
func (c *MasterConfig) RunPersistentVolumeClaimRecycler(recyclerImageName string, client *client.Client) {
defaultScrubPod := volume.NewPersistentVolumeRecyclerPodTemplate()
defaultScrubPod.Spec.Containers[0].Image = recyclerImageName
defaultScrubPod.Spec.Containers[0].Command = []string{"/usr/share/openshift/scripts/volumes/recycler.sh"}
Expand All @@ -96,7 +96,7 @@ func (c *MasterConfig) RunPersistentVolumeClaimRecycler(recyclerImageName string
allPlugins = append(allPlugins, host_path.ProbeVolumePlugins(hostPathConfig)...)
allPlugins = append(allPlugins, nfs.ProbeVolumePlugins(nfsConfig)...)

recycler, err := volumeclaimbinder.NewPersistentVolumeRecycler(c.KubeClient, c.ControllerManager.PVClaimBinderSyncPeriod, allPlugins)
recycler, err := volumeclaimbinder.NewPersistentVolumeRecycler(client, c.ControllerManager.PVClaimBinderSyncPeriod, allPlugins)
if err != nil {
glog.Fatalf("Could not start Persistent Volume Recycler: %+v", err)
}
Expand Down
17 changes: 11 additions & 6 deletions pkg/cmd/server/origin/ensure.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func (c *MasterConfig) ensureOpenShiftInfraNamespace() {
// Ensure service accounts exist
serviceAccounts := []string{
c.BuildControllerServiceAccount, c.DeploymentControllerServiceAccount, c.ReplicationControllerServiceAccount,
c.JobControllerServiceAccount, c.HPAControllerServiceAccount,
c.JobControllerServiceAccount, c.HPAControllerServiceAccount, c.PersistentVolumeControllerServiceAccount,
}
for _, serviceAccountName := range serviceAccounts {
_, err := c.KubeClient().ServiceAccounts(ns).Create(&kapi.ServiceAccount{ObjectMeta: kapi.ObjectMeta{Name: serviceAccountName}})
Expand All @@ -68,11 +68,12 @@ func (c *MasterConfig) ensureOpenShiftInfraNamespace() {

// Ensure service account cluster role bindings exist
clusterRolesToSubjects := map[string][]kapi.ObjectReference{
bootstrappolicy.BuildControllerRoleName: {{Namespace: ns, Name: c.BuildControllerServiceAccount, Kind: "ServiceAccount"}},
bootstrappolicy.DeploymentControllerRoleName: {{Namespace: ns, Name: c.DeploymentControllerServiceAccount, Kind: "ServiceAccount"}},
bootstrappolicy.ReplicationControllerRoleName: {{Namespace: ns, Name: c.ReplicationControllerServiceAccount, Kind: "ServiceAccount"}},
bootstrappolicy.JobControllerRoleName: {{Namespace: ns, Name: c.JobControllerServiceAccount, Kind: "ServiceAccount"}},
bootstrappolicy.HPAControllerRoleName: {{Namespace: ns, Name: c.HPAControllerServiceAccount, Kind: "ServiceAccount"}},
bootstrappolicy.BuildControllerRoleName: {{Namespace: ns, Name: c.BuildControllerServiceAccount, Kind: "ServiceAccount"}},
bootstrappolicy.DeploymentControllerRoleName: {{Namespace: ns, Name: c.DeploymentControllerServiceAccount, Kind: "ServiceAccount"}},
bootstrappolicy.ReplicationControllerRoleName: {{Namespace: ns, Name: c.ReplicationControllerServiceAccount, Kind: "ServiceAccount"}},
bootstrappolicy.JobControllerRoleName: {{Namespace: ns, Name: c.JobControllerServiceAccount, Kind: "ServiceAccount"}},
bootstrappolicy.HPAControllerRoleName: {{Namespace: ns, Name: c.HPAControllerServiceAccount, Kind: "ServiceAccount"}},
bootstrappolicy.PersistentVolumeControllerRoleName: {{Namespace: ns, Name: c.PersistentVolumeControllerServiceAccount, Kind: "ServiceAccount"}},
}
roleAccessor := policy.NewClusterRoleBindingAccessor(c.ServiceAccountRoleBindingClient())
for clusterRole, subjects := range clusterRolesToSubjects {
Expand Down Expand Up @@ -171,6 +172,10 @@ func (c *MasterConfig) ensureDefaultSecurityContextConstraints() {
bootstrapSCCGroups, bootstrapSCCUsers := bootstrappolicy.GetBoostrapSCCAccess()
bootstrapSCCUsers[bootstrappolicy.SecurityContextConstraintPrivileged] = append(bootstrapSCCUsers[bootstrappolicy.SecurityContextConstraintPrivileged], buildControllerUsername)

// add the pv controller to the HostMount SCC access. Recyclers created by the controller are admin tasks performed by the controller.
pvControllerUsername := serviceaccount.MakeUsername(ns, c.PersistentVolumeControllerServiceAccount)
bootstrapSCCUsers[bootstrappolicy.SecurityContextConstraintHostMount] = append(bootstrapSCCUsers[bootstrappolicy.SecurityContextConstraintHostMount], pvControllerUsername)

for _, scc := range bootstrappolicy.GetBootstrapSecurityContextConstraints(bootstrapSCCGroups, bootstrapSCCUsers) {
_, err = c.KubeClient().SecurityContextConstraints().Create(&scc)
if err != nil {
Expand Down
13 changes: 8 additions & 5 deletions pkg/cmd/server/origin/master_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,8 @@ type MasterConfig struct {
JobControllerServiceAccount string
// HPAControllerServiceAccount is the name of the service account in the infra namespace to use to run the hpa controller
HPAControllerServiceAccount string
// PersistentVolumeControllerServiceAccount is the name of the service account in the infra namespace to use to run the persistent volume controller
PersistentVolumeControllerServiceAccount string
}

// BuildMasterConfig builds and returns the OpenShift master configuration based on the
Expand Down Expand Up @@ -217,11 +219,12 @@ func BuildMasterConfig(options configapi.MasterConfig) (*MasterConfig, error) {
PrivilegedLoopbackOpenShiftClient: privilegedLoopbackOpenShiftClient,
PrivilegedLoopbackKubernetesClient: privilegedLoopbackKubeClient,

BuildControllerServiceAccount: bootstrappolicy.InfraBuildControllerServiceAccountName,
DeploymentControllerServiceAccount: bootstrappolicy.InfraDeploymentControllerServiceAccountName,
ReplicationControllerServiceAccount: bootstrappolicy.InfraReplicationControllerServiceAccountName,
JobControllerServiceAccount: bootstrappolicy.InfraJobControllerServiceAccountName,
HPAControllerServiceAccount: bootstrappolicy.InfraHPAControllerServiceAccountName,
BuildControllerServiceAccount: bootstrappolicy.InfraBuildControllerServiceAccountName,
DeploymentControllerServiceAccount: bootstrappolicy.InfraDeploymentControllerServiceAccountName,
ReplicationControllerServiceAccount: bootstrappolicy.InfraReplicationControllerServiceAccountName,
JobControllerServiceAccount: bootstrappolicy.InfraJobControllerServiceAccountName,
HPAControllerServiceAccount: bootstrappolicy.InfraHPAControllerServiceAccountName,
PersistentVolumeControllerServiceAccount: bootstrappolicy.InfraPersistentVolumeControllerServiceAccountName,
}

return config, nil
Expand Down
7 changes: 6 additions & 1 deletion pkg/cmd/server/start/start_master.go
Original file line number Diff line number Diff line change
Expand Up @@ -539,6 +539,11 @@ func startControllers(oc *origin.MasterConfig, kc *kubernetes.MasterConfig) erro
glog.Fatalf("Could not get client for HPA controller: %v", err)
}

_, pvKClient, err := oc.GetServiceAccountClients(oc.PersistentVolumeControllerServiceAccount)
if err != nil {
glog.Fatalf("Could not get client for persistent volume controller: %v", err)
}

// called by admission control
kc.RunResourceQuotaManager()

Expand All @@ -551,7 +556,7 @@ func startControllers(oc *origin.MasterConfig, kc *kubernetes.MasterConfig) erro
kc.RunEndpointController()
kc.RunNamespaceController()
kc.RunPersistentVolumeClaimBinder()
kc.RunPersistentVolumeClaimRecycler(oc.ImageFor("deployer"))
kc.RunPersistentVolumeClaimRecycler(oc.ImageFor("deployer"), pvKClient)

glog.Infof("Started Kubernetes Controllers")
}
Expand Down