Skip to content

Commit 5be29ac

Browse files
committed
docs: describe cache interfaces in the comments themselves
Drop ticket and process notes so type and test comments state the adapter split, who owns each capability, and what each test asserts. Build the sensitive-path index test with sensitive.PathIndex after the rebase. Signed-off-by: Markus Vahlenkamp <markus.vahlenkamp@nokia.com>
1 parent 6194619 commit 5be29ac

14 files changed

Lines changed: 57 additions & 95 deletions

‎pkg/cache/cache.go‎

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -21,39 +21,32 @@ import (
2121
"github.com/sdcio/sdc-protos/tree_persist"
2222
)
2323

24-
// IntentReader reads real Intents. Every backend implements this directly —
25-
// it's the one capability every Cache.Type genuinely has data for.
24+
// IntentReader reads real Intents. Every cache backend implements it.
2625
type IntentReader interface {
2726
InstanceIntentsList(ctx context.Context, cacheInstanceName string) ([]string, error)
2827
InstanceIntentGet(ctx context.Context, cacheName string, intentName string) (importer.IntentAdapter, error)
2928
InstanceIntentExists(ctx context.Context, cacheName string, intentName string) (bool, error)
3029
InstanceIntentGetAll(ctx context.Context, cacheName string, excludeIntentNames []string, intentChan chan<- importer.IntentAdapter, errChan chan<- error)
3130
}
3231

33-
// IntentWriter persists real Intents. Backends that don't own real-Intent
34-
// writes (e.g. config-server, where kube-api owns them) compose a no-op
35-
// implementation instead of implementing this directly, so the type system
36-
// makes that lack of ownership visible.
32+
// IntentWriter persists real Intents. A backend that does not own those
33+
// writes (config-server: kube-api writes them) composes noopIntentWriter.
3734
type IntentWriter interface {
3835
InstanceIntentModify(ctx context.Context, cacheName string, intent *tree_persist.Intent) error
3936
InstanceIntentDelete(ctx context.Context, cacheName string, intentName string, IgnoreNonExisting bool) error
4037
}
4138

42-
// RunningStore reads/writes "running": split out of the generic Intent
43-
// surface, independent of Cache.Type. LocalCache keeps its existing
44-
// disk-backed store for it (unchanged on-disk behavior); other backends may
45-
// back it however they see fit (e.g. purely in-memory), since it's never
46-
// config-server's data to begin with.
39+
// RunningStore reads and writes "running", the synced device-state intent.
40+
// It is independent of Cache.Type: LocalCache keeps it on disk; other
41+
// backends may keep it in memory.
4742
type RunningStore interface {
4843
InstanceRunningGet(ctx context.Context, cacheName string) (importer.ImportConfigAdapter, error)
4944
InstanceRunningModify(ctx context.Context, cacheName string, intent *tree_persist.Intent) error
5045
}
5146

52-
// InstanceLifecycle creates/destroys/enumerates cache instances. Under
53-
// ConfigServerCache this only ever governs its in-memory running store — it
54-
// has no relationship to whether real-Intent data exists for a target under
55-
// that backend, unlike LocalCache where it governs the one shared disk store
56-
// underlying everything.
47+
// InstanceLifecycle creates, closes, and enumerates cache instances.
48+
// On a config-server backend this covers only the in-memory running store,
49+
// not whether real Intent data exists for a target.
5750
type InstanceLifecycle interface {
5851
InstanceCreate(ctx context.Context, cacheInstanceName string) error
5952
InstanceDelete(ctx context.Context, cacheInstanceName string) error
@@ -62,6 +55,8 @@ type InstanceLifecycle interface {
6255
InstancesList(ctx context.Context) []string
6356
}
6457

58+
// Client is a full cache backend: intent read and write, running, and
59+
// instance lifecycle.
6560
type Client interface {
6661
IntentReader
6762
IntentWriter

‎pkg/cache/cacheClientBound.go‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,34 +21,35 @@ import (
2121
"github.com/sdcio/sdc-protos/tree_persist"
2222
)
2323

24-
// BoundIntentReader is the bound-call equivalent of IntentReader.
24+
// BoundIntentReader is IntentReader scoped to one cache instance.
2525
type BoundIntentReader interface {
2626
IntentsList(ctx context.Context) ([]string, error)
2727
IntentGet(ctx context.Context, intentName string) (importer.IntentAdapter, error)
2828
IntentExists(ctx context.Context, intentName string) (bool, error)
2929
IntentGetAll(ctx context.Context, excludeIntentNames []string, intentChan chan<- importer.IntentAdapter, errChan chan<- error)
3030
}
3131

32-
// BoundIntentWriter is the bound-call equivalent of IntentWriter.
32+
// BoundIntentWriter is IntentWriter scoped to one cache instance.
3333
type BoundIntentWriter interface {
3434
IntentModify(ctx context.Context, intent *tree_persist.Intent) error
3535
IntentDelete(ctx context.Context, intentName string, IgnoreNonExisting bool) error
3636
}
3737

38-
// BoundRunningStore is the bound-call equivalent of RunningStore.
38+
// BoundRunningStore is RunningStore scoped to one cache instance.
3939
type BoundRunningStore interface {
4040
RunningGet(ctx context.Context) (importer.ImportConfigAdapter, error)
4141
RunningModify(ctx context.Context, intent *tree_persist.Intent) error
4242
}
4343

44-
// BoundInstanceLifecycle is the bound-call equivalent of InstanceLifecycle.
44+
// BoundInstanceLifecycle is InstanceLifecycle scoped to one cache instance.
4545
type BoundInstanceLifecycle interface {
4646
InstanceCreate(ctx context.Context) error
4747
InstanceDelete(ctx context.Context) error
4848
InstanceClose(ctx context.Context) error
4949
InstanceExists(ctx context.Context) bool
5050
}
5151

52+
// CacheClientBound is Client with the cache instance already selected.
5253
type CacheClientBound interface {
5354
BoundIntentReader
5455
BoundIntentWriter

‎pkg/cache/cache_test.go‎

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,7 @@
1414

1515
package cache
1616

17-
// Compile-time assertions that the capability interfaces compose back into
18-
// Client with no change to its method surface, and that *LocalCache keeps
19-
// satisfying Client (and, by extension, all four capabilities) with zero
20-
// code changes.
17+
// *LocalCache satisfies Client and each capability.
2118
var (
2219
_ Client = (*LocalCache)(nil)
2320

@@ -27,9 +24,8 @@ var (
2724
_ InstanceLifecycle = (*LocalCache)(nil)
2825
)
2926

30-
// composedClient documents that Client is exactly the sum of the four
31-
// capabilities — nothing more, nothing less — from the perspective of any
32-
// caller assembling one from the parts.
27+
// composedClient is Client as the four capabilities, so a value assembled
28+
// from those parts still satisfies Client.
3329
type composedClient interface {
3430
IntentReader
3531
IntentWriter
@@ -40,9 +36,7 @@ type composedClient interface {
4036
var _ Client = composedClient(nil)
4137
var _ composedClient = Client(nil)
4238

43-
// Same compile-time shape check for the bound side: CacheClientBoundImpl
44-
// already implements every method needed, so it should keep satisfying
45-
// CacheClientBound and each bound capability with zero code changes.
39+
// *CacheClientBoundImpl satisfies CacheClientBound and each bound capability.
4640
var (
4741
_ CacheClientBound = (*CacheClientBoundImpl)(nil)
4842

‎pkg/cache/local.go‎

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,8 @@ type LocalCache struct {
4949
*cache.Cache
5050
}
5151

52-
// decodeIntent unmarshals the disk-backed store's raw bytes into a
53-
// *tree_persist.Intent and wraps it as an importer.IntentAdapter — the
54-
// shared decode step every InstanceIntentGet/InstanceIntentGetAll/
55-
// InstanceRunningGet call site needs. Running callers narrow to
56-
// ImportConfigAdapter at the RunningStore boundary.
52+
// decodeIntent unmarshals stored bytes into an IntentAdapter.
53+
// Running reads use the same bytes and narrow the result to ImportConfigAdapter.
5754
func (l *LocalCache) decodeIntent(b []byte) (importer.IntentAdapter, error) {
5855
result := &tree_persist.Intent{}
5956
if err := proto.Unmarshal(b, result); err != nil {
@@ -114,10 +111,7 @@ func (l *LocalCache) InstanceIntentModify(ctx context.Context, cacheName string,
114111
return l.Cache.InstanceIntentModify(ctx, cacheName, intent.GetIntentName(), b)
115112
}
116113

117-
// InstanceRunningGet and InstanceRunningModify are thin passthroughs to the same
118-
// disk-backed mechanism InstanceIntentGet/InstanceIntentModify already use, so the
119-
// local backend's on-disk behavior for "running" is unchanged by the split — it
120-
// simply becomes unreachable via the intent-name-keyed InstanceIntent* surface.
114+
// InstanceRunningGet loads "running" from the disk store under the running intent name.
121115
func (l *LocalCache) InstanceRunningGet(ctx context.Context, cacheName string) (importer.ImportConfigAdapter, error) {
122116
b, err := l.Cache.InstanceIntentGet(ctx, cacheName, consts.RunningIntentName)
123117
if err != nil {
@@ -126,6 +120,7 @@ func (l *LocalCache) InstanceRunningGet(ctx context.Context, cacheName string) (
126120
return l.decodeIntent(b)
127121
}
128122

123+
// InstanceRunningModify stores "running" on disk under the running intent name.
129124
func (l *LocalCache) InstanceRunningModify(ctx context.Context, cacheName string, intent *tree_persist.Intent) error {
130125
b, err := proto.Marshal(intent)
131126
if err != nil {

‎pkg/cache/local_test.go‎

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,8 @@ func newTestLocalCache(t *testing.T) *LocalCache {
2424
return lc
2525
}
2626

27-
// TestLocalCache_InstanceIntentGetRoundTrip verifies InstanceIntentModify/InstanceIntentGet
28-
// round-trip a *tree_persist.Intent through the disk-backed store — a regression check
29-
// pinning current decode behavior before extracting it into a shared helper.
27+
// TestLocalCache_InstanceIntentGetRoundTrip: InstanceIntentModify then
28+
// InstanceIntentGet returns the stored intent name and priority.
3029
func TestLocalCache_InstanceIntentGetRoundTrip(t *testing.T) {
3130
ctx := context.Background()
3231
lc := newTestLocalCache(t)
@@ -61,12 +60,8 @@ func TestLocalCache_InstanceIntentGetRoundTrip(t *testing.T) {
6160
}
6261
}
6362

64-
// TestLocalCache_RunningRoundTrip verifies InstanceRunningModify/InstanceRunningGet
65-
// are thin passthroughs to the same disk-backed store InstanceIntentGet/Modify use,
66-
// so the local backend's on-disk behavior for "running" is unchanged by the split.
67-
// InstanceRunningGet returns an importer.ImportConfigAdapter (Intent reads return
68-
// IntentAdapter) rather than the raw *tree_persist.Intent, so the assertions go
69-
// through its accessors.
63+
// TestLocalCache_RunningRoundTrip: InstanceRunningModify then InstanceRunningGet
64+
// returns the running intent through ImportConfigAdapter.
7065
func TestLocalCache_RunningRoundTrip(t *testing.T) {
7166
ctx := context.Background()
7267
lc := newTestLocalCache(t)
@@ -101,10 +96,8 @@ func TestLocalCache_RunningRoundTrip(t *testing.T) {
10196
}
10297
}
10398

104-
// TestLocalCache_RunningExcludedFromIntentGetAll verifies that once callers ask
105-
// for real intents via InstanceIntentGetAll with running explicitly excluded (the
106-
// pattern every real call site now uses), "running" never shows up, even though
107-
// LocalCache still persists it in the same underlying disk-backed store.
99+
// TestLocalCache_RunningExcludedFromIntentGetAll: excluding the running intent
100+
// name keeps it out of InstanceIntentGetAll, even though it shares the disk store.
108101
func TestLocalCache_RunningExcludedFromIntentGetAll(t *testing.T) {
109102
ctx := context.Background()
110103
lc := newTestLocalCache(t)

‎pkg/cache/noop_intent_writer.go‎

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,14 +20,8 @@ import (
2020
"github.com/sdcio/sdc-protos/tree_persist"
2121
)
2222

23-
// noopIntentWriter is a generic IntentWriter for backends that don't own
24-
// real-Intent writes (e.g. config-server, where kube-api is the sole
25-
// writer). It is composed into a full Client at the one legitimate
26-
// type-switch point, Server.createCacheClient, rather than living as
27-
// no-op-shaped methods inside the read-only backend's own type — that keeps
28-
// the backend's type signature honest about what it can actually do, and
29-
// gives any future read-only backend a name to compose instead of writing
30-
// its own no-op boilerplate.
23+
// noopIntentWriter is an IntentWriter whose modify and delete always succeed.
24+
// Read-only backends compose it when another system owns real-Intent writes.
3125
type noopIntentWriter struct{}
3226

3327
func (noopIntentWriter) InstanceIntentModify(ctx context.Context, cacheName string, intent *tree_persist.Intent) error {

‎pkg/cache/noop_intent_writer_test.go‎

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,7 @@ import (
2323

2424
var _ IntentWriter = noopIntentWriter{}
2525

26-
// TestNoopIntentWriter_AlwaysNil verifies InstanceIntentModify/
27-
// InstanceIntentDelete return nil unconditionally, regardless of input —
28-
// there is no backend to fail against, so there is no error path to
29-
// exercise.
26+
// TestNoopIntentWriter_AlwaysNil: modify and delete succeed for any input.
3027
func TestNoopIntentWriter_AlwaysNil(t *testing.T) {
3128
w := noopIntentWriter{}
3229
ctx := context.Background()

‎pkg/config/datastore.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,7 @@ func (c *CacheConfig) validateSetDefaults() error {
279279
c.Dir = defaultCacheDir
280280
}
281281
case cacheTypeConfigServer:
282-
// no connection settings yet; added by a follow-up ticket.
282+
// Known type; CacheConfig has no defaults for it.
283283
default:
284284
return fmt.Errorf("unknown cache type: %q", c.Type)
285285
}

‎pkg/datastore/datastore_rpc_test.go‎

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,15 @@ import (
77
"github.com/sdcio/data-server/mocks/mockcacheclient"
88
"github.com/sdcio/data-server/pkg/tree/importer"
99
treeproto "github.com/sdcio/data-server/pkg/tree/importer/proto"
10-
treetypes "github.com/sdcio/data-server/pkg/tree/types"
10+
"github.com/sdcio/data-server/pkg/tree/sensitive"
1111
sdcpb "github.com/sdcio/sdc-protos/sdcpb"
1212
"github.com/sdcio/sdc-protos/tree_persist"
1313
"go.uber.org/mock/gomock"
1414
)
1515

16-
// TestPopulateSensitivePathIndex_NarrowIntentReader verifies
17-
// populateSensitivePathIndex loads sensitive_paths from every intent that
18-
// declares them, skipping intents with none. It is built against a
19-
// MockBoundIntentReader — not the full MockCacheClientBound — since
20-
// populateSensitivePathIndex only ever reads real Intents via forEachIntent.
16+
// TestPopulateSensitivePathIndex_NarrowIntentReader loads sensitive paths from
17+
// intents that declare them and skips intents with none. The reader is a
18+
// BoundIntentReader; the index only needs intent reads.
2119
func TestPopulateSensitivePathIndex_NarrowIntentReader(t *testing.T) {
2220
ctx := context.Background()
2321
ctrl := gomock.NewController(t)
@@ -39,7 +37,7 @@ func TestPopulateSensitivePathIndex_NarrowIntentReader(t *testing.T) {
3937
close(errChan)
4038
})
4139

42-
s := treetypes.NewSensitivePathIndex()
40+
s := sensitive.NewPathIndex()
4341
if err := populateSensitivePathIndex(ctx, s, reader); err != nil {
4442
t.Fatalf("populateSensitivePathIndex() error = %v", err)
4543
}

‎pkg/datastore/sensitive_path_union_test.go‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -236,7 +236,7 @@ func TestGetIntent_CrossIntentPathsRedact(t *testing.T) {
236236
}
237237

238238
resp, err := ds.GetIntent(ctx, GetIntentOpts{
239-
IntentName: "data-intent",
239+
IntentName: "data-intent",
240240
NorthboundSensitivityOpts: NorthboundSensitivityOpts{IncludeSensitive: tt.exposeSensitive},
241241
})
242242
if err != nil {
@@ -320,7 +320,7 @@ func TestGetIntent_OwnSensitivePaths_Redacted(t *testing.T) {
320320
}
321321

322322
resp, err := ds.GetIntent(ctx, GetIntentOpts{
323-
IntentName: "data-intent",
323+
IntentName: "data-intent",
324324
NorthboundSensitivityOpts: NorthboundSensitivityOpts{IncludeSensitive: tt.exposeSensitive},
325325
})
326326
if err != nil {

0 commit comments

Comments
 (0)