Skip to content

Commit

Permalink
Merge pull request #1 from enj/enj/h/matt_bootstrap_file/19756
Browse files Browse the repository at this point in the history
Fix create_bootstrappolicy_file
  • Loading branch information
Matt Rogers authored May 22, 2018
2 parents a0e846d + 2724e20 commit 288c12f
Show file tree
Hide file tree
Showing 2 changed files with 768 additions and 1,391 deletions.
23 changes: 17 additions & 6 deletions pkg/cmd/server/admin/create_bootstrappolicy_file.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,12 @@ import (
"github.com/spf13/cobra"

rbacv1 "k8s.io/api/rbac/v1"
"k8s.io/apimachinery/pkg/util/sets"
"k8s.io/kubernetes/pkg/api/legacyscheme"
kcmdutil "k8s.io/kubernetes/pkg/kubectl/cmd/util"
kprinters "k8s.io/kubernetes/pkg/printers"

"github.com/openshift/origin/pkg/api/latest"
"github.com/openshift/origin/pkg/cmd/server/bootstrappolicy"
templateapi "github.com/openshift/origin/pkg/template/apis/template"
)
Expand Down Expand Up @@ -91,28 +93,37 @@ func (o CreateBootstrapPolicyFileOptions) CreateBootstrapPolicyFile() error {
policyTemplate.Objects = append(policyTemplate.Objects, versionedObject)
}

for namespace, roles := range policy.Roles {
// iterate in a defined order
for _, namespace := range sets.StringKeySet(policy.Roles).List() {
roles := policy.Roles[namespace]
for i := range roles {
versionedObject, err := legacyscheme.Scheme.ConvertToVersion(&policy.Roles[namespace][i], rbacv1.SchemeGroupVersion)
versionedObject, err := legacyscheme.Scheme.ConvertToVersion(&roles[i], rbacv1.SchemeGroupVersion)
if err != nil {
return err
}
policyTemplate.Objects = append(policyTemplate.Objects, versionedObject)
}
}

for namespace, rbs := range policy.RoleBindings {
for i := range rbs {
versionedObject, err := legacyscheme.Scheme.ConvertToVersion(&policy.RoleBindings[namespace][i], rbacv1.SchemeGroupVersion)
// iterate in a defined order
for _, namespace := range sets.StringKeySet(policy.RoleBindings).List() {
roleBindings := policy.RoleBindings[namespace]
for i := range roleBindings {
versionedObject, err := legacyscheme.Scheme.ConvertToVersion(&roleBindings[i], rbacv1.SchemeGroupVersion)
if err != nil {
return err
}
policyTemplate.Objects = append(policyTemplate.Objects, versionedObject)
}
}

versionedPolicyTemplate, err := legacyscheme.Scheme.ConvertToVersion(policyTemplate, latest.Version)
if err != nil {
return err
}

buffer := &bytes.Buffer{}
(&kprinters.JSONPrinter{}).PrintObj(policyTemplate, buffer)
(&kprinters.JSONPrinter{}).PrintObj(versionedPolicyTemplate, buffer)

if err := ioutil.WriteFile(o.File, buffer.Bytes(), 0644); err != nil {
return err
Expand Down
Loading

0 comments on commit 288c12f

Please sign in to comment.