Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(kubernetes): allow backup volumes from a custom list of namespaces #395

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions cmd/manager/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ func init() {
envs["KUBERNETES_NAMESPACE"] = "kubernetes.namespace"
managerCmd.Flags().BoolVarP(&Orchestrators.Kubernetes.AllNamespaces, "kubernetes.all-namespaces", "", false, "Backup volumes of all namespaces.")
envs["KUBERNETES_ALL_NAMESPACES"] = "kubernetes.all-namespaces"
managerCmd.Flags().StringVarP(&Orchestrators.Kubernetes.CustomNamespaces, "kubernetes.custom-namespaces", "", "", "Backup volumes from a custom namespaces list.")
envs["KUBERNETES_CUSTOM_NAMESPACES"] = "kubernetes.custom-namespaces"
managerCmd.Flags().StringVarP(&Orchestrators.Kubernetes.KubeConfig, "kubernetes.kubeconfig", "", "", "Path to your kuberconfig file.")
envs["KUBERNETES_KUBECONFIG"] = "kubernetes.kubeconfig"
managerCmd.Flags().StringVarP(&Orchestrators.Kubernetes.AgentServiceAccount, "kubernetes.agent-service-account", "", "", "Specify service account for agents.")
Expand Down
15 changes: 15 additions & 0 deletions pkg/orchestrators/kubernetes.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import (
type KubernetesConfig struct {
Namespace string
AllNamespaces bool
CustomNamespaces string
KubeConfig string
AgentServiceAccount string
AgentLabelsInline string
Expand Down Expand Up @@ -556,6 +557,20 @@ func (o *KubernetesOrchestrator) getNamespaces() (namespaces []string, err error
for _, namespace := range nms.Items {
namespaces = append(namespaces, namespace.Name)
}
} else if o.config.CustomNamespaces != "" {
nms, err := o.client.CoreV1().Namespaces().List(metav1.ListOptions{})
if err != nil {
err = fmt.Errorf("failed to retrieve the list of namespaces: %s", err)
return []string{}, err
}
customNamespaces := strings.Split(o.config.CustomNamespaces, ",")
for _, namespace := range nms.Items {
for _, ns := range customNamespaces {
if ns == namespace.Name {
namespaces = append(namespaces, namespace.Name)
}
}
}
} else {
namespaces = append(namespaces, o.config.Namespace)
}
Expand Down
Loading