Skip to content

Commit

Permalink
add resource priority
Browse files Browse the repository at this point in the history
  • Loading branch information
strokyl committed Jun 24, 2024
1 parent 4695534 commit 993b91e
Show file tree
Hide file tree
Showing 9 changed files with 12,249 additions and 55 deletions.
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

0 comments on commit 993b91e

Please sign in to comment.