Skip to content

Commit

Permalink
add backup loki option
Browse files Browse the repository at this point in the history
  • Loading branch information
d2285 committed Feb 21, 2025
1 parent c8cedf2 commit 8a68ba4
Show file tree
Hide file tree
Showing 3 changed files with 421 additions and 0 deletions.
2 changes: 2 additions & 0 deletions internal/backup/cmd/backup.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ limitations under the License.
package backup

import (
"github.com/deckhouse/deckhouse-cli/internal/backup/cmd/loki"
"github.com/spf13/cobra"
"k8s.io/kubectl/pkg/util/templates"

Expand All @@ -41,6 +42,7 @@ func NewCommand() *cobra.Command {
backupCmd.AddCommand(
etcd.NewCommand(),
cluster_config.NewCommand(),
loki.NewCommand(),
)

return backupCmd
Expand Down
63 changes: 63 additions & 0 deletions internal/backup/cmd/loki/flags.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/*
Copyright 2024 Flant JSC
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package loki

import (
"fmt"
"github.com/spf13/pflag"
"os"

"github.com/spf13/cobra"
)

func addFlags(flagSet *pflag.FlagSet) {
flagSet.StringVar(
&endTimestamp,
"end",
"",
"Set end timestamp range to dump logs from Loki. (Default get max end timestamp from Loki, ex. \"2025-01-14 15:04:05\".)",
)
flagSet.StringVar(
&startTimestamp,
"start",
"",
"Set start timestamp range to dump logs from Loki. (Default get max start timestamp from Loki, ex. \"2025-01-12 15:04:05\".)",
)
flagSet.StringVar(
&limitFlag,
"limit",
"",
"Limit max string to output per queue from Loki. (Default 100000 max limit strings per queue.)",
)
}

func validateFlags(cmd *cobra.Command) error {
kubeconfigPath, err := cmd.Flags().GetString("kubeconfig")
if err != nil {
return fmt.Errorf("Failed to setup Kubernetes client: %w", err)
}

stats, err := os.Stat(kubeconfigPath)
if err != nil {
return fmt.Errorf("Invalid --kubeconfig: %w", err)
}
if !stats.Mode().IsRegular() {
return fmt.Errorf("Invalid --kubeconfig: %s is not a regular file", kubeconfigPath)
}

return nil
}
Loading

0 comments on commit 8a68ba4

Please sign in to comment.