diff --git a/pkg/common/common.go b/pkg/common/common.go index 295e839..27d51fa 100644 --- a/pkg/common/common.go +++ b/pkg/common/common.go @@ -164,7 +164,7 @@ func expandTilde(args []string) []string { return args } -func (p ParamsStruct) CreateObjForPlugin(gvk schema.GroupVersionKind, yamlData []byte, objName, objResource, namespace string, objectJSON []byte) { +func (p ParamsStruct) CreateObjForPlugin(gvk schema.GroupVersionKind, yamlData []byte, objName, objResource, namespace string, objectJSON []byte) error { gvr := schema.GroupVersionResource{ Group: gvk.Group, Version: gvk.Version, @@ -184,8 +184,9 @@ func (p ParamsStruct) CreateObjForPlugin(gvk schema.GroupVersionKind, yamlData [ _, err := p.createObject(p.DynamicClient, namespace, gvr, objectJSON) if err != nil { log.Printf(" 🔴 failed to create %v object %q in namespace %v.\n", objResource, objName, namespace) + return err } - + return nil } func (p ParamsStruct) createObject(ocDynamicClientCoreOrWds dynamic.Interface, namespace string, gvr schema.GroupVersionResource, objectJSON []byte) (string, error) { diff --git a/pkg/plugin-bp-creator/plugin-bp-creator.go b/pkg/plugin-bp-creator/plugin-bp-creator.go index f62977c..86f3e70 100644 --- a/pkg/plugin-bp-creator/plugin-bp-creator.go +++ b/pkg/plugin-bp-creator/plugin-bp-creator.go @@ -120,13 +120,18 @@ func PluginCreateBP(p c.ParamsStruct, reflect bool) []string { } if p.Params["l-bp-wds"] != "" { - log.Printf(" 🚀 Attempting to create %v object %q in WDS %q", k, n, p.Params["l-bp-wds"]) + log.Printf(" 🚀 attempting to create %v object %q in WDS %q", k, n, p.Params["l-bp-wds"]) objectJSON, err := json.Marshal(bindingPolicy) if err != nil { fmt.Println("Error marshaling JSON:", err) return []string{} } - p.CreateObjForPlugin(gvk, yamlData, n, r, p.Params["l-bp-wds"], objectJSON) + err = p.CreateObjForPlugin(gvk, yamlData, n, r, p.Params["l-bp-wds"], objectJSON) + if err != nil { + log.Printf(" 🔴 failed to create %v object %q in namespace %v.\n", r, n, p.Params["namespaceArg"]) + } else { + log.Printf(" 🟢 successfully created %v object %q in namespace %v.\n", r, n, p.Params["namespaceArg"]) + } } else { fmt.Printf("%v", string(yamlData)) } diff --git a/pkg/plugin-ocm-creator/plugin-ocm-creator.go b/pkg/plugin-ocm-creator/plugin-ocm-creator.go index a962768..4244b0f 100644 --- a/pkg/plugin-ocm-creator/plugin-ocm-creator.go +++ b/pkg/plugin-ocm-creator/plugin-ocm-creator.go @@ -91,7 +91,7 @@ func PluginCreateMW(p c.ParamsStruct, reflect bool) []string { // log.Printf("yamlData: \n%v", string(yamlData)) if p.Flags["l-mw-create"] { - log.Printf(" 🚀 Attempting to create %v object %q in namespace %q", k, n, p.Params["namespaceArg"]) + log.Printf(" 🚀 attempting to create %v object %q in namespace %q", k, n, p.Params["namespaceArg"]) // log.Printf("%v %v %v %v %v %v", gvk.Group, gvk.Version, gvk.Kind, n, r, p.Params["namespaceArg"]) objectJSON, err := json.Marshal(manifestWork) if err != nil { @@ -99,7 +99,12 @@ func PluginCreateMW(p c.ParamsStruct, reflect bool) []string { return []string{} } // log.Printf("objectJSON: \n%v", string(objectJSON)) - p.CreateObjForPlugin(gvk, yamlData, n, r, p.Params["namespaceArg"], objectJSON) + err = p.CreateObjForPlugin(gvk, yamlData, n, r, p.Params["namespaceArg"], objectJSON) + if err != nil { + log.Printf(" 🔴 failed to create %v object %q in namespace %v.\n", r, n, p.Params["namespaceArg"]) + } else { + log.Printf(" 🟢 successfully created %v object %q in namespace %v.\n", r, n, p.Params["namespaceArg"]) + } } else { fmt.Printf("%v", string(yamlData)) }