Skip to content

feat: clean stale provisioner files #9545

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

Merged
merged 27 commits into from
Sep 11, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
WIP
  • Loading branch information
mtojek committed Sep 6, 2023
commit 85a74cdc2f8f140920ccf96192e64f7dfee2298b
9 changes: 7 additions & 2 deletions provisioner/terraform/provision.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ import (
"github.com/coder/terraform-provider-coder/provider"
)

const staleTerraformPluginRetention = 30 * 24 * time.Hour

func (s *server) setupContexts(parent context.Context, canceledOrComplete <-chan struct{}) (
ctx context.Context, cancel func(), killCtx context.Context, kill func(),
) {
Expand Down Expand Up @@ -301,8 +303,11 @@ func cleanStaleTerraformPlugins(ctx context.Context, cachePath string, now time.
if err != nil {
return xerrors.Errorf("unable to evaluate latest access time for directory %q: %w", pluginPath, err)
}

if accessTime.Add(staleTerraformPluginRetention).Before(now) {
stalePlugins = append(stalePlugins, pluginPath)
}
}
// TODO

// Remove stale plugins
// TODO
Expand All @@ -314,5 +319,5 @@ func cleanStaleTerraformPlugins(ctx context.Context, cachePath string, now time.
}

func latestAccessTime(path string) (time.Time, error) {

// TODO
}
6 changes: 3 additions & 3 deletions provisionersdk/session.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ const (
// ReadmeFile is the location we look for to extract documentation from template versions.
ReadmeFile = "README.md"

sessionDirPrefix = "Session"
staleSessionDaysThreshold = 7 * 24 * time.Hour
sessionDirPrefix = "Session"
staleSessionRetention = 7 * 24 * time.Hour
)

// protoServer is a wrapper that translates the dRPC protocol into a Session with method calls into the Server.
Expand Down Expand Up @@ -347,7 +347,7 @@ func cleanStaleSessions(ctx context.Context, workDirectory string, now time.Time
}

timeSpec := times.Get(fi)
if timeSpec.AccessTime().Add(staleSessionDaysThreshold).After(now) {
if timeSpec.AccessTime().Add(staleSessionRetention).After(now) {
continue
}

Expand Down