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
  • Loading branch information
nvanthao committed Mar 4, 2024
1 parent a9b889e commit 2e11a65
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions pkg/analyze/velero.go
Original file line number Diff line number Diff line change
Expand Up @@ -653,19 +653,22 @@ func getVeleroVersion(excludedFiles []string, findFiles getChildCollectedFileCon
veleroDeploymentDir := "cluster-resources/deployments"
veleroVersion := ""
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)
veleroDeploymentJson, _ := findFiles(veleroDeploymentGlob, excludedFiles)
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 +679,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 2e11a65

Please sign in to comment.