Compare commits
6 Commits
feat/env_s
...
bfl/fix/re
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
ac03f2a13d | ||
|
|
f6eb6574d6 | ||
|
|
9113e14b7a | ||
|
|
fc62d8280a | ||
|
|
b8d6e2f3cc | ||
|
|
763c80c5fa |
@@ -266,7 +266,7 @@ spec:
|
||||
|
||||
containers:
|
||||
- name: api
|
||||
image: beclab/bfl:v0.4.39
|
||||
image: beclab/bfl:v0.4.40
|
||||
imagePullPolicy: IfNotPresent
|
||||
securityContext:
|
||||
runAsUser: 1000
|
||||
|
||||
@@ -299,111 +299,6 @@ func (r *NginxController) generateNginxServers() ([]config.Server, error) {
|
||||
|
||||
ctx := context.TODO()
|
||||
|
||||
// get the bfl service
|
||||
var svc corev1.Service
|
||||
err := r.Get(ctx, types.NamespacedName{Namespace: constants.Namespace, Name: constants.BFLServiceName}, &svc)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("no bfl service found, %v", err)
|
||||
}
|
||||
|
||||
latestAppPort := func(portName string) int {
|
||||
// compute the latest and available app port
|
||||
var latestPort, maxAppPort int32
|
||||
|
||||
if len(svc.Spec.Ports) < 1 {
|
||||
return int(constants.AppListenFromPort)
|
||||
} else {
|
||||
maxPort := svc.Spec.Ports[0].Port
|
||||
for _, p := range svc.Spec.Ports {
|
||||
if p.Name == portName {
|
||||
// never used
|
||||
// latestPort = p.Port
|
||||
break
|
||||
}
|
||||
if p.Port > maxPort {
|
||||
maxPort = p.Port
|
||||
}
|
||||
if strings.HasPrefix(p.Name, constants.AppPortNamePrefix) && p.Port > maxAppPort {
|
||||
maxAppPort = p.Port
|
||||
}
|
||||
}
|
||||
if maxAppPort+1 > constants.AppListenFromPort && maxAppPort+1 < maxPort {
|
||||
latestPort = maxAppPort + 1
|
||||
} else if maxAppPort < constants.AppListenFromPort {
|
||||
latestPort = constants.AppListenFromPort
|
||||
} else {
|
||||
latestPort = maxPort + 1
|
||||
}
|
||||
}
|
||||
klog.InfoS("Figure out the latest port", "maxAppPort", maxAppPort, "latestPort", latestPort)
|
||||
|
||||
portExists := false
|
||||
|
||||
for _, app := range svc.Spec.Ports {
|
||||
if portName == app.Name {
|
||||
app.Port = latestPort
|
||||
app.TargetPort = intstr.FromInt(int(latestPort))
|
||||
portExists = true
|
||||
break
|
||||
}
|
||||
}
|
||||
if !portExists {
|
||||
// update svc
|
||||
svcPort := corev1.ServicePort{
|
||||
Name: portName,
|
||||
Protocol: "TCP",
|
||||
Port: latestPort,
|
||||
TargetPort: intstr.FromInt(int(latestPort)),
|
||||
}
|
||||
svc.Spec.Ports = append(svc.Spec.Ports, svcPort)
|
||||
}
|
||||
return int(latestPort)
|
||||
}
|
||||
|
||||
// For each applications port server
|
||||
for _, app := range r.apps {
|
||||
if len(app.Spec.Entrances) == 0 {
|
||||
klog.Warningf("invalid app %q, ignore it. app=%s", app.Spec.Name, utils.PrettyJSON(app.Spec))
|
||||
continue
|
||||
}
|
||||
|
||||
for _, entrance := range app.Spec.Entrances {
|
||||
if entrance.Host == "" {
|
||||
continue
|
||||
}
|
||||
appPortName := fmt.Sprintf("%s%s", constants.AppPortNamePrefix, entrance.Name)
|
||||
appPort := latestAppPort(appPortName)
|
||||
|
||||
s := config.Server{
|
||||
Port: appPort,
|
||||
Locations: []config.Location{
|
||||
{
|
||||
Prefix: "/",
|
||||
ProxyPass: fmt.Sprintf("http://%s.%s.svc.cluster.local:%d", entrance.Host, app.Spec.Namespace, entrance.Port),
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
// server patches
|
||||
if patches, ok := patches[entrance.Name]; ok {
|
||||
for _, patch := range patches {
|
||||
_, err = patch(ctx, r, &s)
|
||||
if err != nil {
|
||||
klog.Errorf("failed to apply patch for app %s, %v", app.Spec.Name, err)
|
||||
return nil, err
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
servers = append(servers, s)
|
||||
}
|
||||
}
|
||||
klog.Infof("Prepared and updating service ports:\n%v", utils.PrettyJSON(svc.Spec.Ports))
|
||||
err = r.Update(context.TODO(), &svc)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
// For each domain servers
|
||||
|
||||
if r.sslConfigData != nil {
|
||||
|
||||
@@ -281,7 +281,7 @@ func (h *Handler) handleTerminusInfo(req *restful.Request, resp *restful.Respons
|
||||
tInfo.TailScaleEnable = denyAll == 1
|
||||
}
|
||||
|
||||
tInfo.LoginBackground = userOp.GetLoginBackground(user)
|
||||
tInfo.LoginBackground, tInfo.Style = userOp.GetLoginBackground(user)
|
||||
tInfo.Avatar = userOp.GetAvatar(user)
|
||||
tInfo.UserDID = userOp.GetUserDID(user)
|
||||
|
||||
@@ -347,7 +347,7 @@ func (h *Handler) handleOlaresInfo(req *restful.Request, resp *restful.Response)
|
||||
tInfo.TailScaleEnable = denyAll == 1
|
||||
}
|
||||
|
||||
tInfo.LoginBackground = userOp.GetLoginBackground(user)
|
||||
tInfo.LoginBackground, tInfo.Style = userOp.GetLoginBackground(user)
|
||||
tInfo.Avatar = userOp.GetAvatar(user)
|
||||
tInfo.UserDID = userOp.GetUserDID(user)
|
||||
|
||||
|
||||
@@ -40,6 +40,7 @@ type TerminusInfo struct {
|
||||
UserDID string `json:"did"`
|
||||
ReverseProxy string `json:"reverseProxy"`
|
||||
Terminusd string `json:"terminusd"`
|
||||
Style string `json:"style"`
|
||||
}
|
||||
|
||||
type OlaresInfo struct {
|
||||
@@ -53,6 +54,7 @@ type OlaresInfo struct {
|
||||
ID string `json:"id"`
|
||||
UserDID string `json:"did"`
|
||||
Olaresd string `json:"olaresd"`
|
||||
Style string `json:"style"`
|
||||
}
|
||||
|
||||
type MyAppsParam struct {
|
||||
|
||||
@@ -127,13 +127,18 @@ func (o *UserOperator) GetReverseProxyType() (string, error) {
|
||||
return o.GetUserAnnotation(user, constants.UserAnnotationReverseProxyType), nil
|
||||
}
|
||||
|
||||
func (o *UserOperator) GetLoginBackground(user *iamV1alpha2.User) string {
|
||||
func (o *UserOperator) GetLoginBackground(user *iamV1alpha2.User) (string, string) {
|
||||
b := o.GetUserAnnotation(user, constants.UserLoginBackground)
|
||||
s := o.GetUserAnnotation(user, constants.UserLoginBackgroundStyle)
|
||||
if b == "" {
|
||||
return "/bg/0.jpg"
|
||||
b = "/bg/0.jpg"
|
||||
}
|
||||
|
||||
return b
|
||||
if s == "" {
|
||||
s = "fill"
|
||||
}
|
||||
|
||||
return b, s
|
||||
}
|
||||
|
||||
func (o *UserOperator) GetAvatar(user *iamV1alpha2.User) string {
|
||||
|
||||
@@ -612,6 +612,7 @@ func (h *Handler) handleUpdateLocale(req *restful.Request, resp *restful.Respons
|
||||
func (h *Handler) handlerUpdateUserLoginBackground(req *restful.Request, resp *restful.Response) {
|
||||
var background struct {
|
||||
Background string `json:"background"`
|
||||
Style string `json:"style"`
|
||||
}
|
||||
|
||||
err := req.ReadEntity(&background)
|
||||
@@ -636,6 +637,7 @@ func (h *Handler) handlerUpdateUserLoginBackground(req *restful.Request, resp *r
|
||||
err = userOp.UpdateUser(user, []func(*iamV1alpha2.User){
|
||||
func(u *iamV1alpha2.User) {
|
||||
u.Annotations[constants.UserLoginBackground] = background.Background
|
||||
u.Annotations[constants.UserLoginBackgroundStyle] = background.Style
|
||||
},
|
||||
})
|
||||
|
||||
|
||||
@@ -175,7 +175,8 @@ var (
|
||||
|
||||
UserAvatar = fmt.Sprintf("%s/avatar", AnnotationGroup)
|
||||
|
||||
UserLoginBackground = fmt.Sprintf("%s/login-background", AnnotationGroup)
|
||||
UserLoginBackground = fmt.Sprintf("%s/login-background", AnnotationGroup)
|
||||
UserLoginBackgroundStyle = fmt.Sprintf("%s/login-background-style", AnnotationGroup)
|
||||
)
|
||||
|
||||
var (
|
||||
|
||||
Reference in New Issue
Block a user