2 Commits

Author SHA1 Message Date
7ef824830e added command and args to status
Some checks failed
Build and Push Docker Image / Build image (push) Has been cancelled
2025-04-05 22:35:43 +03:00
39f1c0d92c added config path to file
Some checks failed
Build and Push Docker Image / Build image (push) Has been cancelled
2025-04-05 17:15:00 +03:00
10 changed files with 137 additions and 48 deletions

View File

@@ -44,6 +44,8 @@ type ServerStatus struct {
Domain string `json:"domain,omitempty"` Domain string `json:"domain,omitempty"`
Running bool `json:"running,omitempty"` Running bool `json:"running,omitempty"`
HostPorts []PortMapping `json:"host_ports,omitempty"` HostPorts []PortMapping `json:"host_ports,omitempty"`
Args []string `json:"args,omitempty"`
Command []string `json:"command,omitempty"`
} }
type ServerSpec struct { type ServerSpec struct {

View File

@@ -333,6 +333,16 @@ func (in *ServerStatus) DeepCopyInto(out *ServerStatus) {
*out = make([]PortMapping, len(*in)) *out = make([]PortMapping, len(*in))
copy(*out, *in) copy(*out, *in)
} }
if in.Args != nil {
in, out := &in.Args, &out.Args
*out = make([]string, len(*in))
copy(*out, *in)
}
if in.Command != nil {
in, out := &in.Command, &out.Command
*out = make([]string, len(*in))
copy(*out, *in)
}
} }
// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ServerStatus. // DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ServerStatus.

View File

@@ -146,8 +146,13 @@ func main() {
setupLog.Error(err, "unable to start manager") setupLog.Error(err, "unable to start manager")
os.Exit(1) os.Exit(1)
} }
configPath := os.Getenv("CONFIG_PATH")
if configPath == "" {
configPath = "config.yaml"
}
config := &controller.ServerManagerReconcilerConfig{} config := &controller.ServerManagerReconcilerConfig{}
configData, err := os.ReadFile("config.yaml") configData, err := os.ReadFile(configPath)
if err != nil { if err != nil {
setupLog.Error(err, "unable to read config file") setupLog.Error(err, "unable to read config file")
} }

View File

@@ -94,6 +94,14 @@ spec:
INSERT ADDITIONAL STATUS FIELD - define observed state of cluster INSERT ADDITIONAL STATUS FIELD - define observed state of cluster
Important: Run "make" to regenerate code after modifying this file Important: Run "make" to regenerate code after modifying this file
properties: properties:
args:
items:
type: string
type: array
command:
items:
type: string
type: array
domain: domain:
type: string type: string
host_ports: host_ports:

View File

@@ -0,0 +1,31 @@
# https://kubernetes.io/docs/concepts/configuration/configmap/
apiVersion: v1
kind: ConfigMap
metadata:
name: server-manager-config
namespace: server-manager
data:
config.yaml: |
domain_label: "ddns.acooldomain.co/hostname"
default_domain: "acooldomain.co"
browser:
domain: games.acooldomain.co
sub_path: /browsers
auth_header: x-authentik-username
cert_resolver: letsencrypt
entrypoints:
- websecure
additional_routes:
- kind: Rule
match: "Host(`games.acooldomain.co`) && PathPrefix(`/outpost.goauthentik.io/`)"
priority: 15
services:
- kind: Service
name: ak-outpost-traefik
namespace: authentik
port: 9000
middleware:
name: authentik
namespace: authentik

View File

@@ -1,2 +1,3 @@
resources: resources:
- manager.yaml - config.yaml
- manager.yaml

View File

@@ -5,13 +5,13 @@ metadata:
control-plane: controller-manager control-plane: controller-manager
app.kubernetes.io/name: kubernetes-operator app.kubernetes.io/name: kubernetes-operator
app.kubernetes.io/managed-by: kustomize app.kubernetes.io/managed-by: kustomize
name: system name: server-manager
--- ---
apiVersion: apps/v1 apiVersion: apps/v1
kind: Deployment kind: Deployment
metadata: metadata:
name: controller-manager name: controller-manager
namespace: system namespace: server-manager
labels: labels:
control-plane: controller-manager control-plane: controller-manager
app.kubernetes.io/name: kubernetes-operator app.kubernetes.io/name: kubernetes-operator
@@ -48,6 +48,11 @@ spec:
# operator: In # operator: In
# values: # values:
# - linux # - linux
volumes:
- name: config
configMap:
name: server-manager-config
securityContext: securityContext:
runAsNonRoot: true runAsNonRoot: true
# TODO(user): For common cases that do not require escalating privileges # TODO(user): For common cases that do not require escalating privileges
@@ -55,41 +60,44 @@ spec:
# More info: https://kubernetes.io/docs/concepts/security/pod-security-standards/#restricted # More info: https://kubernetes.io/docs/concepts/security/pod-security-standards/#restricted
# Please uncomment the following code if your project does NOT have to work on old Kubernetes # Please uncomment the following code if your project does NOT have to work on old Kubernetes
# versions < 1.19 or on vendors versions which do NOT support this field by default (i.e. Openshift < 4.11 ). # versions < 1.19 or on vendors versions which do NOT support this field by default (i.e. Openshift < 4.11 ).
# seccompProfile: seccompProfile:
# type: RuntimeDefault type: RuntimeDefault
containers: containers:
- command: - command:
- /manager - /manager
args: image: git.acooldomain.co/server-manager/kubernetes-operator:v0.0.3
- --leader-elect env:
- --health-probe-bind-address=:8081 - name: CONFIG_PATH
image: controller:latest value: /etc/server-manager/config.yaml
name: manager volumeMounts:
securityContext: - name: config
allowPrivilegeEscalation: false mountPath: /etc/server-manager
capabilities: name: manager
drop: securityContext:
- "ALL" allowPrivilegeEscalation: false
livenessProbe: capabilities:
httpGet: drop:
path: /healthz - "ALL"
port: 8081 livenessProbe:
initialDelaySeconds: 15 httpGet:
periodSeconds: 20 path: /healthz
readinessProbe: port: 8081
httpGet: initialDelaySeconds: 15
path: /readyz periodSeconds: 20
port: 8081 readinessProbe:
initialDelaySeconds: 5 httpGet:
periodSeconds: 10 path: /readyz
# TODO(user): Configure the resources accordingly based on the project requirements. port: 8081
# More info: https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/ initialDelaySeconds: 5
resources: periodSeconds: 10
limits: # TODO(user): Configure the resources accordingly based on the project requirements.
cpu: 500m # More info: https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/
memory: 128Mi resources:
requests: limits:
cpu: 10m cpu: 500m
memory: 64Mi memory: 128Mi
serviceAccountName: controller-manager requests:
cpu: 10m
memory: 64Mi
serviceAccountName: server-manager
terminationGracePeriodSeconds: 10 terminationGracePeriodSeconds: 10

View File

@@ -4,12 +4,12 @@ metadata:
labels: labels:
app.kubernetes.io/name: kubernetes-operator app.kubernetes.io/name: kubernetes-operator
app.kubernetes.io/managed-by: kustomize app.kubernetes.io/managed-by: kustomize
name: manager-rolebinding name: server-manager-rolebinding
roleRef: roleRef:
apiGroup: rbac.authorization.k8s.io apiGroup: rbac.authorization.k8s.io
kind: ClusterRole kind: ClusterRole
name: manager-role name: server-manager-role
subjects: subjects:
- kind: ServiceAccount - kind: ServiceAccount
name: controller-manager name: server-manager
namespace: system namespace: server-manager

View File

@@ -4,5 +4,5 @@ metadata:
labels: labels:
app.kubernetes.io/name: kubernetes-operator app.kubernetes.io/name: kubernetes-operator
app.kubernetes.io/managed-by: kustomize app.kubernetes.io/managed-by: kustomize
name: controller-manager name: server-manager
namespace: system namespace: server-manager

View File

@@ -185,11 +185,27 @@ func (r *ServerManagerReconciler) Reconcile(ctx context.Context, req ctrl.Reques
s.Status.Server.Running = true s.Status.Server.Running = true
statusChanged = true statusChanged = true
} }
if s.Status.Server.Command == nil {
s.Status.Server.Command = serverPod.Spec.Containers[0].Command
statusChanged = true
}
if s.Status.Server.Args == nil {
s.Status.Server.Args = serverPod.Spec.Containers[0].Args
statusChanged = true
}
default: default:
if s.Status.Server.Running { if s.Status.Server.Running {
s.Status.Server.Running = false s.Status.Server.Running = false
statusChanged = true statusChanged = true
} }
if len(s.Status.Server.Args) != 0 {
s.Status.Server.Args = nil
statusChanged = true
}
if len(s.Status.Server.Command) != 0 {
s.Status.Server.Command = nil
statusChanged = true
}
} }
} }
@@ -198,6 +214,14 @@ func (r *ServerManagerReconciler) Reconcile(ctx context.Context, req ctrl.Reques
s.Status.Server.Running = false s.Status.Server.Running = false
statusChanged = true statusChanged = true
} }
if len(s.Status.Server.Args) != 0 {
s.Status.Server.Args = nil
statusChanged = true
}
if len(s.Status.Server.Command) != 0 {
s.Status.Server.Command = nil
statusChanged = true
}
} }
logging.Info("verified pod") logging.Info("verified pod")
@@ -301,7 +325,7 @@ func (r *ServerManagerReconciler) Reconcile(ctx context.Context, req ctrl.Reques
} }
} }
} }
if errors.IsNotFound(err) && !s.Spec.Server.On { if errors.IsNotFound(err) && !s.Spec.Browser.On {
if s.Status.Browser.Running { if s.Status.Browser.Running {
s.Status.Browser.Running = false s.Status.Browser.Running = false
statusChanged = true statusChanged = true