Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add resource priority #45

Merged
merged 1 commit into from
Jun 24, 2024
Merged
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
69 changes: 36 additions & 33 deletions cmd/apply.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,45 +2,16 @@ package cmd

import (
"fmt"
"os"

"github.com/conduktor/ctl/resource"
"github.com/conduktor/ctl/schema"
"github.com/spf13/cobra"
"os"
)

var filePath *[]string
var dryRun *bool

// applyCmd represents the apply command
var applyCmd = &cobra.Command{
Use: "apply",
Short: "Upsert a resource on Conduktor",
Long: ``,
Run: func(cmd *cobra.Command, args []string) {
var resources = make([]resource.Resource, 0)
for _, path := range *filePath {
r, err := resourceForPath(path)
if err != nil {
fmt.Fprintf(os.Stderr, "%s\n", err)
os.Exit(1)
}
resources = append(resources, r...)
}
var allSuccess = true
for _, resource := range resources {
upsertResult, err := apiClient().Apply(&resource, *dryRun)
if err != nil {
fmt.Fprintf(os.Stderr, "Could not apply resource %s/%s: %s\n", resource.Kind, resource.Name, err)
allSuccess = false
} else {
fmt.Printf("%s/%s: %s\n", resource.Kind, resource.Name, upsertResult)
}
}
if !allSuccess {
os.Exit(1)
}
},
}

func resourceForPath(path string) ([]resource.Resource, error) {
directory, err := isDirectory(path)
if err != nil {
Expand All @@ -54,7 +25,39 @@ func resourceForPath(path string) ([]resource.Resource, error) {
}
}

func initApply() {
func initApply(kinds schema.KindCatalog) {
// applyCmd represents the apply command
var applyCmd = &cobra.Command{
Use: "apply",
Short: "Upsert a resource on Conduktor",
Long: ``,
Run: func(cmd *cobra.Command, args []string) {
var resources = make([]resource.Resource, 0)
for _, path := range *filePath {
r, err := resourceForPath(path)
if err != nil {
fmt.Fprintf(os.Stderr, "%s\n", err)
os.Exit(1)
}
resources = append(resources, r...)
}
var allSuccess = true
schema.SortResources(kinds, resources, *debug)
for _, resource := range resources {
upsertResult, err := apiClient().Apply(&resource, *dryRun)
if err != nil {
fmt.Fprintf(os.Stderr, "Could not apply resource %s/%s: %s\n", resource.Kind, resource.Name, err)
allSuccess = false
} else {
fmt.Printf("%s/%s: %s\n", resource.Kind, resource.Name, upsertResult)
}
}
if !allSuccess {
os.Exit(1)
}
},
}

rootCmd.AddCommand(applyCmd)

// Here you will define your flags and configuration settings.
Expand Down
5 changes: 3 additions & 2 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ package cmd

import (
"fmt"
"os"

"github.com/conduktor/ctl/client"
"github.com/conduktor/ctl/schema"
"github.com/spf13/cobra"
"os"
)

var debug *bool
Expand Down Expand Up @@ -58,7 +59,7 @@ func init() {
debug = rootCmd.PersistentFlags().BoolP("verbose", "v", false, "show more information for debugging")
initGet(kinds)
initDelete(kinds)
initApply()
initApply(kinds)
initMkKind()
initPrintKind(kinds)
}
2 changes: 1 addition & 1 deletion schema/default-schema.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"Application":{"Versions":{"1":{"ListPath":"/public/self-serve/v1/application","Name":"Application","ParentPathParam":[]}}},"ApplicationGroup":{"Versions":{"1":{"ListPath":"/public/self-serve/v1/application-group","Name":"ApplicationGroup","ParentPathParam":[]}}},"ApplicationInstance":{"Versions":{"1":{"ListPath":"/public/self-serve/v1/application-instance","Name":"ApplicationInstance","ParentPathParam":[]}}},"ApplicationInstancePermission":{"Versions":{"1":{"ListPath":"/public/self-serve/v1/application-instance-permission","Name":"ApplicationInstancePermission","ParentPathParam":[]}}},"Group":{"Versions":{"2":{"ListPath":"/public/iam/v2/group","Name":"Group","ParentPathParam":[]}}},"KafkaCluster":{"Versions":{"2":{"ListPath":"/public/console/v2/kafka-cluster","Name":"KafkaCluster","ParentPathParam":[]}}},"Subject":{"Versions":{"2":{"ListPath":"/public/kafka/v2/cluster/{cluster}/subject","Name":"Subject","ParentPathParam":["cluster"]}}},"Topic":{"Versions":{"2":{"ListPath":"/public/kafka/v2/cluster/{cluster}/topic","Name":"Topic","ParentPathParam":["cluster"]}}},"TopicPolicy":{"Versions":{"1":{"ListPath":"/public/self-serve/v1/topic-policy","Name":"TopicPolicy","ParentPathParam":[]}}},"User":{"Versions":{"2":{"ListPath":"/public/iam/v2/user","Name":"User","ParentPathParam":[]}}}}
{"Application":{"Versions":{"1":{"ListPath":"/public/self-serve/v1/application","Name":"Application","ParentPathParam":[],"Order":6}}},"ApplicationGroup":{"Versions":{"1":{"ListPath":"/public/self-serve/v1/application-group","Name":"ApplicationGroup","ParentPathParam":[],"Order":9}}},"ApplicationInstance":{"Versions":{"1":{"ListPath":"/public/self-serve/v1/application-instance","Name":"ApplicationInstance","ParentPathParam":[],"Order":7}}},"ApplicationInstancePermission":{"Versions":{"1":{"ListPath":"/public/self-serve/v1/application-instance-permission","Name":"ApplicationInstancePermission","ParentPathParam":[],"Order":8}}},"Group":{"Versions":{"2":{"ListPath":"/public/iam/v2/group","Name":"Group","ParentPathParam":[],"Order":1}}},"KafkaCluster":{"Versions":{"2":{"ListPath":"/public/console/v2/kafka-cluster","Name":"KafkaCluster","ParentPathParam":[],"Order":2}}},"Subject":{"Versions":{"2":{"ListPath":"/public/kafka/v2/cluster/{cluster}/subject","Name":"Subject","ParentPathParam":["cluster"],"Order":4}}},"Topic":{"Versions":{"2":{"ListPath":"/public/kafka/v2/cluster/{cluster}/topic","Name":"Topic","ParentPathParam":["cluster"],"Order":3}}},"TopicPolicy":{"Versions":{"1":{"ListPath":"/public/self-serve/v1/topic-policy","Name":"TopicPolicy","ParentPathParam":[],"Order":5}}},"User":{"Versions":{"2":{"ListPath":"/public/iam/v2/user","Name":"User","ParentPathParam":[],"Order":0}}}}
Loading
Loading