Skip to content

Commit

Permalink
feat: use customizing caddy by default
Browse files Browse the repository at this point in the history
Signed-off-by: joshua <[email protected]>
  • Loading branch information
sujoshua committed Aug 25, 2024
1 parent 0ed54f4 commit cf8658b
Show file tree
Hide file tree
Showing 3 changed files with 69 additions and 41 deletions.
102 changes: 63 additions & 39 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,11 @@ func getConfig() controller.Config {
debug = true
}

enableMetric := false
if os.Getenv("ENABLE_METRIC") != "" {
enableMetric = true
}

c := controller.Config{
ManagerImage: os.Getenv("MANAGER_IMAGE"),
WorkerImage: os.Getenv("WORKER_IMAGE"),
Expand All @@ -170,6 +175,7 @@ func getConfig() controller.Config {
FrontTLS: os.Getenv("FRONT_TLS"),
FrontClass: os.Getenv("FRONT_CLASS"),
FrontAnn: annItems,
EnableMetric: enableMetric,
Debug: debug,
}

Expand All @@ -184,67 +190,85 @@ func mergeDefaults(config *controller.Config) {
defaultConfig := &controller.Config{
ManagerImage: "cquptmirror/manager:latest",
WorkerImage: "cquptmirror/worker:latest",
FrontMode: "caddy",
FrontMode: "cquptmirror/caddy:latest",
RsyncImage: "",
FrontCmd: "caddy run -c /etc/frontConfig",
FrontConfig: `{
"apps": {
FrontCmd: "",
FrontConfig: `
{
"logging": {
"logs": {
"default": {},
"loki": {
"writer": {
"labels": {
"job": "{env.JOB_NAME}",
"instance": "{env.HOSTNAME}"
"component": "caddy"
},
"output": "loki",
"url": "http://loki:3000/loki/api/v1/push"
},
"encoder": {
"format": "json"
},
"level": "INFO",
"include": [
"http.log.access"
]
}
}
},
"apps": {
"http": {
"servers": {
"static": {
"metric": {
"listen": [
":80"
":2019"
],
"read_header_timeout": 10000000000,
"idle_timeout": 30000000000,
"max_header_bytes": 10240,
"routes": [
{
"handle": [
{
"encodings": {
"gzip": {
},
"zstd": {
}
},
"handler": "encode",
"prefer": [
"zstd",
"gzip"
]
},
"handler": "metrics"
}
]
}
]
},
"file_server": {
"listen": [
":80"
],
"routes": [
{
"handle": [
{
"browse": {
},
"browse": {},
"handler": "file_server",
"root": "/data",
"index_names": [
"_noindex"
]
"root": "/data"
}
]
}
],
"automatic_https": {
"disable": true
}
}
}
}
}}
`,
"logs": {
"default_logger_name": "loki"
},
"metrics": {}
}
}
}
}
}
`,
RsyncCmd: "",
FrontHost: "mirrors.cqupt.edu.cn",
FrontTLS: "",
FrontClass: "traefik",
FrontAnn: map[string]string{
"traefik.ingress.kubernetes.io/router.entrypoints": "web",
},
Debug: false,
EnableMetric: false,
Debug: false,
}

// 用反射实现
Expand Down
7 changes: 5 additions & 2 deletions internal/controller/job_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -307,8 +307,11 @@ func (r *JobReconciler) desiredDeployment(job *v1beta1.Job, manager string, fron
Name: job.Name + "-front",
Image: frontImage,
ImagePullPolicy: pullPolicy,
LivenessProbe: frontProbe,
ReadinessProbe: frontProbe,
Env: []corev1.EnvVar{
{Name: "JOB_NAME", Value: job.Name},
},
LivenessProbe: frontProbe,
ReadinessProbe: frontProbe,
VolumeMounts: []corev1.VolumeMount{
{
Name: job.Name,
Expand Down
1 change: 1 addition & 0 deletions internal/controller/manager_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ type Config struct {
FrontTLS string
FrontClass string
FrontAnn map[string]string
EnableMetric bool
Debug bool
}

Expand Down

0 comments on commit cf8658b

Please sign in to comment.