This commit is contained in:
ACoolName 2025-04-01 21:23:47 +03:00
parent ae058f92e6
commit d83bc3368a
2 changed files with 29 additions and 5 deletions

View File

@ -166,6 +166,16 @@ func (in *ServerManagerStatus) DeepCopy() *ServerManagerStatus {
// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil.
func (in *ServerSpec) DeepCopyInto(out *ServerSpec) {
*out = *in
if in.Command != nil {
in, out := &in.Command, &out.Command
*out = make([]string, 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.Ports != nil {
in, out := &in.Ports, &out.Ports
*out = make([]Port, len(*in))

View File

@ -72,8 +72,8 @@ func (r *ServerManagerReconciler) Reconcile(ctx context.Context, req ctrl.Reques
}
pvc := r.ServerPvc(s)
found := &corev1.PersistentVolumeClaim{}
err = r.Get(ctx, client.ObjectKey{Namespace: pvc.Namespace, Name: pvc.Name}, found)
found_pvc := &corev1.PersistentVolumeClaim{}
err = r.Get(ctx, client.ObjectKey{Namespace: pvc.Namespace, Name: pvc.Name}, found_pvc)
if err != nil {
if errors.IsNotFound(err) {
err = r.Create(ctx, pvc)
@ -97,6 +97,7 @@ func (r *ServerManagerReconciler) Reconcile(ctx context.Context, req ctrl.Reques
return ctrl.Result{}, err
}
}
domain := r.Config.DefaultDomain
if r.Config.DomainLabel != "" {
node := &corev1.Node{}
@ -105,20 +106,33 @@ func (r *ServerManagerReconciler) Reconcile(ctx context.Context, req ctrl.Reques
logging.Error(err, fmt.Sprintf("Failed to find node %s", found.Spec.NodeName))
return ctrl.Result{}, err
}
labelDomain, ok := node.GetLabels()[r.Config.DomainLabel]
if ok {
domain = labelDomain
}
}
if domain != s.Status.Server.Domain {
s.Status.Server.Domain = domain
err = r.Update(ctx, s)
return ctrl.Result{}, err
}
}
service := r.ServerService(s)
found_service := &corev1.Service{}
err = r.Get(ctx, client.ObjectKeyFromObject(service), found_service)
if err != nil {
if !errors.IsNotFound(err) {
return ctrl.Result{}, err
}
err = r.Create(ctx, service)
if err != nil {
return ctrl.Result{}, err
}
}
return ctrl.Result{}, nil
}
@ -130,8 +144,8 @@ func (r *ServerManagerReconciler) ServerService(s *servermanagerv1alpha1.ServerM
}
service := &corev1.Service{
ObjectMeta: metav1.ObjectMeta{
Name: s.Name,
Namespce: s.Namespace,
Name: s.Name,
Namespace: s.Namespace,
},
Spec: corev1.ServiceSpec{
Ports: ports,