Skip to content

[installer] Actually add 'inactivityPeriodForReposInDays' to server configmap #14177

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 4 commits into from
Oct 26, 2022
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
9 changes: 5 additions & 4 deletions components/server/ee/src/prebuilds/prebuild-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -406,17 +406,18 @@ export class PrebuildManager {

private async shouldSkipInactiveRepository(ctx: TraceContext, cloneURL: string): Promise<boolean> {
const span = TraceContext.startSpan("shouldSkipInactiveRepository", ctx);
const { inactivityPeriodForRepos } = this.config;
if (!inactivityPeriodForRepos) {
// skipping is disabled if `inactivityPeriodForRepos` is not set
const { inactivityPeriodForReposInDays } = this.config;
if (!inactivityPeriodForReposInDays) {
// skipping is disabled if `inactivityPeriodForReposInDays` is not set
span.finish();
return false;
}
try {
return (
(await this.workspaceDB
.trace({ span })
.getWorkspaceCountByCloneURL(cloneURL, inactivityPeriodForRepos /* in days */, "regular")) === 0
.getWorkspaceCountByCloneURL(cloneURL, inactivityPeriodForReposInDays /* in days */, "regular")) ===
0
);
} catch (error) {
log.error("cannot compute activity for repository", { cloneURL }, error);
Expand Down
14 changes: 7 additions & 7 deletions components/server/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export type Config = Omit<
stripeSecrets?: { publishableKey: string; secretKey: string };
stripeConfig?: StripeConfig;
builtinAuthProvidersConfigured: boolean;
inactivityPeriodForRepos?: number;
inactivityPeriodForReposInDays?: number;
};

export interface WorkspaceDefaults {
Expand Down Expand Up @@ -203,7 +203,7 @@ export interface ConfigSerialized {
* If a numeric value interpreted as days is set, repositories not beeing opened with Gitpod are
* considered inactive.
*/
inactivityPeriodForRepos?: number;
inactivityPeriodForReposInDays?: number;

/**
* Supported workspace classes
Expand Down Expand Up @@ -285,10 +285,10 @@ export namespace ConfigFile {
if (licenseFile) {
license = fs.readFileSync(filePathTelepresenceAware(licenseFile), "utf-8");
}
let inactivityPeriodForRepos: number | undefined;
if (typeof config.inactivityPeriodForRepos === "number") {
if (config.inactivityPeriodForRepos >= 1) {
inactivityPeriodForRepos = config.inactivityPeriodForRepos;
let inactivityPeriodForReposInDays: number | undefined;
if (typeof config.inactivityPeriodForReposInDays === "number") {
if (config.inactivityPeriodForReposInDays >= 1) {
inactivityPeriodForReposInDays = config.inactivityPeriodForReposInDays;
}
}

Expand Down Expand Up @@ -320,7 +320,7 @@ export namespace ConfigFile {
? new Date(config.workspaceGarbageCollection.startDate).getTime()
: Date.now(),
},
inactivityPeriodForRepos,
inactivityPeriodForReposInDays,
};
}
}
5 changes: 3 additions & 2 deletions install/installer/cmd/testdata/render/aws-setup/output.golden

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions install/installer/cmd/testdata/render/gcp-setup/output.golden

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions install/installer/cmd/testdata/render/minimal/output.golden

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 3 additions & 2 deletions install/installer/cmd/testdata/render/shortname/output.golden

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 10 additions & 1 deletion install/installer/pkg/components/server/configmap.go
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,14 @@ func configmap(ctx *common.RenderContext) ([]runtime.Object, error) {
return nil
})

inactivityPeriodForReposInDays := 0
_ = ctx.WithExperimental(func(cfg *experimental.Config) error {
if cfg.WebApp != nil && cfg.WebApp.Server != nil && cfg.WebApp.Server.InactivityPeriodForReposInDays != nil {
inactivityPeriodForReposInDays = *cfg.WebApp.Server.InactivityPeriodForReposInDays
}
return nil
})

// todo(sje): all these values are configurable
scfg := ConfigSerialized{
Version: ctx.VersionManifest.Version,
Expand Down Expand Up @@ -263,7 +271,8 @@ func configmap(ctx *common.RenderContext) ([]runtime.Object, error) {
// default limit for all cloneURLs
"*": 50,
},
WorkspaceClasses: workspaceClasses,
WorkspaceClasses: workspaceClasses,
InactivityPeriodForReposInDays: inactivityPeriodForReposInDays,
}

fc, err := common.ToJSONString(scfg)
Expand Down
5 changes: 3 additions & 2 deletions install/installer/pkg/components/server/types.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,9 @@ type ConfigSerialized struct {
CodeSync CodeSync `json:"codeSync"`
// PrebuildLimiter defines the number of prebuilds allowed for each cloneURL in a given 1 minute interval
// Key of "*" defines the default limit, unless there exists a cloneURL in the map which overrides it.
PrebuildLimiter map[string]int `json:"prebuildLimiter"`
WorkspaceClasses []WorkspaceClass `json:"workspaceClasses"`
PrebuildLimiter map[string]int `json:"prebuildLimiter"`
WorkspaceClasses []WorkspaceClass `json:"workspaceClasses"`
InactivityPeriodForReposInDays int `json:"inactivityPeriodForReposInDays"`
}
type CodeSyncResources struct {
RevLimit int32 `json:"revLimit"`
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,7 @@ type ServerConfig struct {
EnableLocalApp *bool `json:"enableLocalApp"`
RunDbDeleter *bool `json:"runDbDeleter"`
DisableWorkspaceGarbageCollection bool `json:"disableWorkspaceGarbageCollection"`
InactivityPeriodForReposInDays *int `json:"inactivityPeriodForReposInDays"`

// @deprecated use containerRegistry.privateBaseImageAllowList instead
DefaultBaseImageRegistryWhiteList []string `json:"defaultBaseImageRegistryWhitelist"`
Expand Down