|
|
|
@ -165,29 +165,9 @@ func (r *MsbDeploymentReconciler) Reconcile(ctx context.Context, req ctrl.Reques
|
|
|
|
|
svc := new(corev1.Service)
|
|
|
|
|
if err := r.Client.Get(ctx, req.NamespacedName, svc); err != nil {
|
|
|
|
|
if errors.IsNotFound(err) {
|
|
|
|
|
// 3.1 不存在
|
|
|
|
|
// 3.1.1 mode 为 ingress
|
|
|
|
|
if strings.ToLower(mdCopy.Spec.Expose.Mode) == myAppsv1.ModeIngress {
|
|
|
|
|
// 3.1.1.1 创建普通service
|
|
|
|
|
if err := r.createService(ctx, mdCopy); err != nil {
|
|
|
|
|
return ctrl.Result{}, err
|
|
|
|
|
}
|
|
|
|
|
} else if strings.ToLower(mdCopy.Spec.Expose.Mode) == myAppsv1.ModeNodePort {
|
|
|
|
|
// 3.1.2 mode 为 nodeport
|
|
|
|
|
// 3.1.2.1 创建 nodeport 模式的 service
|
|
|
|
|
if err := r.createNPService(ctx, mdCopy); err != nil {
|
|
|
|
|
return ctrl.Result{}, err
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
return ctrl.Result{}, myAppsv1.ErrorNotSupportMode
|
|
|
|
|
}
|
|
|
|
|
if _, errStatus := r.updateStatus(ctx,
|
|
|
|
|
mdCopy,
|
|
|
|
|
myAppsv1.ConditionTypeService,
|
|
|
|
|
fmt.Sprintf(myAppsv1.ConditionMessageServiceNotFmt, req.Name),
|
|
|
|
|
myAppsv1.ConditonStatusFalse,
|
|
|
|
|
myAppsv1.ConditionReasonServiceNotReady); errStatus != nil {
|
|
|
|
|
return ctrl.Result{}, errStatus
|
|
|
|
|
// 3.1 不存在 创建 service
|
|
|
|
|
if err := r.createService(ctx, mdCopy); err != nil {
|
|
|
|
|
return ctrl.Result{}, err
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
if _, errStatus := r.updateStatus(ctx,
|
|
|
|
@ -201,22 +181,12 @@ func (r *MsbDeploymentReconciler) Reconcile(ctx context.Context, req ctrl.Reques
|
|
|
|
|
return ctrl.Result{}, err
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
// 3.2 存在
|
|
|
|
|
if strings.ToLower(mdCopy.Spec.Expose.Mode) == myAppsv1.ModeIngress {
|
|
|
|
|
// 3.2.1 mode 为 ingress
|
|
|
|
|
// 3.2.1.1 更新普通的 service
|
|
|
|
|
if err := r.updateService(ctx, mdCopy, svc); err != nil {
|
|
|
|
|
return ctrl.Result{}, err
|
|
|
|
|
}
|
|
|
|
|
} else if strings.ToLower(mdCopy.Spec.Expose.Mode) == myAppsv1.ModeNodePort {
|
|
|
|
|
// 3.2.2 mode 为 nodeport
|
|
|
|
|
// 3.2.2.1 更新nodeport模式的service
|
|
|
|
|
if err := r.updateNPService(ctx, mdCopy, svc); err != nil {
|
|
|
|
|
return ctrl.Result{}, err
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
return ctrl.Result{}, myAppsv1.ErrorNotSupportMode
|
|
|
|
|
// 3.2 存在 更新 service
|
|
|
|
|
if err := r.updateService(ctx, mdCopy, svc); err != nil {
|
|
|
|
|
return ctrl.Result{}, err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 检查 现有状态来更新 status
|
|
|
|
|
if _, errStatus := r.updateStatus(ctx,
|
|
|
|
|
mdCopy,
|
|
|
|
|
myAppsv1.ConditionTypeService,
|
|
|
|
@ -339,32 +309,26 @@ func (r *MsbDeploymentReconciler) SetupWithManager(mgr ctrl.Manager) error {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (r *MsbDeploymentReconciler) createDeployment(ctx context.Context, md *myAppsv1.MsbDeployment) error {
|
|
|
|
|
deploy, err := NewDeployment(md)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
deploy := NewDeployment(md)
|
|
|
|
|
|
|
|
|
|
// 设置 deployment 所属于 md
|
|
|
|
|
if err := controllerutil.SetControllerReference(md, deploy, r.Scheme); err != nil {
|
|
|
|
|
if err := controllerutil.SetControllerReference(md, &deploy, r.Scheme); err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return r.Client.Create(ctx, deploy)
|
|
|
|
|
return r.Client.Create(ctx, &deploy)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (r *MsbDeploymentReconciler) updateDeployment(ctx context.Context, md *myAppsv1.MsbDeployment, dp *appsv1.Deployment) error {
|
|
|
|
|
deploy, err := NewDeployment(md)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
deploy := NewDeployment(md)
|
|
|
|
|
|
|
|
|
|
// 设置 deployment 所属于 md
|
|
|
|
|
if err := controllerutil.SetControllerReference(md, deploy, r.Scheme); err != nil {
|
|
|
|
|
if err := controllerutil.SetControllerReference(md, &deploy, r.Scheme); err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 预更新deployment,得到更新后的数据
|
|
|
|
|
if err := r.Update(ctx, deploy, client.DryRunAll); err != nil {
|
|
|
|
|
if err := r.Update(ctx, &deploy, client.DryRunAll); err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -373,50 +337,30 @@ func (r *MsbDeploymentReconciler) updateDeployment(ctx context.Context, md *myAp
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return r.Client.Update(ctx, deploy)
|
|
|
|
|
return r.Client.Update(ctx, &deploy)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (r *MsbDeploymentReconciler) createService(ctx context.Context, md *myAppsv1.MsbDeployment) error {
|
|
|
|
|
svc, err := NewService(md)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 设置 service 所属于 md
|
|
|
|
|
if err := controllerutil.SetControllerReference(md, svc, r.Scheme); err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return r.Client.Create(ctx, svc)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (r *MsbDeploymentReconciler) createNPService(ctx context.Context, md *myAppsv1.MsbDeployment) error {
|
|
|
|
|
svc, err := NewServiceNP(md)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
svc := NewService(md)
|
|
|
|
|
|
|
|
|
|
// 设置 service 所属于 md
|
|
|
|
|
if err := controllerutil.SetControllerReference(md, svc, r.Scheme); err != nil {
|
|
|
|
|
if err := controllerutil.SetControllerReference(md, &svc, r.Scheme); err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return r.Client.Create(ctx, svc)
|
|
|
|
|
return r.Client.Create(ctx, &svc)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (r *MsbDeploymentReconciler) updateService(ctx context.Context, md *myAppsv1.MsbDeployment, service *corev1.Service) error {
|
|
|
|
|
svc, err := NewService(md)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
svc := NewService(md)
|
|
|
|
|
|
|
|
|
|
// 设置 service 所属于 md
|
|
|
|
|
if err := controllerutil.SetControllerReference(md, svc, r.Scheme); err != nil {
|
|
|
|
|
if err := controllerutil.SetControllerReference(md, &svc, r.Scheme); err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 预更新service,得到更新后的数据
|
|
|
|
|
if err := r.Update(ctx, svc, client.DryRunAll); err != nil {
|
|
|
|
|
if err := r.Update(ctx, &svc, client.DryRunAll); err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -425,55 +369,25 @@ func (r *MsbDeploymentReconciler) updateService(ctx context.Context, md *myAppsv
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return r.Client.Update(ctx, svc)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (r *MsbDeploymentReconciler) updateNPService(ctx context.Context, md *myAppsv1.MsbDeployment, service *corev1.Service) error {
|
|
|
|
|
svc, err := NewServiceNP(md)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 设置 service 所属于 md
|
|
|
|
|
if err := controllerutil.SetControllerReference(md, svc, r.Scheme); err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 预更新service,得到更新后的数据
|
|
|
|
|
if err := r.Update(ctx, svc, client.DryRunAll); err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 和之前的数据进行比较,如果相同,说明更新不需要。
|
|
|
|
|
if reflect.DeepEqual(service.Spec, svc.Spec) {
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return r.Client.Update(ctx, svc)
|
|
|
|
|
return r.Client.Update(ctx, &svc)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (r *MsbDeploymentReconciler) createIngress(ctx context.Context, md *myAppsv1.MsbDeployment) error {
|
|
|
|
|
ig, err := NewIngress(md)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
ig := NewIngress(md)
|
|
|
|
|
|
|
|
|
|
// 设置 ingress 所属于 md
|
|
|
|
|
if err := controllerutil.SetControllerReference(md, ig, r.Scheme); err != nil {
|
|
|
|
|
if err := controllerutil.SetControllerReference(md, &ig, r.Scheme); err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return r.Client.Create(ctx, ig)
|
|
|
|
|
return r.Client.Create(ctx, &ig)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (r *MsbDeploymentReconciler) updateIngress(ctx context.Context, md *myAppsv1.MsbDeployment, ingress *networkv1.Ingress) error {
|
|
|
|
|
ig, err := NewIngress(md)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
ig := NewIngress(md)
|
|
|
|
|
|
|
|
|
|
// 设置 ingress 所属于 md
|
|
|
|
|
if err := controllerutil.SetControllerReference(md, ig, r.Scheme); err != nil {
|
|
|
|
|
if err := controllerutil.SetControllerReference(md, &ig, r.Scheme); err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -487,15 +401,13 @@ func (r *MsbDeploymentReconciler) updateIngress(ctx context.Context, md *myAppsv
|
|
|
|
|
return nil
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return r.Client.Update(ctx, ig)
|
|
|
|
|
return r.Client.Update(ctx, &ig)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func (r *MsbDeploymentReconciler) deleteIngress(ctx context.Context, md *myAppsv1.MsbDeployment) error {
|
|
|
|
|
ig, err := NewIngress(md)
|
|
|
|
|
if err != nil {
|
|
|
|
|
return err
|
|
|
|
|
}
|
|
|
|
|
return r.Client.Delete(ctx, ig)
|
|
|
|
|
ig := NewIngress(md)
|
|
|
|
|
|
|
|
|
|
return r.Client.Delete(ctx, &ig)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 处理status
|
|
|
|
|