Skip to content

Commit 82f57b3

Browse files
waveywavestekton-robot
authored andcommitted
refactor: remove unused cacheConfigStore field from Reconciler
1 parent 1938f28 commit 82f57b3

File tree

4 files changed

+22
-168
lines changed

4 files changed

+22
-168
lines changed

pkg/remoteresolution/resolver/framework/cache/setup_test.go

Lines changed: 19 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -20,28 +20,12 @@ import (
2020
"context"
2121
"testing"
2222

23+
pipelinev1 "github.com/tektoncd/pipeline/pkg/apis/pipeline/v1"
2324
_ "knative.dev/pkg/system/testing" // Setup system.Namespace()
2425

2526
logtesting "knative.dev/pkg/logging/testing"
2627
)
2728

28-
func TestGet(t *testing.T) {
29-
ctx := logtesting.TestContextWithLogger(t)
30-
31-
// Test getting cache from context
32-
resolverCache := Get(ctx)
33-
if resolverCache == nil {
34-
t.Error("Expected resolver cache but got nil")
35-
}
36-
37-
// Get creates a new wrapper with logger each time
38-
// but the underlying cache data is shared
39-
resolverCache2 := Get(ctx)
40-
if resolverCache2 == nil {
41-
t.Error("Expected resolver cache but got nil on second call")
42-
}
43-
}
44-
4529
func TestGetWithContextValue(t *testing.T) {
4630
logger := logtesting.TestLogger(t)
4731
ctx := t.Context()
@@ -61,17 +45,6 @@ func TestGetWithContextValue(t *testing.T) {
6145
}
6246
}
6347

64-
func TestGetFallback(t *testing.T) {
65-
// Create a plain context without any injected cache
66-
ctx := logtesting.TestContextWithLogger(t)
67-
68-
// Should fall back to shared cache
69-
resolverCache := Get(ctx)
70-
if resolverCache == nil {
71-
t.Error("Expected resolver cache but got nil")
72-
}
73-
}
74-
7548
func TestCacheSharing(t *testing.T) {
7649
// Create two different contexts
7750
ctx1 := logtesting.TestContextWithLogger(t)
@@ -89,10 +62,23 @@ func TestCacheSharing(t *testing.T) {
8962
t.Fatal("Expected cache from ctx2")
9063
}
9164

92-
// Both contexts should share the same underlying cache storage
93-
// even though they have different logger wrappers
94-
// We can verify this by checking they're both non-nil and functional
95-
if cache1 == nil || cache2 == nil {
96-
t.Error("Cache instances should be available from both contexts")
65+
// Verify they share the same underlying cache storage by adding data
66+
// to cache1 and checking it appears in cache2
67+
testParams := []pipelinev1.Param{
68+
{Name: "url", Value: pipelinev1.ParamValue{Type: pipelinev1.ParamTypeString, StringVal: "https://example.com"}},
69+
}
70+
testResource := &mockResolvedResource{data: []byte("test-data")}
71+
72+
// Add to cache1
73+
cache1.Add("test-resolver", testParams, testResource)
74+
75+
// Verify it exists in cache2 (proving they share the same underlying storage)
76+
retrieved, found := cache2.Get("test-resolver", testParams)
77+
if !found {
78+
t.Fatal("Expected to find resource in cache2 that was added to cache1 - caches are not shared")
79+
}
80+
81+
if string(retrieved.Data()) != string(testResource.Data()) {
82+
t.Errorf("Expected data %q, got %q", string(testResource.Data()), string(retrieved.Data()))
9783
}
9884
}

pkg/remoteresolution/resolver/framework/controller.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,8 +121,8 @@ func watchCacheConfigChanges(ctx context.Context, reconciler *Reconciler, cmw co
121121
return
122122
}
123123

124-
reconciler.cacheConfigStore = rrcache.NewCacheConfigStore(cacheConfigName, logger)
125-
reconciler.cacheConfigStore.WatchConfigs(cmw)
124+
cacheConfigStore := rrcache.NewCacheConfigStore(cacheConfigName, logger)
125+
cacheConfigStore.WatchConfigs(cmw)
126126
}
127127

128128
// applyModifiersAndDefaults applies the given modifiers to

pkg/remoteresolution/resolver/framework/reconciler.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,7 @@ type Reconciler struct {
7676
resolutionRequestLister rrv1beta1.ResolutionRequestLister
7777
resolutionRequestClientSet rrclient.Interface
7878

79-
configStore *framework.ConfigStore
80-
cacheConfigStore *rrcache.CacheConfigStore
79+
configStore *framework.ConfigStore
8180
}
8281

8382
var _ reconciler.LeaderAware = &Reconciler{}

test/resolver_cache_test.go

Lines changed: 0 additions & 131 deletions
Original file line numberDiff line numberDiff line change
@@ -244,33 +244,6 @@ spec:
244244
`, name, namespace, repo, taskName, cacheMode))
245245
}
246246

247-
func createGitTaskRun(t *testing.T, namespace, name, revision string) *v1.TaskRun {
248-
t.Helper()
249-
return parse.MustParseV1TaskRun(t, fmt.Sprintf(`
250-
metadata:
251-
name: %s
252-
namespace: %s
253-
spec:
254-
workspaces:
255-
- name: output
256-
emptyDir: {}
257-
taskRef:
258-
resolver: git
259-
params:
260-
- name: url
261-
value: https://github.com/tektoncd/catalog.git
262-
- name: pathInRepo
263-
value: task/git-clone/0.10/git-clone.yaml
264-
- name: revision
265-
value: %s
266-
params:
267-
- name: url
268-
value: https://github.com/tektoncd/pipeline
269-
- name: deleteExisting
270-
value: "true"
271-
`, name, namespace, revision))
272-
}
273-
274247
func createGitTaskRunWithCache(t *testing.T, namespace, name, revision, cacheMode string) *v1.TaskRun {
275248
t.Helper()
276249
return parse.MustParseV1TaskRun(t, fmt.Sprintf(`
@@ -760,107 +733,3 @@ func createTaskRunAndWait(ctx context.Context, t *testing.T, c *clients, tr *v1.
760733
t.Fatalf("Error waiting for TaskRun %s to finish: %s", tr.Name, err)
761734
}
762735
}
763-
764-
// getImageDigest gets the digest of an image from the local registry
765-
func getImageDigest(ctx context.Context, t *testing.T, c *clients, namespace, imageRef string) string {
766-
t.Helper()
767-
768-
// Create a pod to run skopeo inspect
769-
podName := "get-digest-" + helpers.ObjectNameForTest(t)
770-
po, err := c.KubeClient.CoreV1().Pods(namespace).Create(ctx, &corev1.Pod{
771-
ObjectMeta: metav1.ObjectMeta{
772-
Namespace: namespace,
773-
Name: podName,
774-
},
775-
Spec: corev1.PodSpec{
776-
Containers: []corev1.Container{{
777-
Name: "skopeo",
778-
Image: "ghcr.io/tektoncd/catalog/upstream/tasks/skopeo-copy:latest",
779-
Command: []string{"/bin/sh", "-c"},
780-
Args: []string{"skopeo inspect --tls-verify=false docker://" + imageRef + " | jq -r '.Digest'"},
781-
}},
782-
RestartPolicy: corev1.RestartPolicyNever,
783-
},
784-
}, metav1.CreateOptions{})
785-
if err != nil {
786-
t.Fatalf("Failed to create digest pod: %v", err)
787-
}
788-
789-
// Wait for pod to complete
790-
if err := WaitForPodState(ctx, c, po.Name, namespace, func(pod *corev1.Pod) (bool, error) {
791-
return pod.Status.Phase == "Succeeded", nil
792-
}, "PodContainersTerminated"); err != nil {
793-
req := c.KubeClient.CoreV1().Pods(namespace).GetLogs(po.GetName(), &corev1.PodLogOptions{Container: "skopeo"})
794-
logs, err := req.DoRaw(ctx)
795-
if err != nil {
796-
t.Fatalf("Error getting pod logs: %v", err)
797-
}
798-
t.Fatalf("Failed to get digest. Pod logs: \n%s", string(logs))
799-
}
800-
801-
// Get the digest from pod logs
802-
req := c.KubeClient.CoreV1().Pods(namespace).GetLogs(po.GetName(), &corev1.PodLogOptions{Container: "skopeo"})
803-
logs, err := req.DoRaw(ctx)
804-
if err != nil {
805-
t.Fatalf("Error getting pod logs: %v", err)
806-
}
807-
808-
digest := strings.TrimSpace(string(logs))
809-
if digest == "" {
810-
t.Fatalf("Empty digest returned")
811-
}
812-
813-
return digest
814-
}
815-
816-
// getGitCommitHash gets the commit hash for a branch in the catalog repository
817-
func getGitCommitHash(ctx context.Context, t *testing.T, c *clients, namespace, branch string) string {
818-
t.Helper()
819-
820-
// Create a pod to run git ls-remote
821-
podName := "get-commit-" + helpers.ObjectNameForTest(t)
822-
po, err := c.KubeClient.CoreV1().Pods(namespace).Create(ctx, &corev1.Pod{
823-
ObjectMeta: metav1.ObjectMeta{
824-
Namespace: namespace,
825-
Name: podName,
826-
},
827-
Spec: corev1.PodSpec{
828-
Containers: []corev1.Container{{
829-
Name: "git",
830-
Image: "alpine/git:latest",
831-
Command: []string{"/bin/sh", "-c"},
832-
Args: []string{"git ls-remote https://github.com/tektoncd/catalog.git " + branch + " | cut -f1"},
833-
}},
834-
RestartPolicy: corev1.RestartPolicyNever,
835-
},
836-
}, metav1.CreateOptions{})
837-
if err != nil {
838-
t.Fatalf("Failed to create git pod: %v", err)
839-
}
840-
841-
// Wait for pod to complete
842-
if err := WaitForPodState(ctx, c, po.Name, namespace, func(pod *corev1.Pod) (bool, error) {
843-
return pod.Status.Phase == "Succeeded", nil
844-
}, "PodContainersTerminated"); err != nil {
845-
req := c.KubeClient.CoreV1().Pods(namespace).GetLogs(po.GetName(), &corev1.PodLogOptions{Container: "git"})
846-
logs, err := req.DoRaw(ctx)
847-
if err != nil {
848-
t.Fatalf("Error getting pod logs: %v", err)
849-
}
850-
t.Fatalf("Failed to get commit hash. Pod logs: \n%s", string(logs))
851-
}
852-
853-
// Get the commit hash from pod logs
854-
req := c.KubeClient.CoreV1().Pods(namespace).GetLogs(po.GetName(), &corev1.PodLogOptions{Container: "git"})
855-
logs, err := req.DoRaw(ctx)
856-
if err != nil {
857-
t.Fatalf("Error getting pod logs: %v", err)
858-
}
859-
860-
commitHash := strings.TrimSpace(string(logs))
861-
if commitHash == "" {
862-
t.Fatalf("Empty commit hash returned")
863-
}
864-
865-
return commitHash
866-
}

0 commit comments

Comments
 (0)