diff --git a/api/base/v1alpha1/application_types.go b/api/base/v1alpha1/application_types.go index d54938791..1f7670db9 100644 --- a/api/base/v1alpha1/application_types.go +++ b/api/base/v1alpha1/application_types.go @@ -37,6 +37,10 @@ type ApplicationSpec struct { IsPublic bool `json:"isPublic,omitempty"` // IsRecommended Set whether the current application is recognized as recommended to users IsRecommended bool `json:"isRecommended,omitempty"` + + // Category Application category + Category string `json:"category,omitempty"` + // WebConfig is the configuration for web interface WebConfig `json:",inline"` // prologue, show in the chat top diff --git a/apiserver/pkg/application/application.go b/apiserver/pkg/application/application.go index c7b698bd6..3d50ce2cb 100644 --- a/apiserver/pkg/application/application.go +++ b/apiserver/pkg/application/application.go @@ -44,17 +44,14 @@ import ( func addCategory(app *v1alpha1.Application, category []*string) *v1alpha1.Application { if len(category) == 0 { - delete(app.Labels, v1alpha1.AppCategoryLabelKey) + app.Spec.Category = "" return app } - if app.Annotations == nil { - app.Annotations = make(map[string]string, 1) - } c := make([]string, len(category)) for i := range category { c[i] = *category[i] } - app.Labels[v1alpha1.AppCategoryLabelKey] = strings.Join(c, ",") + app.Spec.Category = strings.Join(c, ",") return app } @@ -202,7 +199,9 @@ func CreateApplication(ctx context.Context, c client.Client, input generated.Cre Nodes: []v1alpha1.Node{}, }, } - app = addCategory(app, input.Category) + if len(input.Category) > 0 { + app = addCategory(app, input.Category) + } common.SetCreator(ctx, &app.Spec.CommonSpec) if err := c.Create(ctx, app); err != nil { return nil, err @@ -216,9 +215,15 @@ func UpdateApplication(ctx context.Context, c client.Client, input generated.Upd return nil, err } oldApp := app.DeepCopy() - app.Labels = utils.MapAny2Str(input.Labels) - app.Annotations = utils.MapAny2Str(input.Annotations) - app = addCategory(app, input.Category) + if len(input.Labels) > 0 { + app.Labels = utils.MapAny2Str(input.Labels) + } + if len(input.Annotations) > 0 { + app.Annotations = utils.MapAny2Str(input.Annotations) + } + if len(input.Category) > 0 { + app = addCategory(app, input.Category) + } app.Spec.DisplayName = input.DisplayName app.Spec.Description = pointer.StringDeref(input.Description, app.Spec.Description) app.Spec.Icon = input.Icon diff --git a/config/crd/bases/arcadia.kubeagi.k8s.com.cn_applications.yaml b/config/crd/bases/arcadia.kubeagi.k8s.com.cn_applications.yaml index 4cdc52f62..4a51a9182 100644 --- a/config/crd/bases/arcadia.kubeagi.k8s.com.cn_applications.yaml +++ b/config/crd/bases/arcadia.kubeagi.k8s.com.cn_applications.yaml @@ -35,6 +35,9 @@ spec: spec: description: ApplicationSpec defines the desired state of Application properties: + category: + description: Category Application category + type: string chatTimeoutSecond: default: 60 description: ChatTimeoutSecond is the timeout of chat diff --git a/controllers/base/application_controller.go b/controllers/base/application_controller.go index 76eada85d..6c230184e 100644 --- a/controllers/base/application_controller.go +++ b/controllers/base/application_controller.go @@ -163,11 +163,8 @@ func (r *ApplicationReconciler) Reconcile(ctx context.Context, req ctrl.Request) func MigrateAppCategory(app *arcadiav1alpha1.Application) bool { if v, ok := app.Annotations[arcadiav1alpha1.AppCategoryLabelKey]; ok && len(validation.IsValidLabelValue(v)) == 0 { // TODO: In version 0.3, the categories in annotations will be removed. - if app.Labels == nil { - app.Labels = make(map[string]string) - } - if _, ok := app.Labels[arcadiav1alpha1.AppCategoryLabelKey]; !ok { - app.Labels[arcadiav1alpha1.AppCategoryLabelKey] = v + if app.Spec.Category == "" { + app.Spec.Category = v return true } } @@ -323,6 +320,16 @@ func (r *ApplicationReconciler) reconcile(ctx context.Context, log logr.Logger, } else { delete(app.Labels, arcadiav1alpha1.AppRecommendedLabelKey) } + if app.Spec.Category != "" { + if app.Labels == nil { + app.Labels = make(map[string]string) + } + if v, ok := app.Labels[arcadiav1alpha1.AppCategoryLabelKey]; !ok || v != app.Spec.Category { + app.Labels[arcadiav1alpha1.AppCategoryLabelKey] = app.Spec.Category + } + } else { + delete(app.Labels, arcadiav1alpha1.AppCategoryLabelKey) + } if !reflect.DeepEqual(app, appRaw) { return app, ctrl.Result{Requeue: true}, r.Patch(ctx, app, client.MergeFrom(appRaw)) diff --git a/deploy/charts/arcadia/crds/arcadia.kubeagi.k8s.com.cn_applications.yaml b/deploy/charts/arcadia/crds/arcadia.kubeagi.k8s.com.cn_applications.yaml index 4cdc52f62..4a51a9182 100644 --- a/deploy/charts/arcadia/crds/arcadia.kubeagi.k8s.com.cn_applications.yaml +++ b/deploy/charts/arcadia/crds/arcadia.kubeagi.k8s.com.cn_applications.yaml @@ -35,6 +35,9 @@ spec: spec: description: ApplicationSpec defines the desired state of Application properties: + category: + description: Category Application category + type: string chatTimeoutSecond: default: 60 description: ChatTimeoutSecond is the timeout of chat