Compare commits
5 Commits
Author | SHA1 | Date | |
---|---|---|---|
4ebb402015 | |||
a54c905cc7 | |||
8f005effa3 | |||
7776d546e9 | |||
7ef824830e |
@@ -44,6 +44,8 @@ type ServerStatus struct {
|
||||
Domain string `json:"domain,omitempty"`
|
||||
Running bool `json:"running,omitempty"`
|
||||
HostPorts []PortMapping `json:"host_ports,omitempty"`
|
||||
Args []string `json:"args,omitempty"`
|
||||
Command []string `json:"command,omitempty"`
|
||||
}
|
||||
|
||||
type ServerSpec struct {
|
||||
|
@@ -333,6 +333,16 @@ func (in *ServerStatus) DeepCopyInto(out *ServerStatus) {
|
||||
*out = make([]PortMapping, len(*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.
|
||||
|
@@ -94,6 +94,14 @@ spec:
|
||||
INSERT ADDITIONAL STATUS FIELD - define observed state of cluster
|
||||
Important: Run "make" to regenerate code after modifying this file
|
||||
properties:
|
||||
args:
|
||||
items:
|
||||
type: string
|
||||
type: array
|
||||
command:
|
||||
items:
|
||||
type: string
|
||||
type: array
|
||||
domain:
|
||||
type: string
|
||||
host_ports:
|
||||
|
@@ -65,7 +65,7 @@ spec:
|
||||
containers:
|
||||
- command:
|
||||
- /manager
|
||||
image: git.acooldomain.co/server-manager/kubernetes-operator:v0.0.3
|
||||
image: git.acooldomain.co/server-manager/kubernetes-operator:v0.0.5
|
||||
env:
|
||||
- name: CONFIG_PATH
|
||||
value: /etc/server-manager/config.yaml
|
||||
|
@@ -2,81 +2,69 @@
|
||||
apiVersion: rbac.authorization.k8s.io/v1
|
||||
kind: ClusterRole
|
||||
metadata:
|
||||
name: server-manager-role
|
||||
name: manager-role
|
||||
rules:
|
||||
- resources:
|
||||
- persistentvolumeclaims
|
||||
- services
|
||||
verbs:
|
||||
- create
|
||||
- delete
|
||||
- get
|
||||
- list
|
||||
- patch
|
||||
- update
|
||||
- watch
|
||||
apiGroups:
|
||||
- ""
|
||||
- resources:
|
||||
- pods
|
||||
verbs:
|
||||
- create
|
||||
- delete
|
||||
- get
|
||||
- list
|
||||
- watch
|
||||
apiGroups:
|
||||
- ""
|
||||
- apiGroups:
|
||||
- ""
|
||||
resources:
|
||||
- nodes
|
||||
verbs:
|
||||
- get
|
||||
- list
|
||||
- apiGroups:
|
||||
- server-manager.acooldomain.co
|
||||
resources:
|
||||
- images
|
||||
verbs:
|
||||
- get
|
||||
- list
|
||||
- watch
|
||||
- apiGroups:
|
||||
- server-manager.acooldomain.co
|
||||
resources:
|
||||
- servermanagers
|
||||
verbs:
|
||||
- create
|
||||
- delete
|
||||
- get
|
||||
- list
|
||||
- patch
|
||||
- update
|
||||
- watch
|
||||
- apiGroups:
|
||||
- server-manager.acooldomain.co
|
||||
resources:
|
||||
- servermanagers/finalizers
|
||||
verbs:
|
||||
- update
|
||||
- apiGroups:
|
||||
- server-manager.acooldomain.co
|
||||
resources:
|
||||
- servermanagers/status
|
||||
verbs:
|
||||
- get
|
||||
- patch
|
||||
- update
|
||||
- apiGroups:
|
||||
- traefik.io
|
||||
resources:
|
||||
- ingressroutes
|
||||
verbs:
|
||||
- create
|
||||
- delete
|
||||
- get
|
||||
- list
|
||||
- patch
|
||||
- update
|
||||
- watch
|
||||
- resources:
|
||||
- persistentvolumeclaims
|
||||
- services
|
||||
verbs:
|
||||
- create
|
||||
- delete
|
||||
- get
|
||||
- list
|
||||
- patch
|
||||
- update
|
||||
- watch
|
||||
- resources:
|
||||
- pods
|
||||
verbs:
|
||||
- create
|
||||
- delete
|
||||
- get
|
||||
- list
|
||||
- watch
|
||||
- apiGroups:
|
||||
- server-manager.acooldomain.co
|
||||
resources:
|
||||
- images
|
||||
verbs:
|
||||
- get
|
||||
- list
|
||||
- apiGroups:
|
||||
- server-manager.acooldomain.co
|
||||
resources:
|
||||
- servermanagers
|
||||
verbs:
|
||||
- create
|
||||
- delete
|
||||
- get
|
||||
- list
|
||||
- patch
|
||||
- update
|
||||
- watch
|
||||
- apiGroups:
|
||||
- server-manager.acooldomain.co
|
||||
resources:
|
||||
- servermanagers/finalizers
|
||||
verbs:
|
||||
- update
|
||||
- apiGroups:
|
||||
- server-manager.acooldomain.co
|
||||
resources:
|
||||
- servermanagers/status
|
||||
verbs:
|
||||
- get
|
||||
- patch
|
||||
- update
|
||||
- apiGroups:
|
||||
- traefik.io
|
||||
resources:
|
||||
- ingressroutes
|
||||
verbs:
|
||||
- create
|
||||
- delete
|
||||
- get
|
||||
- list
|
||||
- patch
|
||||
- update
|
||||
- watch
|
||||
|
@@ -157,6 +157,11 @@ func (r *ServerManagerReconciler) Reconcile(ctx context.Context, req ctrl.Reques
|
||||
logging.Error(err, "Failed to get image")
|
||||
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)
|
||||
found := &corev1.Pod{}
|
||||
@@ -185,11 +190,27 @@ func (r *ServerManagerReconciler) Reconcile(ctx context.Context, req ctrl.Reques
|
||||
s.Status.Server.Running = 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:
|
||||
if s.Status.Server.Running {
|
||||
s.Status.Server.Running = false
|
||||
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
|
||||
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")
|
||||
@@ -368,7 +397,7 @@ func (r *ServerManagerReconciler) GenerateBrowserUrl(s *servermanagerv1alpha1.Se
|
||||
}
|
||||
|
||||
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)
|
||||
} else {
|
||||
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 {
|
||||
serverPorts := image.Spec.Ports
|
||||
if len(s.Spec.Server.Ports) > 0 {
|
||||
serverPorts = s.Spec.Server.Ports
|
||||
}
|
||||
|
||||
ports := make([]corev1.ContainerPort, len(serverPorts))
|
||||
|
||||
for i, port := range s.Spec.Server.Ports {
|
||||
for i, port := range serverPorts {
|
||||
ports[i] = corev1.ContainerPort{
|
||||
ContainerPort: port.Port,
|
||||
Protocol: port.Protocol,
|
||||
|
Reference in New Issue
Block a user