-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add guardrails orchestrator controller
- Loading branch information
1 parent
b76a51d
commit 765ca02
Showing
10 changed files
with
1,154 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/* | ||
Copyright 2024. | ||
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 contains API Schema definitions for the trustyai.opendatahub.io v1alpha1 API group | ||
// +kubebuilder:object:generate=true | ||
// +groupName=trustyai.opendatahub.io | ||
package v1alpha1 | ||
|
||
import ( | ||
"k8s.io/apimachinery/pkg/runtime/schema" | ||
"sigs.k8s.io/controller-runtime/pkg/scheme" | ||
) | ||
|
||
const ( | ||
GroupName = "trustyai.opendatahub.io" | ||
Version = "v1alpha1" | ||
KindName = "GuardrailsOrchestrator" | ||
FinalizerName = "trustyai.opendatahub.io/guardrails-finalizer" | ||
) | ||
|
||
var ( | ||
// GroupVersion is group version used to register these objects | ||
GroupVersion = schema.GroupVersion{Group: GroupName, Version: Version} | ||
|
||
// SchemeBuilder is used to add go types to the GroupVersionKind scheme | ||
SchemeBuilder = &scheme.Builder{GroupVersion: GroupVersion} | ||
|
||
// AddToScheme adds the types in this group-version to the given scheme. | ||
AddToScheme = SchemeBuilder.AddToScheme | ||
) |
171 changes: 171 additions & 0 deletions
171
api/guardrails/v1alpha1/guardrailsorchestrator_types.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,171 @@ | ||
package v1alpha1 | ||
|
||
import ( | ||
corev1 "k8s.io/api/core/v1" | ||
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" | ||
) | ||
|
||
func (g *GuardrailsOrchestrator) SetStatus(condType, reason, message string, status corev1.ConditionStatus) { | ||
now := metav1.Now() | ||
condition := Condition{ | ||
Type: condType, | ||
Status: status, | ||
Reason: reason, | ||
Message: message, | ||
LastTransitionTime: now, | ||
} | ||
// Replace or append condition | ||
found := false | ||
for i, cond := range g.Status.Conditions { | ||
if cond.Type == condType { | ||
g.Status.Conditions[i] = condition | ||
found = true | ||
break | ||
} | ||
} | ||
if !found { | ||
g.Status.Conditions = append(g.Status.Conditions, condition) | ||
} | ||
} | ||
|
||
type ServiceSpec struct { | ||
Hostname string `json:"hostname"` | ||
Port int `json:"port"` | ||
// TLS credentials path | ||
TLS string `json:"tls"` | ||
} | ||
|
||
type GeneratorSpec struct { | ||
// Provider name | ||
Provider string `json:"provider"` | ||
// Service | ||
Service ServiceSpec `json:"service"` | ||
} | ||
|
||
type ChunkerSpec struct { | ||
Type string `json:"type"` | ||
Service ServiceSpec `json:"service"` | ||
} | ||
|
||
type DetectorSpec struct { | ||
// Detector name | ||
Type string `json:"type"` | ||
// Service | ||
Service ServiceSpec `json:"service"` | ||
// Chunker ID | ||
ChunkerID string `json:"chunker_id"` | ||
DefaultThreshold string `json:"default_threshold"` | ||
} | ||
|
||
type TLSSpec struct { | ||
Type string `json:"type"` | ||
CertPath string `json:"cert_path"` | ||
KeyPath string `json:"key_path"` | ||
CACertPath string `json:"ca_cert_path"` | ||
} | ||
|
||
// GuardrailsOrchestratorStatus defines the desired state of GuardrailsOrchestrator | ||
type GuardrailsOrchestratorSpec struct { | ||
// Number of replicas | ||
Replicas int32 `json:"replicas"` | ||
// Generator name | ||
Generator GeneratorSpec `json:"generator"` | ||
// Chunker name | ||
Chunker ChunkerSpec `json:"chunker"` | ||
// Detector name(s) | ||
Detectors []DetectorSpec `json:"detectors"` | ||
// TLS | ||
TLS TLSSpec `json:"tls"` | ||
} | ||
|
||
type GuardrailsOrchestratorPod struct { | ||
Container *GuardrailsOrchestratorContainer `json:"container"` | ||
Volumes []corev1.Volume `json:"volumes, omitempty"` | ||
} | ||
|
||
// The following Getter-ish functions avoid nil pointer panic | ||
func (p *GuardrailsOrchestratorPod) GetContainer() *GuardrailsOrchestratorContainer { | ||
if p == nil { | ||
return nil | ||
} | ||
return p.Container | ||
} | ||
|
||
func (p *GuardrailsOrchestratorPod) GetVolumes() []corev1.Volume { | ||
if p == nil { | ||
return nil | ||
} | ||
return p.Volumes | ||
} | ||
|
||
type GuardrailsOrchestratorContainer struct { | ||
// Define Env information for the main container | ||
// +optional | ||
Env []corev1.EnvVar `json:"env,omitempty"` | ||
// Define the volume mount information | ||
// +optional | ||
VolumeMounts []corev1.VolumeMount `json:"volumeMounts,omitempty"` | ||
// Compute Resources required by this container. | ||
// More info: https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/ | ||
// +optional | ||
Resources *corev1.ResourceRequirements `json:"resources,omitempty"` | ||
} | ||
|
||
// The following Getter-ish functions avoid nil pointer panic | ||
func (c *GuardrailsOrchestratorContainer) GetEnv() []corev1.EnvVar { | ||
if c == nil { | ||
return nil | ||
} | ||
return c.Env | ||
} | ||
|
||
func (c *GuardrailsOrchestratorContainer) GetVolumeMounts() []corev1.VolumeMount { | ||
if c == nil { | ||
return nil | ||
} | ||
return c.VolumeMounts | ||
} | ||
|
||
func (c *GuardrailsOrchestratorContainer) GetResources() *corev1.ResourceRequirements { | ||
if c == nil { | ||
return nil | ||
} | ||
return c.Resources | ||
} | ||
|
||
// Condition defines the condition of the GuardrailsOrchestrator | ||
type Condition struct { | ||
Type string `json:"type"` | ||
Status corev1.ConditionStatus `json:"status"` | ||
LastTransitionTime metav1.Time `json:"lastTransitionTime"` | ||
Reason string `json:"reason"` | ||
Message string `json:"message"` | ||
} | ||
|
||
// GuardrailsOrchestratorStatus defines the observed state of GuardrailsOrchestrator | ||
type GuardrailsOrchestratorStatus struct { | ||
Phase string `json:"phase"` | ||
Replicas int32 `json:"replicas"` | ||
Conditions []Condition `json:"conditions"` | ||
Ready corev1.ConditionStatus `json:"ready,omitempty"` | ||
} | ||
|
||
// GuardrailsOrchestrator is the Schema for the GuardrailsOrchestrator API | ||
type GuardrailsOrchestrator struct { | ||
metav1.TypeMeta `json:",inline"` | ||
metav1.ObjectMeta `json:"metadata,omitempty"` | ||
|
||
Spec GuardrailsOrchestratorSpec `json:"spec,omitempty"` | ||
Status GuardrailsOrchestratorStatus `json:"status,omitempty"` | ||
} | ||
|
||
// GuardrailsOrchestratorList contains a list of GuardrailsOrchestrator | ||
type GuardrailsOrchestratorList struct { | ||
metav1.TypeMeta `json:",inline"` | ||
metav1.ListMeta `json:"metadata,omitempty"` | ||
Items []GuardrailsOrchestrator `json:"items"` | ||
} | ||
|
||
func init() { | ||
SchemeBuilder.Register(&GuardrailsOrchestrator{}, &GuardrailsOrchestratorList{}) | ||
} |
Oops, something went wrong.