@@ -30,7 +30,7 @@ import (
3030 "github.com/spf13/cobra"
3131 metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
3232 "k8s.io/client-go/kubernetes"
33- _ "k8s.io/client-go/plugin/pkg/client/auth"
33+ _ "k8s.io/client-go/plugin/pkg/client/auth" // Register auth plugins
3434 "k8s.io/client-go/rest"
3535 "k8s.io/client-go/tools/remotecommand"
3636 "k8s.io/kubectl/pkg/util/templates"
@@ -130,6 +130,9 @@ func backupLoki(cmd *cobra.Command, _ []string) error {
130130 chunkStart := chunkEnd - chunkSize .Nanoseconds ()
131131 if startTimestamp != "" {
132132 chunkStart , err = getStartTimestamp ()
133+ if err != nil {
134+ return err
135+ }
133136 }
134137 curlParamStreamList := CurlRequest {
135138 BaseURL : "series" ,
@@ -152,7 +155,7 @@ func backupLoki(cmd *cobra.Command, _ []string) error {
152155 }
153156
154157 for _ , r := range streamListDumpJSON .Data {
155- err := fetchLogs (chunkStart , chunkEnd , endDumpTimestamp , token , r , config , kubeCl )
158+ err := fetchLogs (chunkStart , endDumpTimestamp , token , r , config , kubeCl )
156159 if err != nil {
157160 return fmt .Errorf ("error get logs from loki: %w" , err )
158161 }
@@ -161,14 +164,14 @@ func backupLoki(cmd *cobra.Command, _ []string) error {
161164 return nil
162165}
163166
164- func fetchLogs (chunkStart , chunkEnd , endDumpTimestamp int64 , token string , r map [string ]string , config * rest.Config , kubeCl kubernetes.Interface ) error {
165- var filters []string
167+ func fetchLogs (chunkStart , endDumpTimestamp int64 , token string , r map [string ]string , config * rest.Config , kubeCl kubernetes.Interface ) error {
168+ filters := make ( []string , 0 , len ( r ))
166169 for key , value := range r {
167170 filters = append (filters , fmt .Sprintf (`%s=%q` , key , value ))
168171 }
169172 q := fmt .Sprintf (`{%s}` , strings .Join (filters , ", " ))
170173
171- chunkEnd = endDumpTimestamp
174+ chunkEnd : = endDumpTimestamp
172175 for chunkEnd > chunkStart {
173176 curlParamDumpLog := CurlRequest {
174177 BaseURL : "query_range" ,
@@ -213,7 +216,7 @@ func fetchLogs(chunkStart, chunkEnd, endDumpTimestamp int64, token string, r map
213216}
214217
215218func (c * CurlRequest ) GenerateCurlCommand () []string {
216- curlParts := append ( []string {"curl" , "--insecure" , "-v" })
219+ curlParts := []string {"curl" , "--insecure" , "-v" }
217220 curlParts = append (curlParts , fmt .Sprintf ("%s/%s" , lokiURL , c .BaseURL ))
218221 for key , value := range c .Params {
219222 if value != "" {
@@ -341,7 +344,7 @@ func getLogWithRetry(config *rest.Config, kubeCl kubernetes.Interface, fullComma
341344 context .TODO (),
342345 Logger ,
343346 "error get json response from Loki" ,
344- task .WithConstantRetries (5 , 10 * time .Second , func (ctx context.Context ) error {
347+ task .WithConstantRetries (5 , 10 * time .Second , func (_ context.Context ) error {
345348 QueryRangeDump , SeriesAPIDump , err = getLogTimestamp (config , kubeCl , fullCommand )
346349 if err != nil {
347350 return fmt .Errorf ("error get JSON response from loki: %w" , err )
0 commit comments