Skip to content

Commit

Permalink
Rely on only container name while parsing feature flags (vmware-tanzu…
Browse files Browse the repository at this point in the history
…#422)

The PR ensures that the plugin uses only the container name to determine velero container.

Signed-off-by: Deepak Kinni <dkinni@vmware.com>
  • Loading branch information
Deepak Kinni committed Dec 7, 2021
1 parent 179348d commit 83e8195
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pkg/cmd/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ func GetVeleroFeatureFlags(kubeClient kubernetes.Interface, ns string) ([]string
func GetFeatureFlagsFromImage(containers []v1.Container, containerName string) ([]string, error) {
var containerArgs = []string{}
for _, container := range containers {
if containerName == container.Name && containerName == utils.GetComponentFromImage(container.Image, constants.ImageContainerComponent) {
if containerName == container.Name {
containerArgs = container.Args[1:]
break
}
Expand Down
54 changes: 54 additions & 0 deletions pkg/cmd/utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -314,6 +314,60 @@ func TestGetVeleroFeatureFlags(t *testing.T) {
expectedFeatureFlags: []string{},
expectedError: nil,
},
{
name: "VeleroImageWithSha256",
veleroDeployment: &appsv1.Deployment{
ObjectMeta: metav1.ObjectMeta{
Namespace: "velero",
Name: constants.VeleroDeployment,
},
Spec: appsv1.DeploymentSpec{
Template: corev1.PodTemplateSpec{
Spec: corev1.PodSpec{
Containers: []corev1.Container{
{
Name: "velero",
Image: "velero/velero@sha256:934dae8b2e17b4298bca95f45ec3620a283647297fb8ba8c0f5977e8238a97ee",
Args: []string{
"server",
"--features=EnableLocalMode",
},
},
},
},
},
},
},
expectedFeatureFlags: []string{"EnableLocalMode"},
expectedError: nil,
},
{
name: "VeleroImageWithSha256MultipleFlags",
veleroDeployment: &appsv1.Deployment{
ObjectMeta: metav1.ObjectMeta{
Namespace: "velero",
Name: constants.VeleroDeployment,
},
Spec: appsv1.DeploymentSpec{
Template: corev1.PodTemplateSpec{
Spec: corev1.PodSpec{
Containers: []corev1.Container{
{
Name: "velero",
Image: "velero/velero@sha256:934dae8b2e17b4298bca95f45ec3620a283647297fb8ba8c0f5977e8238a97ee",
Args: []string{
"server",
"--features=EnableVSphereItemActionPlugin,EnableLocalMode",
},
},
},
},
},
},
},
expectedFeatureFlags: []string{"EnableVSphereItemActionPlugin", "EnableLocalMode"},
expectedError: nil,
},
}
for _, test := range tests {
t.Run(test.name, func(t *testing.T) {
Expand Down

0 comments on commit 83e8195

Please sign in to comment.