MCPcopy Index your code
hub / github.com/coder/coder / processUpdatedContainersLocked

Method processUpdatedContainersLocked

agent/agentcontainers/api.go:905–1071  ·  view source on GitHub ↗

processUpdatedContainersLocked updates the devcontainer state based on the latest list of containers. This method assumes that api.mu is held.

(ctx context.Context, updated codersdk.WorkspaceAgentListContainersResponse)

Source from the content-addressed store, hash-verified

903// on the latest list of containers. This method assumes that api.mu is
904// held.
905func (api *API) processUpdatedContainersLocked(ctx context.Context, updated codersdk.WorkspaceAgentListContainersResponse) {
906 dcFields := func(dc codersdk.WorkspaceAgentDevcontainer) []slog.Field {
907 f := []slog.Field{
908 slog.F("devcontainer_id", dc.ID),
909 slog.F("devcontainer_name", dc.Name),
910 slog.F("workspace_folder", dc.WorkspaceFolder),
911 slog.F("config_path", dc.ConfigPath),
912 }
913 if dc.Container != nil {
914 f = append(f, slog.F("container_id", dc.Container.ID))
915 f = append(f, slog.F("container_name", dc.Container.FriendlyName))
916 }
917 return f
918 }
919
920 // Reset the container links in known devcontainers to detect if
921 // they still exist.
922 for _, dc := range api.knownDevcontainers {
923 dc.Container = nil
924 api.knownDevcontainers[dc.WorkspaceFolder] = dc
925 }
926
927 // Check if the container is running and update the known devcontainers.
928 for i := range updated.Containers {
929 container := &updated.Containers[i] // Grab a reference to the container to allow mutating it.
930
931 workspaceFolder := container.Labels[DevcontainerLocalFolderLabel]
932 configFile := container.Labels[DevcontainerConfigFileLabel]
933
934 if workspaceFolder == "" {
935 continue
936 }
937
938 logger := api.logger.With(
939 slog.F("container_id", updated.Containers[i].ID),
940 slog.F("container_name", updated.Containers[i].FriendlyName),
941 slog.F("workspace_folder", workspaceFolder),
942 slog.F("config_file", configFile),
943 )
944
945 // If we haven't set any include filters, we should explicitly ignore test devcontainers.
946 if len(api.containerLabelIncludeFilter) == 0 && container.Labels[DevcontainerIsTestRunLabel] == "true" {
947 continue
948 }
949
950 // Filter out devcontainer tests, unless explicitly set in include filters.
951 if len(api.containerLabelIncludeFilter) > 0 {
952 includeContainer := true
953 for label, value := range api.containerLabelIncludeFilter {
954 v, found := container.Labels[label]
955
956 includeContainer = includeContainer && (found && v == value)
957 }
958 // Verbose debug logging is fine here since typically filters
959 // are only used in development or testing environments.
960 if !includeContainer {
961 logger.Debug(ctx, "container does not match include filter, ignoring devcontainer", slog.F("container_labels", container.Labels), slog.F("include_filter", api.containerLabelIncludeFilter))
962 continue

Callers 1

updateContainersMethod · 0.95

Calls 5

makeAgentNameMethod · 0.95
AddMethod · 0.65
NewMethod · 0.65
ErrorMethod · 0.45

Tested by

no test coverage detected