Skip to content

Commit

Permalink
fix: json-properties flag not working on k8s nodepool (#464)
Browse files Browse the repository at this point in the history
* remove viper binding for json-properties and json-properties-example

* update changelog

* save vars in k8s test for teardown
  • Loading branch information
glimberea authored Nov 8, 2024
1 parent e6d2e81 commit 43d5ac9
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 4 deletions.
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
# Changelog

## [v6.8.0]
## [v6.8.0] (???)

### Added
- Added support for CDN operations

### Fixed
- Removed Viper binding for `json-properties` and `json-properties-example` (fixes [463](https://github.com/ionos-cloud/ionosctl/issues/463))

## [v6.7.8] (October 2024)

### Added
Expand Down
3 changes: 2 additions & 1 deletion commands/cloudapi-v6/k8s_nodepool.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,9 +150,10 @@ Required values to run a command (for Private Kubernetes Cluster):
)
},
CmdRun: func(c *core.CommandConfig) error {
if viper.IsSet(constants.FlagJsonProperties) {
if c.Command.Command.Flags().Changed(constants.FlagJsonProperties) {
return RunK8sNodePoolCreateFromJSON(c, nodepoolViaJsonPropertiesFlag)
}

return RunK8sNodePoolCreate(c)
},
InitClient: true,
Expand Down
2 changes: 0 additions & 2 deletions internal/core/command_runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,11 @@ func NewCommandWithJsonProperties(ctx context.Context, parent *Command, jsonExam

cmd.Command.Flags().String(constants.FlagJsonProperties, "",
"Path to a JSON file containing the desired properties. Overrides any other properties set.")
viper.BindPFlag(constants.FlagJsonProperties, cmd.Command.Flags().Lookup(constants.FlagJsonProperties))

if jsonExample != "" {
cmd.Command.Flags().Bool(constants.FlagJsonPropertiesExample, false,
fmt.Sprintf("If set, prints a complete JSON which could be used for --%s "+
"and exits. Hint: Pipe me to a .json file", constants.FlagJsonProperties))
viper.BindPFlag(constants.FlagJsonPropertiesExample, cmd.Command.Flags().Lookup(constants.FlagJsonPropertiesExample))
}

return cmd
Expand Down
18 changes: 18 additions & 0 deletions test/bats/cloudapi/k8s.bats
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ location="es/vit"
setup_file() {
uuid_v4_regex='^[0-9a-f]{8}-[0-9a-f]{4}-[4][0-9a-f]{3}-[89ab][0-9a-f]{3}-[0-9a-f]{12}$'
ip_regex='^([0-9]{1,3}\.){3}[0-9]{1,3}(\/[0-9]{1,2})?$'

mkdir -p /tmp/bats_test
}

@test "Create K8s Nodepool" {
Expand All @@ -21,6 +23,8 @@ setup_file() {
[ -n "$datacenter_id" ] || fail "$datacenter_id is empty"
assert_regex "$datacenter_id" "$uuid_v4_regex"

echo $datacenter_id >> /tmp/bats_test/datacenter_id

cluster_id=$(find_or_create_resource \
"ionosctl k8s cluster list -F public=true,state=available -M 1 -o json 2> /dev/null | jq -r '.items[] | .id'" \
"ionosctl k8s cluster create --name \"CLI-Test-$(randStr 8)\" -o json 2> /dev/null | jq -r '.id'")
Expand All @@ -29,13 +33,21 @@ setup_file() {

sleep 120

# Use retry_until to check if the cluster is in "active" state
retry_until "ionosctl k8s cluster get --cluster-id $cluster_id -o json 2> /dev/null | jq -r '.metadata.state'" \
"[[ \$output == \"ACTIVE\" ]]" 10 60

echo $cluster_id >> /tmp/bats_test/cluster_id

echo "Trying to create k8s nodepool in cluster $cluster_id and datacenter $datacenter_id"
run ionosctl k8s nodepool create --name "CLI-Test-$(randStr 8)" --cluster-id "$cluster_id" --datacenter-id "$datacenter_id" -o json 2> /dev/null -W -t 600
assert_success
nodepool_id=$(echo "$output" | jq -r '.id')
assert_regex "nodepool_id" "$uuid_v4_regex"
echo "created k8s nodepool $nodepool_id"

echo $nodepool_id >> /tmp/bats_test/nodepool_id

run ionosctl k8s node list --cluster-id "$cluster_id" --nodepool-id "$nodepool_id" --cols PublicIP --no-headers
assert_success
node_ip=$(echo "$output")
Expand All @@ -47,10 +59,16 @@ setup_file() {
}

teardown_file() {
datacenter_id=$(cat /tmp/bats_test/datacenter_id)
cluster_id=$(cat /tmp/bats_test/cluster_id)
nodepool_id=$(cat /tmp/bats_test/nodepool_id)

echo "cleaning up datacenter $datacenter_id and k8s resources $cluster_id ; $nodepool_id"
retry_command run ionosctl k8s nodepool delete --cluster-id "$cluster_id" --nodepool-id "$nodepool_id" -f -w -t 1200
sleep 30
retry_command run ionosctl k8s cluster delete --cluster-id "$cluster_id" -f -w -t 1200
sleep 30
retry_command run ionosctl datacenter delete --datacenter_id "$datacenter_id" -f -w -t 1200

rm -rf /tmp/bats_test
}

0 comments on commit 43d5ac9

Please sign in to comment.