Skip to content

Commit

Permalink
fix panic in Velero analyzer when there's no Velero deployment found (#…
Browse files Browse the repository at this point in the history
…1497)

* fix panic in Velero analyzer when there's no Velero deployment found

* do not omit error in find files
  • Loading branch information
nvanthao authored Mar 5, 2024
1 parent 29435b1 commit 553d709
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions pkg/analyze/velero.go
Original file line number Diff line number Diff line change
Expand Up @@ -655,17 +655,23 @@ func getVeleroVersion(excludedFiles []string, findFiles getChildCollectedFileCon
veleroDeploymentGlob := filepath.Join(veleroDeploymentDir, "velero.json")
veleroDeploymentJson, err := findFiles(veleroDeploymentGlob, excludedFiles)
if err != nil {
return "", errors.Wrapf(err, "failed to find velero deployment file under %s", veleroDeploymentDir)
return "", errors.Wrapf(err, "failed to find Velero deployment")
}
if len(veleroDeploymentJson) == 0 {
return "", errors.Errorf("could not find Velero deployment in %s", veleroDeploymentDir)
}
var deploymentList *appsV1.DeploymentList
// should run only once
for key, veleroDeploymentJsonBytes := range veleroDeploymentJson {
err := json.Unmarshal(veleroDeploymentJsonBytes, &deploymentList)
if err != nil {
return "", errors.Wrapf(err, "failed to unmarshal velero deployment json from %s", key)
return "", errors.Wrapf(err, "failed to unmarshal Velero deployment json from %s", key)
}
break
}
if deploymentList == nil {
return "", errors.Errorf("could not find Velero deployment")
}
for _, deployment := range deploymentList.Items {
for _, container := range deployment.Spec.Template.Spec.Containers {
if container.Name == "velero" {
Expand All @@ -676,7 +682,7 @@ func getVeleroVersion(excludedFiles []string, findFiles getChildCollectedFileCon
}
}

return "", errors.Errorf("Unable to get velero version. Could not find velero container in deployment!")
return "", errors.Errorf("could not find Velero container in deployment")
}

func GetVeleroBackupsDirectory() string {
Expand Down

0 comments on commit 553d709

Please sign in to comment.