From 5020922508a46374d779f319487d5075c0ca14ba Mon Sep 17 00:00:00 2001 From: Julien Salleyron Date: Fri, 22 Nov 2024 17:58:04 +0100 Subject: [PATCH] Adds AIService --- pkg/apis/hub/v1alpha1/ai_service.go | 144 +++++++++ .../crd/hub.traefik.io_aiservices.yaml | 245 ++++++++++++++ pkg/apis/hub/v1alpha1/register.go | 2 + .../hub/v1alpha1/zz_generated.deepcopy.go | 300 ++++++++++++++++++ .../versioned/typed/hub/v1alpha1/aiservice.go | 181 +++++++++++ .../typed/hub/v1alpha1/fake/fake_aiservice.go | 132 ++++++++ .../hub/v1alpha1/fake/fake_hub_client.go | 4 + .../typed/hub/v1alpha1/generated_expansion.go | 2 + .../typed/hub/v1alpha1/hub_client.go | 5 + .../informers/externalversions/generic.go | 2 + .../hub/v1alpha1/aiservice.go | 93 ++++++ .../hub/v1alpha1/interface.go | 7 + pkg/client/listers/hub/v1alpha1/aiservice.go | 102 ++++++ .../hub/v1alpha1/expansion_generated.go | 8 + pkg/validation/v1alpha1/ai_service_test.go | 93 ++++++ script/code-gen-docker.sh | 4 +- 16 files changed, 1322 insertions(+), 2 deletions(-) create mode 100644 pkg/apis/hub/v1alpha1/ai_service.go create mode 100644 pkg/apis/hub/v1alpha1/crd/hub.traefik.io_aiservices.yaml create mode 100644 pkg/client/clientset/versioned/typed/hub/v1alpha1/aiservice.go create mode 100644 pkg/client/clientset/versioned/typed/hub/v1alpha1/fake/fake_aiservice.go create mode 100644 pkg/client/informers/externalversions/hub/v1alpha1/aiservice.go create mode 100644 pkg/client/listers/hub/v1alpha1/aiservice.go create mode 100644 pkg/validation/v1alpha1/ai_service_test.go diff --git a/pkg/apis/hub/v1alpha1/ai_service.go b/pkg/apis/hub/v1alpha1/ai_service.go new file mode 100644 index 0000000..48eda01 --- /dev/null +++ b/pkg/apis/hub/v1alpha1/ai_service.go @@ -0,0 +1,144 @@ +/* +Copyright (C) 2022-2024 Traefik Labs + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU Affero General Public License as published +by the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Affero General Public License for more details. + +You should have received a copy of the GNU Affero General Public License +along with this program. If not, see . +*/ + +package v1alpha1 + +import metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" + +// +genclient +// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object + +// AIService is a Kubernetes-like Service to interact with a text-based LLM provider. It defines the parameters and credentials required to interact with various LLM providers. +type AIService struct { + metav1.TypeMeta `json:",inline"` + // +optional + metav1.ObjectMeta `json:"metadata,omitempty"` + + // The desired behavior of this AIService. + Spec AIServiceSpec `json:"spec,omitempty"` +} + +// +k8s:deepcopy-gen=true + +// AIServiceSpec describes the LLM service provider. +type AIServiceSpec struct { + Anthropic *Anthropic `json:"anthropic,omitempty"` + AzureOpenAI *AzureOpenAI `json:"azureOpenai,omitempty"` + Bedrock *Bedrock `json:"bedrock,omitempty"` + Cohere *Cohere `json:"cohere,omitempty"` + Gemini *Gemini `json:"gemini,omitempty"` + Mistral *Mistral `json:"mistral,omitempty"` + Ollama *Ollama `json:"ollama,omitempty"` + OpenAI *OpenAI `json:"openai,omitempty"` +} + +// +k8s:deepcopy-gen=true + +// Anthropic configures Anthropic backend. +type Anthropic struct { + Token string `json:"token"` + Model string `json:"model,omitempty"` + Params *Params `json:"params,omitempty"` +} + +// +k8s:deepcopy-gen=true + +// AzureOpenAI configures AzureOpenAI. +type AzureOpenAI struct { + APIKey string `json:"apiKey"` + Model string `json:"model,omitempty"` + DeploymentName string `json:"deploymentName"` + BaseURL string `json:"baseUrl"` + Params *Params `json:"params,omitempty"` +} + +// +k8s:deepcopy-gen=true + +// Bedrock configures Bedrock backend. +type Bedrock struct { + Model string `json:"model,omitempty"` + Region string `json:"region,omitempty"` + SystemMessage bool `json:"systemMessage,string,omitempty"` + Params *Params `json:"params,omitempty"` +} + +// +k8s:deepcopy-gen=true + +// Cohere configures Cohere backend. +type Cohere struct { + Token string `json:"token"` + Model string `json:"model,omitempty"` + Params *Params `json:"params,omitempty"` +} + +// +k8s:deepcopy-gen=true + +// Gemini configures Gemini backend. +type Gemini struct { + APIKey string `json:"apiKey"` + Model string `json:"model,omitempty"` + Params *Params `json:"params,omitempty"` +} + +// +k8s:deepcopy-gen=true + +// Mistral configures Mistral AI backend. +type Mistral struct { + APIKey string `json:"apiKey"` + Model string `json:"model,omitempty"` + Params *Params `json:"params,omitempty"` +} + +// +k8s:deepcopy-gen=true + +// Ollama configures Ollama backend. +type Ollama struct { + Model string `json:"model,omitempty"` + BaseURL string `json:"baseUrl"` + Params *Params `json:"params,omitempty"` +} + +// +k8s:deepcopy-gen=true + +// OpenAI configures OpenAI. +type OpenAI struct { + Token string `json:"token"` + Model string `json:"model,omitempty"` + Params *Params `json:"params,omitempty"` +} + +// +k8s:deepcopy-gen=true + +// Params holds the LLM hyperparameters. +type Params struct { + Temperature float32 `json:"temperature,omitempty"` + TopP float32 `json:"topP,omitempty"` + MaxTokens int `json:"maxTokens,omitempty"` + FrequencyPenalty float32 `json:"frequencyPenalty,omitempty"` + PresencePenalty float32 `json:"presencePenalty,omitempty"` +} + +// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object + +// AIServiceList defines a list of AIService. +type AIServiceList struct { + metav1.TypeMeta `json:",inline"` + // +optional + metav1.ListMeta `json:"metadata,omitempty"` + + Items []AIService `json:"items"` +} diff --git a/pkg/apis/hub/v1alpha1/crd/hub.traefik.io_aiservices.yaml b/pkg/apis/hub/v1alpha1/crd/hub.traefik.io_aiservices.yaml new file mode 100644 index 0000000..9fc4813 --- /dev/null +++ b/pkg/apis/hub/v1alpha1/crd/hub.traefik.io_aiservices.yaml @@ -0,0 +1,245 @@ +--- +apiVersion: apiextensions.k8s.io/v1 +kind: CustomResourceDefinition +metadata: + annotations: + controller-gen.kubebuilder.io/version: v0.14.0 + name: aiservices.hub.traefik.io +spec: + group: hub.traefik.io + names: + kind: AIService + listKind: AIServiceList + plural: aiservices + singular: aiservice + scope: Namespaced + versions: + - name: v1alpha1 + schema: + openAPIV3Schema: + description: AIService is a Kubernetes-like Service to interact with a text-based + LLM provider. It defines the parameters and credentials required to interact + with various LLM providers. + 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: The desired behavior of this AIService. + properties: + anthropic: + description: Anthropic configures Anthropic backend. + properties: + model: + type: string + params: + description: Params holds the LLM hyperparameters. + properties: + frequencyPenalty: + type: number + maxTokens: + type: integer + presencePenalty: + type: number + temperature: + type: number + topP: + type: number + type: object + token: + type: string + required: + - token + type: object + azureOpenai: + description: AzureOpenAI configures AzureOpenAI. + properties: + apiKey: + type: string + baseUrl: + type: string + deploymentName: + type: string + model: + type: string + params: + description: Params holds the LLM hyperparameters. + properties: + frequencyPenalty: + type: number + maxTokens: + type: integer + presencePenalty: + type: number + temperature: + type: number + topP: + type: number + type: object + required: + - apiKey + - baseUrl + - deploymentName + type: object + bedrock: + description: Bedrock configures Bedrock backend. + properties: + model: + type: string + params: + description: Params holds the LLM hyperparameters. + properties: + frequencyPenalty: + type: number + maxTokens: + type: integer + presencePenalty: + type: number + temperature: + type: number + topP: + type: number + type: object + region: + type: string + systemMessage: + type: boolean + type: object + cohere: + description: Cohere configures Cohere backend. + properties: + model: + type: string + params: + description: Params holds the LLM hyperparameters. + properties: + frequencyPenalty: + type: number + maxTokens: + type: integer + presencePenalty: + type: number + temperature: + type: number + topP: + type: number + type: object + token: + type: string + required: + - token + type: object + gemini: + description: Gemini configures Gemini backend. + properties: + apiKey: + type: string + model: + type: string + params: + description: Params holds the LLM hyperparameters. + properties: + frequencyPenalty: + type: number + maxTokens: + type: integer + presencePenalty: + type: number + temperature: + type: number + topP: + type: number + type: object + required: + - apiKey + type: object + mistral: + description: Mistral configures Mistral AI backend. + properties: + apiKey: + type: string + model: + type: string + params: + description: Params holds the LLM hyperparameters. + properties: + frequencyPenalty: + type: number + maxTokens: + type: integer + presencePenalty: + type: number + temperature: + type: number + topP: + type: number + type: object + required: + - apiKey + type: object + ollama: + description: Ollama configures Ollama backend. + properties: + baseUrl: + type: string + model: + type: string + params: + description: Params holds the LLM hyperparameters. + properties: + frequencyPenalty: + type: number + maxTokens: + type: integer + presencePenalty: + type: number + temperature: + type: number + topP: + type: number + type: object + required: + - baseUrl + type: object + openai: + description: OpenAI configures OpenAI. + properties: + model: + type: string + params: + description: Params holds the LLM hyperparameters. + properties: + frequencyPenalty: + type: number + maxTokens: + type: integer + presencePenalty: + type: number + temperature: + type: number + topP: + type: number + type: object + token: + type: string + required: + - token + type: object + type: object + type: object + served: true + storage: true diff --git a/pkg/apis/hub/v1alpha1/register.go b/pkg/apis/hub/v1alpha1/register.go index b2d3e1d..4bbe22a 100644 --- a/pkg/apis/hub/v1alpha1/register.go +++ b/pkg/apis/hub/v1alpha1/register.go @@ -64,6 +64,8 @@ func addKnownTypes(scheme *runtime.Scheme) error { &ManagedSubscriptionList{}, &APICatalogItem{}, &APICatalogItemList{}, + &AIService{}, + &AIServiceList{}, ) metav1.AddToGroupVersion( diff --git a/pkg/apis/hub/v1alpha1/zz_generated.deepcopy.go b/pkg/apis/hub/v1alpha1/zz_generated.deepcopy.go index 347a8e2..45719dc 100644 --- a/pkg/apis/hub/v1alpha1/zz_generated.deepcopy.go +++ b/pkg/apis/hub/v1alpha1/zz_generated.deepcopy.go @@ -30,6 +30,122 @@ import ( runtime "k8s.io/apimachinery/pkg/runtime" ) +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *AIService) DeepCopyInto(out *AIService) { + *out = *in + out.TypeMeta = in.TypeMeta + in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) + in.Spec.DeepCopyInto(&out.Spec) + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new AIService. +func (in *AIService) DeepCopy() *AIService { + if in == nil { + return nil + } + out := new(AIService) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *AIService) DeepCopyObject() runtime.Object { + if c := in.DeepCopy(); c != nil { + return c + } + return nil +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *AIServiceList) DeepCopyInto(out *AIServiceList) { + *out = *in + out.TypeMeta = in.TypeMeta + in.ListMeta.DeepCopyInto(&out.ListMeta) + if in.Items != nil { + in, out := &in.Items, &out.Items + *out = make([]AIService, len(*in)) + for i := range *in { + (*in)[i].DeepCopyInto(&(*out)[i]) + } + } + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new AIServiceList. +func (in *AIServiceList) DeepCopy() *AIServiceList { + if in == nil { + return nil + } + out := new(AIServiceList) + in.DeepCopyInto(out) + return out +} + +// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. +func (in *AIServiceList) DeepCopyObject() runtime.Object { + if c := in.DeepCopy(); c != nil { + return c + } + return nil +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *AIServiceSpec) DeepCopyInto(out *AIServiceSpec) { + *out = *in + if in.Anthropic != nil { + in, out := &in.Anthropic, &out.Anthropic + *out = new(Anthropic) + (*in).DeepCopyInto(*out) + } + if in.AzureOpenAI != nil { + in, out := &in.AzureOpenAI, &out.AzureOpenAI + *out = new(AzureOpenAI) + (*in).DeepCopyInto(*out) + } + if in.Bedrock != nil { + in, out := &in.Bedrock, &out.Bedrock + *out = new(Bedrock) + (*in).DeepCopyInto(*out) + } + if in.Cohere != nil { + in, out := &in.Cohere, &out.Cohere + *out = new(Cohere) + (*in).DeepCopyInto(*out) + } + if in.Gemini != nil { + in, out := &in.Gemini, &out.Gemini + *out = new(Gemini) + (*in).DeepCopyInto(*out) + } + if in.Mistral != nil { + in, out := &in.Mistral, &out.Mistral + *out = new(Mistral) + (*in).DeepCopyInto(*out) + } + if in.Ollama != nil { + in, out := &in.Ollama, &out.Ollama + *out = new(Ollama) + (*in).DeepCopyInto(*out) + } + if in.OpenAI != nil { + in, out := &in.OpenAI, &out.OpenAI + *out = new(OpenAI) + (*in).DeepCopyInto(*out) + } + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new AIServiceSpec. +func (in *AIServiceSpec) DeepCopy() *AIServiceSpec { + if in == nil { + return nil + } + out := new(AIServiceSpec) + in.DeepCopyInto(out) + return out +} + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *API) DeepCopyInto(out *API) { *out = *in @@ -1381,6 +1497,27 @@ func (in *AccessControlPolicyStatus) DeepCopy() *AccessControlPolicyStatus { return out } +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *Anthropic) DeepCopyInto(out *Anthropic) { + *out = *in + if in.Params != nil { + in, out := &in.Params, &out.Params + *out = new(Params) + **out = **in + } + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Anthropic. +func (in *Anthropic) DeepCopy() *Anthropic { + if in == nil { + return nil + } + out := new(Anthropic) + in.DeepCopyInto(out) + return out +} + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *ApplicationReference) DeepCopyInto(out *ApplicationReference) { *out = *in @@ -1397,6 +1534,90 @@ func (in *ApplicationReference) DeepCopy() *ApplicationReference { return out } +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *AzureOpenAI) DeepCopyInto(out *AzureOpenAI) { + *out = *in + if in.Params != nil { + in, out := &in.Params, &out.Params + *out = new(Params) + **out = **in + } + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new AzureOpenAI. +func (in *AzureOpenAI) DeepCopy() *AzureOpenAI { + if in == nil { + return nil + } + out := new(AzureOpenAI) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *Bedrock) DeepCopyInto(out *Bedrock) { + *out = *in + if in.Params != nil { + in, out := &in.Params, &out.Params + *out = new(Params) + **out = **in + } + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Bedrock. +func (in *Bedrock) DeepCopy() *Bedrock { + if in == nil { + return nil + } + out := new(Bedrock) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *Cohere) DeepCopyInto(out *Cohere) { + *out = *in + if in.Params != nil { + in, out := &in.Params, &out.Params + *out = new(Params) + **out = **in + } + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Cohere. +func (in *Cohere) DeepCopy() *Cohere { + if in == nil { + return nil + } + out := new(Cohere) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *Gemini) DeepCopyInto(out *Gemini) { + *out = *in + if in.Params != nil { + in, out := &in.Params, &out.Params + *out = new(Params) + **out = **in + } + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Gemini. +func (in *Gemini) DeepCopy() *Gemini { + if in == nil { + return nil + } + out := new(Gemini) + in.DeepCopyInto(out) + return out +} + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *HTTPClientConfig) DeepCopyInto(out *HTTPClientConfig) { *out = *in @@ -1561,6 +1782,27 @@ func (in *ManagedSubscriptionStatus) DeepCopy() *ManagedSubscriptionStatus { return out } +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *Mistral) DeepCopyInto(out *Mistral) { + *out = *in + if in.Params != nil { + in, out := &in.Params, &out.Params + *out = new(Params) + **out = **in + } + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Mistral. +func (in *Mistral) DeepCopy() *Mistral { + if in == nil { + return nil + } + out := new(Mistral) + in.DeepCopyInto(out) + return out +} + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *OIDCConfigStatus) DeepCopyInto(out *OIDCConfigStatus) { *out = *in @@ -1582,6 +1824,48 @@ func (in *OIDCConfigStatus) DeepCopy() *OIDCConfigStatus { return out } +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *Ollama) DeepCopyInto(out *Ollama) { + *out = *in + if in.Params != nil { + in, out := &in.Params, &out.Params + *out = new(Params) + **out = **in + } + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Ollama. +func (in *Ollama) DeepCopy() *Ollama { + if in == nil { + return nil + } + out := new(Ollama) + in.DeepCopyInto(out) + return out +} + +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *OpenAI) DeepCopyInto(out *OpenAI) { + *out = *in + if in.Params != nil { + in, out := &in.Params, &out.Params + *out = new(Params) + **out = **in + } + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new OpenAI. +func (in *OpenAI) DeepCopy() *OpenAI { + if in == nil { + return nil + } + out := new(OpenAI) + in.DeepCopyInto(out) + return out +} + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *OpenAPISpec) DeepCopyInto(out *OpenAPISpec) { *out = *in @@ -1700,6 +1984,22 @@ func (in *Override) DeepCopy() *Override { return out } +// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. +func (in *Params) DeepCopyInto(out *Params) { + *out = *in + return +} + +// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new Params. +func (in *Params) DeepCopy() *Params { + if in == nil { + return nil + } + out := new(Params) + in.DeepCopyInto(out) + return out +} + // DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. func (in *Quota) DeepCopyInto(out *Quota) { *out = *in diff --git a/pkg/client/clientset/versioned/typed/hub/v1alpha1/aiservice.go b/pkg/client/clientset/versioned/typed/hub/v1alpha1/aiservice.go new file mode 100644 index 0000000..cc6a2db --- /dev/null +++ b/pkg/client/clientset/versioned/typed/hub/v1alpha1/aiservice.go @@ -0,0 +1,181 @@ +/* +The GNU AFFERO GENERAL PUBLIC LICENSE + +Copyright (c) 2020-2024 Traefik Labs + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU Affero General Public License as published +by the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Affero General Public License for more details. + +You should have received a copy of the GNU Affero General Public License +along with this program. If not, see . +*/ + +// Code generated by client-gen. DO NOT EDIT. + +package v1alpha1 + +import ( + "context" + "time" + + v1alpha1 "github.com/traefik/hub-crds/pkg/apis/hub/v1alpha1" + scheme "github.com/traefik/hub-crds/pkg/client/clientset/versioned/scheme" + v1 "k8s.io/apimachinery/pkg/apis/meta/v1" + types "k8s.io/apimachinery/pkg/types" + watch "k8s.io/apimachinery/pkg/watch" + rest "k8s.io/client-go/rest" +) + +// AIServicesGetter has a method to return a AIServiceInterface. +// A group's client should implement this interface. +type AIServicesGetter interface { + AIServices(namespace string) AIServiceInterface +} + +// AIServiceInterface has methods to work with AIService resources. +type AIServiceInterface interface { + Create(ctx context.Context, aIService *v1alpha1.AIService, opts v1.CreateOptions) (*v1alpha1.AIService, error) + Update(ctx context.Context, aIService *v1alpha1.AIService, opts v1.UpdateOptions) (*v1alpha1.AIService, error) + Delete(ctx context.Context, name string, opts v1.DeleteOptions) error + DeleteCollection(ctx context.Context, opts v1.DeleteOptions, listOpts v1.ListOptions) error + Get(ctx context.Context, name string, opts v1.GetOptions) (*v1alpha1.AIService, error) + List(ctx context.Context, opts v1.ListOptions) (*v1alpha1.AIServiceList, error) + Watch(ctx context.Context, opts v1.ListOptions) (watch.Interface, error) + Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts v1.PatchOptions, subresources ...string) (result *v1alpha1.AIService, err error) + AIServiceExpansion +} + +// aIServices implements AIServiceInterface +type aIServices struct { + client rest.Interface + ns string +} + +// newAIServices returns a AIServices +func newAIServices(c *HubV1alpha1Client, namespace string) *aIServices { + return &aIServices{ + client: c.RESTClient(), + ns: namespace, + } +} + +// Get takes name of the aIService, and returns the corresponding aIService object, and an error if there is any. +func (c *aIServices) Get(ctx context.Context, name string, options v1.GetOptions) (result *v1alpha1.AIService, err error) { + result = &v1alpha1.AIService{} + err = c.client.Get(). + Namespace(c.ns). + Resource("aiservices"). + Name(name). + VersionedParams(&options, scheme.ParameterCodec). + Do(ctx). + Into(result) + return +} + +// List takes label and field selectors, and returns the list of AIServices that match those selectors. +func (c *aIServices) List(ctx context.Context, opts v1.ListOptions) (result *v1alpha1.AIServiceList, err error) { + var timeout time.Duration + if opts.TimeoutSeconds != nil { + timeout = time.Duration(*opts.TimeoutSeconds) * time.Second + } + result = &v1alpha1.AIServiceList{} + err = c.client.Get(). + Namespace(c.ns). + Resource("aiservices"). + VersionedParams(&opts, scheme.ParameterCodec). + Timeout(timeout). + Do(ctx). + Into(result) + return +} + +// Watch returns a watch.Interface that watches the requested aIServices. +func (c *aIServices) Watch(ctx context.Context, opts v1.ListOptions) (watch.Interface, error) { + var timeout time.Duration + if opts.TimeoutSeconds != nil { + timeout = time.Duration(*opts.TimeoutSeconds) * time.Second + } + opts.Watch = true + return c.client.Get(). + Namespace(c.ns). + Resource("aiservices"). + VersionedParams(&opts, scheme.ParameterCodec). + Timeout(timeout). + Watch(ctx) +} + +// Create takes the representation of a aIService and creates it. Returns the server's representation of the aIService, and an error, if there is any. +func (c *aIServices) Create(ctx context.Context, aIService *v1alpha1.AIService, opts v1.CreateOptions) (result *v1alpha1.AIService, err error) { + result = &v1alpha1.AIService{} + err = c.client.Post(). + Namespace(c.ns). + Resource("aiservices"). + VersionedParams(&opts, scheme.ParameterCodec). + Body(aIService). + Do(ctx). + Into(result) + return +} + +// Update takes the representation of a aIService and updates it. Returns the server's representation of the aIService, and an error, if there is any. +func (c *aIServices) Update(ctx context.Context, aIService *v1alpha1.AIService, opts v1.UpdateOptions) (result *v1alpha1.AIService, err error) { + result = &v1alpha1.AIService{} + err = c.client.Put(). + Namespace(c.ns). + Resource("aiservices"). + Name(aIService.Name). + VersionedParams(&opts, scheme.ParameterCodec). + Body(aIService). + Do(ctx). + Into(result) + return +} + +// Delete takes name of the aIService and deletes it. Returns an error if one occurs. +func (c *aIServices) Delete(ctx context.Context, name string, opts v1.DeleteOptions) error { + return c.client.Delete(). + Namespace(c.ns). + Resource("aiservices"). + Name(name). + Body(&opts). + Do(ctx). + Error() +} + +// DeleteCollection deletes a collection of objects. +func (c *aIServices) DeleteCollection(ctx context.Context, opts v1.DeleteOptions, listOpts v1.ListOptions) error { + var timeout time.Duration + if listOpts.TimeoutSeconds != nil { + timeout = time.Duration(*listOpts.TimeoutSeconds) * time.Second + } + return c.client.Delete(). + Namespace(c.ns). + Resource("aiservices"). + VersionedParams(&listOpts, scheme.ParameterCodec). + Timeout(timeout). + Body(&opts). + Do(ctx). + Error() +} + +// Patch applies the patch and returns the patched aIService. +func (c *aIServices) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts v1.PatchOptions, subresources ...string) (result *v1alpha1.AIService, err error) { + result = &v1alpha1.AIService{} + err = c.client.Patch(pt). + Namespace(c.ns). + Resource("aiservices"). + Name(name). + SubResource(subresources...). + VersionedParams(&opts, scheme.ParameterCodec). + Body(data). + Do(ctx). + Into(result) + return +} diff --git a/pkg/client/clientset/versioned/typed/hub/v1alpha1/fake/fake_aiservice.go b/pkg/client/clientset/versioned/typed/hub/v1alpha1/fake/fake_aiservice.go new file mode 100644 index 0000000..089f02b --- /dev/null +++ b/pkg/client/clientset/versioned/typed/hub/v1alpha1/fake/fake_aiservice.go @@ -0,0 +1,132 @@ +/* +The GNU AFFERO GENERAL PUBLIC LICENSE + +Copyright (c) 2020-2024 Traefik Labs + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU Affero General Public License as published +by the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Affero General Public License for more details. + +You should have received a copy of the GNU Affero General Public License +along with this program. If not, see . +*/ + +// Code generated by client-gen. DO NOT EDIT. + +package fake + +import ( + "context" + + v1alpha1 "github.com/traefik/hub-crds/pkg/apis/hub/v1alpha1" + v1 "k8s.io/apimachinery/pkg/apis/meta/v1" + labels "k8s.io/apimachinery/pkg/labels" + types "k8s.io/apimachinery/pkg/types" + watch "k8s.io/apimachinery/pkg/watch" + testing "k8s.io/client-go/testing" +) + +// FakeAIServices implements AIServiceInterface +type FakeAIServices struct { + Fake *FakeHubV1alpha1 + ns string +} + +var aiservicesResource = v1alpha1.SchemeGroupVersion.WithResource("aiservices") + +var aiservicesKind = v1alpha1.SchemeGroupVersion.WithKind("AIService") + +// Get takes name of the aIService, and returns the corresponding aIService object, and an error if there is any. +func (c *FakeAIServices) Get(ctx context.Context, name string, options v1.GetOptions) (result *v1alpha1.AIService, err error) { + obj, err := c.Fake. + Invokes(testing.NewGetAction(aiservicesResource, c.ns, name), &v1alpha1.AIService{}) + + if obj == nil { + return nil, err + } + return obj.(*v1alpha1.AIService), err +} + +// List takes label and field selectors, and returns the list of AIServices that match those selectors. +func (c *FakeAIServices) List(ctx context.Context, opts v1.ListOptions) (result *v1alpha1.AIServiceList, err error) { + obj, err := c.Fake. + Invokes(testing.NewListAction(aiservicesResource, aiservicesKind, c.ns, opts), &v1alpha1.AIServiceList{}) + + if obj == nil { + return nil, err + } + + label, _, _ := testing.ExtractFromListOptions(opts) + if label == nil { + label = labels.Everything() + } + list := &v1alpha1.AIServiceList{ListMeta: obj.(*v1alpha1.AIServiceList).ListMeta} + for _, item := range obj.(*v1alpha1.AIServiceList).Items { + if label.Matches(labels.Set(item.Labels)) { + list.Items = append(list.Items, item) + } + } + return list, err +} + +// Watch returns a watch.Interface that watches the requested aIServices. +func (c *FakeAIServices) Watch(ctx context.Context, opts v1.ListOptions) (watch.Interface, error) { + return c.Fake. + InvokesWatch(testing.NewWatchAction(aiservicesResource, c.ns, opts)) + +} + +// Create takes the representation of a aIService and creates it. Returns the server's representation of the aIService, and an error, if there is any. +func (c *FakeAIServices) Create(ctx context.Context, aIService *v1alpha1.AIService, opts v1.CreateOptions) (result *v1alpha1.AIService, err error) { + obj, err := c.Fake. + Invokes(testing.NewCreateAction(aiservicesResource, c.ns, aIService), &v1alpha1.AIService{}) + + if obj == nil { + return nil, err + } + return obj.(*v1alpha1.AIService), err +} + +// Update takes the representation of a aIService and updates it. Returns the server's representation of the aIService, and an error, if there is any. +func (c *FakeAIServices) Update(ctx context.Context, aIService *v1alpha1.AIService, opts v1.UpdateOptions) (result *v1alpha1.AIService, err error) { + obj, err := c.Fake. + Invokes(testing.NewUpdateAction(aiservicesResource, c.ns, aIService), &v1alpha1.AIService{}) + + if obj == nil { + return nil, err + } + return obj.(*v1alpha1.AIService), err +} + +// Delete takes name of the aIService and deletes it. Returns an error if one occurs. +func (c *FakeAIServices) Delete(ctx context.Context, name string, opts v1.DeleteOptions) error { + _, err := c.Fake. + Invokes(testing.NewDeleteActionWithOptions(aiservicesResource, c.ns, name, opts), &v1alpha1.AIService{}) + + return err +} + +// DeleteCollection deletes a collection of objects. +func (c *FakeAIServices) DeleteCollection(ctx context.Context, opts v1.DeleteOptions, listOpts v1.ListOptions) error { + action := testing.NewDeleteCollectionAction(aiservicesResource, c.ns, listOpts) + + _, err := c.Fake.Invokes(action, &v1alpha1.AIServiceList{}) + return err +} + +// Patch applies the patch and returns the patched aIService. +func (c *FakeAIServices) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts v1.PatchOptions, subresources ...string) (result *v1alpha1.AIService, err error) { + obj, err := c.Fake. + Invokes(testing.NewPatchSubresourceAction(aiservicesResource, c.ns, name, pt, data, subresources...), &v1alpha1.AIService{}) + + if obj == nil { + return nil, err + } + return obj.(*v1alpha1.AIService), err +} diff --git a/pkg/client/clientset/versioned/typed/hub/v1alpha1/fake/fake_hub_client.go b/pkg/client/clientset/versioned/typed/hub/v1alpha1/fake/fake_hub_client.go index 878f64c..5c49515 100644 --- a/pkg/client/clientset/versioned/typed/hub/v1alpha1/fake/fake_hub_client.go +++ b/pkg/client/clientset/versioned/typed/hub/v1alpha1/fake/fake_hub_client.go @@ -31,6 +31,10 @@ type FakeHubV1alpha1 struct { *testing.Fake } +func (c *FakeHubV1alpha1) AIServices(namespace string) v1alpha1.AIServiceInterface { + return &FakeAIServices{c, namespace} +} + func (c *FakeHubV1alpha1) APIs(namespace string) v1alpha1.APIInterface { return &FakeAPIs{c, namespace} } diff --git a/pkg/client/clientset/versioned/typed/hub/v1alpha1/generated_expansion.go b/pkg/client/clientset/versioned/typed/hub/v1alpha1/generated_expansion.go index d3c66ed..e6a4c48 100644 --- a/pkg/client/clientset/versioned/typed/hub/v1alpha1/generated_expansion.go +++ b/pkg/client/clientset/versioned/typed/hub/v1alpha1/generated_expansion.go @@ -21,6 +21,8 @@ along with this program. If not, see . package v1alpha1 +type AIServiceExpansion interface{} + type APIExpansion interface{} type APIAccessExpansion interface{} diff --git a/pkg/client/clientset/versioned/typed/hub/v1alpha1/hub_client.go b/pkg/client/clientset/versioned/typed/hub/v1alpha1/hub_client.go index cc30634..ac1bdf0 100644 --- a/pkg/client/clientset/versioned/typed/hub/v1alpha1/hub_client.go +++ b/pkg/client/clientset/versioned/typed/hub/v1alpha1/hub_client.go @@ -31,6 +31,7 @@ import ( type HubV1alpha1Interface interface { RESTClient() rest.Interface + AIServicesGetter APIsGetter APIAccessesGetter APIBundlesGetter @@ -48,6 +49,10 @@ type HubV1alpha1Client struct { restClient rest.Interface } +func (c *HubV1alpha1Client) AIServices(namespace string) AIServiceInterface { + return newAIServices(c, namespace) +} + func (c *HubV1alpha1Client) APIs(namespace string) APIInterface { return newAPIs(c, namespace) } diff --git a/pkg/client/informers/externalversions/generic.go b/pkg/client/informers/externalversions/generic.go index 11035db..999471f 100644 --- a/pkg/client/informers/externalversions/generic.go +++ b/pkg/client/informers/externalversions/generic.go @@ -56,6 +56,8 @@ func (f *genericInformer) Lister() cache.GenericLister { func (f *sharedInformerFactory) ForResource(resource schema.GroupVersionResource) (GenericInformer, error) { switch resource { // Group=hub.traefik.io, Version=v1alpha1 + case v1alpha1.SchemeGroupVersion.WithResource("aiservices"): + return &genericInformer{resource: resource.GroupResource(), informer: f.Hub().V1alpha1().AIServices().Informer()}, nil case v1alpha1.SchemeGroupVersion.WithResource("apis"): return &genericInformer{resource: resource.GroupResource(), informer: f.Hub().V1alpha1().APIs().Informer()}, nil case v1alpha1.SchemeGroupVersion.WithResource("apiaccesses"): diff --git a/pkg/client/informers/externalversions/hub/v1alpha1/aiservice.go b/pkg/client/informers/externalversions/hub/v1alpha1/aiservice.go new file mode 100644 index 0000000..3f66992 --- /dev/null +++ b/pkg/client/informers/externalversions/hub/v1alpha1/aiservice.go @@ -0,0 +1,93 @@ +/* +The GNU AFFERO GENERAL PUBLIC LICENSE + +Copyright (c) 2020-2024 Traefik Labs + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU Affero General Public License as published +by the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Affero General Public License for more details. + +You should have received a copy of the GNU Affero General Public License +along with this program. If not, see . +*/ + +// Code generated by informer-gen. DO NOT EDIT. + +package v1alpha1 + +import ( + "context" + time "time" + + hubv1alpha1 "github.com/traefik/hub-crds/pkg/apis/hub/v1alpha1" + versioned "github.com/traefik/hub-crds/pkg/client/clientset/versioned" + internalinterfaces "github.com/traefik/hub-crds/pkg/client/informers/externalversions/internalinterfaces" + v1alpha1 "github.com/traefik/hub-crds/pkg/client/listers/hub/v1alpha1" + v1 "k8s.io/apimachinery/pkg/apis/meta/v1" + runtime "k8s.io/apimachinery/pkg/runtime" + watch "k8s.io/apimachinery/pkg/watch" + cache "k8s.io/client-go/tools/cache" +) + +// AIServiceInformer provides access to a shared informer and lister for +// AIServices. +type AIServiceInformer interface { + Informer() cache.SharedIndexInformer + Lister() v1alpha1.AIServiceLister +} + +type aIServiceInformer struct { + factory internalinterfaces.SharedInformerFactory + tweakListOptions internalinterfaces.TweakListOptionsFunc + namespace string +} + +// NewAIServiceInformer constructs a new informer for AIService type. +// Always prefer using an informer factory to get a shared informer instead of getting an independent +// one. This reduces memory footprint and number of connections to the server. +func NewAIServiceInformer(client versioned.Interface, namespace string, resyncPeriod time.Duration, indexers cache.Indexers) cache.SharedIndexInformer { + return NewFilteredAIServiceInformer(client, namespace, resyncPeriod, indexers, nil) +} + +// NewFilteredAIServiceInformer constructs a new informer for AIService type. +// Always prefer using an informer factory to get a shared informer instead of getting an independent +// one. This reduces memory footprint and number of connections to the server. +func NewFilteredAIServiceInformer(client versioned.Interface, namespace string, resyncPeriod time.Duration, indexers cache.Indexers, tweakListOptions internalinterfaces.TweakListOptionsFunc) cache.SharedIndexInformer { + return cache.NewSharedIndexInformer( + &cache.ListWatch{ + ListFunc: func(options v1.ListOptions) (runtime.Object, error) { + if tweakListOptions != nil { + tweakListOptions(&options) + } + return client.HubV1alpha1().AIServices(namespace).List(context.TODO(), options) + }, + WatchFunc: func(options v1.ListOptions) (watch.Interface, error) { + if tweakListOptions != nil { + tweakListOptions(&options) + } + return client.HubV1alpha1().AIServices(namespace).Watch(context.TODO(), options) + }, + }, + &hubv1alpha1.AIService{}, + resyncPeriod, + indexers, + ) +} + +func (f *aIServiceInformer) defaultInformer(client versioned.Interface, resyncPeriod time.Duration) cache.SharedIndexInformer { + return NewFilteredAIServiceInformer(client, f.namespace, resyncPeriod, cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc}, f.tweakListOptions) +} + +func (f *aIServiceInformer) Informer() cache.SharedIndexInformer { + return f.factory.InformerFor(&hubv1alpha1.AIService{}, f.defaultInformer) +} + +func (f *aIServiceInformer) Lister() v1alpha1.AIServiceLister { + return v1alpha1.NewAIServiceLister(f.Informer().GetIndexer()) +} diff --git a/pkg/client/informers/externalversions/hub/v1alpha1/interface.go b/pkg/client/informers/externalversions/hub/v1alpha1/interface.go index 5b90565..bb0d04d 100644 --- a/pkg/client/informers/externalversions/hub/v1alpha1/interface.go +++ b/pkg/client/informers/externalversions/hub/v1alpha1/interface.go @@ -27,6 +27,8 @@ import ( // Interface provides access to all the informers in this group version. type Interface interface { + // AIServices returns a AIServiceInformer. + AIServices() AIServiceInformer // APIs returns a APIInformer. APIs() APIInformer // APIAccesses returns a APIAccessInformer. @@ -60,6 +62,11 @@ func New(f internalinterfaces.SharedInformerFactory, namespace string, tweakList return &version{factory: f, namespace: namespace, tweakListOptions: tweakListOptions} } +// AIServices returns a AIServiceInformer. +func (v *version) AIServices() AIServiceInformer { + return &aIServiceInformer{factory: v.factory, namespace: v.namespace, tweakListOptions: v.tweakListOptions} +} + // APIs returns a APIInformer. func (v *version) APIs() APIInformer { return &aPIInformer{factory: v.factory, namespace: v.namespace, tweakListOptions: v.tweakListOptions} diff --git a/pkg/client/listers/hub/v1alpha1/aiservice.go b/pkg/client/listers/hub/v1alpha1/aiservice.go new file mode 100644 index 0000000..0eba9ac --- /dev/null +++ b/pkg/client/listers/hub/v1alpha1/aiservice.go @@ -0,0 +1,102 @@ +/* +The GNU AFFERO GENERAL PUBLIC LICENSE + +Copyright (c) 2020-2024 Traefik Labs + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU Affero General Public License as published +by the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Affero General Public License for more details. + +You should have received a copy of the GNU Affero General Public License +along with this program. If not, see . +*/ + +// Code generated by lister-gen. DO NOT EDIT. + +package v1alpha1 + +import ( + v1alpha1 "github.com/traefik/hub-crds/pkg/apis/hub/v1alpha1" + "k8s.io/apimachinery/pkg/api/errors" + "k8s.io/apimachinery/pkg/labels" + "k8s.io/client-go/tools/cache" +) + +// AIServiceLister helps list AIServices. +// All objects returned here must be treated as read-only. +type AIServiceLister interface { + // List lists all AIServices in the indexer. + // Objects returned here must be treated as read-only. + List(selector labels.Selector) (ret []*v1alpha1.AIService, err error) + // AIServices returns an object that can list and get AIServices. + AIServices(namespace string) AIServiceNamespaceLister + AIServiceListerExpansion +} + +// aIServiceLister implements the AIServiceLister interface. +type aIServiceLister struct { + indexer cache.Indexer +} + +// NewAIServiceLister returns a new AIServiceLister. +func NewAIServiceLister(indexer cache.Indexer) AIServiceLister { + return &aIServiceLister{indexer: indexer} +} + +// List lists all AIServices in the indexer. +func (s *aIServiceLister) List(selector labels.Selector) (ret []*v1alpha1.AIService, err error) { + err = cache.ListAll(s.indexer, selector, func(m interface{}) { + ret = append(ret, m.(*v1alpha1.AIService)) + }) + return ret, err +} + +// AIServices returns an object that can list and get AIServices. +func (s *aIServiceLister) AIServices(namespace string) AIServiceNamespaceLister { + return aIServiceNamespaceLister{indexer: s.indexer, namespace: namespace} +} + +// AIServiceNamespaceLister helps list and get AIServices. +// All objects returned here must be treated as read-only. +type AIServiceNamespaceLister interface { + // List lists all AIServices in the indexer for a given namespace. + // Objects returned here must be treated as read-only. + List(selector labels.Selector) (ret []*v1alpha1.AIService, err error) + // Get retrieves the AIService from the indexer for a given namespace and name. + // Objects returned here must be treated as read-only. + Get(name string) (*v1alpha1.AIService, error) + AIServiceNamespaceListerExpansion +} + +// aIServiceNamespaceLister implements the AIServiceNamespaceLister +// interface. +type aIServiceNamespaceLister struct { + indexer cache.Indexer + namespace string +} + +// List lists all AIServices in the indexer for a given namespace. +func (s aIServiceNamespaceLister) List(selector labels.Selector) (ret []*v1alpha1.AIService, err error) { + err = cache.ListAllByNamespace(s.indexer, s.namespace, selector, func(m interface{}) { + ret = append(ret, m.(*v1alpha1.AIService)) + }) + return ret, err +} + +// Get retrieves the AIService from the indexer for a given namespace and name. +func (s aIServiceNamespaceLister) Get(name string) (*v1alpha1.AIService, error) { + obj, exists, err := s.indexer.GetByKey(s.namespace + "/" + name) + if err != nil { + return nil, err + } + if !exists { + return nil, errors.NewNotFound(v1alpha1.Resource("aiservice"), name) + } + return obj.(*v1alpha1.AIService), nil +} diff --git a/pkg/client/listers/hub/v1alpha1/expansion_generated.go b/pkg/client/listers/hub/v1alpha1/expansion_generated.go index 389b379..1ccb700 100644 --- a/pkg/client/listers/hub/v1alpha1/expansion_generated.go +++ b/pkg/client/listers/hub/v1alpha1/expansion_generated.go @@ -21,6 +21,14 @@ along with this program. If not, see . package v1alpha1 +// AIServiceListerExpansion allows custom methods to be added to +// AIServiceLister. +type AIServiceListerExpansion interface{} + +// AIServiceNamespaceListerExpansion allows custom methods to be added to +// AIServiceNamespaceLister. +type AIServiceNamespaceListerExpansion interface{} + // APIListerExpansion allows custom methods to be added to // APILister. type APIListerExpansion interface{} diff --git a/pkg/validation/v1alpha1/ai_service_test.go b/pkg/validation/v1alpha1/ai_service_test.go new file mode 100644 index 0000000..87822be --- /dev/null +++ b/pkg/validation/v1alpha1/ai_service_test.go @@ -0,0 +1,93 @@ +/* +Copyright (C) 2022-2024 Traefik Labs + +This program is free software: you can redistribute it and/or modify +it under the terms of the GNU Affero General Public License as published +by the Free Software Foundation, either version 3 of the License, or +(at your option) any later version. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU Affero General Public License for more details. + +You should have received a copy of the GNU Affero General Public License +along with this program. If not, see . +*/ + +package v1alpha1_test + +import ( + "testing" + + "k8s.io/apimachinery/pkg/util/validation/field" +) + +func TestAIService_Validation(t *testing.T) { + t.Parallel() + + tests := []validationTestCase{ + { + desc: "missing resource namespace", + manifest: []byte(` +apiVersion: hub.traefik.io/v1alpha1 +kind: AIService +metadata: + name: "my-ai-service" +spec: + openai: + token: xxx`), + wantErrs: field.ErrorList{{Type: field.ErrorTypeRequired, Field: "metadata.namespace", BadValue: ""}}, + }, + { + desc: "valid: minimal", + manifest: []byte(` +apiVersion: hub.traefik.io/v1alpha1 +kind: AIService +metadata: + name: my-ai-service + namespace: default +spec: + openai: + token: xxxx`), + }, + { + desc: "invalid resource name", + manifest: []byte(` +apiVersion: hub.traefik.io/v1alpha1 +kind: AIService +metadata: + name: .non-dns-compliant-access + namespace: default`), + wantErrs: field.ErrorList{{Type: field.ErrorTypeInvalid, Field: "metadata.name", BadValue: ".non-dns-compliant-access", Detail: "a lowercase RFC 1123 label must consist of lower case alphanumeric characters or '-', and must start and end with an alphanumeric character (e.g. 'my-name', or '123-abc', regex used for validation is '[a-z0-9]([-a-z0-9]*[a-z0-9])?')"}}, + }, + { + desc: "missing resource name", + manifest: []byte(` +apiVersion: hub.traefik.io/v1alpha1 +kind: AIService +metadata: + name: "" + namespace: default`), + wantErrs: field.ErrorList{{Type: field.ErrorTypeRequired, Field: "metadata.name", BadValue: "", Detail: "name or generateName is required"}}, + }, + { + desc: "resource name is too long", + manifest: []byte(` +apiVersion: hub.traefik.io/v1alpha1 +kind: AIService +metadata: + name: ai-service-with-a-way-toooooooooooooooooooooooooooooooooooooo-long-name + namespace: default`), + wantErrs: field.ErrorList{{Type: field.ErrorTypeInvalid, Field: "metadata.name", BadValue: "ai-service-with-a-way-toooooooooooooooooooooooooooooooooooooo-long-name", Detail: "must be no more than 63 characters"}}, + }, + } + + for _, test := range tests { + t.Run(test.desc, func(t *testing.T) { + t.Parallel() + + checkValidation(t, test) + }) + } +} diff --git a/script/code-gen-docker.sh b/script/code-gen-docker.sh index cb23a01..41e1158 100755 --- a/script/code-gen-docker.sh +++ b/script/code-gen-docker.sh @@ -29,6 +29,6 @@ docker run --rm \ -v "${CURRENT_DIR}:/go/src/${PROJECT_MODULE}" \ -w "/go/src/${PROJECT_MODULE}" \ "${IMAGE_NAME}" \ - controller-gen crd:crdVersions=v1 \ + controller-gen crd:crdVersions=v1,allowDangerousTypes=true \ paths=./pkg/apis/hub/v1alpha1/... \ - output:dir=./pkg/apis/hub/v1alpha1/crd + output:dir=./pkg/apis/hub/v1alpha1/crd \