Skip to content

Commit

Permalink
feat: set creator value in apiserver
Browse files Browse the repository at this point in the history
Signed-off-by: Abirdcfly <[email protected]>
  • Loading branch information
Abirdcfly committed Dec 29, 2023
1 parent 3ed0634 commit 7288f25
Show file tree
Hide file tree
Showing 10 changed files with 21 additions and 0 deletions.
1 change: 1 addition & 0 deletions apiserver/pkg/application/application.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ func CreateApplication(ctx context.Context, c dynamic.Interface, input generated
Nodes: []v1alpha1.Node{},
},
}
common.SetCreator(ctx, &app.Spec.CommonSpec)
object, err := runtime.DefaultUnstructuredConverter.ToUnstructured(app)
if err != nil {
return nil, err
Expand Down
6 changes: 6 additions & 0 deletions apiserver/pkg/common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (

"github.com/kubeagi/arcadia/api/base/v1alpha1"
"github.com/kubeagi/arcadia/apiserver/graph/generated"
"github.com/kubeagi/arcadia/apiserver/pkg/auth"
"github.com/kubeagi/arcadia/pkg/config"
"github.com/kubeagi/arcadia/pkg/datasource"
)
Expand Down Expand Up @@ -192,3 +193,8 @@ func WithPageNodeConvertFunc(convertFunc PageNodeConvertFunc) ListOptionsFunc {
option.ConvertFunc = convertFunc
}
}

func SetCreator(ctx context.Context, common *v1alpha1.CommonSpec) {
currentUser, _ := ctx.Value(auth.UserNameContextKey).(string)
common.Creator = currentUser
}
1 change: 1 addition & 0 deletions apiserver/pkg/dataset/dataset.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ func CreateDataset(ctx context.Context, c dynamic.Interface, input *generated.Cr
}
dataset.Labels = utils.MapAny2Str(input.Labels)
dataset.Annotations = utils.MapAny2Str(input.Annotations)
common.SetCreator(ctx, &dataset.Spec.CommonSpec)

u, err := runtime.DefaultUnstructuredConverter.ToUnstructured(dataset)
if err != nil {
Expand Down
3 changes: 3 additions & 0 deletions apiserver/pkg/datasource/datasource.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import (
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/client-go/dynamic"
"k8s.io/utils/pointer"

"github.com/kubeagi/arcadia/api/base/v1alpha1"
"github.com/kubeagi/arcadia/apiserver/graph/generated"
Expand Down Expand Up @@ -80,6 +81,7 @@ func datasource2model(obj *unstructured.Unstructured) *generated.Datasource {
ID: &id,
Name: datasource.Name,
Namespace: datasource.Namespace,
Creator: pointer.String(datasource.Spec.Creator),
Labels: graphqlutils.MapStr2Any(obj.GetLabels()),
Annotations: graphqlutils.MapStr2Any(obj.GetAnnotations()),
DisplayName: &datasource.Spec.DisplayName,
Expand Down Expand Up @@ -121,6 +123,7 @@ func CreateDatasource(ctx context.Context, c dynamic.Interface, input generated.
},
},
}
common.SetCreator(ctx, &datasource.Spec.CommonSpec)

// make endpoint
endpoint, err := common.MakeEndpoint(ctx, c, generated.TypedObjectReferenceInput{
Expand Down
3 changes: 3 additions & 0 deletions apiserver/pkg/embedder/embedder.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import (
"k8s.io/apimachinery/pkg/runtime"
"k8s.io/apimachinery/pkg/runtime/schema"
"k8s.io/client-go/dynamic"
"k8s.io/utils/pointer"

"github.com/kubeagi/arcadia/api/base/v1alpha1"
"github.com/kubeagi/arcadia/apiserver/graph/generated"
Expand Down Expand Up @@ -76,6 +77,7 @@ func Embedder2model(ctx context.Context, c dynamic.Interface, obj *unstructured.
ID: &id,
Name: obj.GetName(),
Namespace: obj.GetNamespace(),
Creator: pointer.String(embedder.Spec.Creator),
CreationTimestamp: &creationtimestamp,
Labels: graphqlutils.MapStr2Any(obj.GetLabels()),
Annotations: graphqlutils.MapStr2Any(obj.GetAnnotations()),
Expand Down Expand Up @@ -146,6 +148,7 @@ func CreateEmbedder(ctx context.Context, c dynamic.Interface, input generated.Cr
Namespace: &input.Namespace,
}
}
common.SetCreator(ctx, &embedder.Spec.CommonSpec)

unstructuredEmbedder, err := runtime.DefaultUnstructuredConverter.ToUnstructured(&embedder)
if err != nil {
Expand Down
2 changes: 2 additions & 0 deletions apiserver/pkg/knowledgebase/knowledgebase.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ func knowledgebase2model(obj *unstructured.Unstructured) *generated.KnowledgeBas
ID: &id,
Name: obj.GetName(),
Namespace: obj.GetNamespace(),
Creator: &knowledgebase.Spec.Creator,
Labels: graphqlutils.MapStr2Any(obj.GetLabels()),
Annotations: graphqlutils.MapStr2Any(obj.GetAnnotations()),
DisplayName: &knowledgebase.Spec.DisplayName,
Expand Down Expand Up @@ -140,6 +141,7 @@ func CreateKnowledgeBase(ctx context.Context, c dynamic.Interface, name, namespa
FileGroups: filegroups,
},
}
common.SetCreator(ctx, &knowledgebase.Spec.CommonSpec)

unstructuredKnowledgeBase, err := runtime.DefaultUnstructuredConverter.ToUnstructured(&knowledgebase)
if err != nil {
Expand Down
2 changes: 2 additions & 0 deletions apiserver/pkg/llm/llm.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ func LLM2model(ctx context.Context, c dynamic.Interface, obj *unstructured.Unstr
ID: &id,
Name: obj.GetName(),
Namespace: obj.GetNamespace(),
Creator: &llm.Spec.Creator,
CreationTimestamp: &creationtimestamp,
Labels: graphqlutils.MapStr2Any(obj.GetLabels()),
Annotations: graphqlutils.MapStr2Any(obj.GetAnnotations()),
Expand Down Expand Up @@ -221,6 +222,7 @@ func CreateLLM(ctx context.Context, c dynamic.Interface, input generated.CreateL
Type: llms.LLMType(APIType),
},
}
common.SetCreator(ctx, &llm.Spec.CommonSpec)

// create auth secret
if input.Endpointinput.Auth != nil {
Expand Down
1 change: 1 addition & 0 deletions apiserver/pkg/model/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ func CreateModel(ctx context.Context, c dynamic.Interface, input generated.Creat
Types: types,
},
}
common.SetCreator(ctx, &model.Spec.CommonSpec)
unstructuredModel, err := runtime.DefaultUnstructuredConverter.ToUnstructured(&model)
if err != nil {
return nil, err
Expand Down
1 change: 1 addition & 0 deletions apiserver/pkg/versioneddataset/versioned_dataset.go
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,7 @@ func CreateVersionedDataset(ctx context.Context, c dynamic.Interface, input *gen
if input.Description != nil {
vds.Spec.Description = *input.Description
}
common.SetCreator(ctx, &vds.Spec.CommonSpec)
vds.SetLabels(graphqlutils.MapAny2Str(input.Labels))
vds.SetAnnotations(graphqlutils.MapAny2Str(input.Annotations))
if len(input.FileGrups) > 0 {
Expand Down
1 change: 1 addition & 0 deletions apiserver/pkg/worker/worker.go
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,7 @@ func CreateWorker(ctx context.Context, c dynamic.Interface, input generated.Crea
},
},
}
common.SetCreator(ctx, &worker.Spec.CommonSpec)

// cpu & memory
resources := v1.ResourceRequirements{
Expand Down

0 comments on commit 7288f25

Please sign in to comment.