5 Commits

Author SHA1 Message Date
4ebb402015 fixed stupid bug
All checks were successful
Build and Push Docker Image / Build image (push) Successful in 1m45s
2025-04-09 17:15:02 +03:00
a54c905cc7 updated deployment to latest version
Some checks failed
Build and Push Docker Image / Build image (push) Has been cancelled
2025-04-07 13:48:24 +03:00
8f005effa3 fixed bug where server ports is nil
Some checks failed
Build and Push Docker Image / Build image (push) Has been cancelled
2025-04-07 13:45:53 +03:00
7776d546e9 fixed bug where server ports is nil
All checks were successful
Build and Push Docker Image / Build image (push) Successful in 1m45s
2025-04-07 13:36:07 +03:00
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
6 changed files with 117 additions and 83 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

@@ -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

@@ -65,7 +65,7 @@ spec:
containers: containers:
- command: - command:
- /manager - /manager
image: git.acooldomain.co/server-manager/kubernetes-operator:v0.0.3 image: git.acooldomain.co/server-manager/kubernetes-operator:v0.0.5
env: env:
- name: CONFIG_PATH - name: CONFIG_PATH
value: /etc/server-manager/config.yaml value: /etc/server-manager/config.yaml

View File

@@ -2,81 +2,69 @@
apiVersion: rbac.authorization.k8s.io/v1 apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRole kind: ClusterRole
metadata: metadata:
name: server-manager-role name: manager-role
rules: rules:
- resources: - resources:
- persistentvolumeclaims - persistentvolumeclaims
- services - services
verbs: verbs:
- create - create
- delete - delete
- get - get
- list - list
- patch - patch
- update - update
- watch - watch
apiGroups: - resources:
- "" - pods
- resources: verbs:
- pods - create
verbs: - delete
- create - get
- delete - list
- get - watch
- list - apiGroups:
- watch - server-manager.acooldomain.co
apiGroups: resources:
- "" - images
- apiGroups: verbs:
- "" - get
resources: - list
- nodes - apiGroups:
verbs: - server-manager.acooldomain.co
- get resources:
- list - servermanagers
- apiGroups: verbs:
- server-manager.acooldomain.co - create
resources: - delete
- images - get
verbs: - list
- get - patch
- list - update
- watch - watch
- apiGroups: - apiGroups:
- server-manager.acooldomain.co - server-manager.acooldomain.co
resources: resources:
- servermanagers - servermanagers/finalizers
verbs: verbs:
- create - update
- delete - apiGroups:
- get - server-manager.acooldomain.co
- list resources:
- patch - servermanagers/status
- update verbs:
- watch - get
- apiGroups: - patch
- server-manager.acooldomain.co - update
resources: - apiGroups:
- servermanagers/finalizers - traefik.io
verbs: resources:
- update - ingressroutes
- apiGroups: verbs:
- server-manager.acooldomain.co - create
resources: - delete
- servermanagers/status - get
verbs: - list
- get - patch
- patch - update
- update - watch
- apiGroups:
- traefik.io
resources:
- ingressroutes
verbs:
- create
- delete
- get
- list
- patch
- update
- watch

View File

@@ -157,6 +157,11 @@ func (r *ServerManagerReconciler) Reconcile(ctx context.Context, req ctrl.Reques
logging.Error(err, "Failed to get image") logging.Error(err, "Failed to get image")
return reconcile.Result{}, err return reconcile.Result{}, err
} }
if len(s.Spec.Server.Ports) == 0 {
s.Spec.Server.Ports = image.Spec.Ports
err := r.Update(ctx, s)
return reconcile.Result{}, err
}
serverPod := r.ServerPod(s, pvc, image) serverPod := r.ServerPod(s, pvc, image)
found := &corev1.Pod{} found := &corev1.Pod{}
@@ -185,11 +190,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 +219,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")
@@ -368,7 +397,7 @@ func (r *ServerManagerReconciler) GenerateBrowserUrl(s *servermanagerv1alpha1.Se
} }
func (r *ServerManagerReconciler) GenerateBrowserSubPath(s *servermanagerv1alpha1.ServerManager) string { func (r *ServerManagerReconciler) GenerateBrowserSubPath(s *servermanagerv1alpha1.ServerManager) string {
if r.Config.Browser.SubPath == "" { if r.Config.Browser.SubPath != "" {
return fmt.Sprintf("%s/%s/%s", r.Config.Browser.SubPath, s.Namespace, s.Name) return fmt.Sprintf("%s/%s/%s", r.Config.Browser.SubPath, s.Namespace, s.Name)
} else { } else {
return fmt.Sprintf("/%s/%s", s.Namespace, s.Name) return fmt.Sprintf("/%s/%s", s.Namespace, s.Name)
@@ -611,13 +640,10 @@ func (r *ServerManagerReconciler) ServerPvc(s *servermanagerv1alpha1.ServerManag
func (r *ServerManagerReconciler) ServerPod(s *servermanagerv1alpha1.ServerManager, pvc *corev1.PersistentVolumeClaim, image *servermanagerv1alpha1.Image) *corev1.Pod { func (r *ServerManagerReconciler) ServerPod(s *servermanagerv1alpha1.ServerManager, pvc *corev1.PersistentVolumeClaim, image *servermanagerv1alpha1.Image) *corev1.Pod {
serverPorts := image.Spec.Ports serverPorts := image.Spec.Ports
if len(s.Spec.Server.Ports) > 0 {
serverPorts = s.Spec.Server.Ports
}
ports := make([]corev1.ContainerPort, len(serverPorts)) ports := make([]corev1.ContainerPort, len(serverPorts))
for i, port := range s.Spec.Server.Ports { for i, port := range serverPorts {
ports[i] = corev1.ContainerPort{ ports[i] = corev1.ContainerPort{
ContainerPort: port.Port, ContainerPort: port.Port,
Protocol: port.Protocol, Protocol: port.Protocol,