Skip to content

Commit

Permalink
fixed issue with manifestwork object not creating
Browse files Browse the repository at this point in the history
  • Loading branch information
clubanderson committed Apr 19, 2024
1 parent 81e7c7b commit 183e693
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 6 deletions.
5 changes: 3 additions & 2 deletions pkg/common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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) {
Expand Down
9 changes: 7 additions & 2 deletions pkg/plugin-bp-creator/plugin-bp-creator.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
Expand Down
9 changes: 7 additions & 2 deletions pkg/plugin-ocm-creator/plugin-ocm-creator.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,15 +91,20 @@ 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 {
fmt.Println("Error marshaling JSON:", err)
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))
}
Expand Down

0 comments on commit 183e693

Please sign in to comment.