INNER CODE UNIT · Go

backupAnnotatedPods

k8up-io/k8up · cmd/restic/main.go:308

func backupAnnotatedPods(ctx context.Context, resticCLI *resticCli.Restic, mainLogger logr.Logger) error {
	_, serviceErr := os.Stat("/var/run/secrets/kubernetes.io")
	_, kubeconfigErr := os.Stat(cfg.Config.KubeConfig)

	if serviceErr != nil && kubeconfigErr != nil {
		mainLogger.Info("No kubernetes credentials configured: Can't check for annotated Pods.", "KUBECONFIG", cfg.Config.KubeConfig)
		return nil
	}

	k8cli, err := kubernetes.NewTypedClient(mainLogger)
	if err != nil {
		return fmt.Errorf("could not create kubernetes client: %w", err)
	}
	podLister := kubernetes.NewPodLister(ctx, k8cli, cfg.Config.BackupCommandAnnotation, cfg.Config.BackupFileExtensionAnnotation, cfg.Config.BackupContainerAnnotation, cfg.Config.Hostname, cfg.Config.TargetPods, cfg.Config.SkipPreBackup, mainLogger)
	podList, err := podLister.ListPods()
	if err != nil {
		mainLogger.Error(err, "could not list pods", "namespace", cfg.Config.Hostname)
		return fmt.Errorf("could not list pods: %w", err)

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…