diff --git a/internal/reconstitution/cache.go b/internal/reconstitution/cache.go index ad3dad7e..487b6232 100644 --- a/internal/reconstitution/cache.go +++ b/internal/reconstitution/cache.go @@ -51,7 +51,7 @@ func (c *cache) Get(ctx context.Context, ref *ResourceRef, gen int64) (*Resource func (c *cache) HasSynthesis(ctx context.Context, comp types.NamespacedName, synthesis *apiv1.Synthesis) bool { key := synthesisKey{ Composition: comp, - Generation: synthesis.ObservedGeneration, + Generation: synthesis.ObservedCompositionGeneration, } c.mut.Lock() @@ -74,7 +74,7 @@ func (c *cache) Fill(ctx context.Context, comp types.NamespacedName, synthesis * c.mut.Lock() defer c.mut.Unlock() - synKey := synthesisKey{Composition: comp, Generation: synthesis.ObservedGeneration} + synKey := synthesisKey{Composition: comp, Generation: synthesis.ObservedCompositionGeneration} c.resources[synKey] = resources c.synthesesByComposition[comp] = append(c.synthesesByComposition[comp], synKey.Generation) @@ -165,7 +165,7 @@ func (c *cache) Purge(ctx context.Context, compNSN types.NamespacedName, comp *a remainingSyns := []int64{} for _, syn := range c.synthesesByComposition[compNSN] { // Don't touch any syntheses still referenced by the composition - if comp != nil && ((comp.Status.CurrentState != nil && comp.Status.CurrentState.ObservedGeneration == syn) || (comp.Status.PreviousState != nil && comp.Status.PreviousState.ObservedGeneration == syn)) { + if comp != nil && ((comp.Status.CurrentState != nil && comp.Status.CurrentState.ObservedCompositionGeneration == syn) || (comp.Status.PreviousState != nil && comp.Status.PreviousState.ObservedCompositionGeneration == syn)) { remainingSyns = append(remainingSyns, syn) continue // still referenced by the Generation } diff --git a/internal/reconstitution/cache_test.go b/internal/reconstitution/cache_test.go index cfc1a578..3d9f471b 100644 --- a/internal/reconstitution/cache_test.go +++ b/internal/reconstitution/cache_test.go @@ -36,12 +36,12 @@ func TestCacheBasics(t *testing.T) { assert.True(t, c.HasSynthesis(ctx, comp, synth)) // negative - assert.False(t, c.HasSynthesis(ctx, comp, &apiv1.Synthesis{ObservedGeneration: 123})) + assert.False(t, c.HasSynthesis(ctx, comp, &apiv1.Synthesis{ObservedCompositionGeneration: 123})) }) t.Run("get", func(t *testing.T) { // positive - resource, exists := c.Get(ctx, &expectedReqs[0].ResourceRef, synth.ObservedGeneration) + resource, exists := c.Get(ctx, &expectedReqs[0].ResourceRef, synth.ObservedCompositionGeneration) require.True(t, exists) assert.NotEmpty(t, resource.Manifest) assert.Equal(t, "ConfigMap", resource.Object().GetKind()) @@ -56,7 +56,7 @@ func TestCacheBasics(t *testing.T) { c.Purge(ctx, comp, nil) // confirm - _, exists := c.Get(ctx, &expectedReqs[0].ResourceRef, synth.ObservedGeneration) + _, exists := c.Get(ctx, &expectedReqs[0].ResourceRef, synth.ObservedCompositionGeneration) assert.False(t, exists) assert.Len(t, c.resources, 0) @@ -103,7 +103,7 @@ func TestCacheSecret(t *testing.T) { assert.Equal(t, expectedReqs, reqs) // Confirm cache was filled correctly - resource, exists := c.Get(ctx, &expectedReqs[0].ResourceRef, synth.ObservedGeneration) + resource, exists := c.Get(ctx, &expectedReqs[0].ResourceRef, synth.ObservedCompositionGeneration) require.True(t, exists) assert.NotEmpty(t, resource.Manifest) assert.Equal(t, "ConfigMap", resource.Object().GetKind()) @@ -150,7 +150,7 @@ func TestCacheReconcileInterval(t *testing.T) { require.NoError(t, err) assert.Equal(t, expectedReqs, reqs) - resource, exists := c.Get(ctx, &expectedReqs[0].ResourceRef, synth.ObservedGeneration) + resource, exists := c.Get(ctx, &expectedReqs[0].ResourceRef, synth.ObservedCompositionGeneration) require.True(t, exists) assert.Equal(t, interval, resource.ReconcileInterval) } @@ -165,12 +165,12 @@ func TestCachePartialPurge(t *testing.T) { compNSN, synth, resources, _ := newCacheTestFixtures(3, 4) _, err := c.Fill(ctx, compNSN, synth, resources) require.NoError(t, err) - originalGen := synth.ObservedGeneration + originalGen := synth.ObservedCompositionGeneration // Add another resource to the composition but synthesized from a newer generation _, _, resources, expectedReqs := newCacheTestFixtures(1, 1) - synth.ObservedGeneration++ - resources[0].Spec.CompositionGeneration = synth.ObservedGeneration + synth.ObservedCompositionGeneration++ + resources[0].Spec.CompositionGeneration = synth.ObservedCompositionGeneration expectedReqs[0].Composition = compNSN _, err = c.Fill(ctx, compNSN, synth, resources) require.NoError(t, err) @@ -191,7 +191,7 @@ func TestCachePartialPurge(t *testing.T) { c.Purge(ctx, compNSN, comp) // The newer resource should still exist - _, exists := c.Get(ctx, &expectedReqs[0].ResourceRef, synth.ObservedGeneration) + _, exists := c.Get(ctx, &expectedReqs[0].ResourceRef, synth.ObservedCompositionGeneration) assert.True(t, exists) // The older resource is not referenced by the composition and should have been removed @@ -208,7 +208,7 @@ func TestCachePartialPurge(t *testing.T) { func newCacheTestFixtures(sliceCount, resPerSliceCount int) (types.NamespacedName, *apiv1.Synthesis, []apiv1.ResourceSlice, []*Request) { comp := types.NamespacedName{Namespace: string(uuid.NewUUID()), Name: string(uuid.NewUUID())} - synth := &apiv1.Synthesis{ObservedGeneration: 3} // just not 0 + synth := &apiv1.Synthesis{ObservedCompositionGeneration: 3} // just not 0 resources := make([]apiv1.ResourceSlice, sliceCount) requests := []*Request{} @@ -217,7 +217,7 @@ func newCacheTestFixtures(sliceCount, resPerSliceCount int) (types.NamespacedNam slice.Name = string(uuid.NewUUID()) slice.Namespace = "slice-ns" slice.Spec.Resources = make([]apiv1.Manifest, resPerSliceCount) - slice.Spec.CompositionGeneration = synth.ObservedGeneration + slice.Spec.CompositionGeneration = synth.ObservedCompositionGeneration for j := 0; j < resPerSliceCount; j++ { resource := &corev1.ConfigMap{} diff --git a/internal/reconstitution/reconstituter.go b/internal/reconstitution/reconstituter.go index 5565c433..fb136615 100644 --- a/internal/reconstitution/reconstituter.go +++ b/internal/reconstitution/reconstituter.go @@ -88,7 +88,7 @@ func (r *reconstituter) populateCache(ctx context.Context, comp *apiv1.Compositi } compNSN := types.NamespacedName{Namespace: comp.Namespace, Name: comp.Name} - logger = logger.WithValues("synthesisGen", synthesis.ObservedGeneration) + logger = logger.WithValues("synthesisGen", synthesis.ObservedCompositionGeneration) ctx = logr.NewContext(ctx, logger) if r.cache.HasSynthesis(ctx, compNSN, synthesis) { logger.V(1).Info("this synthesis has already been cached") @@ -97,7 +97,7 @@ func (r *reconstituter) populateCache(ctx context.Context, comp *apiv1.Compositi slices := &apiv1.ResourceSliceList{} err := r.client.List(ctx, slices, client.InNamespace(comp.Namespace), client.MatchingFields{ - manager.IdxSlicesByCompositionGeneration: manager.NewSlicesByCompositionGenerationKey(comp.Name, synthesis.ObservedGeneration), + manager.IdxSlicesByCompositionGeneration: manager.NewSlicesByCompositionGenerationKey(comp.Name, synthesis.ObservedCompositionGeneration), }) if err != nil { return fmt.Errorf("listing resource slices: %w", err) diff --git a/internal/reconstitution/reconstituter_test.go b/internal/reconstitution/reconstituter_test.go index ce6efbf6..a9e3f071 100644 --- a/internal/reconstitution/reconstituter_test.go +++ b/internal/reconstitution/reconstituter_test.go @@ -32,8 +32,8 @@ func TestReconstituterIntegration(t *testing.T) { one := int64(1) comp.Status.CurrentState = &apiv1.Synthesis{ - ObservedGeneration: comp.Generation, - ResourceSliceCount: &one, + ObservedCompositionGeneration: comp.Generation, + ResourceSliceCount: &one, } require.NoError(t, client.Status().Update(ctx, comp))