Skip to content
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

アクセスのない Runtime App を自動で落とせるようにする #965

Merged
merged 24 commits into from
Nov 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
24 commits
Select commit Hold shift + click to select a range
c7da369
deps: add sablier to local_manifest
pirosiki197 Oct 10, 2024
31f45dc
feat: add sablier config for ns k8s backend
pirosiki197 Oct 10, 2024
5347541
feat: apply sablier middleware for runtime apps
pirosiki197 Oct 10, 2024
7b6b43c
feat: add new container status "idle"
pirosiki197 Oct 10, 2024
30f4a56
feat: update db schema
pirosiki197 Oct 10, 2024
d8d2eae
chore: fix adminer port
pirosiki197 Oct 10, 2024
a8e212c
chore: fix test case name
pirosiki197 Oct 10, 2024
e934a30
feat: generate gateway api and add simple UIs
pirosiki197 Oct 10, 2024
642ab96
fix: nil check
pirosiki197 Oct 10, 2024
0aacf08
chore: go mod tidy
pirosiki197 Oct 10, 2024
7864f19
fix (k8s backend): return ContainerStateMissing when the StatefulSet …
pirosiki197 Oct 11, 2024
8a01a29
chore: regenerate protobuf code with the latest version
pirosiki197 Oct 11, 2024
148eddd
remove: container state 'idle' from db and protobuf
pirosiki197 Oct 18, 2024
c62e49e
fix pbconvert
pirosiki197 Oct 23, 2024
15b053f
feat (dashboard): add AutoShutdown option to the runtime app configur…
pirosiki197 Oct 23, 2024
c2475b7
fix: update dashboard test
pirosiki197 Oct 23, 2024
b550844
chore: update sablier
pirosiki197 Nov 2, 2024
08b9ad4
feat: blocking strategy
pirosiki197 Nov 2, 2024
c8602b3
feat: implement runtime config field of the deploy config form
pirosiki197 Nov 2, 2024
ad772fb
Merge branch 'main' into feat/auto-shutdown
pirosiki197 Nov 4, 2024
68cc55e
add default values for sablier middleware config
pirosiki197 Nov 5, 2024
2f8bfca
remove startup behavior 'undefined' from application config table
pirosiki197 Nov 5, 2024
e58120c
Merge branch 'main' into feat/auto-shutdown
pirosiki197 Nov 18, 2024
5568226
chore: regenerate protobuf
pirosiki197 Nov 18, 2024
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: 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
pirosiki197 marked this conversation as resolved.
Show resolved Hide resolved
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