-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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
Bootstrap Kube namespaced roles and bindings #16517
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,7 +10,9 @@ import ( | |
|
||
"github.com/spf13/cobra" | ||
|
||
"k8s.io/apimachinery/pkg/util/sets" | ||
kapi "k8s.io/kubernetes/pkg/api" | ||
"k8s.io/kubernetes/pkg/apis/rbac" | ||
kcmdutil "k8s.io/kubernetes/pkg/kubectl/cmd/util" | ||
kprinters "k8s.io/kubernetes/pkg/printers" | ||
|
||
|
@@ -53,6 +55,7 @@ func NewCommandCreateBootstrapPolicyFile(commandName string, fullName string, ou | |
|
||
flags.StringVar(&options.File, "filename", DefaultPolicyFile, "The policy template file that will be written with roles and bindings.") | ||
flags.StringVar(&options.OpenShiftSharedResourcesNamespace, "openshift-namespace", "openshift", "Namespace for shared resources.") | ||
flags.MarkDeprecated("openshift-namespace", "this field is no longer supported and using it can lead to undefined behavior") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We got rid of openshift-infra choice. I don't remember removing the shared namespace choice. If openshift-infra was changed, we simply created what needed to be. If they used a custom shared namespace, we cannot recreate that for them. @smarterclayton its easier if we remove it, but I'm not sure about breaks. Opinion? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Ansible doesn't allow it to be set. If a user changes it, I think its up to him to make sure all his roles are ready There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think we should remove it. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Deprecate in 3.7 and remove in 3.8 seems reasonable to me. Removing it completely in 3.7 seems a bit sudden, but I have a feeling that no sane person ever messed with this so I can stomp on it if you really want. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
@enj You already have removed it in this pull. You just don't realize that you have. It no longer functions as it used to. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hm yeah I killed the bootstrapping of it which is what matters. |
||
|
||
// autocompletion hints | ||
cmd.MarkFlagFilename("filename") | ||
|
@@ -80,11 +83,11 @@ func (o CreateBootstrapPolicyFileOptions) CreateBootstrapPolicyFile() error { | |
} | ||
|
||
policyTemplate := &templateapi.Template{} | ||
policy := bootstrappolicy.Policy() | ||
|
||
clusterRoles := bootstrappolicy.GetBootstrapClusterRoles() | ||
for i := range clusterRoles { | ||
for i := range policy.ClusterRoles { | ||
originObject := &authorizationapi.ClusterRole{} | ||
if err := kapi.Scheme.Convert(&clusterRoles[i], originObject, nil); err != nil { | ||
if err := kapi.Scheme.Convert(&policy.ClusterRoles[i], originObject, nil); err != nil { | ||
return err | ||
} | ||
versionedObject, err := kapi.Scheme.ConvertToVersion(originObject, latest.Version) | ||
|
@@ -94,10 +97,9 @@ func (o CreateBootstrapPolicyFileOptions) CreateBootstrapPolicyFile() error { | |
policyTemplate.Objects = append(policyTemplate.Objects, versionedObject) | ||
} | ||
|
||
clusterRoleBindings := bootstrappolicy.GetBootstrapClusterRoleBindings() | ||
for i := range clusterRoleBindings { | ||
for i := range policy.ClusterRoleBindings { | ||
originObject := &authorizationapi.ClusterRoleBinding{} | ||
if err := kapi.Scheme.Convert(&clusterRoleBindings[i], originObject, nil); err != nil { | ||
if err := kapi.Scheme.Convert(&policy.ClusterRoleBindings[i], originObject, nil); err != nil { | ||
return err | ||
} | ||
versionedObject, err := kapi.Scheme.ConvertToVersion(originObject, latest.Version) | ||
|
@@ -107,30 +109,64 @@ func (o CreateBootstrapPolicyFileOptions) CreateBootstrapPolicyFile() error { | |
policyTemplate.Objects = append(policyTemplate.Objects, versionedObject) | ||
} | ||
|
||
openshiftRoles := bootstrappolicy.GetBootstrapOpenshiftRoles(o.OpenShiftSharedResourcesNamespace) | ||
for i := range openshiftRoles { | ||
originObject := &authorizationapi.Role{} | ||
if err := kapi.Scheme.Convert(&openshiftRoles[i], originObject, nil); err != nil { | ||
return err | ||
openshiftRoles := map[string][]rbac.Role{} | ||
for namespace, roles := range policy.Roles { | ||
if namespace == bootstrappolicy.DefaultOpenShiftSharedResourcesNamespace { | ||
r := make([]rbac.Role, len(roles)) | ||
for i := range roles { | ||
r[i] = roles[i] | ||
r[i].Namespace = o.OpenShiftSharedResourcesNamespace | ||
} | ||
openshiftRoles[o.OpenShiftSharedResourcesNamespace] = r | ||
} else { | ||
openshiftRoles[namespace] = roles | ||
} | ||
versionedObject, err := kapi.Scheme.ConvertToVersion(originObject, latest.Version) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
// iterate in a defined order | ||
for _, namespace := range sets.StringKeySet(openshiftRoles).List() { | ||
roles := openshiftRoles[namespace] | ||
for i := range roles { | ||
originObject := &authorizationapi.Role{} | ||
if err := kapi.Scheme.Convert(&roles[i], originObject, nil); err != nil { | ||
return err | ||
} | ||
versionedObject, err := kapi.Scheme.ConvertToVersion(originObject, latest.Version) | ||
if err != nil { | ||
return err | ||
} | ||
policyTemplate.Objects = append(policyTemplate.Objects, versionedObject) | ||
} | ||
policyTemplate.Objects = append(policyTemplate.Objects, versionedObject) | ||
} | ||
|
||
openshiftRoleBindings := bootstrappolicy.GetBootstrapOpenshiftRoleBindings(o.OpenShiftSharedResourcesNamespace) | ||
for i := range openshiftRoleBindings { | ||
originObject := &authorizationapi.RoleBinding{} | ||
if err := kapi.Scheme.Convert(&openshiftRoleBindings[i], originObject, nil); err != nil { | ||
return err | ||
openshiftRoleBindings := map[string][]rbac.RoleBinding{} | ||
for namespace, roleBindings := range policy.RoleBindings { | ||
if namespace == bootstrappolicy.DefaultOpenShiftSharedResourcesNamespace { | ||
rb := make([]rbac.RoleBinding, len(roleBindings)) | ||
for i := range roleBindings { | ||
rb[i] = roleBindings[i] | ||
rb[i].Namespace = o.OpenShiftSharedResourcesNamespace | ||
} | ||
openshiftRoleBindings[o.OpenShiftSharedResourcesNamespace] = rb | ||
} else { | ||
openshiftRoleBindings[namespace] = roleBindings | ||
} | ||
versionedObject, err := kapi.Scheme.ConvertToVersion(originObject, latest.Version) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
// iterate in a defined order | ||
for _, namespace := range sets.StringKeySet(openshiftRoleBindings).List() { | ||
roleBindings := openshiftRoleBindings[namespace] | ||
for i := range roleBindings { | ||
originObject := &authorizationapi.RoleBinding{} | ||
if err := kapi.Scheme.Convert(&roleBindings[i], originObject, nil); err != nil { | ||
return err | ||
} | ||
versionedObject, err := kapi.Scheme.ConvertToVersion(originObject, latest.Version) | ||
if err != nil { | ||
return err | ||
} | ||
policyTemplate.Objects = append(policyTemplate.Objects, versionedObject) | ||
} | ||
policyTemplate.Objects = append(policyTemplate.Objects, versionedObject) | ||
} | ||
|
||
versionedPolicyTemplate, err := kapi.Scheme.ConvertToVersion(policyTemplate, latest.Version) | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,14 @@ | ||
package bootstrappolicy | ||
|
||
import ( | ||
"k8s.io/kubernetes/pkg/apis/rbac" | ||
rbacrest "k8s.io/kubernetes/pkg/registry/rbac/rest" | ||
) | ||
|
||
func Policy() *rbacrest.PolicyData { | ||
return &rbacrest.PolicyData{ | ||
ClusterRoles: GetBootstrapClusterRoles(), | ||
ClusterRoleBindings: GetBootstrapClusterRoleBindings(), | ||
Roles: map[string][]rbac.Role{ | ||
DefaultOpenShiftSharedResourcesNamespace: GetBootstrapOpenshiftRoles(DefaultOpenShiftSharedResourcesNamespace), | ||
}, | ||
RoleBindings: map[string][]rbac.RoleBinding{ | ||
DefaultOpenShiftSharedResourcesNamespace: GetBootstrapOpenshiftRoleBindings(DefaultOpenShiftSharedResourcesNamespace), | ||
}, | ||
Roles: GetBootstrapNamespaceRoles(), | ||
RoleBindings: GetBootstrapNamespaceRoleBindings(), | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
this entire command should just die.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
3.8