Skip to content

Only one change image rule can match when restore change image #6344

@wawa0210

Description

@wawa0210

What steps did you take and what happened:

When I try to restore with the velero change image rule, multiple rules only hit one

What did you expect to happen:

It is hoped that the image can be hit by all rules and change completed

The following information will help us better understand what's going on:

this is origin pod yaml

apiVersion: v1
kind: Pod
metadata:
  name: demo-pod
spec:
  containers:
  - name: container1
    image: docker.m.daocloud.io/abc:test
    command: ['sh', '-c', 'echo The app is running! && sleep 3600']

Below is my change rule configmap

apiVersion: v1
kind: ConfigMap
metadata:
  # any name can be used; Velero uses the labels (below)
  # to identify it rather than the name
  name: change-image-name-config
  # must be in the velero namespace
  namespace: velero
  # the below labels should be used verbatim in your
  # ConfigMap.
  labels:
    # this value-less label identifies the ConfigMap as
    # config for a plugin (i.e. the built-in restore item action plugin)
    velero.io/plugin-config: ""
    # this label identifies the name and kind of plugin
    # that this ConfigMap is for.
    velero.io/change-image-name: RestoreItemAction
data:
  "case1": "docker.m.daocloud.io,docker.m1.daocloud.io"
  "case5": ":test,:v1.2.0"

I hope the effect after the restore is

apiVersion: v1
kind: Pod
metadata:
  name: demo-pod
spec:
  containers:
  - name: container1
    image: docker.m1.daocloud.io/abc:v1.2.0
    command: ['sh', '-c', 'echo The app is running! && sleep 3600']

but actual is

apiVersion: v1
kind: Pod
metadata:
  name: demo-pod
spec:
  containers:
  - name: container1
    image: docker.m1.daocloud.io/abc:test
    command: ['sh', '-c', 'echo The app is running! && sleep 3600']

After checking the code, it is found that once a certain rule is matched, it will return directly, ignoring subsequent matches

for _, row := range cm.Data {
if !strings.Contains(row, delimiterValue) {
continue
}
if strings.Contains(oldImageName, strings.TrimSpace(row[0:strings.Index(row, delimiterValue)])) && len(row[strings.Index(row, delimiterValue):]) > len(delimiterValue) {
log.Infoln("match specific case:", row)
oldImagePart := strings.TrimSpace(row[0:strings.Index(row, delimiterValue)])
newImagePart := strings.TrimSpace(row[strings.Index(row, delimiterValue)+len(delimiterValue):])
newImageName = strings.Replace(oldImageName, oldImagePart, newImagePart, -1)
return true, newImageName, nil
}

Anything else you would like to add:

Environment:

velero v1.11.0

Vote on this issue!

This is an invitation to the Velero community to vote on issues, you can see the project's top voted issues listed here.
Use the "reaction smiley face" up to the right of this comment to vote.

  • 👍 for "I would like to see this bug fixed as soon as possible"
  • 👎 for "There are more important bugs to focus on right now"

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions