Skip to content

Commit 7e1d0eb

Browse files
committed
(deps) advance clusterAPI to v1.12.4
Advance go to v1.26.1 Advance k8s library to v1.25.3
1 parent 35368b2 commit 7e1d0eb

15 files changed

Lines changed: 163 additions & 92 deletions

File tree

.devcontainer/devcontainer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
"dockerfile": "${localWorkspaceFolder}/.devcontainer/Dockerfile",
99
"context": "${localWorkspaceFolder}",
1010
"args": {
11-
"GO_VERSION": "1.25.6",
11+
"GO_VERSION": "1.26.1",
1212
"KUBECTX_VERSION": "0.9.5",
1313
"SVELTOSCTL_VERSION": "0.53.0"
1414
}

.github/workflows/main.yaml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ jobs:
1818
- name: Set up Go
1919
uses: actions/setup-go@4b73464bb391d4059bd26b0524d20df3927bd417 # v6.3.0
2020
with:
21-
go-version: 1.25.6
21+
go-version: 1.26.1
2222
- name: Build
2323
run: make build
2424
- name: FMT
@@ -37,7 +37,7 @@ jobs:
3737
- name: Set up Go
3838
uses: actions/setup-go@4b73464bb391d4059bd26b0524d20df3927bd417 # v6.3.0
3939
with:
40-
go-version: 1.25.6
40+
go-version: 1.26.1
4141
- name: ut
4242
run: make test
4343
env:
@@ -50,7 +50,7 @@ jobs:
5050
- name: Set up Go
5151
uses: actions/setup-go@4b73464bb391d4059bd26b0524d20df3927bd417 # v6.3.0
5252
with:
53-
go-version: 1.25.6
53+
go-version: 1.26.1
5454
- name: Free Disk Space (Ubuntu)
5555
uses: jlumbroso/free-disk-space@main
5656
with:
@@ -78,7 +78,7 @@ jobs:
7878
- name: Set up Go
7979
uses: actions/setup-go@4b73464bb391d4059bd26b0524d20df3927bd417 # v6.3.0
8080
with:
81-
go-version: 1.25.6
81+
go-version: 1.26.1
8282
- name: Free Disk Space (Ubuntu)
8383
uses: jlumbroso/free-disk-space@main
8484
with:
@@ -106,7 +106,7 @@ jobs:
106106
- name: Set up Go
107107
uses: actions/setup-go@4b73464bb391d4059bd26b0524d20df3927bd417 # v6.3.0
108108
with:
109-
go-version: 1.25.6
109+
go-version: 1.26.1
110110
- name: Free Disk Space (Ubuntu)
111111
uses: jlumbroso/free-disk-space@main
112112
with:
@@ -134,7 +134,7 @@ jobs:
134134
- name: Set up Go
135135
uses: actions/setup-go@4b73464bb391d4059bd26b0524d20df3927bd417 # v6.3.0
136136
with:
137-
go-version: 1.25.6
137+
go-version: 1.26.1
138138
- name: Free Disk Space (Ubuntu)
139139
uses: jlumbroso/free-disk-space@main
140140
with:
@@ -162,7 +162,7 @@ jobs:
162162
- name: Set up Go
163163
uses: actions/setup-go@4b73464bb391d4059bd26b0524d20df3927bd417 # v6.3.0
164164
with:
165-
go-version: 1.25.6
165+
go-version: 1.26.1
166166
- name: Free Disk Space (Ubuntu)
167167
uses: jlumbroso/free-disk-space@main
168168
with:
@@ -190,7 +190,7 @@ jobs:
190190
- name: Set up Go
191191
uses: actions/setup-go@4b73464bb391d4059bd26b0524d20df3927bd417 # v6.3.0
192192
with:
193-
go-version: 1.25.6
193+
go-version: 1.26.1
194194
- name: Free Disk Space (Ubuntu)
195195
uses: jlumbroso/free-disk-space@main
196196
with:

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Build the manager binary
2-
FROM golang:1.25.6 AS builder
2+
FROM golang:1.26.1 AS builder
33

44
ARG BUILDOS
55
ARG TARGETARCH

Dockerfile_WithGit

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
# Build the manager binary
2-
FROM golang:1.25.6 AS builder
2+
FROM golang:1.26.1 AS builder
33

44
ARG BUILDOS
55
ARG TARGETARCH

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ KIND := $(TOOLS_BIN_DIR)/kind
7272
KUBECTL := $(TOOLS_BIN_DIR)/kubectl
7373

7474
GOVULNCHECK_VERSION := "v1.1.4"
75-
GOLANGCI_LINT_VERSION := "v2.8.0"
75+
GOLANGCI_LINT_VERSION := "v2.11.3"
7676
CLUSTERCTL_VERSION := v1.12.3
7777

7878
KUSTOMIZE_VER := v5.8.0

controllers/clustersummary_watchers.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,7 @@ func (m *manager) startWatcher(ctx context.Context, gvk *schema.GroupVersionKind
373373
return err
374374
}
375375

376-
watcherCtx, cancel := context.WithCancel(ctx)
376+
watcherCtx, cancel := context.WithCancel(ctx) //nolint:gosec // cancel is stored in m.watchers and called when the watcher is stopped
377377
m.watchers[*gvk] = cancel
378378
go m.runInformer(watcherCtx.Done(), dcinformer.Informer(), logger)
379379
return nil

controllers/dependencymanager/manager.go

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -489,10 +489,20 @@ func (m *instance) updateClusterProfile(ctx context.Context, c client.Client, cl
489489
}
490490

491491
func (m *instance) updateProfiles(ctx context.Context, c client.Client, logger logr.Logger) {
492+
const interval = 30 * time.Second
492493
for {
493494
m.chartMux.Lock()
494495

496+
canceled := false
495497
for profile := range m.profileToBeUpdated {
498+
select {
499+
case <-ctx.Done():
500+
canceled = true
501+
default:
502+
}
503+
if canceled {
504+
break
505+
}
496506
clusters := m.profileClusterRequests.getClusterDeployments(&profile)
497507
logger.V(logs.LogDebug).Info(fmt.Sprintf("updating prerequestite profile %s/%s", profile.Namespace, profile.Name))
498508
err := m.updateProfileInstance(ctx, c, &profile, clusters)
@@ -503,8 +513,15 @@ func (m *instance) updateProfiles(ctx context.Context, c client.Client, logger l
503513

504514
m.chartMux.Unlock()
505515

506-
const interval = 30 * time.Second
507-
time.Sleep(interval)
516+
if canceled {
517+
return
518+
}
519+
520+
select {
521+
case <-ctx.Done():
522+
return
523+
case <-time.After(interval):
524+
}
508525
}
509526
}
510527

controllers/handlers_helm_test.go

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1038,20 +1038,19 @@ resources:
10381038
})
10391039

10401040
It("getCredentialsAndCAFiles returns files containing credentials and CA", func() {
1041-
type Credentials struct {
1042-
Username string
1043-
Password string
1044-
RefreshToken string
1045-
AccessToken string
1046-
}
1047-
1048-
credentials := Credentials{
1041+
credentials := struct {
1042+
Username string `json:"username"`
1043+
Password string `json:"password"`
1044+
RefreshToken string `json:"refresh_token"`
1045+
AccessToken string `json:"access_token"`
1046+
}{
10491047
Username: randomString(),
10501048
Password: randomString(),
10511049
RefreshToken: randomString(),
10521050
AccessToken: randomString(),
10531051
}
10541052

1053+
//nolint:gosec // This is dummy data for testing purposes
10551054
credentialsBytes, err := json.Marshal(credentials)
10561055
Expect(err).To(BeNil())
10571056

controllers/handlers_kustomize_test.go

Lines changed: 37 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import (
2222
"context"
2323
"fmt"
2424
"io"
25+
"io/fs"
2526
"os"
2627
"path/filepath"
2728
"reflect"
@@ -601,15 +602,13 @@ var _ = Describe("Hash methods", func() {
601602
})
602603

603604
func createTarGz(dest string) {
604-
// Create the test directory and some test files.
605-
err := os.MkdirAll("testdata/testdir", 0755)
606-
Expect(err).To(BeNil())
607-
err = os.WriteFile("testdata/test.txt", []byte("This is a test file."), 0600)
608-
Expect(err).To(BeNil())
609-
err = os.WriteFile("testdata/testdir/test.txt", []byte("This is another test file."), 0600)
610-
Expect(err).To(BeNil())
605+
baseDir := "testdata"
606+
// Create the test directory and files
607+
Expect(os.MkdirAll(filepath.Join(baseDir, "testdir"), 0755)).To(Succeed())
608+
Expect(os.WriteFile(filepath.Join(baseDir, "test.txt"), []byte("This is a test file."), 0600)).To(Succeed())
609+
Expect(os.WriteFile(filepath.Join(baseDir, "testdir", "test.txt"), []byte("This is another test file."), 0600)).To(Succeed())
611610

612-
// Create the testdata/test.tar.gz file.
611+
// Create the destination archive
613612
file, err := os.Create(dest)
614613
Expect(err).To(BeNil())
615614
defer file.Close()
@@ -620,28 +619,53 @@ func createTarGz(dest string) {
620619
tarWriter := tar.NewWriter(gzWriter)
621620
defer tarWriter.Close()
622621

623-
err = filepath.Walk("testdata/", func(path string, info os.FileInfo, err error) error {
622+
// 1. Open the root of the walking operation
623+
root, err := os.OpenRoot(baseDir)
624+
Expect(err).To(BeNil())
625+
defer root.Close()
626+
627+
// 2. Use WalkDir (more efficient than Walk)
628+
err = filepath.WalkDir(baseDir, func(path string, d fs.DirEntry, err error) error {
629+
if err != nil {
630+
return err
631+
}
632+
633+
// Get info for the tar header
634+
info, err := d.Info()
624635
if err != nil {
625636
return err
626637
}
638+
627639
header, err := tar.FileInfoHeader(info, "")
628640
if err != nil {
629641
return err
630642
}
631-
header.Name = path[len("testdata")+1:]
643+
644+
// Clean up the path for the tar header
645+
rel, _ := filepath.Rel(baseDir, path)
646+
header.Name = rel
647+
if rel == "." {
648+
return nil
649+
} // Skip the root directory itself if needed
650+
632651
err = tarWriter.WriteHeader(header)
633652
if err != nil {
634653
return err
635654
}
655+
636656
if !info.Mode().IsRegular() {
637657
return nil
638658
}
639-
file, err := os.Open(path)
659+
660+
// 3. SECURE FIX: Open file relative to the root handle
661+
// This prevents G122 by ensuring no symlinks escaped 'testdata'
662+
f, err := root.Open(rel)
640663
if err != nil {
641664
return err
642665
}
643-
defer file.Close()
644-
_, err = io.Copy(tarWriter, file)
666+
defer f.Close()
667+
668+
_, err = io.Copy(tarWriter, f)
645669
return err
646670
})
647671
Expect(err).To(BeNil())

controllers/handlers_utils.go

Lines changed: 34 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ import (
2222
"encoding/hex"
2323
"encoding/json"
2424
"fmt"
25+
"io"
26+
"io/fs"
2527
"os"
2628
"path/filepath"
2729
"sort"
@@ -174,20 +176,44 @@ func deployContentOfSource(ctx context.Context, deployingToMgmtCluster bool, des
174176

175177
func readFiles(dir string) (map[string]string, error) {
176178
files := make(map[string]string)
177-
err := filepath.Walk(dir, func(path string, info os.FileInfo, err error) error {
179+
180+
// 1. Open the directory as a Root handle
181+
root, err := os.OpenRoot(dir)
182+
if err != nil {
183+
return nil, err
184+
}
185+
defer root.Close()
186+
187+
// 2. WalkDir is faster than Walk as it doesn't Lstat every file unnecessarily
188+
err = filepath.WalkDir(dir, func(path string, d fs.DirEntry, err error) error {
178189
if err != nil {
179190
return err
180191
}
181192

182-
if !info.IsDir() {
183-
content, err := os.ReadFile(path)
193+
if !d.IsDir() {
194+
// 3. Get the path relative to the root directory
195+
rel, err := filepath.Rel(dir, path)
184196
if err != nil {
185197
return err
186198
}
187-
files[filepath.Base(path)] = string(content)
199+
200+
// 4. Open the file via the Root handle to prevent symlink traversal
201+
f, err := root.Open(rel)
202+
if err != nil {
203+
return err
204+
}
205+
defer f.Close()
206+
207+
content, err := io.ReadAll(f)
208+
if err != nil {
209+
return err
210+
}
211+
212+
files[d.Name()] = string(content)
188213
}
189214
return nil
190215
})
216+
191217
return files, err
192218
}
193219

@@ -1092,12 +1118,12 @@ func getDeployedGroupVersionKinds(clusterSummary *configv1beta1.ClusterSummary,
10921118
gvks := make([]schema.GroupVersionKind, 0)
10931119
// For backward compatible we still look at this field.
10941120
// New code set only FeatureDeploymentInfo
1095-
fs := getFeatureSummaryForFeatureID(clusterSummary, featureID)
1096-
if fs != nil {
1121+
featureSummary := getFeatureSummaryForFeatureID(clusterSummary, featureID)
1122+
if featureSummary != nil {
10971123
//nolint:staticcheck // using for backward compatibility
1098-
for j := range fs.DeployedGroupVersionKind {
1124+
for j := range featureSummary.DeployedGroupVersionKind {
10991125
//nolint:staticcheck // using for backward compatibility
1100-
gvk, _ := schema.ParseKindArg(fs.DeployedGroupVersionKind[j])
1126+
gvk, _ := schema.ParseKindArg(featureSummary.DeployedGroupVersionKind[j])
11011127
gvks = append(gvks, *gvk)
11021128
}
11031129
}

0 commit comments

Comments
 (0)