Compare commits

...

2 Commits

Author SHA1 Message Date
hys
a822538fc3 feat: add deviceName to helm values 2025-12-22 17:36:31 +08:00
hys
c5610cbcb7 fix: pending canceled namespace delete 2025-12-19 20:54:16 +08:00
8 changed files with 213 additions and 15 deletions

View File

@@ -170,7 +170,7 @@ spec:
priorityClassName: "system-cluster-critical"
containers:
- name: app-service
image: beclab/app-service:0.4.66
image: beclab/app-service:0.4.67
imagePullPolicy: IfNotPresent
securityContext:
runAsUser: 0
@@ -228,6 +228,8 @@ spec:
valueFrom:
fieldRef:
fieldPath: status.hostIP
- name: OLARESD_HOST
value: $(HOSTIP):18088
volumeMounts:
- mountPath: /charts
name: charts-store

View File

@@ -406,7 +406,7 @@ func (r *ApplicationReconciler) updateApplication(ctx context.Context, req ctrl.
} else {
appid = appv1alpha1.AppName(name).GetAppID()
}
_, sharedEntrances := r.getAppSettings(ctx, name, appid, owner, deployment, isMultiApp, entrancesMap[name])
settings, sharedEntrances := r.getAppSettings(ctx, name, appid, owner, deployment, isMultiApp, entrancesMap[name])
appCopy.Spec.Name = name
appCopy.Spec.Namespace = deployment.GetNamespace()
@@ -416,6 +416,12 @@ func (r *ApplicationReconciler) updateApplication(ctx context.Context, req ctrl.
appCopy.Spec.SharedEntrances = sharedEntrances
appCopy.Spec.Ports = servicePortsMap[name]
appCopy.Spec.Entrances = entrancesMap[name]
if settings["defaultThirdLevelDomainConfig"] != "" {
if appCopy.Spec.Settings == nil {
appCopy.Spec.Settings = make(map[string]string)
}
appCopy.Spec.Settings["defaultThirdLevelDomainConfig"] = settings["defaultThirdLevelDomainConfig"]
}
if tailScale != nil {
appCopy.Spec.TailScale = *tailScale

View File

@@ -6,7 +6,7 @@ import (
"os"
"path/filepath"
"k8s.io/apimachinery/pkg/api/errors"
apierrors "k8s.io/apimachinery/pkg/api/errors"
"bytetrade.io/web3os/app-service/api/app.bytetrade.io/v1alpha1"
"bytetrade.io/web3os/app-service/pkg/appcfg"
@@ -258,6 +258,13 @@ func (h *HelmOps) SetValues() (values map[string]interface{}, err error) {
klog.Infof("values[node]: %#v", values["nodes"])
deviceName, err := utils.GetDeviceName()
if err != nil {
klog.Errorf("failed to get deviceName %v", err)
return values, err
}
values["deviceName"] = deviceName
return values, err
}
@@ -296,7 +303,7 @@ func (h *HelmOps) getInstalledApps(ctx context.Context) (installed bool, app []*
func (h *HelmOps) AddEnvironmentVariables(values map[string]interface{}) error {
values[constants.OlaresEnvHelmValuesKey] = make(map[string]interface{})
appEnv, err := h.client.AppClient.SysV1alpha1().AppEnvs(h.app.Namespace).Get(h.ctx, apputils.FormatAppEnvName(h.app.AppName, h.app.OwnerName), metav1.GetOptions{})
if errors.IsNotFound(err) {
if apierrors.IsNotFound(err) {
return nil
}
if err != nil {

View File

@@ -181,6 +181,14 @@ func (p *DownloadingApp) exec(ctx context.Context) error {
}
values["nodes"] = nodeInfo
deviceName, err := utils.GetDeviceName()
if err != nil {
klog.Errorf("failed to get deviceName %v", err)
return err
}
values["deviceName"] = deviceName
refs, err := p.getRefsForImageManager(appConfig, values)
if err != nil {
klog.Errorf("get image refs from resources failed %v", err)

View File

@@ -1,18 +1,25 @@
package appstate
import (
"context"
"time"
appsv1 "bytetrade.io/web3os/app-service/api/app.bytetrade.io/v1alpha1"
apputils "bytetrade.io/web3os/app-service/pkg/utils/app"
corev1 "k8s.io/api/core/v1"
apierrors "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/types"
"k8s.io/klog/v2"
"sigs.k8s.io/controller-runtime/pkg/client"
)
// FIXME: impossible state
var _ StatefulApp = &PendingCancelFailedApp{}
var _ OperationApp = &PendingCancelFailedApp{}
type PendingCancelFailedApp struct {
*DoNothingApp
*baseOperationApp
}
func NewPendingCancelFailedApp(c client.Client,
@@ -20,7 +27,8 @@ func NewPendingCancelFailedApp(c client.Client,
return appFactory.New(c, manager, 0,
func(c client.Client, manager *appsv1.ApplicationManager, ttl time.Duration) StatefulApp {
return &PendingCancelFailedApp{
DoNothingApp: &DoNothingApp{
baseOperationApp: &baseOperationApp{
ttl: ttl,
baseStatefulApp: &baseStatefulApp{
manager: manager,
client: c,
@@ -30,11 +38,25 @@ func NewPendingCancelFailedApp(c client.Client,
})
}
//func (p *PendingCancelFailedApp) Exec(ctx context.Context) (StatefulInProgressApp, error) {
// // FIXME: should set a max retry count for cancel operation
// err := p.updateStatus(ctx, p.manager, appsv1.PendingCanceling, nil, appsv1.PendingCanceling.String())
// if err != nil {
// klog.Errorf("update app manager %s to %s state failed %v", p.manager.Name, appsv1.PendingCanceling, err)
// }
// return nil, err
//}
func (p *PendingCancelFailedApp) Exec(ctx context.Context) (StatefulInProgressApp, error) {
if !apputils.IsProtectedNamespace(p.manager.Spec.AppNamespace) {
var ns corev1.Namespace
err := p.client.Get(ctx, types.NamespacedName{Name: p.manager.Spec.AppNamespace}, &ns)
if err != nil && !apierrors.IsNotFound(err) {
return nil, err
}
if err == nil {
e := p.client.Delete(ctx, &ns)
if e != nil {
klog.Errorf("failed to delete ns %s, err=%v", p.manager.Spec.AppNamespace, e)
return nil, e
}
}
}
return nil, nil
}
func (p *PendingCancelFailedApp) Cancel(ctx context.Context) error {
return nil
}

View File

@@ -2,9 +2,15 @@ package appstate
import (
"context"
"fmt"
"time"
appsv1 "bytetrade.io/web3os/app-service/api/app.bytetrade.io/v1alpha1"
apputils "bytetrade.io/web3os/app-service/pkg/utils/app"
corev1 "k8s.io/api/core/v1"
apierrors "k8s.io/apimachinery/pkg/api/errors"
"k8s.io/apimachinery/pkg/types"
"k8s.io/klog/v2"
"sigs.k8s.io/controller-runtime/pkg/client"
)
@@ -41,6 +47,21 @@ func (p *PendingCancelingApp) Exec(ctx context.Context) (StatefulInProgressApp,
klog.Errorf("app %s operation is not ", p.manager.Name)
}
if !apputils.IsProtectedNamespace(p.manager.Spec.AppNamespace) {
var ns corev1.Namespace
err := p.client.Get(ctx, types.NamespacedName{Name: p.manager.Spec.AppNamespace}, &ns)
if err != nil && !apierrors.IsNotFound(err) {
klog.Errorf("failed to get namespace %s, %v", p.manager.Spec.AppNamespace, err)
return nil, err
}
if err == nil {
if delErr := p.client.Delete(ctx, &ns); delErr != nil && !apierrors.IsNotFound(delErr) {
klog.Errorf("failed to delete namespace %s, %v", p.manager.Spec.AppNamespace, delErr)
return nil, delErr
}
}
}
err := p.updateStatus(ctx, p.manager, appsv1.PendingCanceled, nil, appsv1.PendingCanceled.String(), "")
if err != nil {
klog.Errorf("update app manager %s to %s state failed %v", p.manager.Name, appsv1.PendingCanceled, err)
@@ -59,3 +80,58 @@ func (p *PendingCancelingApp) Cancel(ctx context.Context) error {
return nil
}
var _ PollableStatefulInProgressApp = &pendingCancelInProgressApp{}
type pendingCancelInProgressApp struct {
*PendingCancelingApp
*basePollableStatefulInProgressApp
}
func (p *pendingCancelInProgressApp) Exec(ctx context.Context) (StatefulInProgressApp, error) {
return nil, nil
}
func (p *pendingCancelInProgressApp) poll(ctx context.Context) error {
if apputils.IsProtectedNamespace(p.manager.Spec.AppNamespace) {
return nil
}
timer := time.NewTicker(time.Second)
defer timer.Stop()
for {
select {
case <-timer.C:
var ns corev1.Namespace
err := p.client.Get(ctx, types.NamespacedName{Name: p.manager.Spec.AppNamespace}, &ns)
klog.Infof("pending cancel poll namespace %s err %v", p.manager.Spec.AppNamespace, err)
if apierrors.IsNotFound(err) {
return nil
}
case <-ctx.Done():
return fmt.Errorf("app %s execute cancel operation failed %w", p.manager.Spec.AppName, ctx.Err())
}
}
}
func (p *pendingCancelInProgressApp) WaitAsync(ctx context.Context) {
appFactory.waitForPolling(ctx, p, func(err error) {
if err != nil {
updateErr := p.updateStatus(context.TODO(), p.manager, appsv1.PendingCancelFailed, nil, appsv1.PendingCancelFailed.String(), "")
if updateErr != nil {
klog.Errorf("update app manager %s to %s state failed %v", p.manager.Name, appsv1.PendingCancelFailed.String(), updateErr)
return
}
return
}
updateErr := p.updateStatus(context.TODO(), p.manager, appsv1.PendingCanceled, nil, appsv1.PendingCanceled.String(), "")
if updateErr != nil {
klog.Errorf("update app manager %s to %s state failed %v", p.manager.Name, appsv1.PendingCanceled.String(), updateErr)
return
}
})
}

View File

@@ -235,6 +235,14 @@ func (p *UpgradingApp) exec(ctx context.Context) error {
}
values["nodes"] = nodeInfo
deviceName, err := utils.GetDeviceName()
if err != nil {
klog.Errorf("failed to get deviceName %v", err)
return err
}
values["deviceName"] = deviceName
refs, err := p.getRefsForImageManager(appConfig, values)
if err != nil {
klog.Errorf("get image refs from resources failed %v", err)

View File

@@ -4,8 +4,11 @@ import (
"context"
"errors"
"fmt"
"github.com/go-resty/resty/v2"
"net"
"net/http"
"net/url"
"os"
"strconv"
"strings"
"time"
@@ -399,3 +402,69 @@ func GetNodeInfo(ctx context.Context) (ret []api.NodeInfo, err error) {
}
return
}
type SystemStatusResponse struct {
Code int `json:"code"`
Message string `json:"message"`
Data struct {
TerminusdState string `json:"terminusdState"`
TerminusState string `json:"terminusState"`
TerminusName string `json:"terminusName"`
TerminusVersion string `json:"terminusVersion"`
InstalledTime int64 `json:"installedTime"`
InitializedTime int64 `json:"initializedTime"`
OlaresdVersion string `json:"olaresdVersion"`
DeviceName string `json:"device_name"`
HostName string `json:"host_name"`
OsType string `json:"os_type"`
OsArch string `json:"os_arch"`
OsInfo string `json:"os_info"`
OsVersion string `json:"os_version"`
CpuInfo string `json:"cpu_info"`
GpuInfo string `json:"gpu_info"`
Memory string `json:"memory"`
Disk string `json:"disk"`
WifiConnected bool `json:"wifiConnected"`
WiredConnected bool `json:"wiredConnected"`
HostIp string `json:"hostIp"`
ExternalIp string `json:"externalIp"`
InstallingState string `json:"installingState"`
InstallingProgress string `json:"installingProgress"`
UninstallingState string `json:"uninstallingState"`
UninstallingProgress string `json:"uninstallingProgress"`
UpgradingTarget string `json:"upgradingTarget"`
UpgradingRetryNum int `json:"upgradingRetryNum"`
UpgradingState string `json:"upgradingState"`
UpgradingStep string `json:"upgradingStep"`
UpgradingProgress string `json:"upgradingProgress"`
UpgradingError string `json:"upgradingError"`
UpgradingDownloadState string `json:"upgradingDownloadState"`
UpgradingDownloadStep string `json:"upgradingDownloadStep"`
UpgradingDownloadProgress string `json:"upgradingDownloadProgress"`
UpgradingDownloadError string `json:"upgradingDownloadError"`
CollectingLogsState string `json:"collectingLogsState"`
CollectingLogsError string `json:"collectingLogsError"`
DefaultFrpServer string `json:"defaultFrpServer"`
FrpEnable string `json:"frpEnable"`
} `json:"data"`
}
func GetDeviceName() (string, error) {
url := fmt.Sprintf("http://%s/system/status", os.Getenv("OLARESD_HOST"))
var result SystemStatusResponse
client := resty.New()
resp, err := client.R().SetResult(&result).Get(url)
if err != nil {
klog.Errorf("failed to send request to olaresd %v", err)
return "", err
}
if resp.StatusCode() != http.StatusOK {
klog.Errorf("failed to get system status from olaresd %v", err)
return "", errors.New(string(resp.Body()))
}
if result.Code != http.StatusOK {
return "", fmt.Errorf("not exepcted result code: %v,message: %v", result.Code, result.Message)
}
klog.Infof("getDeviceName: %#v", result.Data)
return result.Data.DeviceName, nil
}