Skip to content

Commit

Permalink
feat: improve error message when conflict action name (#12)
Browse files Browse the repository at this point in the history
  • Loading branch information
Moran-k authored Jul 14, 2024
1 parent 50c6399 commit 4e82b71
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 8 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ HOSTNAME=github.com
NAMESPACE=komodorio
NAME=komodor
BINARY=terraform-provider-${NAME}
VERSION=1.0.8
VERSION=1.0.9
OS_ARCH=darwin_amd64

default: install
Expand Down
12 changes: 6 additions & 6 deletions komodor/custom_k8s_action.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,24 +61,24 @@ func (c *Client) GetCustomK8sAction(id string) (*CustomK8sAction, int, error) {
return &customK8sAction, statusCode, nil
}

func (c *Client) CreateCustomK8sAction(p *NewCustomK8sAction) (*CustomK8sAction, error) {
func (c *Client) CreateCustomK8sAction(p *NewCustomK8sAction) (*CustomK8sAction, int, error) {
jsonCustomK8sAction, err := json.Marshal(p)
if err != nil {
return nil, err
return nil, 0, err
}

res, _, err := c.executeHttpRequest(http.MethodPost, CustomK8sActionUrl, &jsonCustomK8sAction)
res, statusCode, err := c.executeHttpRequest(http.MethodPost, CustomK8sActionUrl, &jsonCustomK8sAction)
if err != nil {
return nil, err
return nil, statusCode, err
}

var customK8sAction CustomK8sAction
err = json.Unmarshal(res, &customK8sAction)
if err != nil {
return nil, err
return nil, statusCode, err
}

return &customK8sAction, nil
return &customK8sAction, statusCode, nil
}

func (c *Client) DeleteCustomK8sAction(id string) error {
Expand Down
5 changes: 4 additions & 1 deletion komodor/resource_komodor_custom_k8s_action.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,8 +64,11 @@ func resourceKomodorCustomK8sActionCreate(ctx context.Context, d *schema.Resourc
Ruleset: customK8sActionStatements,
}

customK8sAction, err := client.CreateCustomK8sAction(newCustomK8sAction)
customK8sAction, statusCode, err := client.CreateCustomK8sAction(newCustomK8sAction)
if err != nil {
if statusCode == 409 {
return diag.Errorf("Action name '%s' is already in use or marked for deletion. Please choose a different name or try again later", actionName)
}
return diag.Errorf("Error creating Custom K8S Action: %s, %v", err, customK8sActionStatements)
}

Expand Down

0 comments on commit 4e82b71

Please sign in to comment.