Skip to content

Commit 5697564

Browse files
committed
Externalize admin commands depending on graph library
1 parent 7dc0f86 commit 5697564

File tree

14 files changed

+798
-779
lines changed

14 files changed

+798
-779
lines changed

pkg/oc/cli/admin/buildchain/buildchain.go

+11-19
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,13 @@ import (
1515
"k8s.io/kubernetes/pkg/kubectl/genericclioptions"
1616

1717
"github.com/openshift/api/image"
18-
buildclientinternal "github.com/openshift/origin/pkg/build/generated/internalclientset"
19-
buildclient "github.com/openshift/origin/pkg/build/generated/internalclientset/typed/build/internalversion"
18+
buildv1client "github.com/openshift/client-go/build/clientset/versioned/typed/build/v1"
19+
imagev1client "github.com/openshift/client-go/image/clientset/versioned/typed/image/v1"
20+
projectv1client "github.com/openshift/client-go/project/clientset/versioned/typed/project/v1"
2021
osutil "github.com/openshift/origin/pkg/cmd/util"
2122
imageapi "github.com/openshift/origin/pkg/image/apis/image"
22-
imageclientinternal "github.com/openshift/origin/pkg/image/generated/internalclientset"
23-
imageclient "github.com/openshift/origin/pkg/image/generated/internalclientset/typed/image/internalversion"
2423
"github.com/openshift/origin/pkg/oc/lib/describe"
2524
imagegraph "github.com/openshift/origin/pkg/oc/lib/graph/imagegraph/nodes"
26-
projectclientinternal "github.com/openshift/origin/pkg/project/generated/internalclientset"
27-
projectclient "github.com/openshift/origin/pkg/project/generated/internalclientset/typed/project/internalversion"
2825
)
2926

3027
// BuildChainRecommendedCommandName is the recommended command name
@@ -61,9 +58,9 @@ type BuildChainOptions struct {
6158

6259
output string
6360

64-
buildClient buildclient.BuildConfigsGetter
65-
imageClient imageclient.ImageStreamTagsGetter
66-
projectClient projectclient.ProjectsGetter
61+
buildClient buildv1client.BuildV1Interface
62+
imageClient imagev1client.ImageV1Interface
63+
projectClient projectv1client.ProjectV1Interface
6764
}
6865

6966
// NewCmdBuildChain implements the OpenShift experimental build-chain command
@@ -100,21 +97,18 @@ func (o *BuildChainOptions) Complete(f kcmdutil.Factory, cmd *cobra.Command, arg
10097
if err != nil {
10198
return err
10299
}
103-
buildClient, err := buildclientinternal.NewForConfig(clientConfig)
100+
o.buildClient, err = buildv1client.NewForConfig(clientConfig)
104101
if err != nil {
105102
return err
106103
}
107-
imageClient, err := imageclientinternal.NewForConfig(clientConfig)
104+
o.imageClient, err = imagev1client.NewForConfig(clientConfig)
108105
if err != nil {
109106
return err
110107
}
111-
projectClient, err := projectclientinternal.NewForConfig(clientConfig)
108+
o.projectClient, err = projectv1client.NewForConfig(clientConfig)
112109
if err != nil {
113110
return err
114111
}
115-
o.buildClient = buildClient.Build()
116-
o.imageClient = imageClient.Image()
117-
o.projectClient = projectClient.Project()
118112

119113
resource := schema.GroupResource{}
120114
mapper, err := f.ToRESTMapper()
@@ -147,14 +141,12 @@ func (o *BuildChainOptions) Complete(f kcmdutil.Factory, cmd *cobra.Command, arg
147141
}
148142
}
149143

150-
namespace, _, err := f.ToRawKubeConfigLoader().Namespace()
144+
o.defaultNamespace, _, err = f.ToRawKubeConfigLoader().Namespace()
151145
if err != nil {
152146
return err
153147
}
154-
155-
o.defaultNamespace = namespace
156148
glog.V(4).Infof("Using %q as the namespace for %q", o.defaultNamespace, o.name)
157-
o.namespaces.Insert(namespace)
149+
o.namespaces.Insert(o.defaultNamespace)
158150
glog.V(4).Infof("Will look for deps in %s", strings.Join(o.namespaces.List(), ","))
159151

160152
return nil

pkg/oc/cli/admin/prune/imageprune/helper.go

+12-11
Original file line numberDiff line numberDiff line change
@@ -10,19 +10,20 @@ import (
1010
"github.com/docker/distribution/registry/api/errcode"
1111
"github.com/golang/glog"
1212

13+
corev1 "k8s.io/api/core/v1"
1314
kmeta "k8s.io/apimachinery/pkg/api/meta"
1415
"k8s.io/apimachinery/pkg/runtime"
1516
kerrors "k8s.io/apimachinery/pkg/util/errors"
17+
ref "k8s.io/client-go/tools/reference"
1618
"k8s.io/kubernetes/pkg/api/legacyscheme"
17-
kapiref "k8s.io/kubernetes/pkg/api/ref"
18-
kapi "k8s.io/kubernetes/pkg/apis/core"
1919

20+
imagev1 "github.com/openshift/api/image/v1"
2021
imageapi "github.com/openshift/origin/pkg/image/apis/image"
2122
"github.com/openshift/origin/pkg/util/netutils"
2223
)
2324

2425
// order younger images before older
25-
type imgByAge []*imageapi.Image
26+
type imgByAge []*imagev1.Image
2627

2728
func (ba imgByAge) Len() int { return len(ba) }
2829
func (ba imgByAge) Swap(i, j int) { ba[i], ba[j] = ba[j], ba[i] }
@@ -31,7 +32,7 @@ func (ba imgByAge) Less(i, j int) bool {
3132
}
3233

3334
// order younger image stream before older
34-
type isByAge []imageapi.ImageStream
35+
type isByAge []imagev1.ImageStream
3536

3637
func (ba isByAge) Len() int { return len(ba) }
3738
func (ba isByAge) Swap(i, j int) { ba[i], ba[j] = ba[j], ba[i] }
@@ -41,9 +42,9 @@ func (ba isByAge) Less(i, j int) bool {
4142

4243
// DetermineRegistryHost returns registry host embedded in a pull-spec of the latest unmanaged image or the
4344
// latest imagestream from the provided lists. If no such pull-spec is found, error is returned.
44-
func DetermineRegistryHost(images *imageapi.ImageList, imageStreams *imageapi.ImageStreamList) (string, error) {
45+
func DetermineRegistryHost(images *imagev1.ImageList, imageStreams *imagev1.ImageStreamList) (string, error) {
4546
var pullSpec string
46-
var managedImages []*imageapi.Image
47+
var managedImages []*imagev1.Image
4748

4849
// 1st try to determine registry url from a pull spec of the youngest managed image
4950
for i := range images.Items {
@@ -223,7 +224,7 @@ type ErrBadReference struct {
223224
reason string
224225
}
225226

226-
func newErrBadReferenceToImage(reference string, obj *kapi.ObjectReference, reason string) error {
227+
func newErrBadReferenceToImage(reference string, obj *corev1.ObjectReference, reason string) error {
227228
kind := "<UnknownType>"
228229
namespace := ""
229230
name := "<unknown-name>"
@@ -242,7 +243,7 @@ func newErrBadReferenceToImage(reference string, obj *kapi.ObjectReference, reas
242243
}
243244
}
244245

245-
func newErrBadReferenceTo(targetKind, reference string, obj *kapi.ObjectReference, reason string) error {
246+
func newErrBadReferenceTo(targetKind, reference string, obj *corev1.ObjectReference, reason string) error {
246247
return &ErrBadReference{
247248
kind: obj.Kind,
248249
namespace: obj.Namespace,
@@ -282,7 +283,7 @@ func getName(obj runtime.Object) string {
282283
return fmt.Sprintf("%s/%s", ns, accessor.GetName())
283284
}
284285

285-
func getKindName(obj *kapi.ObjectReference) string {
286+
func getKindName(obj *corev1.ObjectReference) string {
286287
if obj == nil {
287288
return "unknown object"
288289
}
@@ -293,8 +294,8 @@ func getKindName(obj *kapi.ObjectReference) string {
293294
return fmt.Sprintf("%s[%s]", obj.Kind, name)
294295
}
295296

296-
func getRef(obj runtime.Object) *kapi.ObjectReference {
297-
ref, err := kapiref.GetReference(legacyscheme.Scheme, obj)
297+
func getRef(obj runtime.Object) *corev1.ObjectReference {
298+
ref, err := ref.GetReference(legacyscheme.Scheme, obj)
298299
if err != nil {
299300
glog.Errorf("failed to get reference to object %T: %v", obj, err)
300301
return nil

0 commit comments

Comments
 (0)