| ... | ... |
@@ -25,6 +25,7 @@ import ( |
| 25 | 25 |
"github.com/openshift/origin/pkg/cmd/admin/groups/sync/interfaces" |
| 26 | 26 |
"github.com/openshift/origin/pkg/cmd/server/api" |
| 27 | 27 |
"github.com/openshift/origin/pkg/cmd/server/api/validation" |
| 28 |
+ ocmdutil "github.com/openshift/origin/pkg/cmd/util" |
|
| 28 | 29 |
"github.com/openshift/origin/pkg/cmd/util/clientcmd" |
| 29 | 30 |
) |
| 30 | 31 |
|
| ... | ... |
@@ -385,6 +386,11 @@ func (o *SyncOptions) Run(cmd *cobra.Command, f *clientcmd.Factory) error {
|
| 385 | 385 |
for _, item := range openshiftGroups {
|
| 386 | 386 |
list.Items = append(list.Items, item) |
| 387 | 387 |
} |
| 388 |
+ list.Items, err = ocmdutil.ConvertItemsForDisplayFromDefaultCommand(cmd, list.Items) |
|
| 389 |
+ if err != nil {
|
|
| 390 |
+ return err |
|
| 391 |
+ } |
|
| 392 |
+ |
|
| 388 | 393 |
if err := f.Factory.PrintObject(cmd, list, o.Out); err != nil {
|
| 389 | 394 |
return err |
| 390 | 395 |
} |
| ... | ... |
@@ -14,6 +14,7 @@ import ( |
| 14 | 14 |
authorizationapi "github.com/openshift/origin/pkg/authorization/api" |
| 15 | 15 |
"github.com/openshift/origin/pkg/client" |
| 16 | 16 |
"github.com/openshift/origin/pkg/cmd/server/bootstrappolicy" |
| 17 |
+ ocmdutil "github.com/openshift/origin/pkg/cmd/util" |
|
| 17 | 18 |
"github.com/openshift/origin/pkg/cmd/util/clientcmd" |
| 18 | 19 |
uservalidation "github.com/openshift/origin/pkg/user/api/validation" |
| 19 | 20 |
) |
| ... | ... |
@@ -144,6 +145,10 @@ func (o *ReconcileClusterRoleBindingsOptions) RunReconcileClusterRoleBindings(cm |
| 144 | 144 |
for _, item := range changedClusterRoleBindings {
|
| 145 | 145 |
list.Items = append(list.Items, item) |
| 146 | 146 |
} |
| 147 |
+ list.Items, err = ocmdutil.ConvertItemsForDisplayFromDefaultCommand(cmd, list.Items) |
|
| 148 |
+ if err != nil {
|
|
| 149 |
+ return err |
|
| 150 |
+ } |
|
| 147 | 151 |
|
| 148 | 152 |
if err := f.Factory.PrintObject(cmd, list, o.Out); err != nil {
|
| 149 | 153 |
return err |
| ... | ... |
@@ -16,6 +16,7 @@ import ( |
| 16 | 16 |
"github.com/openshift/origin/pkg/authorization/rulevalidation" |
| 17 | 17 |
"github.com/openshift/origin/pkg/client" |
| 18 | 18 |
"github.com/openshift/origin/pkg/cmd/server/bootstrappolicy" |
| 19 |
+ ocmdutil "github.com/openshift/origin/pkg/cmd/util" |
|
| 19 | 20 |
osutil "github.com/openshift/origin/pkg/cmd/util" |
| 20 | 21 |
"github.com/openshift/origin/pkg/cmd/util/clientcmd" |
| 21 | 22 |
) |
| ... | ... |
@@ -145,6 +146,11 @@ func (o *ReconcileClusterRolesOptions) RunReconcileClusterRoles(cmd *cobra.Comma |
| 145 | 145 |
list.Items = append(list.Items, item) |
| 146 | 146 |
} |
| 147 | 147 |
|
| 148 |
+ list.Items, err = ocmdutil.ConvertItemsForDisplayFromDefaultCommand(cmd, list.Items) |
|
| 149 |
+ if err != nil {
|
|
| 150 |
+ return err |
|
| 151 |
+ } |
|
| 152 |
+ |
|
| 148 | 153 |
if err := f.Factory.PrintObject(cmd, list, o.Out); err != nil {
|
| 149 | 154 |
return err |
| 150 | 155 |
} |
| ... | ... |
@@ -4,6 +4,7 @@ import ( |
| 4 | 4 |
"errors" |
| 5 | 5 |
"fmt" |
| 6 | 6 |
"io" |
| 7 |
+ "sort" |
|
| 7 | 8 |
|
| 8 | 9 |
"github.com/spf13/cobra" |
| 9 | 10 |
|
| ... | ... |
@@ -14,8 +15,8 @@ import ( |
| 14 | 14 |
"k8s.io/kubernetes/pkg/util/sets" |
| 15 | 15 |
|
| 16 | 16 |
"github.com/openshift/origin/pkg/cmd/server/bootstrappolicy" |
| 17 |
+ ocmdutil "github.com/openshift/origin/pkg/cmd/util" |
|
| 17 | 18 |
"github.com/openshift/origin/pkg/cmd/util/clientcmd" |
| 18 |
- "sort" |
|
| 19 | 19 |
) |
| 20 | 20 |
|
| 21 | 21 |
// ReconcileSCCRecommendedName is the recommended command name |
| ... | ... |
@@ -149,6 +150,11 @@ func (o *ReconcileSCCOptions) RunReconcileSCCs(cmd *cobra.Command, f *clientcmd. |
| 149 | 149 |
for _, item := range changedSCCs {
|
| 150 | 150 |
list.Items = append(list.Items, item) |
| 151 | 151 |
} |
| 152 |
+ list.Items, err = ocmdutil.ConvertItemsForDisplayFromDefaultCommand(cmd, list.Items) |
|
| 153 |
+ if err != nil {
|
|
| 154 |
+ return err |
|
| 155 |
+ } |
|
| 156 |
+ |
|
| 152 | 157 |
if err := f.Factory.PrintObject(cmd, list, o.Out); err != nil {
|
| 153 | 158 |
return err |
| 154 | 159 |
} |
| ... | ... |
@@ -18,6 +18,7 @@ import ( |
| 18 | 18 |
"k8s.io/kubernetes/pkg/runtime" |
| 19 | 19 |
"k8s.io/kubernetes/pkg/util/intstr" |
| 20 | 20 |
|
| 21 |
+ ocmdutil "github.com/openshift/origin/pkg/cmd/util" |
|
| 21 | 22 |
"github.com/openshift/origin/pkg/cmd/util/clientcmd" |
| 22 | 23 |
"github.com/openshift/origin/pkg/cmd/util/variable" |
| 23 | 24 |
configcmd "github.com/openshift/origin/pkg/config/cmd" |
| ... | ... |
@@ -336,6 +337,11 @@ func RunCmdRegistry(f *clientcmd.Factory, cmd *cobra.Command, out io.Writer, cfg |
| 336 | 336 |
list := &kapi.List{Items: objects}
|
| 337 | 337 |
|
| 338 | 338 |
if output {
|
| 339 |
+ list.Items, err = ocmdutil.ConvertItemsForDisplayFromDefaultCommand(cmd, list.Items) |
|
| 340 |
+ if err != nil {
|
|
| 341 |
+ return err |
|
| 342 |
+ } |
|
| 343 |
+ |
|
| 339 | 344 |
if err := f.PrintObject(cmd, list, out); err != nil {
|
| 340 | 345 |
return fmt.Errorf("unable to print object: %v", err)
|
| 341 | 346 |
} |
| ... | ... |
@@ -20,6 +20,7 @@ import ( |
| 20 | 20 |
"k8s.io/kubernetes/pkg/serviceaccount" |
| 21 | 21 |
"k8s.io/kubernetes/pkg/util/intstr" |
| 22 | 22 |
|
| 23 |
+ ocmdutil "github.com/openshift/origin/pkg/cmd/util" |
|
| 23 | 24 |
"github.com/openshift/origin/pkg/cmd/util/clientcmd" |
| 24 | 25 |
"github.com/openshift/origin/pkg/cmd/util/variable" |
| 25 | 26 |
configcmd "github.com/openshift/origin/pkg/config/cmd" |
| ... | ... |
@@ -622,6 +623,11 @@ func RunCmdRouter(f *clientcmd.Factory, cmd *cobra.Command, out io.Writer, cfg * |
| 622 | 622 |
list := &kapi.List{Items: objects}
|
| 623 | 623 |
|
| 624 | 624 |
if output {
|
| 625 |
+ list.Items, err = ocmdutil.ConvertItemsForDisplayFromDefaultCommand(cmd, list.Items) |
|
| 626 |
+ if err != nil {
|
|
| 627 |
+ return err |
|
| 628 |
+ } |
|
| 629 |
+ |
|
| 625 | 630 |
if err := f.PrintObject(cmd, list, out); err != nil {
|
| 626 | 631 |
return fmt.Errorf("Unable to print object: %v", err)
|
| 627 | 632 |
} |
| ... | ... |
@@ -29,6 +29,7 @@ import ( |
| 29 | 29 |
|
| 30 | 30 |
buildapi "github.com/openshift/origin/pkg/build/api" |
| 31 | 31 |
cmdutil "github.com/openshift/origin/pkg/cmd/util" |
| 32 |
+ ocmdutil "github.com/openshift/origin/pkg/cmd/util" |
|
| 32 | 33 |
"github.com/openshift/origin/pkg/cmd/util/clientcmd" |
| 33 | 34 |
dockerutil "github.com/openshift/origin/pkg/cmd/util/docker" |
| 34 | 35 |
configcmd "github.com/openshift/origin/pkg/config/cmd" |
| ... | ... |
@@ -190,6 +191,11 @@ func RunNewApplication(fullName string, f *clientcmd.Factory, out io.Writer, c * |
| 190 | 190 |
} |
| 191 | 191 |
|
| 192 | 192 |
if len(output) != 0 {
|
| 193 |
+ result.List.Items, err = ocmdutil.ConvertItemsForDisplayFromDefaultCommand(c, result.List.Items) |
|
| 194 |
+ if err != nil {
|
|
| 195 |
+ return err |
|
| 196 |
+ } |
|
| 197 |
+ |
|
| 193 | 198 |
return f.Factory.PrintObject(c, result.List, out) |
| 194 | 199 |
} |
| 195 | 200 |
|
| ... | ... |
@@ -220,6 +226,11 @@ func RunNewApplication(fullName string, f *clientcmd.Factory, out io.Writer, c * |
| 220 | 220 |
case shortOutput: |
| 221 | 221 |
indent = "" |
| 222 | 222 |
case len(output) != 0: |
| 223 |
+ result.List.Items, err = ocmdutil.ConvertItemsForDisplayFromDefaultCommand(c, result.List.Items) |
|
| 224 |
+ if err != nil {
|
|
| 225 |
+ return err |
|
| 226 |
+ } |
|
| 227 |
+ |
|
| 223 | 228 |
return f.Factory.PrintObject(c, result.List, out) |
| 224 | 229 |
case !result.GeneratedJobs: |
| 225 | 230 |
if len(config.Labels) > 0 {
|
| ... | ... |
@@ -9,12 +9,14 @@ import ( |
| 9 | 9 |
|
| 10 | 10 |
. "github.com/MakeNowJust/heredoc/dot" |
| 11 | 11 |
"github.com/spf13/cobra" |
| 12 |
+ |
|
| 12 | 13 |
kcmdutil "k8s.io/kubernetes/pkg/kubectl/cmd/util" |
| 13 | 14 |
"k8s.io/kubernetes/pkg/kubectl/resource" |
| 14 | 15 |
"k8s.io/kubernetes/pkg/util/errors" |
| 15 | 16 |
|
| 16 | 17 |
buildapi "github.com/openshift/origin/pkg/build/api" |
| 17 | 18 |
cmdutil "github.com/openshift/origin/pkg/cmd/util" |
| 19 |
+ ocmdutil "github.com/openshift/origin/pkg/cmd/util" |
|
| 18 | 20 |
"github.com/openshift/origin/pkg/cmd/util/clientcmd" |
| 19 | 21 |
configcmd "github.com/openshift/origin/pkg/config/cmd" |
| 20 | 22 |
newapp "github.com/openshift/origin/pkg/generate/app" |
| ... | ... |
@@ -168,6 +170,11 @@ func RunNewBuild(fullName string, f *clientcmd.Factory, out io.Writer, in io.Rea |
| 168 | 168 |
case shortOutput: |
| 169 | 169 |
indent = "" |
| 170 | 170 |
case len(output) != 0: |
| 171 |
+ result.List.Items, err = ocmdutil.ConvertItemsForDisplayFromDefaultCommand(c, result.List.Items) |
|
| 172 |
+ if err != nil {
|
|
| 173 |
+ return err |
|
| 174 |
+ } |
|
| 175 |
+ |
|
| 171 | 176 |
return f.Factory.PrintObject(c, result.List, out) |
| 172 | 177 |
default: |
| 173 | 178 |
if len(config.Labels) > 0 {
|
| ... | ... |
@@ -1,4 +1,4 @@ |
| 1 |
-package bootstrappolicy |
|
| 1 |
+package bootstrappolicy_test |
|
| 2 | 2 |
|
| 3 | 3 |
import ( |
| 4 | 4 |
"fmt" |
| ... | ... |
@@ -12,10 +12,14 @@ import ( |
| 12 | 12 |
"k8s.io/kubernetes/pkg/util" |
| 13 | 13 |
|
| 14 | 14 |
"github.com/openshift/origin/pkg/api/v1" |
| 15 |
+ "github.com/openshift/origin/pkg/cmd/server/bootstrappolicy" |
|
| 16 |
+ |
|
| 17 |
+ // install all APIs |
|
| 18 |
+ _ "github.com/openshift/origin/pkg/api/install" |
|
| 15 | 19 |
) |
| 16 | 20 |
|
| 17 | 21 |
func TestOpenshiftRoles(t *testing.T) {
|
| 18 |
- roles := GetBootstrapOpenshiftRoles("openshift")
|
|
| 22 |
+ roles := bootstrappolicy.GetBootstrapOpenshiftRoles("openshift")
|
|
| 19 | 23 |
list := &api.List{}
|
| 20 | 24 |
for i := range roles {
|
| 21 | 25 |
list.Items = append(list.Items, &roles[i]) |
| ... | ... |
@@ -24,7 +28,7 @@ func TestOpenshiftRoles(t *testing.T) {
|
| 24 | 24 |
} |
| 25 | 25 |
|
| 26 | 26 |
func TestBootstrapProjectRoleBindings(t *testing.T) {
|
| 27 |
- roleBindings := GetBootstrapServiceAccountProjectRoleBindings("myproject")
|
|
| 27 |
+ roleBindings := bootstrappolicy.GetBootstrapServiceAccountProjectRoleBindings("myproject")
|
|
| 28 | 28 |
list := &api.List{}
|
| 29 | 29 |
for i := range roleBindings {
|
| 30 | 30 |
list.Items = append(list.Items, &roleBindings[i]) |
| ... | ... |
@@ -33,7 +37,7 @@ func TestBootstrapProjectRoleBindings(t *testing.T) {
|
| 33 | 33 |
} |
| 34 | 34 |
|
| 35 | 35 |
func TestBootstrapClusterRoleBindings(t *testing.T) {
|
| 36 |
- roleBindings := GetBootstrapClusterRoleBindings() |
|
| 36 |
+ roleBindings := bootstrappolicy.GetBootstrapClusterRoleBindings() |
|
| 37 | 37 |
list := &api.List{}
|
| 38 | 38 |
for i := range roleBindings {
|
| 39 | 39 |
list.Items = append(list.Items, &roleBindings[i]) |
| ... | ... |
@@ -42,7 +46,7 @@ func TestBootstrapClusterRoleBindings(t *testing.T) {
|
| 42 | 42 |
} |
| 43 | 43 |
|
| 44 | 44 |
func TestBootstrapClusterRoles(t *testing.T) {
|
| 45 |
- roles := GetBootstrapClusterRoles() |
|
| 45 |
+ roles := bootstrappolicy.GetBootstrapClusterRoles() |
|
| 46 | 46 |
list := &api.List{}
|
| 47 | 47 |
for i := range roles {
|
| 48 | 48 |
list.Items = append(list.Items, &roles[i]) |
| ... | ... |
@@ -57,7 +61,11 @@ func testObjects(t *testing.T, list *api.List, fixtureFilename string) {
|
| 57 | 57 |
t.Fatal(err) |
| 58 | 58 |
} |
| 59 | 59 |
|
| 60 |
- jsonData, err := v1.Codec.Encode(list) |
|
| 60 |
+ if err := runtime.EncodeList(api.Codecs.LegacyCodec(v1.SchemeGroupVersion), list.Items); err != nil {
|
|
| 61 |
+ t.Fatal(err) |
|
| 62 |
+ } |
|
| 63 |
+ |
|
| 64 |
+ jsonData, err := runtime.Encode(api.Codecs.LegacyCodec(v1.SchemeGroupVersion), list) |
|
| 61 | 65 |
if err != nil {
|
| 62 | 66 |
t.Fatal(err) |
| 63 | 67 |
} |
| ... | ... |
@@ -9,9 +9,12 @@ import ( |
| 9 | 9 |
|
| 10 | 10 |
"github.com/spf13/cobra" |
| 11 | 11 |
|
| 12 |
+ kapi "k8s.io/kubernetes/pkg/api" |
|
| 12 | 13 |
"k8s.io/kubernetes/pkg/api/meta" |
| 13 | 14 |
"k8s.io/kubernetes/pkg/api/unversioned" |
| 15 |
+ "k8s.io/kubernetes/pkg/apimachinery/registered" |
|
| 14 | 16 |
kcmdutil "k8s.io/kubernetes/pkg/kubectl/cmd/util" |
| 17 |
+ "k8s.io/kubernetes/pkg/runtime" |
|
| 15 | 18 |
) |
| 16 | 19 |
|
| 17 | 20 |
// ErrExit is a marker interface for cli commands indicating that the response has been processed |
| ... | ... |
@@ -64,3 +67,59 @@ func ResolveResource(defaultResource, resourceString string, mapper meta.RESTMap |
| 64 | 64 |
|
| 65 | 65 |
return defaultResource, name, nil |
| 66 | 66 |
} |
| 67 |
+ |
|
| 68 |
+// ConvertItemsForDisplay returns a new list that contains parallel elements that have been converted to the most preferred external version |
|
| 69 |
+func ConvertItemsForDisplay(objs []runtime.Object, preferredVersions ...unversioned.GroupVersion) ([]runtime.Object, error) {
|
|
| 70 |
+ ret := []runtime.Object{}
|
|
| 71 |
+ |
|
| 72 |
+ for i := range objs {
|
|
| 73 |
+ obj := objs[i] |
|
| 74 |
+ kind, err := kapi.Scheme.ObjectKind(obj) |
|
| 75 |
+ if err != nil {
|
|
| 76 |
+ return nil, err |
|
| 77 |
+ } |
|
| 78 |
+ groupMeta, err := registered.Group(kind.Group) |
|
| 79 |
+ if err != nil {
|
|
| 80 |
+ return nil, err |
|
| 81 |
+ } |
|
| 82 |
+ |
|
| 83 |
+ requestedVersion := unversioned.GroupVersion{}
|
|
| 84 |
+ for _, preferredVersion := range preferredVersions {
|
|
| 85 |
+ if preferredVersion.Group == kind.Group {
|
|
| 86 |
+ requestedVersion = preferredVersion |
|
| 87 |
+ break |
|
| 88 |
+ } |
|
| 89 |
+ } |
|
| 90 |
+ |
|
| 91 |
+ actualOutputVersion := unversioned.GroupVersion{}
|
|
| 92 |
+ for _, externalVersion := range groupMeta.GroupVersions {
|
|
| 93 |
+ if externalVersion == requestedVersion {
|
|
| 94 |
+ actualOutputVersion = externalVersion |
|
| 95 |
+ break |
|
| 96 |
+ } |
|
| 97 |
+ if actualOutputVersion.IsEmpty() {
|
|
| 98 |
+ actualOutputVersion = externalVersion |
|
| 99 |
+ } |
|
| 100 |
+ } |
|
| 101 |
+ |
|
| 102 |
+ convertedObject, err := kapi.Scheme.ConvertToVersion(obj, actualOutputVersion.String()) |
|
| 103 |
+ if err != nil {
|
|
| 104 |
+ return nil, err |
|
| 105 |
+ } |
|
| 106 |
+ |
|
| 107 |
+ ret = append(ret, convertedObject) |
|
| 108 |
+ } |
|
| 109 |
+ |
|
| 110 |
+ return ret, nil |
|
| 111 |
+} |
|
| 112 |
+ |
|
| 113 |
+// ConvertItemsForDisplayFromDefaultCommand returns a new list that contains parallel elements that have been converted to the most preferred external version |
|
| 114 |
+func ConvertItemsForDisplayFromDefaultCommand(cmd *cobra.Command, objs []runtime.Object) ([]runtime.Object, error) {
|
|
| 115 |
+ requestedOutputVersionString := kcmdutil.GetFlagString(cmd, "output-version") |
|
| 116 |
+ requestedOutputVersion, err := unversioned.ParseGroupVersion(requestedOutputVersionString) |
|
| 117 |
+ if err != nil {
|
|
| 118 |
+ return nil, err |
|
| 119 |
+ } |
|
| 120 |
+ |
|
| 121 |
+ return ConvertItemsForDisplay(objs, requestedOutputVersion) |
|
| 122 |
+} |