Skip to content

Commit

Permalink
feat: add CRD Embeddings
Browse files Browse the repository at this point in the history
Signed-off-by: Lanture1064 <[email protected]>
  • Loading branch information
Lanture1064 committed Oct 23, 2023
1 parent e7f3276 commit dc24fd5
Show file tree
Hide file tree
Showing 20 changed files with 741 additions and 23 deletions.
9 changes: 9 additions & 0 deletions PROJECT
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,13 @@ resources:
kind: Datasource
path: github.com/kubeagi/arcadia/api/v1alpha1
version: v1alpha1
- api:
crdVersion: v1
namespaced: true
controller: true
domain: kubeagi.k8s.com.cn
group: arcadia
kind: Embeddings
path: github.com/kubeagi/arcadia/api/v1alpha1
version: v1alpha1
version: "3"
36 changes: 36 additions & 0 deletions api/v1alpha1/embedder.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
Copyright 2023 KubeAGI.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package v1alpha1

import (
"context"

Check failure on line 20 in api/v1alpha1/embedder.go

View workflow job for this annotation

GitHub Actions / Lint Go code

File is not `gci`-ed with --skip-generated -s standard -s default -s prefix(github.com/kubeagi/arcadia) -s blank -s dot --custom-order (gci)
corev1 "k8s.io/api/core/v1"
"k8s.io/apimachinery/pkg/types"
"sigs.k8s.io/controller-runtime/pkg/client"
)

func (e Embedder) AuthAPIKey(ctx context.Context, c client.Client) (string, error) {
if e.Spec.Auth == "" {
return "", nil
}
authSecret := &corev1.Secret{}
err := c.Get(ctx, types.NamespacedName{Name: e.Spec.Auth, Namespace: e.Namespace}, authSecret)
if err != nil {
return "", err
}
return string(authSecret.Data["apiKey"]), nil
}
77 changes: 77 additions & 0 deletions api/v1alpha1/embedder_types.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
/*
Copyright 2023 KubeAGI.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

package v1alpha1

import (
"github.com/kubeagi/arcadia/pkg/embeddings"

Check failure on line 20 in api/v1alpha1/embedder_types.go

View workflow job for this annotation

GitHub Actions / Lint Go code

File is not `gci`-ed with --skip-generated -s standard -s default -s prefix(github.com/kubeagi/arcadia) -s blank -s dot --custom-order (gci)
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"

Check failure on line 21 in api/v1alpha1/embedder_types.go

View workflow job for this annotation

GitHub Actions / Lint Go code

File is not `gci`-ed with --skip-generated -s standard -s default -s prefix(github.com/kubeagi/arcadia) -s blank -s dot --custom-order (gci)
)

// EDIT THIS FILE! THIS IS SCAFFOLDING FOR YOU TO OWN!
// NOTE: json tags are required. Any new fields you add must have json tags for the fields to be serialized.

// EmbedderSpec defines the desired state of Embedder
type EmbedderSpec struct {
// INSERT ADDITIONAL SPEC FIELDS - desired state of cluster
// Important: Run "make" to regenerate code after modifying this file

// Name of the Embedding service
DisplayName string `json:"name,omitempty"`

// ServiceType indicates the source type of embedding service
ServiceType embeddings.EmbeddingType `json:"serviceType,omitempty"`

// URL keeps the URL of the embedding service (Must have)
URL string `json:"url,omitempty"`

// Auth keeps the authentication credentials when access embedding service
// keeps in k8s secret
Auth string `json:"auth,omitempty"`
}

// EmbeddingsStatus defines the observed state of Embedder
type EmbedderStatus struct {
// INSERT ADDITIONAL STATUS FIELD - define observed state of cluster
// Important: Run "make" to regenerate code after modifying this file
// ConditionedStatus is the current status
ConditionedStatus `json:",inline"`
}

//+kubebuilder:object:root=true
//+kubebuilder:subresource:status

// Embedder is the Schema for the embeddings API
type Embedder struct {
metav1.TypeMeta `json:",inline"`
metav1.ObjectMeta `json:"metadata,omitempty"`

Spec EmbedderSpec `json:"spec,omitempty"`
Status EmbedderStatus `json:"status,omitempty"`
}

//+kubebuilder:object:root=true

// EmbedderList contains a list of Embedder
type EmbedderList struct {
metav1.TypeMeta `json:",inline"`
metav1.ListMeta `json:"metadata,omitempty"`
Items []Embedder `json:"items"`
}

func init() {
SchemeBuilder.Register(&Embedder{}, &EmbedderList{})
}
90 changes: 90 additions & 0 deletions api/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion charts/arcadia/Chart.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ apiVersion: v2
name: arcadia
description: A Helm chart(KubeBB Component) for KubeAGI Arcadia
type: application
version: 0.1.7
version: 0.1.8
appVersion: "0.0.0"
keywords:
- kubeagi
Expand Down
99 changes: 99 additions & 0 deletions charts/arcadia/crds/arcadia.kubeagi.k8s.com.cn_embedders.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
---
apiVersion: apiextensions.k8s.io/v1
kind: CustomResourceDefinition
metadata:
annotations:
controller-gen.kubebuilder.io/version: v0.9.2
creationTimestamp: null
name: embedders.arcadia.kubeagi.k8s.com.cn
spec:
group: arcadia.kubeagi.k8s.com.cn
names:
kind: Embedder
listKind: EmbedderList
plural: embedders
singular: embedder
scope: Namespaced
versions:
- name: v1alpha1
schema:
openAPIV3Schema:
description: Embedder is the Schema for the embedders API
properties:
apiVersion:
description: 'APIVersion defines the versioned schema of this representation
of an object. Servers should convert recognized schemas to the latest
internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources'
type: string
kind:
description: 'Kind is a string value representing the REST resource this
object represents. Servers may infer this from the endpoint the client
submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds'
type: string
metadata:
type: object
spec:
description: EmbedderSpec defines the desired state of embedder.
properties:
auth:
description: Auth keeps the authentication credentials when access
embedder, keeps in k8s secret.
type: string
displayName:
type: string
type:
description: Type defines the type of embedder.
type: string
url:
description: URL keeps the URL of the embedder service(Must required)
type: string
required:
- type
type: object
status:
description: EmbedderStatus defines the observed state of embedder.
properties:
conditions:
description: Conditions of the resource.
items:
description: A Condition that may apply to a resource.
properties:
lastSuccessfulTime:
description: LastSuccessfulTime is repository Last Successful
Update Time
format: date-time
type: string
lastTransitionTime:
description: LastTransitionTime is the last time this condition
transitioned from one status to another.
format: date-time
type: string
message:
description: A Message containing details about this condition's
last transition from one status to another, if any.
type: string
reason:
description: A Reason for this condition's last transition from
one status to another.
type: string
status:
description: Status of this condition; is it currently True,
False, or Unknown
type: string
type:
description: Type of this condition. At most one of each condition
type may apply to a resource at any point in time.
type: string
required:
- lastTransitionTime
- reason
- status
- type
type: object
type: array
type: object
type: object
served: true
storage: true
subresources:
status: {}
Loading

0 comments on commit dc24fd5

Please sign in to comment.