@@ -113,27 +113,9 @@ func (c *ApplyTags) Run() error {
113113
114114 c .imageByDigest = c .imageName + "@" + c .Params .Digest
115115
116- var tagsFromLabel []string
117- if c .Params .LabelWithTags != "" {
118- var err error
119- tagsFromLabel , err = c .retrieveTagsFromImageLabel (c .Params .LabelWithTags )
120- if err != nil {
121- l .Logger .Errorf ("failed to retrieve tags from '%s' label value: %s" , c .Params .LabelWithTags , err .Error ())
122- return err
123- }
124- for _ , tag := range tagsFromLabel {
125- if ! common .IsImageTagValid (tag ) {
126- return fmt .Errorf ("tag from label '%s' is invalid" , tag )
127- }
128- }
129-
130- if len (tagsFromLabel ) > 0 {
131- l .Logger .Infof ("Additional tags from '%s' image label: %s" , c .Params .LabelWithTags , strings .Join (tagsFromLabel , ", " ))
132- } else {
133- l .Logger .Warnf ("No tags given in '%s' image label" , c .Params .LabelWithTags )
134- }
135- } else {
136- l .Logger .Debug ("Label with additional tags is not set" )
116+ tagsFromLabel , err := c .retrieveTagsFromImageLabel (c .Params .LabelWithTags )
117+ if err != nil {
118+ return err
137119 }
138120
139121 tags := append (c .Params .NewTags , tagsFromLabel ... )
@@ -166,7 +148,13 @@ func (c *ApplyTags) logParams() {
166148 }
167149}
168150
151+ // retrieveTagsFromImageLabel fetches list of tags from the given image label and interprets the results.
169152func (c * ApplyTags ) retrieveTagsFromImageLabel (labelName string ) ([]string , error ) {
153+ if labelName == "" {
154+ l .Logger .Debug ("Label with additional tags is not set" )
155+ return nil , nil
156+ }
157+
170158 inspectArgs := & cliWrappers.SkopeoInspectArgs {
171159 ImageRef : c .imageByDigest ,
172160 Format : fmt .Sprintf (`{{ index .Labels "%s" }}` , labelName ),
@@ -175,18 +163,40 @@ func (c *ApplyTags) retrieveTagsFromImageLabel(labelName string) ([]string, erro
175163 }
176164 tagsLabelValue , err := c .CliWrappers .SkopeoCli .Inspect (inspectArgs )
177165 if err != nil {
166+ if strings .Contains (err .Error (), cliWrappers .UnsupportedOCIConfigMediaType ) {
167+ // Skip the label with tags for unsupported config media type.
168+ // Print warning message and continue.
169+ l .Logger .Warnf ("unsupported config media type '%s' of input image. Skipping reading %s image label" ,
170+ cliWrappers .UnsupportedOCIConfigMediaType , c .Params .LabelWithTags )
171+ return nil , nil
172+ }
173+ l .Logger .Errorf ("failed to retrieve tags from '%s' label value: %s" , c .Params .LabelWithTags , err .Error ())
178174 return nil , err
179175 }
180176 tagsLabelValue = strings .TrimSpace (tagsLabelValue )
181177 l .Logger .Debugf ("Tags label value: %s" , tagsLabelValue )
182178
183179 if tagsLabelValue == "" {
180+ l .Logger .Warnf ("No tags given in '%s' image label" , c .Params .LabelWithTags )
184181 return nil , nil
185182 }
186183
187184 tagSeparatorRegex := regexp .MustCompile (`[\s,]+` )
188- tags := tagSeparatorRegex .Split (tagsLabelValue , - 1 )
189- return tags , nil
185+ tagsFromLabel := tagSeparatorRegex .Split (tagsLabelValue , - 1 )
186+
187+ // Successfully obtained tags from the image label
188+ // Validate the obtained tags
189+ for _ , tag := range tagsFromLabel {
190+ if ! common .IsImageTagValid (tag ) {
191+ return nil , fmt .Errorf ("tag from label '%s' is invalid" , tag )
192+ }
193+ }
194+
195+ if len (tagsFromLabel ) > 0 {
196+ l .Logger .Infof ("Additional tags from '%s' image label: %s" , c .Params .LabelWithTags , strings .Join (tagsFromLabel , ", " ))
197+ }
198+
199+ return tagsFromLabel , nil
190200}
191201
192202func (c * ApplyTags ) applyTags (tags []string ) error {
0 commit comments