Skip to content

Commit c02ce07

Browse files
author
OpenShift Bot
authored
Merge pull request #9238 from smarterclayton/update_image_ref
Merged by openshift-bot
2 parents 4148579 + 5dbc59d commit c02ce07

File tree

22 files changed

+640
-75
lines changed

22 files changed

+640
-75
lines changed

contrib/completions/bash/oc

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1087,6 +1087,7 @@ _oc_tag()
10871087
flags+=("--delete")
10881088
flags+=("-d")
10891089
flags+=("--insecure")
1090+
flags+=("--reference")
10901091
flags+=("--scheduled")
10911092
flags+=("--source=")
10921093
flags+=("--api-version=")
@@ -7301,6 +7302,48 @@ _oc_create_useridentitymapping()
73017302
must_have_one_noun=()
73027303
}
73037304

7305+
_oc_create_imagestream()
7306+
{
7307+
last_command="oc_create_imagestream"
7308+
commands=()
7309+
7310+
flags=()
7311+
two_word_flags=()
7312+
flags_with_completion=()
7313+
flags_completion=()
7314+
7315+
flags+=("--output=")
7316+
two_word_flags+=("-o")
7317+
flags+=("--api-version=")
7318+
flags+=("--as=")
7319+
flags+=("--certificate-authority=")
7320+
flags_with_completion+=("--certificate-authority")
7321+
flags_completion+=("_filedir")
7322+
flags+=("--client-certificate=")
7323+
flags_with_completion+=("--client-certificate")
7324+
flags_completion+=("_filedir")
7325+
flags+=("--client-key=")
7326+
flags_with_completion+=("--client-key")
7327+
flags_completion+=("_filedir")
7328+
flags+=("--cluster=")
7329+
flags+=("--config=")
7330+
flags_with_completion+=("--config")
7331+
flags_completion+=("_filedir")
7332+
flags+=("--context=")
7333+
flags+=("--google-json-key=")
7334+
flags+=("--insecure-skip-tls-verify")
7335+
flags+=("--log-flush-frequency=")
7336+
flags+=("--match-server-version")
7337+
flags+=("--namespace=")
7338+
two_word_flags+=("-n")
7339+
flags+=("--server=")
7340+
flags+=("--token=")
7341+
flags+=("--user=")
7342+
7343+
must_have_one_flag=()
7344+
must_have_one_noun=()
7345+
}
7346+
73047347
_oc_create()
73057348
{
73067349
last_command="oc_create"
@@ -7315,6 +7358,7 @@ _oc_create()
73157358
commands+=("user")
73167359
commands+=("identity")
73177360
commands+=("useridentitymapping")
7361+
commands+=("imagestream")
73187362

73197363
flags=()
73207364
two_word_flags=()

contrib/completions/bash/openshift

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4675,6 +4675,7 @@ _openshift_cli_tag()
46754675
flags+=("--delete")
46764676
flags+=("-d")
46774677
flags+=("--insecure")
4678+
flags+=("--reference")
46784679
flags+=("--scheduled")
46794680
flags+=("--source=")
46804681
flags+=("--api-version=")
@@ -10889,6 +10890,48 @@ _openshift_cli_create_useridentitymapping()
1088910890
must_have_one_noun=()
1089010891
}
1089110892

10893+
_openshift_cli_create_imagestream()
10894+
{
10895+
last_command="openshift_cli_create_imagestream"
10896+
commands=()
10897+
10898+
flags=()
10899+
two_word_flags=()
10900+
flags_with_completion=()
10901+
flags_completion=()
10902+
10903+
flags+=("--output=")
10904+
two_word_flags+=("-o")
10905+
flags+=("--api-version=")
10906+
flags+=("--as=")
10907+
flags+=("--certificate-authority=")
10908+
flags_with_completion+=("--certificate-authority")
10909+
flags_completion+=("_filedir")
10910+
flags+=("--client-certificate=")
10911+
flags_with_completion+=("--client-certificate")
10912+
flags_completion+=("_filedir")
10913+
flags+=("--client-key=")
10914+
flags_with_completion+=("--client-key")
10915+
flags_completion+=("_filedir")
10916+
flags+=("--cluster=")
10917+
flags+=("--config=")
10918+
flags_with_completion+=("--config")
10919+
flags_completion+=("_filedir")
10920+
flags+=("--context=")
10921+
flags+=("--google-json-key=")
10922+
flags+=("--insecure-skip-tls-verify")
10923+
flags+=("--log-flush-frequency=")
10924+
flags+=("--match-server-version")
10925+
flags+=("--namespace=")
10926+
two_word_flags+=("-n")
10927+
flags+=("--server=")
10928+
flags+=("--token=")
10929+
flags+=("--user=")
10930+
10931+
must_have_one_flag=()
10932+
must_have_one_noun=()
10933+
}
10934+
1089210935
_openshift_cli_create()
1089310936
{
1089410937
last_command="openshift_cli_create"
@@ -10903,6 +10946,7 @@ _openshift_cli_create()
1090310946
commands+=("user")
1090410947
commands+=("identity")
1090510948
commands+=("useridentitymapping")
10949+
commands+=("imagestream")
1090610950

1090710951
flags=()
1090810952
two_word_flags=()

docs/generated/oc_by_example_content.adoc

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -876,6 +876,19 @@ Manually create an identity (only needed if automatic creation is disabled).
876876
====
877877

878878

879+
== oc create imagestream
880+
Create a new empty image stream.
881+
882+
====
883+
884+
[options="nowrap"]
885+
----
886+
# Create a new image stream
887+
oc create imagestream mysql
888+
----
889+
====
890+
891+
879892
== oc create namespace
880893
Create a namespace with the specified name.
881894

pkg/cmd/cli/cmd/create/imagestream.go

Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
package create
2+
3+
import (
4+
"fmt"
5+
"io"
6+
7+
"github.com/spf13/cobra"
8+
9+
kapi "k8s.io/kubernetes/pkg/api"
10+
"k8s.io/kubernetes/pkg/api/meta"
11+
cmdutil "k8s.io/kubernetes/pkg/kubectl/cmd/util"
12+
"k8s.io/kubernetes/pkg/runtime"
13+
14+
"github.com/openshift/origin/pkg/client"
15+
"github.com/openshift/origin/pkg/cmd/util/clientcmd"
16+
imageapi "github.com/openshift/origin/pkg/image/api"
17+
)
18+
19+
const (
20+
ImageStreamRecommendedName = "imagestream"
21+
22+
imageStreamLong = `
23+
Create a new image stream
24+
25+
Image streams allow you to track, tag, and import images from other registries. They also define an
26+
access controlled destination that you can push images to.`
27+
28+
imageStreamExample = ` # Create a new image stream
29+
%[1]s mysql`
30+
)
31+
32+
type CreateImageStreamOptions struct {
33+
IS *imageapi.ImageStream
34+
Client client.ImageStreamsNamespacer
35+
36+
Mapper meta.RESTMapper
37+
OutputFormat string
38+
Out io.Writer
39+
Printer ObjectPrinter
40+
}
41+
42+
// NewCmdCreateImageStream is a macro command to create a new image stream
43+
func NewCmdCreateImageStream(name, fullName string, f *clientcmd.Factory, out io.Writer) *cobra.Command {
44+
o := &CreateImageStreamOptions{Out: out}
45+
46+
cmd := &cobra.Command{
47+
Use: name + " NAME",
48+
Short: "Create a new empty image stream.",
49+
Long: imageStreamLong,
50+
Example: fmt.Sprintf(imageStreamExample, fullName),
51+
Run: func(cmd *cobra.Command, args []string) {
52+
cmdutil.CheckErr(o.Complete(cmd, f, args))
53+
cmdutil.CheckErr(o.Validate())
54+
cmdutil.CheckErr(o.Run())
55+
},
56+
Aliases: []string{"is"},
57+
}
58+
59+
cmdutil.AddOutputFlagsForMutation(cmd)
60+
return cmd
61+
}
62+
63+
func (o *CreateImageStreamOptions) Complete(cmd *cobra.Command, f *clientcmd.Factory, args []string) error {
64+
o.IS = &imageapi.ImageStream{
65+
ObjectMeta: kapi.ObjectMeta{},
66+
Spec: imageapi.ImageStreamSpec{},
67+
}
68+
69+
switch len(args) {
70+
case 0:
71+
return fmt.Errorf("image stream name is required")
72+
case 1:
73+
o.IS.Name = args[0]
74+
default:
75+
return fmt.Errorf("exactly one argument (name) is supported, not: %v", args)
76+
}
77+
78+
var err error
79+
o.IS.Namespace, _, err = f.DefaultNamespace()
80+
if err != nil {
81+
return err
82+
}
83+
84+
o.Client, _, err = f.Clients()
85+
if err != nil {
86+
return err
87+
}
88+
89+
o.Mapper, _ = f.Object(false)
90+
o.OutputFormat = cmdutil.GetFlagString(cmd, "output")
91+
92+
o.Printer = func(obj runtime.Object, out io.Writer) error {
93+
return f.PrintObject(cmd, o.Mapper, obj, out)
94+
}
95+
96+
return nil
97+
}
98+
99+
func (o *CreateImageStreamOptions) Validate() error {
100+
if o.IS == nil {
101+
return fmt.Errorf("IS is required")
102+
}
103+
if o.Client == nil {
104+
return fmt.Errorf("Client is required")
105+
}
106+
if o.Mapper == nil {
107+
return fmt.Errorf("Mapper is required")
108+
}
109+
if o.Out == nil {
110+
return fmt.Errorf("Out is required")
111+
}
112+
if o.Printer == nil {
113+
return fmt.Errorf("Printer is required")
114+
}
115+
116+
return nil
117+
}
118+
119+
func (o *CreateImageStreamOptions) Run() error {
120+
actualObj, err := o.Client.ImageStreams(o.IS.Namespace).Create(o.IS)
121+
if err != nil {
122+
return err
123+
}
124+
125+
if useShortOutput := o.OutputFormat == "name"; useShortOutput || len(o.OutputFormat) == 0 {
126+
cmdutil.PrintSuccess(o.Mapper, useShortOutput, o.Out, "imagestream", actualObj.Name, "created")
127+
return nil
128+
}
129+
130+
return o.Printer(actualObj, o.Out)
131+
}

pkg/cmd/cli/cmd/tag.go

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,12 @@ type TagOptions struct {
2626
out io.Writer
2727
osClient client.Interface
2828

29-
deleteTag bool
30-
aliasTag bool
31-
scheduleTag bool
32-
insecureTag bool
33-
namespace string
29+
deleteTag bool
30+
aliasTag bool
31+
scheduleTag bool
32+
insecureTag bool
33+
referenceTag bool
34+
namespace string
3435

3536
ref imageapi.DockerImageReference
3637
sourceKind string
@@ -86,6 +87,7 @@ func NewCmdTag(fullName string, f *clientcmd.Factory, out io.Writer) *cobra.Comm
8687
cmd.Flags().StringVar(&opts.sourceKind, "source", opts.sourceKind, "Optional hint for the source type; valid values are 'imagestreamtag', 'istag', 'imagestreamimage', 'isimage', and 'docker'")
8788
cmd.Flags().BoolVarP(&opts.deleteTag, "delete", "d", opts.deleteTag, "Delete the provided spec tags")
8889
cmd.Flags().BoolVar(&opts.aliasTag, "alias", false, "Should the destination tag be updated whenever the source tag changes. Defaults to false.")
90+
cmd.Flags().BoolVar(&opts.referenceTag, "reference", false, "Should the destination tag continue to pull from the source namespace. Defaults to false.")
8991
cmd.Flags().BoolVar(&opts.scheduleTag, "scheduled", false, "Set a Docker image to be periodically imported from a remote repository.")
9092
cmd.Flags().BoolVar(&opts.insecureTag, "insecure", false, "Set to true if importing the specified Docker image requires HTTP or has a self-signed certificate.")
9193

@@ -357,6 +359,7 @@ func (o TagOptions) RunTag() error {
357359
targetRef = imageapi.TagReference{}
358360
}
359361

362+
targetRef.Reference = o.referenceTag
360363
targetRef.ImportPolicy.Insecure = o.insecureTag
361364
targetRef.ImportPolicy.Scheduled = o.scheduleTag
362365
targetRef.From = &kapi.ObjectReference{

pkg/cmd/cli/cmd/wrappers.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,7 @@ func NewCmdCreate(parentName string, f *clientcmd.Factory, out io.Writer) *cobra
169169
cmd.AddCommand(create.NewCmdCreateUser(create.UserRecommendedName, parentName+" create "+create.UserRecommendedName, f, out))
170170
cmd.AddCommand(create.NewCmdCreateIdentity(create.IdentityRecommendedName, parentName+" create "+create.IdentityRecommendedName, f, out))
171171
cmd.AddCommand(create.NewCmdCreateUserIdentityMapping(create.UserIdentityMappingRecommendedName, parentName+" create "+create.UserIdentityMappingRecommendedName, f, out))
172+
cmd.AddCommand(create.NewCmdCreateImageStream(create.ImageStreamRecommendedName, parentName+" create "+create.ImageStreamRecommendedName, f, out))
172173

173174
adjustCmdExamples(cmd, parentName, "create")
174175

pkg/cmd/cli/describe/helpers.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ func formatImageStreamTags(out *tabwriter.Writer, stream *imageapi.ImageStream)
249249
}
250250
scheduled, insecure = tagRef.ImportPolicy.Scheduled, tagRef.ImportPolicy.Insecure
251251
hasScheduled = hasScheduled || scheduled
252-
hasInsecure = hasScheduled || insecure
252+
hasInsecure = hasInsecure || insecure
253253
} else {
254254
specTag = "<pushed>"
255255
}
@@ -325,6 +325,7 @@ func formatImageStreamTags(out *tabwriter.Writer, stream *imageapi.ImageStream)
325325
fmt.Fprintf(out, "%s\t%s\t\t<not available>\t<not available>\n", tag, specTag)
326326
}
327327
}
328+
328329
if hasInsecure || hasScheduled {
329330
fmt.Fprintln(out)
330331
if hasScheduled {

pkg/cmd/server/origin/master.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ import (
5252
deployrollback "github.com/openshift/origin/pkg/deploy/registry/rollback"
5353
"github.com/openshift/origin/pkg/dockerregistry"
5454
imageadmission "github.com/openshift/origin/pkg/image/admission"
55+
imageapi "github.com/openshift/origin/pkg/image/api"
5556
"github.com/openshift/origin/pkg/image/importer"
5657
imageimporter "github.com/openshift/origin/pkg/image/importer"
5758
"github.com/openshift/origin/pkg/image/registry/image"
@@ -446,10 +447,10 @@ func (c *MasterConfig) GetRestStorage() map[string]rest.Storage {
446447
imageRegistry := image.NewRegistry(imageStorage)
447448
imageStreamLimitVerifier := imageadmission.NewLimitVerifier(c.KubeClient())
448449
imageStreamSecretsStorage := imagesecret.NewREST(c.ImageStreamSecretClient())
449-
imageStreamStorage, imageStreamStatusStorage, internalImageStreamStorage, err := imagestreametcd.NewREST(c.RESTOptionsGetter, imagestream.DefaultRegistryFunc(defaultRegistryFunc), subjectAccessReviewRegistry, imageStreamLimitVerifier)
450+
imageStreamStorage, imageStreamStatusStorage, internalImageStreamStorage, err := imagestreametcd.NewREST(c.RESTOptionsGetter, imageapi.DefaultRegistryFunc(defaultRegistryFunc), subjectAccessReviewRegistry, imageStreamLimitVerifier)
450451
checkStorageErr(err)
451452
imageStreamRegistry := imagestream.NewRegistry(imageStreamStorage, imageStreamStatusStorage, internalImageStreamStorage)
452-
imageStreamMappingStorage := imagestreammapping.NewREST(imageRegistry, imageStreamRegistry)
453+
imageStreamMappingStorage := imagestreammapping.NewREST(imageRegistry, imageStreamRegistry, imageapi.DefaultRegistryFunc(defaultRegistryFunc))
453454
imageStreamTagStorage := imagestreamtag.NewREST(imageRegistry, imageStreamRegistry)
454455
imageStreamTagRegistry := imagestreamtag.NewRegistry(imageStreamTagStorage)
455456
importerFn := func(r importer.RepositoryRetriever) imageimporter.Interface {

pkg/image/api/helper.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,19 @@ const (
3333
containerImageEntrypointAnnotationFormatKey = "openshift.io/container.%s.image.entrypoint"
3434
)
3535

36+
// DefaultRegistry returns the default Docker registry (host or host:port), or false if it is not available.
37+
type DefaultRegistry interface {
38+
DefaultRegistry() (string, bool)
39+
}
40+
41+
// DefaultRegistryFunc implements DefaultRegistry for a simple function.
42+
type DefaultRegistryFunc func() (string, bool)
43+
44+
// DefaultRegistry implements the DefaultRegistry interface for a function.
45+
func (fn DefaultRegistryFunc) DefaultRegistry() (string, bool) {
46+
return fn()
47+
}
48+
3649
// parseRepositoryTag splits a string into its name component and either tag or id if present.
3750
// TODO remove
3851
func parseRepositoryTag(repos string) (base string, tag string, id string) {

0 commit comments

Comments
 (0)