chore(filebrowser): migrate from filebrowser to filebrowser quantum
Build and Push Docker Image / Build image (push) Successful in 9m10s

This commit is contained in:
2026-06-28 19:22:35 +03:00
parent 7158764d2c
commit 04ad3616c9
2 changed files with 115 additions and 24 deletions
+46
View File
@@ -0,0 +1,46 @@
package controller
type SourceConfig struct {
DefaultEnabled bool `yaml:"DefaultEnabled"`
}
type SourceDefinition struct {
Path string `yaml:"path"`
Config SourceConfig `yaml:"config"`
}
type ServerConfig struct {
Port int `yaml:"port"`
BaseUrl string `yaml:"baseURL"`
Sources []SourceDefinition `yaml:"sources"`
}
type AuthPasswordMethodConfig struct {
Enabled bool `yaml:"enabled"`
MinLength bool `yaml:"minLength"`
}
type AuthProxyMethodConfig struct {
Enabled bool `yaml:"enabled"`
Header string `yaml:"header"`
}
type AuthMethodsConfig struct {
Password AuthPasswordMethodConfig `yaml:"password"`
Proxy AuthProxyMethodConfig `yaml:"proxy"`
}
type AuthConfig struct {
AdminUsername string `yaml:"adminUsername"`
Methods AuthMethodsConfig `yaml:"methods"`
}
type FrontendConfig struct {
Name string `yaml:"name"`
}
type FileBrowserConfig struct {
Server ServerConfig `yaml:"server"`
Auth AuthConfig `yaml:"auth"`
Frontend FrontendConfig `yaml:"frontend"`
}
+69 -24
View File
@@ -23,6 +23,7 @@ import (
"time"
traefikv3 "github.com/traefik/traefik/v3/pkg/provider/kubernetes/crd/traefikio/v1alpha1"
"gopkg.in/yaml.v3"
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/api/resource"
@@ -297,7 +298,19 @@ func (r *ServerManagerReconciler) Reconcile(ctx context.Context, req ctrl.Reques
}
logging.Info("verified server service")
browserPod := r.BrowserPod(s, pvc, browserPvc)
browserConfigMap, err := r.BrowserConfigMap(s)
if err != nil {
return ctrl.Result{}, err
}
var foundBrowserConfigMap *corev1.ConfigMap
err = r.Get(ctx, client.ObjectKeyFromObject(browserConfigMap), foundBrowserConfigMap)
if err != nil {
err = r.Create(ctx, browserConfigMap)
return ctrl.Result{Requeue: true}, err
}
browserPod := r.BrowserPod(s, pvc, browserPvc, browserConfigMap)
foundBrowser := &corev1.Pod{}
err = r.Get(ctx, client.ObjectKeyFromObject(browserPod), foundBrowser)
if err == nil && !s.Spec.Browser.On {
@@ -519,15 +532,51 @@ func (r *ServerManagerReconciler) BrowserService(s *servermanagerv1alpha1.Server
return service
}
func (r *ServerManagerReconciler) BrowserPod(s *servermanagerv1alpha1.ServerManager, pvc *corev1.PersistentVolumeClaim, browserPvc *corev1.PersistentVolumeClaim) *corev1.Pod {
ports := make([]corev1.ContainerPort, len(s.Spec.Server.Ports))
func (r *ServerManagerReconciler) BrowserConfigMap(s *servermanagerv1alpha1.ServerManager) (*corev1.ConfigMap, error) {
serializedConfig, err := yaml.Marshal(FileBrowserConfig{
Server: ServerConfig{
BaseUrl: r.GenerateBrowserSubPath(s),
Sources: []SourceDefinition{
{
Path: "/tmp/data",
Config: SourceConfig{DefaultEnabled: true},
},
},
},
Auth: AuthConfig{
AdminUsername: "admin",
Methods: AuthMethodsConfig{
Password: AuthPasswordMethodConfig{
Enabled: false,
},
Proxy: AuthProxyMethodConfig{
Enabled: true,
Header: "X-Forwarded-User",
},
},
},
Frontend: FrontendConfig{
Name: "ACoolFileBrowser",
},
})
for i, port := range s.Spec.Server.Ports {
ports[i] = corev1.ContainerPort{
ContainerPort: port.Port,
Protocol: port.Protocol,
}
if err != nil {
return nil, err
}
var configMapData map[string]string
configMapData["config.yaml"] = string(serializedConfig)
return &corev1.ConfigMap{
ObjectMeta: metav1.ObjectMeta{
Name: fmt.Sprintf("%s-browser-config", s.Name),
Namespace: s.Namespace,
Labels: map[string]string{"browser": s.Name},
},
Data: configMapData,
}, nil
}
func (r *ServerManagerReconciler) BrowserPod(s *servermanagerv1alpha1.ServerManager, pvc *corev1.PersistentVolumeClaim, browserPvc *corev1.PersistentVolumeClaim, browserConfigMap *corev1.ConfigMap) *corev1.Pod {
var fsGroupValue int64 = 2000
var runAsUserValue int64 = 1000
policy := corev1.FSGroupChangeOnRootMismatch // Optimizes startup speed
@@ -562,19 +611,12 @@ func (r *ServerManagerReconciler) BrowserPod(s *servermanagerv1alpha1.ServerMana
},
},
},
},
InitContainers: []corev1.Container{
{
Name: "proxy-setter",
Image: "filebrowser/filebrowser",
ImagePullPolicy: corev1.PullIfNotPresent,
Ports: ports,
Command: []string{"/bin/sh"},
Args: []string{"-c", fmt.Sprintf("rm /tmp/database/filebrowser.db; filebrowser config init -d /tmp/database/filebrowser.db && filebrowser config set --auth.method=noauth --auth.header=%s -d /tmp/database/filebrowser.db", r.Config.Browser.AuthHeader)},
VolumeMounts: []corev1.VolumeMount{
{
Name: "browser-volume",
MountPath: "/tmp/database",
{Name: "config-volume",
VolumeSource: corev1.VolumeSource{
ConfigMap: &corev1.ConfigMapVolumeSource{
LocalObjectReference: corev1.LocalObjectReference{
Name: browserConfigMap.Name,
},
},
},
},
@@ -582,10 +624,9 @@ func (r *ServerManagerReconciler) BrowserPod(s *servermanagerv1alpha1.ServerMana
Containers: []corev1.Container{
{
Name: "browser",
Image: "filebrowser/filebrowser",
Image: "ghcr.io/gtsteffaniak/filebrowser",
ImagePullPolicy: corev1.PullIfNotPresent,
Ports: ports,
Args: []string{"-d", "/tmp/database/filebrowser.db", "-r", "/tmp/data", "-b", r.GenerateBrowserSubPath(s)},
Args: []string{"-c", "/tmp/config/config.yaml"},
VolumeMounts: []corev1.VolumeMount{
{
Name: "volume",
@@ -595,6 +636,10 @@ func (r *ServerManagerReconciler) BrowserPod(s *servermanagerv1alpha1.ServerMana
Name: "browser-volume",
MountPath: "/tmp/database",
},
{
Name: "config-volume",
MountPath: "/tmp/config",
},
},
},
},