Skip to content

Commit

Permalink
Merge pull request #349 from werf/fix/initial-resource-status-should-…
Browse files Browse the repository at this point in the history
…be-unknown-instead-of-created

fix: initial resource status should be "unknown" instead of "created"
  • Loading branch information
ilya-lesikov authored Dec 6, 2024
2 parents 6d4f29e + 5edd9e4 commit 0fc2d1a
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 2 deletions.
6 changes: 6 additions & 0 deletions pkg/trackers/dyntracker/dynamic_absence_tracker.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,12 @@ func (t *DynamicAbsenceTracker) Track(ctx context.Context) error {
return false, fmt.Errorf("get resource %q: %w", resourceHumanID, err)
}

t.taskState.RWTransaction(func(ats *statestore.AbsenceTaskState) {
ats.ResourceState().RWTransaction(func(rs *statestore.ResourceState) {
rs.SetStatus(statestore.ResourceStatusCreated)
})
})

return false, nil
}); err != nil {
return fmt.Errorf("poll resource %q: %w", resourceHumanID, err)
Expand Down
12 changes: 11 additions & 1 deletion pkg/trackers/dyntracker/dynamic_presence_tracker.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,17 @@ func (t *DynamicPresenceTracker) Track(ctx context.Context) error {

if err := wait.PollImmediate(t.pollPeriod, t.timeout, func() (bool, error) {
if _, err := resourceClient.Get(ctx, name, metav1.GetOptions{}); err != nil {
if apierrors.IsResourceExpired(err) || apierrors.IsGone(err) || err == io.EOF || err == io.ErrUnexpectedEOF || apierrors.IsNotFound(err) {
if apierrors.IsResourceExpired(err) || apierrors.IsGone(err) || err == io.EOF || err == io.ErrUnexpectedEOF {
return false, nil
}

if apierrors.IsNotFound(err) {
t.taskState.RWTransaction(func(pts *statestore.PresenceTaskState) {
pts.ResourceState().RWTransaction(func(rs *statestore.ResourceState) {
rs.SetStatus(statestore.ResourceStatusDeleted)
})
})

return false, nil
}

Expand Down
18 changes: 18 additions & 0 deletions pkg/trackers/dyntracker/dynamic_readiness_tracker.go
Original file line number Diff line number Diff line change
Expand Up @@ -237,6 +237,7 @@ func (t *DynamicReadinessTracker) trackDeployment(ctx context.Context, tracker *
t.taskState.RWTransaction(func(ts *statestore.ReadinessTaskState) {
t.handlePodsFromDeploymentStatus(&status, ts)
t.handleDeploymentStatus(&status, ts)
t.setRootResourceCreated(ts)
abort, abortErr = t.handleTaskStateStatus(ts)
})

Expand Down Expand Up @@ -370,6 +371,7 @@ func (t *DynamicReadinessTracker) trackStatefulSet(ctx context.Context, tracker
t.taskState.RWTransaction(func(ts *statestore.ReadinessTaskState) {
t.handlePodsFromStatefulSetStatus(&status, ts)
t.handleStatefulSetStatus(&status, ts)
t.setRootResourceCreated(ts)
abort, abortErr = t.handleTaskStateStatus(ts)
})

Expand Down Expand Up @@ -489,6 +491,7 @@ func (t *DynamicReadinessTracker) trackDaemonSet(ctx context.Context, tracker *d
t.taskState.RWTransaction(func(ts *statestore.ReadinessTaskState) {
t.handlePodsFromDaemonSetStatus(&status, ts)
t.handleDaemonSetStatus(&status, ts)
t.setRootResourceCreated(ts)
abort, abortErr = t.handleTaskStateStatus(ts)
})

Expand Down Expand Up @@ -608,6 +611,7 @@ func (t *DynamicReadinessTracker) trackJob(ctx context.Context, tracker *job.Tra
t.taskState.RWTransaction(func(ts *statestore.ReadinessTaskState) {
t.handlePodsFromJobStatus(&status, ts)
t.handleJobStatus(&status, ts)
t.setRootResourceCreated(ts)
abort, abortErr = t.handleTaskStateStatus(ts)
})

Expand Down Expand Up @@ -726,6 +730,7 @@ func (t *DynamicReadinessTracker) trackCanary(ctx context.Context, tracker *cana
)
t.taskState.RWTransaction(func(ts *statestore.ReadinessTaskState) {
t.handleCanaryStatus(&status, ts)
t.setRootResourceCreated(ts)
abort, abortErr = t.handleTaskStateStatus(ts)
})

Expand Down Expand Up @@ -811,6 +816,7 @@ func (t *DynamicReadinessTracker) trackGeneric(ctx context.Context, tracker *gen
)
t.taskState.RWTransaction(func(ts *statestore.ReadinessTaskState) {
t.handleGenericResourceStatus(status, ts)
t.setRootResourceCreated(ts)
abort, abortErr = t.handleTaskStateStatus(ts)
})

Expand Down Expand Up @@ -1273,6 +1279,18 @@ func (t *DynamicReadinessTracker) handleTaskStateStatus(taskState *statestore.Re
return abort, abortErr
}

func (t *DynamicReadinessTracker) setRootResourceCreated(taskState *statestore.ReadinessTaskState) {
rss := taskState.ResourceStates()

if len(rss) == 0 {
return
}

rss[0].RWTransaction(func(rs *statestore.ResourceState) {
rs.SetStatus(statestore.ResourceStatusCreated)
})
}

func setReplicasAttribute(resourceState *statestore.ResourceState, replicas int) {
attributes := resourceState.Attributes()

Expand Down
2 changes: 1 addition & 1 deletion pkg/trackers/dyntracker/statestore/resource_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func NewResourceState(name, namespace string, groupVersionKind schema.GroupVersi
name: name,
namespace: namespace,
groupVersionKind: groupVersionKind,
status: ResourceStatusCreated,
status: ResourceStatusUnknown,
errors: make(map[string][]*Error),
}
}
Expand Down
1 change: 1 addition & 0 deletions pkg/trackers/dyntracker/statestore/resource_status.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package statestore
type ResourceStatus string

const (
ResourceStatusUnknown ResourceStatus = "unknown"
ResourceStatusReady ResourceStatus = "ready"
ResourceStatusCreated ResourceStatus = "created"
ResourceStatusDeleted ResourceStatus = "deleted"
Expand Down

0 comments on commit 0fc2d1a

Please sign in to comment.