Skip to content

Commit

Permalink
Support detecting velero from helm chart
Browse files Browse the repository at this point in the history
  • Loading branch information
marccampbell committed May 14, 2020
1 parent f7e6088 commit 6bb7793
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 10 deletions.
58 changes: 48 additions & 10 deletions kotsadm/pkg/snapshot/velero.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (

"github.com/pkg/errors"
veleroclientv1 "github.com/vmware-tanzu/velero/pkg/generated/clientset/versioned/typed/velero/v1"
v1 "k8s.io/api/apps/v1"
kuberneteserrors "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
"k8s.io/client-go/kubernetes"
Expand Down Expand Up @@ -65,13 +66,12 @@ func DetectVelero() (*VeleroStatus, error) {
Plugins: []string{},
}

deployments, err := clientset.AppsV1().Deployments(veleroNamespace).List(metav1.ListOptions{
LabelSelector: "component=velero",
})
possibleDeployments, err := listPossibleVeleroDeployments(clientset, veleroNamespace)
if err != nil {
return nil, errors.Wrap(err, "failed to list deployments")
return nil, errors.Wrap(err, "failed to list possible velero deployments")
}
for _, deployment := range deployments.Items {

for _, deployment := range possibleDeployments {
for _, initContainer := range deployment.Spec.Template.Spec.InitContainers {
// the default installation is to name these like "velero-plugin-for-aws"
veleroStatus.Plugins = append(veleroStatus.Plugins, initContainer.Name)
Expand All @@ -93,13 +93,11 @@ func DetectVelero() (*VeleroStatus, error) {
}
DeploymentFound:

daemonsets, err := clientset.AppsV1().DaemonSets(veleroNamespace).List(metav1.ListOptions{
LabelSelector: "component=velero",
})
daemonsets, err := listPossibleResticDaemonsets(clientset, veleroNamespace)
if err != nil {
return nil, errors.Wrap(err, "failed to list daemonsets")
return nil, errors.Wrap(err, "failed to list restic daemonsets")
}
for _, daemonset := range daemonsets.Items {
for _, daemonset := range daemonsets {
matches := dockerImageNameRegex.FindStringSubmatch(daemonset.Spec.Template.Spec.Containers[0].Image)
if len(matches) == 5 {
status := "NotReady"
Expand All @@ -120,3 +118,43 @@ ResticFound:

return &veleroStatus, nil
}

// listPossibleVeleroDeployments filters with a label selector based on how we've found velero deployed
// using the CLI or the Helm Chart.
func listPossibleVeleroDeployments(clientset *kubernetes.Clientset, namespace string) ([]v1.Deployment, error) {
deployments, err := clientset.AppsV1().Deployments(namespace).List(metav1.ListOptions{
LabelSelector: "component=velero",
})
if err != nil {
return nil, errors.Wrap(err, "failed to list deployments")
}

helmDeployments, err := clientset.AppsV1().Deployments(namespace).List(metav1.ListOptions{
LabelSelector: "app.kubernetes.io/name=velero",
})
if err != nil {
return nil, errors.Wrap(err, "failed to list helm deployments")
}

return append(deployments.Items, helmDeployments.Items...), nil
}

// listPossibleResticDaemonsets filters with a label selector based on how we've found restic deployed
// using the CLI or the Helm Chart.
func listPossibleResticDaemonsets(clientset *kubernetes.Clientset, namespace string) ([]v1.DaemonSet, error) {
daemonsets, err := clientset.AppsV1().DaemonSets(namespace).List(metav1.ListOptions{
LabelSelector: "component=velero",
})
if err != nil {
return nil, errors.Wrap(err, "failed to list daemonsets")
}

helmDaemonsets, err := clientset.AppsV1().DaemonSets(namespace).List(metav1.ListOptions{
LabelSelector: "app.kubernetes.io/name=velero",
})
if err != nil {
return nil, errors.Wrap(err, "failed to list helm daemonsets")
}

return append(daemonsets.Items, helmDaemonsets.Items...), nil
}
2 changes: 2 additions & 0 deletions kotsadm/pkg/supportbundle/backup.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ func CreateBundleForBackup(appID string, backupName string, backupNamespace stri
Selector: []string{
"component=velero",
"deploy=velero",
"app.kubernetes.io/name=velero",
},
},
},
Expand All @@ -76,6 +77,7 @@ func CreateBundleForBackup(appID string, backupName string, backupNamespace stri
Selector: []string{
"component=velero",
"name=restic",
"app.kubernetes.io/name=velero",
},
},
},
Expand Down

0 comments on commit 6bb7793

Please sign in to comment.