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

[d8] Add d8 backup loki option #95

Open
wants to merge 2 commits into
base: main
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 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