Skip to content

Commit

Permalink
Merge pull request volcano-sh#3692 from googs1025/bug_fix/jobtemplate…
Browse files Browse the repository at this point in the history
…_vcctl

vcctl(jobtemplate): fix describe miss APIVersion and Kind bug, and remove ManagedFields
  • Loading branch information
volcano-sh-bot authored Sep 4, 2024
2 parents 0d5830c + 24d508c commit 009748e
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 13 deletions.
4 changes: 2 additions & 2 deletions pkg/cli/jobflow/describe.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,9 @@ func DescribeJobFlow(ctx context.Context) error {
// Remove managedFields
jobFlow.ManagedFields = nil
PrintJobFlowDetail(&jobFlow, describeJobFlowFlags.Format)
// Print a separator if it's not the last element
// Print space if it's not the last element
if len(jobFlows.Items) != 1 && i < len(jobFlows.Items)-1 {
fmt.Println("---------------------------------")
fmt.Printf("\n\n")
}
}
// Get jobflow detail
Expand Down
23 changes: 18 additions & 5 deletions pkg/cli/jobtemplate/describe.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"context"
"encoding/json"
"fmt"
"os"

"github.com/spf13/cobra"

Expand Down Expand Up @@ -66,15 +67,28 @@ func DescribeJobTemplate(ctx context.Context) error {
if err != nil {
return err
}
for _, jobTemplate := range jobTemplates.Items {
for i, jobTemplate := range jobTemplates.Items {
// Remove managedFields
jobTemplate.ManagedFields = nil
PrintJobTemplateDetail(&jobTemplate, describeJobTemplateFlags.Format)
// Print space if it's not the last element
if len(jobTemplates.Items) != 1 && i < len(jobTemplates.Items)-1 {
fmt.Printf("\n\n")
}
}
// Get job template detail
} else {
jobTemplate, err := jobTemplateClient.FlowV1alpha1().JobTemplates(describeJobTemplateFlags.Namespace).Get(ctx, describeJobTemplateFlags.Name, metav1.GetOptions{})
if err != nil {
return err
}
// Remove managedFields
jobTemplate.ManagedFields = nil
// Set APIVersion and Kind if not set
if jobTemplate.APIVersion == "" || jobTemplate.Kind == "" {
jobTemplate.APIVersion = v1alpha1.SchemeGroupVersion.String()
jobTemplate.Kind = "JobTemplate"
}
PrintJobTemplateDetail(jobTemplate, describeJobTemplateFlags.Format)
}

Expand All @@ -98,15 +112,14 @@ func printJSON(jobTemplate *v1alpha1.JobTemplate) {
if err != nil {
fmt.Printf("Error marshaling JSON: %v\n", err)
}
fmt.Println(string(b))
fmt.Println("---------------------------------")
os.Stdout.Write(b)
fmt.Println("")
}

func printYAML(jobTemplate *v1alpha1.JobTemplate) {
b, err := yaml.Marshal(jobTemplate)
if err != nil {
fmt.Printf("Error marshaling YAML: %v\n", err)
}
fmt.Println(string(b))
fmt.Println("---------------------------------")
os.Stdout.Write(b)
}
13 changes: 7 additions & 6 deletions pkg/cli/jobtemplate/jobtemplate_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -284,14 +284,14 @@ func TestDescribeJobTemplate(t *testing.T) {
Name: "test-jobtemplate",
Format: "yaml",
ExpectedErr: nil,
ExpectedOutput: `metadata:
ExpectedOutput: `apiVersion: flow.volcano.sh/v1alpha1
kind: JobTemplate
metadata:
creationTimestamp: null
name: test-jobtemplate
namespace: default
spec: {}
status: {}
---------------------------------`,
status: {}`,
},
{
name: "Normal Case, use json format",
Expand All @@ -306,15 +306,16 @@ status: {}
Format: "json",
ExpectedErr: nil,
ExpectedOutput: `{
"kind": "JobTemplate",
"apiVersion": "flow.volcano.sh/v1alpha1",
"metadata": {
"name": "test-jobtemplate",
"namespace": "default",
"creationTimestamp": null
},
"spec": {},
"status": {}
}
---------------------------------`,
}`,
},
}
for _, testCase := range testCases {
Expand Down

0 comments on commit 009748e

Please sign in to comment.