Skip to content

Commit 65b8607

Browse files
Update deps ans fix linter errors (#67)
Signed-off-by: PulokSaha0706 <puloksaha@appscode.com> Signed-off-by: Anisur Rahman <anisur@appscode.com>
1 parent 2d75961 commit 65b8607

File tree

8 files changed

+55
-23
lines changed

8 files changed

+55
-23
lines changed

.golangci.yml

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
version: "2"
2+
linters:
3+
default: standard
4+
enable:
5+
- unparam
6+
7+
formatters:
8+
enable:
9+
- gofmt
10+
- goimports
11+
settings:
12+
gofmt:
13+
rewrite-rules:
14+
- pattern: 'interface{}'
15+
replacement: 'any'
16+
17+
issues:
18+
max-same-issues: 100
19+
20+
exclude-files:
21+
- generated.*\\.go
22+
23+
exclude-dirs:
24+
- client
25+
- vendor
26+
27+
run:
28+
timeout: 10m

Makefile

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ BIN_PLATFORMS := $(DOCKER_PLATFORMS) windows/amd64 darwin/amd64 darwin/arm64
5353
OS := $(if $(GOOS),$(GOOS),$(shell go env GOOS))
5454
ARCH := $(if $(GOARCH),$(GOARCH),$(shell go env GOARCH))
5555

56-
GO_VERSION ?= 1.25
56+
GO_VERSION ?= 1.25.5
5757
BUILD_IMAGE ?= ghcr.io/appscode/golang-dev:$(GO_VERSION)
5858

5959
RESTIC_VER := 0.17.3
@@ -220,7 +220,7 @@ lint: $(BUILD_DIRS)
220220
--env GO111MODULE=on \
221221
--env GOFLAGS="-mod=vendor" \
222222
$(BUILD_IMAGE) \
223-
golangci-lint run --enable $(ADDTL_LINTERS) --timeout=10m --exclude-files="generated.*\.go$\" --exclude-dirs-use-default
223+
golangci-lint run
224224

225225
$(BUILD_DIRS):
226226
@mkdir -p $@

go.mod

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,6 @@
11
module kubestash.dev/cli
22

3-
go 1.24.0
4-
5-
toolchain go1.24.3
3+
go 1.25.5
64

75
require (
86
github.com/jedib0t/go-pretty/v6 v6.6.8

hack/gendocs/main.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@ func main() {
9292
filePrepender := func(filename string) string {
9393
filename = filepath.Base(filename)
9494
base := strings.TrimSuffix(filename, path.Ext(filename))
95-
name := cases.Title(language.English).String(strings.Replace(base, "_", " ", -1))
95+
name := cases.Title(language.English).String(strings.ReplaceAll(base, "_", " "))
9696
parts := strings.Split(name, " ")
9797
if len(parts) > 1 {
9898
name = strings.Join(parts[1:], " ")
@@ -102,7 +102,7 @@ func main() {
102102
Name string
103103
RootCmd bool
104104
}{
105-
strings.Replace(base, "_", "-", -1),
105+
strings.ReplaceAll(base, "_", "-"),
106106
name,
107107
!strings.ContainsRune(base, '_'),
108108
}

pkg/common/dump/helpers.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ func isCompleted(obj *unstructured.Unstructured) (bool, error) {
161161
return false, nil
162162
}
163163
for _, conditionRaw := range conditions {
164-
condition, ok := conditionRaw.(map[string]interface{})
164+
condition, ok := conditionRaw.(map[string]any)
165165
if !ok {
166166
continue
167167
}

pkg/common/dump/restore.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ func (m *ResourceManager) applyItem(ctx context.Context, groupRes string, itm co
211211

212212
if gvr.Resource == apis.PersistentVolumeClaims.Resource &&
213213
m.StorageClassMappingsStr != "" {
214-
if spec, ok := sObj["spec"].(map[string]interface{}); ok && spec != nil {
214+
if spec, ok := sObj["spec"].(map[string]any); ok && spec != nil {
215215
sObj["spec"] = m.mapStorageClass(spec)
216216
}
217217
}
@@ -257,7 +257,7 @@ func (m *ResourceManager) downloadTheItem(groupRes string, obj *unstructured.Uns
257257
return nil
258258
}
259259

260-
func (m *ResourceManager) mapStorageClass(spec map[string]interface{}) map[string]interface{} {
260+
func (m *ResourceManager) mapStorageClass(spec map[string]any) map[string]any {
261261
if oldStorageClassName, ok := spec["storageClassName"].(string); ok {
262262
if _, exist := m.StorageClassMappings[oldStorageClassName]; exist {
263263
spec["storageClassName"] = m.StorageClassMappings[oldStorageClassName]
@@ -273,7 +273,7 @@ func (m *ResourceManager) ensureNamespace(ctx context.Context, ns string) error
273273
klog.V(2).Infof("Iteration %d: namespace %s exists", m.currentIteration, ns)
274274
return nil
275275
}
276-
obj := &unstructured.Unstructured{Object: map[string]interface{}{"apiVersion": "v1", "kind": "Namespace", "metadata": map[string]interface{}{"name": ns}}}
276+
obj := &unstructured.Unstructured{Object: map[string]any{"apiVersion": "v1", "kind": "Namespace", "metadata": map[string]any{"name": ns}}}
277277
key := getItemKey(obj)
278278
if _, done := m.restoredItems[key]; done {
279279
klog.V(3).Infof("Iteration %d: already restored %s", m.currentIteration, key)
@@ -334,8 +334,8 @@ func (m *ResourceManager) setOwnerReferences(ctx context.Context) error {
334334
continue
335335
}
336336

337-
patchPayload := map[string]interface{}{
338-
"metadata": map[string]interface{}{
337+
patchPayload := map[string]any{
338+
"metadata": map[string]any{
339339
"ownerReferences": validRelinkedOwners,
340340
},
341341
}
@@ -401,7 +401,7 @@ func (m *ResourceManager) shouldRestore(obj *unstructured.Unstructured) bool {
401401
return false
402402
}
403403
labels := LabelsToStrings(obj.GetLabels())
404-
return matchesAny(labels, m.Options.ORedLabelSelectors) && matchesAll(labels, m.Options.ANDedLabelSelectors)
404+
return matchesAny(labels, m.ORedLabelSelectors) && matchesAll(labels, m.ANDedLabelSelectors)
405405
}
406406

407407
func (m *ResourceManager) isNamespaced(groupRes string) (bool, error) {
@@ -430,7 +430,7 @@ func (m *ResourceManager) parseItems() (map[string]*common.ResourceItems, error)
430430
klog.Errorf("Failed to get restic stats: %v", err)
431431
} else {
432432
for _, resticStat := range manifestResticStats {
433-
baseDir := filepath.Join(m.Options.DataDir, m.SnapshotName, apis.ComponentManifest, resticStat.HostPath)
433+
baseDir := filepath.Join(m.DataDir, m.SnapshotName, apis.ComponentManifest, resticStat.HostPath)
434434
entries, err := m.reader.ReadDir(baseDir)
435435
if err != nil {
436436
return nil, fmt.Errorf("failed to read backup directory: %w", err)
@@ -498,7 +498,7 @@ func (m *ResourceManager) getRestoreableItems(r *common.ResourceItems) map[strin
498498
klog.Errorf("Failed to get restic stats: %v", err)
499499
} else {
500500
for _, resticStat := range manifestResticStats {
501-
baseDir := filepath.Join(m.Options.DataDir, m.SnapshotName, apis.ComponentManifest, resticStat.HostPath)
501+
baseDir := filepath.Join(m.DataDir, m.SnapshotName, apis.ComponentManifest, resticStat.HostPath)
502502
resourceForPath := filepath.Join(baseDir, r.GroupResource)
503503
for namespace, items := range r.ItemsByNamespace {
504504
identifier := apis.NamespaceScopedDir

pkg/common/helpers.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ import (
2323
core "k8s.io/api/core/v1"
2424
"k8s.io/apimachinery/pkg/runtime"
2525
utilruntime "k8s.io/apimachinery/pkg/util/runtime"
26-
"k8s.io/client-go/rest"
2726
restclient "k8s.io/client-go/rest"
2827
kmapi "kmodules.xyz/client-go/api/v1"
2928
kubedbapi "kubedb.dev/apimachinery/apis/kubedb/v1alpha2"
@@ -40,7 +39,7 @@ func NewRuntimeClient(cfg *restclient.Config) (client.Client, error) {
4039
utilruntime.Must(kubedbapi.AddToScheme(scheme))
4140
utilruntime.Must(core.AddToScheme(scheme))
4241

43-
hc, err := rest.HTTPClientFor(cfg)
42+
hc, err := restclient.HTTPClientFor(cfg)
4443
if err != nil {
4544
return nil, err
4645
}

pkg/convert.go

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -443,7 +443,7 @@ func configureBackupAddonInfo(bc *v1beta1.BackupConfiguration) *coreapi.AddonInf
443443
}
444444
if bc.Spec.Target != nil && isTargetWorkload(bc.Spec.Target.Ref) {
445445
params := &runtime.RawExtension{}
446-
pathsMap := make(map[string]interface{})
446+
pathsMap := make(map[string]any)
447447

448448
if len(bc.Spec.Target.Paths) > 0 {
449449
pathsMap["paths"] = strings.Join(bc.Spec.Target.Paths, ",")
@@ -667,8 +667,8 @@ func setValidValue(fieldName string) string {
667667
return fmt.Sprintf("### Set Valid %s ###", fieldName)
668668
}
669669

670-
func writeToTargetDir(srcPath string, addSeparator bool, obj interface{}) error {
671-
targetPath := strings.Replace(srcPath, sourceDir, targetDir, -1)
670+
func writeToTargetDir(srcPath string, addSeparator bool, obj any) error {
671+
targetPath := strings.ReplaceAll(srcPath, sourceDir, targetDir)
672672
if err := os.MkdirAll(filepath.Dir(targetPath), os.ModePerm); err != nil {
673673
return err
674674
}
@@ -689,7 +689,7 @@ func writeToTargetDir(srcPath string, addSeparator bool, obj interface{}) error
689689
if err != nil {
690690
return err
691691
}
692-
defer file.Close()
692+
defer closeFileWithLogError(file)
693693
if _, err := file.Write(marshalled); err != nil {
694694
return err
695695
}
@@ -701,10 +701,17 @@ func addSeparatorToTargetFile(filePath string) error {
701701
if err != nil {
702702
return err
703703
}
704-
defer file.Close()
704+
defer closeFileWithLogError(file)
705705
separator := "\n---\n\n"
706706
if _, err := file.WriteString(separator); err != nil {
707707
return err
708708
}
709709
return nil
710710
}
711+
712+
func closeFileWithLogError(file *os.File) {
713+
err := file.Close()
714+
if err != nil {
715+
klog.Errorf("Error closing file: %v", err)
716+
}
717+
}

0 commit comments

Comments
 (0)