Skip to content

Commit

Permalink
Merge pull request #965 from traPtitech/feat/auto-shutdown
Browse files Browse the repository at this point in the history
アクセスのない Runtime App を自動で落とせるようにする
  • Loading branch information
pirosiki197 authored Nov 18, 2024
2 parents dbbdcea + 5568226 commit 0bdfcca
Show file tree
Hide file tree
Showing 40 changed files with 2,361 additions and 2,918 deletions.
9 changes: 9 additions & 0 deletions .local-dev/config/ns.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,15 @@ components:
ipFamilies:
- IPv4
ipFamilyPolicy: SingleStack
middleware:
sablier:
enable: true
url: http://sablier.sablier.svc.cluster.local
sessionDuration: 5m
dynamic:
theme: ghost
blocking:
timeout: 1m
tls:
type: traefik
traefik:
Expand Down
7 changes: 7 additions & 0 deletions .local-dev/config/sablier.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
provider:
name: kubernetes
sessions:
default-duration: 5m
expiration-interval: 20s
logging:
level: trace
2 changes: 1 addition & 1 deletion .local-manifest/db/adminer-deployment.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@ spec:
value: nette
ports:
- name: http
containerPort: 80
containerPort: 8080
1 change: 1 addition & 0 deletions .local-manifest/kustomization.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,5 @@ resources:
- ns-apps
- ns-system
- registry
- sablier
- traefik
7 changes: 7 additions & 0 deletions .local-manifest/sablier/kustomization.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace: sablier
resources:
- sablier-service-account.yaml
- sablier-role.yaml
- sablier-role-binding.yaml
- sablier-deployment.yaml
- sablier-service.yaml
31 changes: 31 additions & 0 deletions .local-manifest/sablier/sablier-deployment.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
apiVersion: apps/v1
kind: Deployment
metadata:
name: sablier
labels:
app: sablier
spec:
replicas: 1
selector:
matchLabels:
app: sablier
template:
metadata:
labels:
app: sablier
spec:
serviceAccountName: sablier
volumes:
- name: project
hostPath:
path: /work
containers:
- name: sablier
image: sablierapp/sablier:1.8
ports:
- name: http
containerPort: 10000
volumeMounts:
- name: project
subPath: .local-dev/config/sablier.yaml
mountPath: /etc/sablier/sablier.yaml
13 changes: 13 additions & 0 deletions .local-manifest/sablier/sablier-role-binding.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: sablier

roleRef:
apiGroup: rbac.authorization.k8s.io
kind: ClusterRole
name: sablier
subjects:
- kind: ServiceAccount
namespace: sablier
name: sablier
27 changes: 27 additions & 0 deletions .local-manifest/sablier/sablier-role.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole
metadata:
name: sablier
rules:
- apiGroups:
- apps
- ""
resources:
- deployments
- statefulsets
verbs:
- get # Retrieve info about specific dep
- list # Events
- watch # Events
- apiGroups:
- apps
- ""
resources:
- deployments/scale
- statefulsets/scale
verbs:
- patch # Scale up and down
- update # Scale up and down
- get # Retrieve info about specific dep
- list # Events
- watch # Events
4 changes: 4 additions & 0 deletions .local-manifest/sablier/sablier-service-account.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
apiVersion: v1
kind: ServiceAccount
metadata:
name: sablier
13 changes: 13 additions & 0 deletions .local-manifest/sablier/sablier-service.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
apiVersion: v1
kind: Service
metadata:
name: sablier

spec:
type: ClusterIP
selector:
app: sablier
ports:
- name: http
port: 80
targetPort: http
3 changes: 3 additions & 0 deletions .local-manifest/traefik/traefik-stateful-set.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,15 @@ spec:
- --api.insecure
- --providers.kubernetescrd
- --providers.kubernetescrd.allowCrossNamespace
- --providers.kubernetescrd.allowEmptyServices
- --providers.kubernetesingress
- --entrypoints.web.address=:80/tcp
- --entrypoints.websecure.address=:443/tcp
- --entrypoints.websecure.http.tls=true
- --entrypoints.traefik.address=:8080/tcp
- --entrypoints.metrics.address=:9100/tcp
- --experimental.plugins.sablier.modulename=github.com/sablierapp/sablier
- --experimental.plugins.sablier.version=v1.8.1
- --api.dashboard=true
- --ping=true
- --metrics.prometheus=true
Expand Down
11 changes: 11 additions & 0 deletions api/proto/neoshowcase/protobuf/gateway.proto
Original file line number Diff line number Diff line change
Expand Up @@ -99,11 +99,22 @@ enum DeployType {
STATIC = 1;
}

message AutoShutdownConfig {
enum StartupBehavior {
UNDEFINED = 0;
LOADING_PAGE = 1;
BLOCKING = 2;
}
bool enabled = 1;
StartupBehavior startup = 2;
}

message RuntimeConfig {
bool use_mariadb = 1;
bool use_mongodb = 2;
string entrypoint = 3;
string command = 4;
AutoShutdownConfig auto_shutdown = 5;
}

message BuildConfigRuntimeBuildpack {
Expand Down
6 changes: 6 additions & 0 deletions cmd/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,6 +191,12 @@ func init() {
viper.SetDefault("components.controller.k8s.service.ipFamilies", nil)
viper.SetDefault("components.controller.k8s.service.ipFamilyPolicy", "PreferDualStack")

viper.SetDefault("components.controller.k8s.middleware.sablier.enable", true)
viper.SetDefault("components.controller.k8s.middleware.sablier.url", "http://sablier:10000")
viper.SetDefault("components.controller.k8s.middleware.sablier.sessionDuration", "1h")
viper.SetDefault("components.controller.k8s.middleware.sablier.dynamic.theme", "ghost")
viper.SetDefault("components.controller.k8s.middleware.sablier.blocking.timeout", "1m")

viper.SetDefault("components.controller.k8s.tls.type", "traefik")
viper.SetDefault("components.controller.k8s.tls.traefik.certResolver", "nsresolver")
viper.SetDefault("components.controller.k8s.tls.traefik.wildcard.domains", nil)
Expand Down
2 changes: 1 addition & 1 deletion dashboard/src/api/neoshowcase/protobuf/gateway_connect.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// @generated by protoc-gen-connect-es v1.4.0 with parameter "target=ts"
// @generated by protoc-gen-connect-es v1.6.1 with parameter "target=ts"
// @generated from file neoshowcase/protobuf/gateway.proto (package neoshowcase.protobuf, syntax proto3)
/* eslint-disable */
// @ts-nocheck
Expand Down
75 changes: 75 additions & 0 deletions dashboard/src/api/neoshowcase/protobuf/gateway_pb.ts
Original file line number Diff line number Diff line change
Expand Up @@ -660,6 +660,75 @@ export class SimpleCommit extends Message<SimpleCommit> {
}
}

/**
* @generated from message neoshowcase.protobuf.AutoShutdownConfig
*/
export class AutoShutdownConfig extends Message<AutoShutdownConfig> {
/**
* @generated from field: bool enabled = 1;
*/
enabled = false;

/**
* @generated from field: neoshowcase.protobuf.AutoShutdownConfig.StartupBehavior startup = 2;
*/
startup = AutoShutdownConfig_StartupBehavior.UNDEFINED;

constructor(data?: PartialMessage<AutoShutdownConfig>) {
super();
proto3.util.initPartial(data, this);
}

static readonly runtime: typeof proto3 = proto3;
static readonly typeName = "neoshowcase.protobuf.AutoShutdownConfig";
static readonly fields: FieldList = proto3.util.newFieldList(() => [
{ no: 1, name: "enabled", kind: "scalar", T: 8 /* ScalarType.BOOL */ },
{ no: 2, name: "startup", kind: "enum", T: proto3.getEnumType(AutoShutdownConfig_StartupBehavior) },
]);

static fromBinary(bytes: Uint8Array, options?: Partial<BinaryReadOptions>): AutoShutdownConfig {
return new AutoShutdownConfig().fromBinary(bytes, options);
}

static fromJson(jsonValue: JsonValue, options?: Partial<JsonReadOptions>): AutoShutdownConfig {
return new AutoShutdownConfig().fromJson(jsonValue, options);
}

static fromJsonString(jsonString: string, options?: Partial<JsonReadOptions>): AutoShutdownConfig {
return new AutoShutdownConfig().fromJsonString(jsonString, options);
}

static equals(a: AutoShutdownConfig | PlainMessage<AutoShutdownConfig> | undefined, b: AutoShutdownConfig | PlainMessage<AutoShutdownConfig> | undefined): boolean {
return proto3.util.equals(AutoShutdownConfig, a, b);
}
}

/**
* @generated from enum neoshowcase.protobuf.AutoShutdownConfig.StartupBehavior
*/
export enum AutoShutdownConfig_StartupBehavior {
/**
* @generated from enum value: UNDEFINED = 0;
*/
UNDEFINED = 0,

/**
* @generated from enum value: LOADING_PAGE = 1;
*/
LOADING_PAGE = 1,

/**
* @generated from enum value: BLOCKING = 2;
*/
BLOCKING = 2,
}
// Retrieve enum metadata with: proto3.getEnumType(AutoShutdownConfig_StartupBehavior)
proto3.util.setEnumType(AutoShutdownConfig_StartupBehavior, "neoshowcase.protobuf.AutoShutdownConfig.StartupBehavior", [
{ no: 0, name: "UNDEFINED" },
{ no: 1, name: "LOADING_PAGE" },
{ no: 2, name: "BLOCKING" },
]);

/**
* @generated from message neoshowcase.protobuf.RuntimeConfig
*/
Expand All @@ -684,6 +753,11 @@ export class RuntimeConfig extends Message<RuntimeConfig> {
*/
command = "";

/**
* @generated from field: neoshowcase.protobuf.AutoShutdownConfig auto_shutdown = 5;
*/
autoShutdown?: AutoShutdownConfig;

constructor(data?: PartialMessage<RuntimeConfig>) {
super();
proto3.util.initPartial(data, this);
Expand All @@ -696,6 +770,7 @@ export class RuntimeConfig extends Message<RuntimeConfig> {
{ no: 2, name: "use_mongodb", kind: "scalar", T: 8 /* ScalarType.BOOL */ },
{ no: 3, name: "entrypoint", kind: "scalar", T: 9 /* ScalarType.STRING */ },
{ no: 4, name: "command", kind: "scalar", T: 9 /* ScalarType.STRING */ },
{ no: 5, name: "auto_shutdown", kind: "message", T: AutoShutdownConfig },
]);

static fromBinary(bytes: Uint8Array, options?: Partial<BinaryReadOptions>): RuntimeConfig {
Expand Down
Loading

0 comments on commit 0bdfcca

Please sign in to comment.