Skip to content

Commit

Permalink
Fix failing Test_WorkspaceListener integration test.
Browse files Browse the repository at this point in the history
Signed-off-by: Thomas Hallgren <[email protected]>
  • Loading branch information
thallgren committed Oct 29, 2024
1 parent 10c09f1 commit 9f03665
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 7 deletions.
23 changes: 21 additions & 2 deletions cmd/traffic/cmd/manager/mutator/workload_state.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ func deploymentState(d *appsv1.Deployment) WorkloadState {
sort.Slice(conds, func(i, j int) bool {
return conds[i].LastTransitionTime.Compare(conds[j].LastTransitionTime.Time) > 0
})
for _, c := range d.Status.Conditions {
for _, c := range conds {
switch c.Type {
case appsv1.DeploymentProgressing:
if c.Status == core.ConditionTrue {
Expand All @@ -40,6 +40,9 @@ func deploymentState(d *appsv1.Deployment) WorkloadState {
}
}
}
if len(conds) == 0 {
return WorkloadStateProgressing
}
return WorkloadStateUnknown
}

Expand All @@ -52,7 +55,7 @@ func replicaSetState(d *appsv1.ReplicaSet) WorkloadState {
return WorkloadStateAvailable
}

func statefulSetState(d *appsv1.StatefulSet) WorkloadState {
func statefulSetState(_ *appsv1.StatefulSet) WorkloadState {
return WorkloadStateAvailable
}

Expand All @@ -77,9 +80,25 @@ func rolloutSetState(r *argorollouts.Rollout) WorkloadState {
}
}
}
if len(conds) == 0 {
return WorkloadStateProgressing
}
return WorkloadStateUnknown
}

func (ws WorkloadState) String() string {
switch ws {
case WorkloadStateProgressing:
return "Progressing"
case WorkloadStateAvailable:
return "Available"
case WorkloadStateFailure:
return "Failure"
default:
return "Unknown"
}
}

func GetWorkloadState(wl k8sapi.Workload) WorkloadState {
if d, ok := k8sapi.DeploymentImpl(wl); ok {
return deploymentState(d)
Expand Down
15 changes: 10 additions & 5 deletions cmd/traffic/cmd/manager/state/workload_info_watcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ func (wf *workloadInfoWatcher) handleWorkloadsSnapshot(ctx context.Context, wes
if w, ok := wf.workloadEvents[wl.GetName()]; ok {
if we.Type == workload.EventTypeDelete && w.Type != rpc.WorkloadEvent_DELETED {
w.Type = rpc.WorkloadEvent_DELETED
dlog.Debugf(ctx, "WorkloadInfoEvent: Workload %s %s %s.%s", we.Type, wl.GetKind(), wl.GetName(), wl.GetNamespace())
dlog.Debugf(ctx, "WorkloadInfoEvent: Workload %s %s %s.%s %s", we.Type, wl.GetKind(), wl.GetName(), wl.GetNamespace(), mutator.GetWorkloadState(wl))
wf.resetTicker()
}
} else {
Expand All @@ -247,7 +247,7 @@ func (wf *workloadInfoWatcher) handleWorkloadsSnapshot(ctx context.Context, wes
break
}
}
dlog.Debugf(ctx, "WorkloadInfoEvent: Workload %s %s %s.%s %s", we.Type, wl.GetKind(), wl.GetName(), wl.GetNamespace(), as)
dlog.Debugf(ctx, "WorkloadInfoEvent: Workload %s %s %s.%s %s %s", we.Type, wl.GetKind(), wl.GetName(), wl.GetNamespace(), as, mutator.GetWorkloadState(wl))
wf.addEvent(we.Type, wl, as, iClients)
}
}
Expand All @@ -260,14 +260,15 @@ func (wf *workloadInfoWatcher) handleAgentSnapshot(ctx context.Context, ais map[
if _, ok := ais[k]; !ok {
name := a.Name
as := rpc.WorkloadInfo_NO_AGENT_UNSPECIFIED
dlog.Debugf(ctx, "WorkloadInfoEvent: AgentInfo %s.%s %s", a.Name, a.Namespace, as)
if w, ok := wf.workloadEvents[name]; ok && w.Type != rpc.WorkloadEvent_DELETED {
wl := w.Workload
if wl.AgentState != as {
wl.AgentState = as
dlog.Debugf(ctx, "WorkloadInfoEvent: AgentInfo %s.%s %s %s", a.Name, a.Namespace, as, wl.State)
wf.resetTicker()
}
} else if wl, err := agentmap.GetWorkload(ctx, name, a.Namespace, ""); err == nil {
dlog.Debugf(ctx, "WorkloadInfoEvent: AgentInfo %s.%s %s %s", a.Name, a.Namespace, as, mutator.GetWorkloadState(wl))
wf.addEvent(workload.EventTypeUpdate, wl, as, nil)
} else {
dlog.Debugf(ctx, "Unable to get workload %s.%s: %v", name, a.Namespace, err)
Expand All @@ -293,15 +294,16 @@ func (wf *workloadInfoWatcher) handleAgentSnapshot(ctx context.Context, ais map[
as = rpc.WorkloadInfo_INTERCEPTED
iClients = iis
}
dlog.Debugf(ctx, "WorkloadInfoEvent: AgentInfo %s.%s %s", a.Name, a.Namespace, as)
if w, ok := wf.workloadEvents[name]; ok && w.Type != rpc.WorkloadEvent_DELETED {
wl := w.Workload
dlog.Debugf(ctx, "WorkloadInfoEvent: AgentInfo %s.%s %s %s", a.Name, a.Namespace, as, w.Workload.State)
if wl.AgentState != as {
wl.AgentState = as
wl.InterceptClients = iClients
wf.resetTicker()
}
} else if wl, err := agentmap.GetWorkload(ctx, name, a.Namespace, ""); err == nil {
dlog.Debugf(ctx, "WorkloadInfoEvent: AgentInfo %s.%s %s %s", a.Name, a.Namespace, as, mutator.GetWorkloadState(wl))
wf.addEvent(workload.EventTypeUpdate, wl, as, iClients)
} else {
dlog.Debugf(ctx, "Unable to get workload %s.%s: %v", name, a.Namespace, err)
Expand All @@ -316,14 +318,15 @@ func (wf *workloadInfoWatcher) handleInterceptSnapshot(ctx context.Context, iis
if _, ok := wf.interceptInfos[k]; !ok {
name := ii.Spec.Agent
as := rpc.WorkloadInfo_INSTALLED
dlog.Debugf(ctx, "InterceptInfo %s.%s %s", name, ii.Spec.Namespace, as)
if w, ok := wf.workloadEvents[name]; ok && w.Type != rpc.WorkloadEvent_DELETED {
if w.Workload.AgentState != as {
w.Workload.AgentState = as
w.Workload.InterceptClients = nil
dlog.Debugf(ctx, "WorkloadInfoEvent: InterceptInfo %s.%s %s %s", w.Workload.Name, w.Workload.Namespace, as, w.Workload.State)
wf.resetTicker()
}
} else if wl, err := agentmap.GetWorkload(ctx, name, wf.namespace, ""); err == nil {
dlog.Debugf(ctx, "WorkloadInfoEvent: InterceptInfo %s.%s %s %s", wl.GetName(), wl.GetNamespace(), as, mutator.GetWorkloadState(wl))
wf.addEvent(workload.EventTypeUpdate, wl, as, nil)
}
}
Expand All @@ -345,9 +348,11 @@ func (wf *workloadInfoWatcher) handleInterceptSnapshot(ctx context.Context, iis
if w.Workload.AgentState != as {
w.Workload.AgentState = as
w.Workload.InterceptClients = iClients
dlog.Debugf(ctx, "WorkloadInfoEvent: InterceptInfo %s.%s %s %s", w.Workload.Name, w.Workload.Namespace, as, w.Workload.State)
wf.resetTicker()
}
} else if wl, err := agentmap.GetWorkload(ctx, name, wf.namespace, ""); err == nil {
dlog.Debugf(ctx, "WorkloadInfoEvent: InterceptInfo %s.%s %s %s", wl.GetName(), wl.GetNamespace(), as, mutator.GetWorkloadState(wl))
wf.addEvent(workload.EventTypeUpdate, wl, as, iClients)
}
}
Expand Down
1 change: 1 addition & 0 deletions integration_test/workspace_watch_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ func (s *notConnectedSuite) Test_WorkspaceListener() {
expectations["agent installed"] = true
}
case manager.WorkloadInfo_INTERCEPTED:
expectations["agent installed"] = true
expectations["agent intercepted"] = true
if ics := ev.Workload.InterceptClients; len(ics) == 1 {
interceptingClient = ics[0].Client
Expand Down

0 comments on commit 9f03665

Please sign in to comment.