Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: initial resource status should be "unknown" instead of "created" #349

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading