2020-11-04 22:30:15 +00:00
|
|
|
package controllers
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/seaweedfs/seaweedfs-operator/controllers/label"
|
|
|
|
ctrl "sigs.k8s.io/controller-runtime"
|
|
|
|
"sigs.k8s.io/controller-runtime/pkg/controller/controllerutil"
|
|
|
|
|
|
|
|
seaweedv1 "github.com/seaweedfs/seaweedfs-operator/api/v1"
|
|
|
|
)
|
|
|
|
|
|
|
|
func (r *SeaweedReconciler) ensureSeaweedIngress(seaweedCR *seaweedv1.Seaweed) (done bool, result ctrl.Result, err error) {
|
|
|
|
|
2020-11-10 08:11:17 +00:00
|
|
|
if seaweedCR.Spec.HostSuffix != nil && len(*seaweedCR.Spec.HostSuffix) != 0 {
|
|
|
|
if done, result, err = r.ensureAllIngress(seaweedCR); done {
|
2020-11-04 22:30:15 +00:00
|
|
|
return
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2020-11-10 08:11:17 +00:00
|
|
|
func (r *SeaweedReconciler) ensureAllIngress(seaweedCR *seaweedv1.Seaweed) (bool, ctrl.Result, error) {
|
|
|
|
log := r.Log.WithValues("sw-ingress", seaweedCR.Name)
|
2020-11-04 22:30:15 +00:00
|
|
|
|
2020-11-10 08:11:17 +00:00
|
|
|
ingressService := r.createAllIngress(seaweedCR)
|
2020-11-04 22:30:15 +00:00
|
|
|
if err := controllerutil.SetControllerReference(seaweedCR, ingressService, r.Scheme); err != nil {
|
|
|
|
return ReconcileResult(err)
|
|
|
|
}
|
|
|
|
_, err := r.CreateOrUpdateIngress(ingressService)
|
|
|
|
|
2020-11-10 08:11:17 +00:00
|
|
|
log.Info("ensure ingress " + ingressService.Name)
|
2020-11-04 22:30:15 +00:00
|
|
|
return ReconcileResult(err)
|
|
|
|
}
|
|
|
|
|
|
|
|
func labelsForIngress(name string) map[string]string {
|
|
|
|
return map[string]string{
|
|
|
|
label.ManagedByLabelKey: "seaweedfs-operator",
|
|
|
|
label.NameLabelKey: "seaweedfs",
|
|
|
|
label.ComponentLabelKey: "ingress",
|
|
|
|
label.InstanceLabelKey: name,
|
|
|
|
}
|
|
|
|
}
|