Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .golangci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ linters:
- unused
- misspell
- whitespace
- errorlint
#- gosec
#- revive

Expand Down Expand Up @@ -121,4 +122,4 @@ issues:
# Default: 50
max-issues-per-linter: 0
# Maximum count of issues with the same text. Set to 0 to disable. Default is 3.
max-same-issues: 0
max-same-issues: 0
40 changes: 20 additions & 20 deletions cli/kthena/cmd/create.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,13 +97,13 @@ func runCreateManifest(cmd *cobra.Command, args []string) error {
// Load template values
values, err := loadTemplateValues()
if err != nil {
return fmt.Errorf("failed to load template values: %v", err)
return fmt.Errorf("failed to load template values: %w", err)
}

// Render template
renderedYAML, err := renderTemplate(templateName, values)
if err != nil {
return fmt.Errorf("failed to render template: %v", err)
return fmt.Errorf("failed to render template: %w", err)
}

// Show rendered YAML
Expand Down Expand Up @@ -134,11 +134,11 @@ func loadTemplateValues() (map[string]interface{}, error) {
if valuesFile != "" {
data, err := os.ReadFile(valuesFile)
if err != nil {
return nil, fmt.Errorf("failed to read values file: %v", err)
return nil, fmt.Errorf("failed to read values file: %w", err)
}

if err := yaml.Unmarshal(data, &values); err != nil {
return nil, fmt.Errorf("failed to parse values file: %v", err)
return nil, fmt.Errorf("failed to parse values file: %w", err)
}
}

Expand Down Expand Up @@ -169,7 +169,7 @@ func renderTemplate(templateName string, values map[string]interface{}) (string,
// Get template content from embedded files
templateData, err := GetTemplateContent(templateName)
if err != nil {
return "", fmt.Errorf("failed to read template: %v", err)
return "", fmt.Errorf("failed to read template: %w", err)
}

// Create Helm template engine
Expand Down Expand Up @@ -199,7 +199,7 @@ func renderTemplate(templateName string, values map[string]interface{}) (string,
// Render template using Helm engine
rendered, err := helmEngine.Render(helmChart, helmValues)
if err != nil {
return "", fmt.Errorf("failed to render template: %v", err)
return "", fmt.Errorf("failed to render template: %w", err)
}

// Get rendered content for our template
Expand Down Expand Up @@ -228,13 +228,13 @@ func applyResources(yamlContent string) error {
// Load kubeconfig
config, err := clientcmd.BuildConfigFromFlags("", clientcmd.RecommendedHomeFile)
if err != nil {
return fmt.Errorf("failed to load kubeconfig: %v", err)
return fmt.Errorf("failed to load kubeconfig: %w", err)
}

// Create kthena client
client, err := versioned.NewForConfig(config)
if err != nil {
return fmt.Errorf("failed to create kthena client: %v", err)
return fmt.Errorf("failed to create kthena client: %w", err)
}

ctx := context.Background()
Expand All @@ -248,7 +248,7 @@ func applyResources(yamlContent string) error {
if err.Error() == "EOF" {
break
}
return fmt.Errorf("failed to decode YAML: %v", err)
return fmt.Errorf("failed to decode YAML: %w", err)
}

if rawObj == nil {
Expand All @@ -270,7 +270,7 @@ func applyResources(yamlContent string) error {

// Apply based on resource type
if err := applyKthenaResource(ctx, client, obj); err != nil {
return fmt.Errorf("failed to apply %s %s: %v", gvk.Kind, resourceName, err)
return fmt.Errorf("failed to apply %s %s: %w", gvk.Kind, resourceName, err)
}

fmt.Printf(" ✓ Applied successfully\n")
Expand All @@ -292,64 +292,64 @@ func applyKthenaResource(ctx context.Context, client versioned.Interface, obj *u
modelServing := &workloadv1alpha1.ModelServing{}
err := runtime.DefaultUnstructuredConverter.FromUnstructured(obj.Object, modelServing)
if err != nil {
return fmt.Errorf("failed to convert unstructured object to ModelServing: %v", err)
return fmt.Errorf("failed to convert unstructured object to ModelServing: %w", err)
}

_, err = client.WorkloadV1alpha1().ModelServings(resourceNamespace).Create(ctx, modelServing, metav1.CreateOptions{})
if err != nil {
return fmt.Errorf("failed to create ModelServing: %v", err)
return fmt.Errorf("failed to create ModelServing: %w", err)
}

case "ModelBooster":
fmt.Printf(" Creating ModelBooster: %s in namespace %s\n", resourceName, resourceNamespace)
model := &workloadv1alpha1.ModelBooster{}
err := runtime.DefaultUnstructuredConverter.FromUnstructured(obj.Object, model)
if err != nil {
return fmt.Errorf("failed to convert unstructured object to ModelBooster: %v", err)
return fmt.Errorf("failed to convert unstructured object to ModelBooster: %w", err)
}

_, err = client.WorkloadV1alpha1().ModelBoosters(resourceNamespace).Create(ctx, model, metav1.CreateOptions{})
if err != nil {
return fmt.Errorf("failed to create ModelBooster: %v", err)
return fmt.Errorf("failed to create ModelBooster: %w", err)
}

case "AutoscalingPolicy":
fmt.Printf(" Creating AutoscalingPolicy: %s in namespace %s\n", resourceName, resourceNamespace)
policy := &workloadv1alpha1.AutoscalingPolicy{}
err := runtime.DefaultUnstructuredConverter.FromUnstructured(obj.Object, policy)
if err != nil {
return fmt.Errorf("failed to convert unstructured object to AutoscalingPolicy: %v", err)
return fmt.Errorf("failed to convert unstructured object to AutoscalingPolicy: %w", err)
}

_, err = client.WorkloadV1alpha1().AutoscalingPolicies(resourceNamespace).Create(ctx, policy, metav1.CreateOptions{})
if err != nil {
return fmt.Errorf("failed to create AutoscalingPolicy: %v", err)
return fmt.Errorf("failed to create AutoscalingPolicy: %w", err)
}

case "ModelRoute":
fmt.Printf(" Creating ModelRoute: %s in namespace %s\n", resourceName, resourceNamespace)
modelRoute := &networkingv1alpha1.ModelRoute{}
err := runtime.DefaultUnstructuredConverter.FromUnstructured(obj.Object, modelRoute)
if err != nil {
return fmt.Errorf("failed to convert unstructured object to ModelRoute: %v", err)
return fmt.Errorf("failed to convert unstructured object to ModelRoute: %w", err)
}

_, err = client.NetworkingV1alpha1().ModelRoutes(resourceNamespace).Create(ctx, modelRoute, metav1.CreateOptions{})
if err != nil {
return fmt.Errorf("failed to create ModelRoute: %v", err)
return fmt.Errorf("failed to create ModelRoute: %w", err)
}

case "ModelServer":
fmt.Printf(" Creating ModelServer: %s in namespace %s\n", resourceName, resourceNamespace)
modelServer := &networkingv1alpha1.ModelServer{}
err := runtime.DefaultUnstructuredConverter.FromUnstructured(obj.Object, modelServer)
if err != nil {
return fmt.Errorf("failed to convert unstructured object to ModelServer: %v", err)
return fmt.Errorf("failed to convert unstructured object to ModelServer: %w", err)
}

_, err = client.NetworkingV1alpha1().ModelServers(resourceNamespace).Create(ctx, modelServer, metav1.CreateOptions{})
if err != nil {
return fmt.Errorf("failed to create ModelServer: %v", err)
return fmt.Errorf("failed to create ModelServer: %w", err)
}

default:
Expand Down
22 changes: 11 additions & 11 deletions cli/kthena/cmd/describe.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ func runDescribeTemplate(cmd *cobra.Command, args []string) error {
// Read template content from embedded files
content, err := GetTemplateContent(templateName)
if err != nil {
return fmt.Errorf("failed to read template: %v", err)
return fmt.Errorf("failed to read template: %w", err)
}
fmt.Println("=================")
fmt.Println("Template Content:")
Expand All @@ -159,7 +159,7 @@ func runDescribeModelBooster(cmd *cobra.Command, args []string) error {

model, err := client.WorkloadV1alpha1().ModelBoosters(namespace).Get(ctx, modelName, metav1.GetOptions{})
if err != nil {
return fmt.Errorf("failed to get Model '%s': %v", modelName, err)
return fmt.Errorf("failed to get Model '%s': %w", modelName, err)
}

fmt.Printf("Model: %s\n", model.Name)
Expand All @@ -171,7 +171,7 @@ func runDescribeModelBooster(cmd *cobra.Command, args []string) error {
// Output the full resource as YAML
data, err := yaml.Marshal(model)
if err != nil {
return fmt.Errorf("failed to marshal Model to YAML: %v", err)
return fmt.Errorf("failed to marshal Model to YAML: %w", err)
}

fmt.Println("Resource Details:")
Expand All @@ -197,7 +197,7 @@ func runDescribeModelServing(cmd *cobra.Command, args []string) error {

modelServing, err := client.WorkloadV1alpha1().ModelServings(namespace).Get(ctx, modelServingName, metav1.GetOptions{})
if err != nil {
return fmt.Errorf("failed to get ModelServing '%s': %v", modelServingName, err)
return fmt.Errorf("failed to get ModelServing '%s': %w", modelServingName, err)
}

fmt.Printf("ModelServing: %s\n", modelServing.Name)
Expand All @@ -209,7 +209,7 @@ func runDescribeModelServing(cmd *cobra.Command, args []string) error {
// Output the full resource as YAML
data, err := yaml.Marshal(modelServing)
if err != nil {
return fmt.Errorf("failed to marshal ModelServing to YAML: %v", err)
return fmt.Errorf("failed to marshal ModelServing to YAML: %w", err)
}

fmt.Println("Resource Details:")
Expand All @@ -235,7 +235,7 @@ func runDescribeAutoscalingPolicy(cmd *cobra.Command, args []string) error {

policy, err := client.WorkloadV1alpha1().AutoscalingPolicies(namespace).Get(ctx, policyName, metav1.GetOptions{})
if err != nil {
return fmt.Errorf("failed to get AutoscalingPolicy '%s': %v", policyName, err)
return fmt.Errorf("failed to get AutoscalingPolicy '%s': %w", policyName, err)
}

fmt.Printf("AutoscalingPolicy: %s\n", policy.Name)
Expand All @@ -247,7 +247,7 @@ func runDescribeAutoscalingPolicy(cmd *cobra.Command, args []string) error {
// Output the full resource as YAML
data, err := yaml.Marshal(policy)
if err != nil {
return fmt.Errorf("failed to marshal AutoscalingPolicy to YAML: %v", err)
return fmt.Errorf("failed to marshal AutoscalingPolicy to YAML: %w", err)
}

fmt.Println("Resource Details:")
Expand All @@ -272,7 +272,7 @@ func runDescribeModelRoute(cmd *cobra.Command, args []string) error {

route, err := client.NetworkingV1alpha1().ModelRoutes(namespace).Get(ctx, routeName, metav1.GetOptions{})
if err != nil {
return fmt.Errorf("failed to get ModelRoute '%s': %v", routeName, err)
return fmt.Errorf("failed to get ModelRoute '%s': %w", routeName, err)
}

fmt.Printf("ModelRoute: %s\n", route.Name)
Expand All @@ -283,7 +283,7 @@ func runDescribeModelRoute(cmd *cobra.Command, args []string) error {

data, err := yaml.Marshal(route)
if err != nil {
return fmt.Errorf("failed to marshal ModelRoute to YAML: %v", err)
return fmt.Errorf("failed to marshal ModelRoute to YAML: %w", err)
}

fmt.Println("Resource Details:")
Expand All @@ -309,7 +309,7 @@ func runDescribeModelServer(cmd *cobra.Command, args []string) error {

server, err := client.NetworkingV1alpha1().ModelServers(namespace).Get(ctx, serverName, metav1.GetOptions{})
if err != nil {
return fmt.Errorf("failed to get ModelServer '%s': %v", serverName, err)
return fmt.Errorf("failed to get ModelServer '%s': %w", serverName, err)
}

fmt.Printf("ModelServer: %s\n", server.Name)
Expand All @@ -320,7 +320,7 @@ func runDescribeModelServer(cmd *cobra.Command, args []string) error {

data, err := yaml.Marshal(server)
if err != nil {
return fmt.Errorf("failed to marshal ModelServer to YAML: %v", err)
return fmt.Errorf("failed to marshal ModelServer to YAML: %w", err)
}

fmt.Println("Resource Details:")
Expand Down
22 changes: 11 additions & 11 deletions cli/kthena/cmd/get.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,7 @@ func init() {
func runGetTemplates(cmd *cobra.Command, args []string) error {
templateNames, err := ListTemplates()
if err != nil {
return fmt.Errorf("failed to read templates: %v", err)
return fmt.Errorf("failed to read templates: %w", err)
}

if len(templateNames) == 0 {
Expand All @@ -152,7 +152,7 @@ func runGetTemplates(cmd *cobra.Command, args []string) error {

data, err := yaml.Marshal(templates)
if err != nil {
return fmt.Errorf("failed to marshal to YAML: %v", err)
return fmt.Errorf("failed to marshal to YAML: %w", err)
}
fmt.Print(string(data))
return nil
Expand Down Expand Up @@ -192,7 +192,7 @@ func runGetTemplate(cmd *cobra.Command, args []string) error {
if outputFormat == "yaml" || outputFormat == "" {
content, err := GetTemplateContent(templateName)
if err != nil {
return fmt.Errorf("failed to read template: %v", err)
return fmt.Errorf("failed to read template: %w", err)
}
fmt.Print(content)
return nil
Expand All @@ -201,7 +201,7 @@ func runGetTemplate(cmd *cobra.Command, args []string) error {
// For other output formats, show template info
manifestInfo, err := GetTemplateInfo(templateName)
if err != nil {
return fmt.Errorf("failed to get template info: %v", err)
return fmt.Errorf("failed to get template info: %w", err)
}

w := tabwriter.NewWriter(os.Stdout, 0, 0, 3, ' ', 0)
Expand All @@ -213,12 +213,12 @@ func runGetTemplate(cmd *cobra.Command, args []string) error {
func getKthenaClient() (*versioned.Clientset, error) {
config, err := clientcmd.BuildConfigFromFlags("", clientcmd.RecommendedHomeFile)
if err != nil {
return nil, fmt.Errorf("failed to load kubeconfig: %v", err)
return nil, fmt.Errorf("failed to load kubeconfig: %w", err)
}

client, err := versioned.NewForConfig(config)
if err != nil {
return nil, fmt.Errorf("failed to create kthena client: %v", err)
return nil, fmt.Errorf("failed to create kthena client: %w", err)
}

return client, nil
Expand Down Expand Up @@ -285,7 +285,7 @@ func runGetModelBoosters(cmd *cobra.Command, args []string) error {

models, err := client.WorkloadV1alpha1().ModelBoosters(namespace).List(ctx, metav1.ListOptions{})
if err != nil {
return fmt.Errorf("failed to list Models: %v", err)
return fmt.Errorf("failed to list Models: %w", err)
}

// Get name filter if provided
Expand Down Expand Up @@ -350,7 +350,7 @@ func runGetModelServings(cmd *cobra.Command, args []string) error {

modelServingList, err := client.WorkloadV1alpha1().ModelServings(namespace).List(ctx, metav1.ListOptions{})
if err != nil {
return fmt.Errorf("failed to list ModelServings: %v", err)
return fmt.Errorf("failed to list ModelServings: %w", err)
}

if len(modelServingList.Items) == 0 {
Expand Down Expand Up @@ -395,7 +395,7 @@ func runGetAutoscalingPolicies(cmd *cobra.Command, args []string) error {

policies, err := client.WorkloadV1alpha1().AutoscalingPolicies(namespace).List(ctx, metav1.ListOptions{})
if err != nil {
return fmt.Errorf("failed to list AutoscalingPolicies: %v", err)
return fmt.Errorf("failed to list AutoscalingPolicies: %w", err)
}

if len(policies.Items) == 0 {
Expand Down Expand Up @@ -455,7 +455,7 @@ func runGetModelRoutes(cmd *cobra.Command, args []string) error {

routes, err := client.NetworkingV1alpha1().ModelRoutes(namespace).List(ctx, metav1.ListOptions{})
if err != nil {
return fmt.Errorf("failed to list ModelRoutes: %v", err)
return fmt.Errorf("failed to list ModelRoutes: %w", err)
}

if len(routes.Items) == 0 {
Expand Down Expand Up @@ -506,7 +506,7 @@ func runGetModelServers(cmd *cobra.Command, args []string) error {

servers, err := client.NetworkingV1alpha1().ModelServers(namespace).List(ctx, metav1.ListOptions{})
if err != nil {
return fmt.Errorf("failed to list ModelServers: %v", err)
return fmt.Errorf("failed to list ModelServers: %w", err)
}

if len(servers.Items) == 0 {
Expand Down
6 changes: 3 additions & 3 deletions cli/kthena/cmd/templates.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ func findTemplatePath(templateName string) (string, error) {
// Fallback: search through all vendor directories (for backward compatibility)
vendors, err := templatesFS.ReadDir("helm/templates")
if err != nil {
return "", fmt.Errorf("failed to read templates directory: %v", err)
return "", fmt.Errorf("failed to read templates directory: %w", err)
}

for _, vendor := range vendors {
Expand All @@ -75,7 +75,7 @@ func GetTemplateContent(templateName string) (string, error) {

content, err := templatesFS.ReadFile(templatePath)
if err != nil {
return "", fmt.Errorf("failed to read template '%s': %v", templateName, err)
return "", fmt.Errorf("failed to read template '%s': %w", templateName, err)
}

return string(content), nil
Expand All @@ -85,7 +85,7 @@ func GetTemplateContent(templateName string) (string, error) {
func ListTemplates() ([]string, error) {
vendors, err := templatesFS.ReadDir("helm/templates")
if err != nil {
return nil, fmt.Errorf("failed to read templates directory: %v", err)
return nil, fmt.Errorf("failed to read templates directory: %w", err)
}

var templates []string
Expand Down
Loading
Loading