Skip to content
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

own up to the attrocities commited in set #19348

Merged
merged 2 commits into from
Apr 16, 2018
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
3 changes: 0 additions & 3 deletions pkg/oc/cli/cmd/set/set.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,6 @@ func NewCmdImage(fullName string, f *clientcmd.Factory, out, err io.Writer) *cob
cmd.Long = setImageLong
cmd.Example = fmt.Sprintf(setImageExample, fullName)

flags := cmd.Flags()
f.ImageResolutionOptions().Bind(flags)

return cmd
}

Expand Down
61 changes: 13 additions & 48 deletions pkg/oc/cli/util/clientcmd/factory_client_access.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,14 @@ import (
kapi "k8s.io/kubernetes/pkg/apis/core"
kclientset "k8s.io/kubernetes/pkg/client/clientset_generated/internalclientset"
"k8s.io/kubernetes/pkg/kubectl"
"k8s.io/kubernetes/pkg/kubectl/cmd/set"
kcmdutil "k8s.io/kubernetes/pkg/kubectl/cmd/util"
"k8s.io/kubernetes/pkg/kubectl/resource"
"k8s.io/kubernetes/pkg/kubectl/util/transport"

appsapiv1 "github.com/openshift/api/apps/v1"
appsapi "github.com/openshift/origin/pkg/apps/apis/apps"
imageclient "github.com/openshift/origin/pkg/image/generated/internalclientset"
imageapi "github.com/openshift/origin/pkg/image/apis/image"
deploymentcmd "github.com/openshift/origin/pkg/oc/cli/deploymentconfigs"
routegen "github.com/openshift/origin/pkg/route/generator"
)
Expand All @@ -40,30 +41,27 @@ type ring0Factory struct {
*OpenshiftCLIClientBuilder

clientConfig kclientcmd.ClientConfig
imageResolutionOptions FlagBinder
kubeClientAccessFactory kcmdutil.ClientAccessFactory
}

type ClientAccessFactory interface {
kcmdutil.ClientAccessFactory
CLIClientBuilder

ImageResolutionOptions() FlagBinder
}

func NewClientAccessFactory(optionalClientConfig kclientcmd.ClientConfig) ClientAccessFactory {
// if we call this factory construction method, we want the openshift style config loading
kclientcmd.UseOpenShiftKubeConfigValues = true
kclientcmd.ErrEmptyConfig = kclientcmd.NewErrConfigurationMissing()
set.ParseDockerImageReferenceToStringFunc = ParseDockerImageReferenceToStringFunc

flags := pflag.NewFlagSet("", pflag.ContinueOnError)
clientConfig := optionalClientConfig
if optionalClientConfig == nil {
clientConfig = kcmdutil.DefaultClientConfig(flags)
}
factory := &ring0Factory{
clientConfig: clientConfig,
imageResolutionOptions: &imageResolutionOptions{},
clientConfig: clientConfig,
}
factory.kubeClientAccessFactory = kcmdutil.NewClientAccessFactoryFromDiscovery(
flags,
Expand Down Expand Up @@ -276,49 +274,8 @@ func (f *ring0Factory) Pauser(info *resource.Info) ([]byte, error) {
}
}

// ImageResolutionOptions provides the "--source" flag to commands that deal with images
// and need to provide extra capabilities for working with ImageStreamTags and
// ImageStreamImages.
type imageResolutionOptions struct {
bound bool
Source string
}

func (o *imageResolutionOptions) Bound() bool {
return o.bound
}

func (o *imageResolutionOptions) Bind(f *pflag.FlagSet) {
if o.Bound() {
return
}
f.StringVarP(&o.Source, "source", "", "docker", "The image source type; valid types are 'imagestreamtag', 'istag', 'imagestreamimage', 'isimage', and 'docker'")
o.bound = true
}

func (f *ring0Factory) ImageResolutionOptions() FlagBinder {
return f.imageResolutionOptions
}

func (f *ring0Factory) ResolveImage(image string) (string, error) {
options := f.imageResolutionOptions.(*imageResolutionOptions)
if isDockerImageSource(options.Source) {
return f.kubeClientAccessFactory.ResolveImage(image)
}
config, err := f.kubeClientAccessFactory.ClientConfig()
if err != nil {
return "", err
}
imageClient, err := imageclient.NewForConfig(config)
if err != nil {
return "", err
}
namespace, _, err := f.DefaultNamespace()
if err != nil {
return "", err
}

return resolveImagePullSpec(imageClient.Image(), options.Source, image, namespace)
return f.kubeClientAccessFactory.ResolveImage(image)
}

func (f *ring0Factory) Resumer(info *resource.Info) ([]byte, error) {
Expand Down Expand Up @@ -416,3 +373,11 @@ func getProtocols(spec kapi.PodSpec) map[string]string {
}
return result
}

func ParseDockerImageReferenceToStringFunc(spec string) (string, error) {
ret, err := imageapi.ParseDockerImageReference(spec)
if err != nil {
return "", err
}
return ret.String(), nil
}
107 changes: 107 additions & 0 deletions vendor/k8s.io/kubernetes/pkg/kubectl/cmd/set/patch_setimage.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 6 additions & 1 deletion vendor/k8s.io/kubernetes/pkg/kubectl/cmd/set/set_image.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.