Skip to content

Commit

Permalink
TEMP
Browse files Browse the repository at this point in the history
  • Loading branch information
jveski committed Dec 11, 2023
1 parent daad054 commit 4cde8ea
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 81 deletions.
5 changes: 2 additions & 3 deletions api/v1/composition.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,11 +50,10 @@ type ResourceInputRef struct {
}

type CompositionStatus struct {
CurrentState *Synthesis `json:"currentState,omitempty"`
PreviousState *Synthesis `json:"previousState,omitempty"`
Syntheses []*Synthesis `json:"syntheses,omitempty"`
}

// Synthesis represents a Synthesizer's specific synthesis of a given Composition.
// Synthesis represents a Synthesizer's synthesis of a Composition.
type Synthesis struct {
ObservedCompositionGeneration int64 `json:"observedCompositionGeneration,omitempty"`
ObservedSynthesizerGeneration int64 `json:"observedSynthesizerGeneration,omitempty"`
Expand Down
74 changes: 26 additions & 48 deletions api/v1/config/crd/eno.azure.io_compositions.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -72,54 +72,32 @@ spec:
type: object
status:
properties:
currentState:
description: Synthesis represents a Synthesizer's specific synthesis
of a given Composition.
properties:
observedCompositionGeneration:
format: int64
type: integer
observedSynthesizerGeneration:
format: int64
type: integer
podCreation:
format: date-time
type: string
ready:
type: boolean
resourceSliceCount:
description: Number of resulting resource slices. Since they are
immutable, this provides adequate timing signal to avoid stale
informer caches.
format: int64
type: integer
synced:
type: boolean
type: object
previousState:
description: Synthesis represents a Synthesizer's specific synthesis
of a given Composition.
properties:
observedCompositionGeneration:
format: int64
type: integer
observedSynthesizerGeneration:
format: int64
type: integer
podCreation:
format: date-time
type: string
ready:
type: boolean
resourceSliceCount:
description: Number of resulting resource slices. Since they are
immutable, this provides adequate timing signal to avoid stale
informer caches.
format: int64
type: integer
synced:
type: boolean
type: object
syntheses:
items:
description: Synthesis represents a Synthesizer's synthesis of a
Composition.
properties:
observedCompositionGeneration:
format: int64
type: integer
observedSynthesizerGeneration:
format: int64
type: integer
podCreation:
format: date-time
type: string
ready:
type: boolean
resourceSliceCount:
description: Number of resulting resource slices. Since they
are immutable, this provides adequate timing signal to avoid
stale informer caches.
format: int64
type: integer
synced:
type: boolean
type: object
type: array
type: object
type: object
served: true
Expand Down
19 changes: 10 additions & 9 deletions api/v1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions internal/controllers/synthesis/integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ import (
"github.com/Azure/eno/internal/testutil"
)

// TODO: Document that we never block forward movement

var minimalTestConfig = &Config{
WrapperImage: "test-wrapper-image",
MaxRestarts: 3,
Expand Down
23 changes: 12 additions & 11 deletions internal/controllers/synthesis/lifecycle.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ import (
"github.com/Azure/eno/internal/manager"
)

// TODO: some notes
// - We should be able to spawn more than one pod per composition concurrently
// - We should delete pods that are no longer needed
// - We should trim states that are no longer needed unless they've been generated

type Config struct {
WrapperImage string
JobSA string
Expand Down Expand Up @@ -83,17 +88,19 @@ func (c *podLifecycleController) Reconcile(ctx context.Context, req ctrl.Request
}

// Swap the state to prepare for resynthesis if needed
if comp.Status.CurrentState == nil || comp.Status.CurrentState.ObservedCompositionGeneration != comp.Generation {
swapStates(syn, comp)
if len(comp.Status.Syntheses) == 0 || comp.Status.Syntheses[0].ObservedCompositionGeneration != comp.Generation {
// TODO: Should we stop re-synthesis at a certain slice length?
comp.Status.Syntheses = append([]*apiv1.Synthesis{{ObservedCompositionGeneration: comp.Generation}}, comp.Status.Syntheses...)

if err := c.client.Status().Update(ctx, comp); err != nil {
return ctrl.Result{}, fmt.Errorf("swapping compisition state: %w", err)
}
logger.Info("swapped composition state because composition was modified since last synthesis")
logger.Info("started a new synthesis because the composition was modified since last synthesis")
return ctrl.Result{}, nil
}

// No need to create a pod if everything is in sync
if comp.Status.CurrentState != nil && comp.Status.CurrentState.ResourceSliceCount != nil {
if len(comp.Status.Syntheses) > 0 && comp.Status.Syntheses[0].ResourceSliceCount != nil {
return ctrl.Result{}, nil
}

Expand Down Expand Up @@ -128,6 +135,7 @@ func (c *podLifecycleController) shouldDeletePod(logger logr.Logger, comp *apiv1
}

// Only create pods when the previous one is deleting or non-existant
// TODO: Should we create pods for new generations?
for _, pod := range pods.Items {
pod := pod
reason, shouldDelete := c.podStatusTerminal(&pod)
Expand Down Expand Up @@ -183,10 +191,3 @@ func (c *podLifecycleController) podStatusTerminal(pod *corev1.Pod) (string, boo
}
return "", false // status not initialized yet
}

func swapStates(syn *apiv1.Synthesizer, comp *apiv1.Composition) {
comp.Status.PreviousState = comp.Status.CurrentState
comp.Status.CurrentState = &apiv1.Synthesis{
ObservedCompositionGeneration: comp.Generation,
}
}
18 changes: 8 additions & 10 deletions internal/controllers/synthesis/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,18 @@ func (c *statusController) Reconcile(ctx context.Context, req ctrl.Request) (ctr
compGen, _ = strconv.ParseInt(pod.Annotations["eno.azure.io/composition-generation"], 10, 0)
synGen, _ = strconv.ParseInt(pod.Annotations["eno.azure.io/synthesizer-generation"], 10, 0)
)
if statusIsOutOfSync(comp, compGen, synGen) {
comp.Status.CurrentState.PodCreation = &pod.CreationTimestamp
comp.Status.CurrentState.ObservedSynthesizerGeneration = synGen
for _, synthesis := range comp.Status.Syntheses {
// TODO: Should we allow retry pods to be created before old ones terminate?
if synthesis.ObservedCompositionGeneration != compGen || synthesis.PodCreation != nil && synthesis.ObservedSynthesizerGeneration != nil {

Check failure on line 76 in internal/controllers/synthesis/status.go

View workflow job for this annotation

GitHub Actions / Kubernetes 1.16

invalid operation: synthesis.ObservedSynthesizerGeneration != nil (mismatched types int64 and untyped nil)

Check failure on line 76 in internal/controllers/synthesis/status.go

View workflow job for this annotation

GitHub Actions / Kubernetes 1.24

invalid operation: synthesis.ObservedSynthesizerGeneration != nil (mismatched types int64 and untyped nil)

Check failure on line 76 in internal/controllers/synthesis/status.go

View workflow job for this annotation

GitHub Actions / Kubernetes 1.26

invalid operation: synthesis.ObservedSynthesizerGeneration != nil (mismatched types int64 and untyped nil)

Check failure on line 76 in internal/controllers/synthesis/status.go

View workflow job for this annotation

GitHub Actions / Kubernetes 1.28

invalid operation: synthesis.ObservedSynthesizerGeneration != nil (mismatched types int64 and untyped nil)

Check failure on line 76 in internal/controllers/synthesis/status.go

View workflow job for this annotation

GitHub Actions / Kubernetes 1.25

invalid operation: synthesis.ObservedSynthesizerGeneration != nil (mismatched types int64 and untyped nil)

Check failure on line 76 in internal/controllers/synthesis/status.go

View workflow job for this annotation

GitHub Actions / Kubernetes 1.12

invalid operation: synthesis.ObservedSynthesizerGeneration != nil (mismatched types int64 and untyped nil)

Check failure on line 76 in internal/controllers/synthesis/status.go

View workflow job for this annotation

GitHub Actions / Kubernetes 1.11

invalid operation: synthesis.ObservedSynthesizerGeneration != nil (mismatched types int64 and untyped nil)

Check failure on line 76 in internal/controllers/synthesis/status.go

View workflow job for this annotation

GitHub Actions / Kubernetes 1.22

invalid operation: synthesis.ObservedSynthesizerGeneration != nil (mismatched types int64 and untyped nil)

Check failure on line 76 in internal/controllers/synthesis/status.go

View workflow job for this annotation

GitHub Actions / Kubernetes 1.20

invalid operation: synthesis.ObservedSynthesizerGeneration != nil (mismatched types int64 and untyped nil)

Check failure on line 76 in internal/controllers/synthesis/status.go

View workflow job for this annotation

GitHub Actions / Kubernetes 1.17

invalid operation: synthesis.ObservedSynthesizerGeneration != nil (mismatched types int64 and untyped nil)

Check failure on line 76 in internal/controllers/synthesis/status.go

View workflow job for this annotation

GitHub Actions / Kubernetes 1.23

invalid operation: synthesis.ObservedSynthesizerGeneration != nil (mismatched types int64 and untyped nil)

Check failure on line 76 in internal/controllers/synthesis/status.go

View workflow job for this annotation

GitHub Actions / Kubernetes 1.19

invalid operation: synthesis.ObservedSynthesizerGeneration != nil (mismatched types int64 and untyped nil)

Check failure on line 76 in internal/controllers/synthesis/status.go

View workflow job for this annotation

GitHub Actions / Kubernetes 1.21

invalid operation: synthesis.ObservedSynthesizerGeneration != nil (mismatched types int64 and untyped nil)

Check failure on line 76 in internal/controllers/synthesis/status.go

View workflow job for this annotation

GitHub Actions / Kubernetes 1.13

invalid operation: synthesis.ObservedSynthesizerGeneration != nil (mismatched types int64 and untyped nil)

Check failure on line 76 in internal/controllers/synthesis/status.go

View workflow job for this annotation

GitHub Actions / Kubernetes 1.10

invalid operation: synthesis.ObservedSynthesizerGeneration != nil (mismatched types int64 and untyped nil)

Check failure on line 76 in internal/controllers/synthesis/status.go

View workflow job for this annotation

GitHub Actions / Kubernetes 1.14

invalid operation: synthesis.ObservedSynthesizerGeneration != nil (mismatched types int64 and untyped nil)

Check failure on line 76 in internal/controllers/synthesis/status.go

View workflow job for this annotation

GitHub Actions / Kubernetes 1.15

invalid operation: synthesis.ObservedSynthesizerGeneration != nil (mismatched types int64 and untyped nil)

Check failure on line 76 in internal/controllers/synthesis/status.go

View workflow job for this annotation

GitHub Actions / Kubernetes 1.27

invalid operation: synthesis.ObservedSynthesizerGeneration != nil (mismatched types int64 and untyped nil)
continue
}
synthesis.PodCreation = &pod.CreationTimestamp
synthesis.ObservedSynthesizerGeneration = synGen

if err := c.client.Status().Update(ctx, comp); err != nil {
return ctrl.Result{}, fmt.Errorf("updating composition status: %w", err)
}
logger.V(1).Info("added synthesizer pod status to its composition resource")
logger.V(1).Info("added synthesizer pod status to its composition resource", "compositionGeneration", compGen)
return ctrl.Result{}, nil
}

Expand All @@ -93,9 +97,3 @@ func (c *statusController) Reconcile(ctx context.Context, req ctrl.Request) (ctr

return ctrl.Result{}, nil
}

func statusIsOutOfSync(comp *apiv1.Composition, podCompGen, podSynGen int64) bool {
// TODO: Unit tests, make sure to cover the pod creation latching logic
return (comp.Status.CurrentState != nil && comp.Status.CurrentState.ObservedCompositionGeneration == podCompGen) &&
(comp.Status.CurrentState.PodCreation == nil || comp.Status.CurrentState.ObservedSynthesizerGeneration != podSynGen)
}

0 comments on commit 4cde8ea

Please sign in to comment.