Skip to content

Commit

Permalink
multi-annotation in a single arg --l-annotatation now working
Browse files Browse the repository at this point in the history
  • Loading branch information
clubanderson committed Apr 18, 2024
1 parent fe33ea7 commit 2e81f5e
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 17 deletions.
6 changes: 0 additions & 6 deletions pkg/common/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -195,10 +195,8 @@ func (p ParamsStruct) createObject(ocDynamicClientCoreOrWds dynamic.Interface, n
return namespace, err
}

// Create an unstructured.Unstructured object from the map
objToCreate := &unstructured.Unstructured{Object: objMap}

// Now objToCreate is an unstructured.Unstructured object representing the JSON data
// log.Printf("objToCreate: %v\n", objToCreate)
metadata, ok, _ := unstructured.NestedMap(objToCreate.Object, "Metadata")
if !ok {
Expand All @@ -212,7 +210,6 @@ func (p ParamsStruct) createObject(ocDynamicClientCoreOrWds dynamic.Interface, n
}

// log.Printf("name: %v\n", name)

_, err = p.GetObject(ocDynamicClientCoreOrWds, namespace, gvr, name)
if err == nil {
// object still exists, can't create
Expand Down Expand Up @@ -311,8 +308,5 @@ func (p ParamsStruct) GetObject(ocDynamicClientCoreOrWds dynamic.Interface, name
return objectJSON, nil
}

if err != nil {
return nil, err
}
return objectJSON, nil
}
22 changes: 11 additions & 11 deletions pkg/helpers/labeler-helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -77,8 +77,18 @@ func AliasRun(args []string, p c.ParamsStruct) error {
}
} else if strings.Contains(arg, "=") {
parts := strings.Split(arg, "=")
var result string
if len(parts) > 2 {
p.Params[parts[0][2:]] = parts[1] + "=" + parts[2]
log.Printf("labeler.go: arg: %v\n", arg)
log.Printf("labeler.go: len parts: %v\n", len(parts))
for i := 1; i < len(parts); i++ {
result += parts[i]
if i < len(parts)-1 {
result += "="
}
}
log.Printf("labeler.go: result: %v\n", result)
p.Params[parts[0][2:]] = result
} else {
p.Params[parts[0][2:]] = parts[1]
}
Expand Down Expand Up @@ -269,16 +279,6 @@ func traverseKubectlOutput(input []string, p c.ParamsStruct) {

namespace := p.Params["namespaceArg"]

// if c.Flags.Label == "" && p.Params["labelKey"] == "" {
// if p.Flags["l-debug"] {
// log.Println("labeler.go: no label provided")
// }
// return
// }
// if c.Flags.Label != "" {
// p.Params["labelKey"], p.Params["labelVal"] = strings.Split(c.Flags.Label, "=")[0], strings.Split(c.Flags.Label, "=")[1]
// }

if len(matches) == 0 {
if p.Flags["l-debug"] {
log.Println("labeler.go: no resources found")
Expand Down
10 changes: 10 additions & 0 deletions test/alias-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,16 @@ else
fi
((test_number++))

echo
echo "---------------------------------------------"
echo "--- kubectl alias with 'creator' AND 'description' annotation (multi-annotation), in default namespace, with --overwrite ---"
echo "k apply -f ../examples/kubectl/pass --l-annotation=creator='John Doe',description='testing 123' --context=kind-kind --namespace=default --overwrite"
if ! k apply -f ../examples/kubectl/pass --l-annotation=creator='John Doe',description='testing 123' --context=kind-kind --namespace=default --overwrite; then
print_error "test $test_number: ERROR"
else
print_success "test $test_number: SUCCESS"
fi
((test_number++))

echo
echo "---------------------------------------------"
Expand Down

0 comments on commit 2e81f5e

Please sign in to comment.