ionos-cloud / ionosctl

The IONOS Cloud CLI (ionosctl) gives the ability to manage IONOS Cloud infrastructure directly from Command Line.
Apache License 2.0
30 stars 6 forks source link

File passed using the `--json-properties` argument is ignored when creating a node pool with `ionosctl` #463

Closed mstoops-ox closed 20 minutes ago

mstoops-ox commented 1 week ago

Description

File passed using the --json-properties argument is ignored when creating a node pool with ionosctl

Expected behavior

The values used to describe a node pool in a json file are used to create the node pool

Environment

Go Version:

go version go1.23.2 darwin/arm64

Ionosctl version:

ionosctl version v6.7.8

OS:

macOS 15.1 (Sequoia)

Shell:

zsh 5.9

Configuration Files

Using ionos token to login in. Have tried using the following in a json file:

{
  "metadata": {},
  "properties": {
    "name": "myTestNodePool",
    "datacenterId": "<datacenter-id>",
    "nodeCount": 4,
    "cpuFamily": "INTEL_XEON",
    "coresCount": 2,
    "ramSize": 8192,
    "availabilityZone": "AUTO",
    "storageType": "HDD",
    "storageSize": 20,
    "k8sVersion": "1.28.10",
    "maintenanceWindow": {
      "dayOfTheWeek": "Sunday",
      "time": "04:24:26Z"
    },
    "autoScaling": {
      "minNodeCount": "3",
      "maxNodeCount": "4"
    },
    "lans": [
      {
        "id": 10,
        "dhcp": true,
        "routes": []
      }
    ],
    "labels": [
      {
        "label1": "value1",
        "label2": "value2",
        "label3": "value3"
      }
    ]
  }
}

How to Reproduce

-- Note: the and values are replaced with my respective cluster and datacenter values

  1. I created a json-properties file using `ionosctl k8s nodepool create --json-properties-example > test-nodepool.json
  2. Make changes so that the file contains the above json (note: the "labels" output to the example file does not seem to be formatted correctly, had to put '[' and ']' around the object).
  3. Executed ionosctl k8s nodepool create --cluster-id <cluster-id> --datacenter-id <datacenter-id> --json-properties test-nodepool.json --verbose

Error and Debug Output

The output with --verbose shows that the values from the json file are completely ignored

[INFO] Query Parameters set: map[QueryParams:map[]], map[]
[INFO] Request Execution Time: 360.282416ms
[INFO] Property Name set: UnnamedNodePool
[INFO] Property K8sVersion set: 1.30.6
[INFO] Property NodeCount set: 1
[INFO] Property DatacenterId set: 87dd4cc7-b47b-43f5-8167-7bc5e26b8f0e
[INFO] Property CPU Family set: INTEL_XEON
[INFO] Property CoresCount set: 2
[INFO] Property RAM Size set: 2048MB
[INFO] Property Availability Zone set: AUTO
[INFO] Property Storage Size set: 10GB
[INFO] Property Storage Type set: HDD
[INFO] Creating K8s NodePool in K8s Cluster with ID: 0e12d365-0238-41a0-8522-a9365638d3bf
Error: 422 Unprocessable Entity {
  "httpStatus" : 422,
  "messages" : [ {
    "errorCode" : "200",
    "message" : "[VDC-14-1830] Operation cannot be executed because the K8s version 1.30.6 is not viable for nodepools in cluster. Available versions are [1.28.15, 1.28.14, 1.28.13, 1.28.12, 1.28.11, 1.28.10, 1.28.9, 1.28.8, 1.28.7, 1.28.6, 1.28.4, 1.28.3, 1.28.2]"
  } ]
}

Additional Notes

Command-line arguments to ionosctl work properly.

References

n/a

avirtopeanu-ionos commented 1 week ago

Hi, thanks for opening this issue, We'll investigate and keep you updated!

glimberea commented 1 week ago

Hi, thanks for reporting this! I have taken a look at the json-properties flag and found the issue, a PR with a fix should be coming soon.

Also, in regards to the labels field, the example follows the object definition from the API docs, where it is defined as a map. The reason it works even when you use an array of maps (how you did it) is because the go/json package will merge it into a single map when unmarshalling the whole example into the nodepool object, which has a map[string][string] corresponding labels property.

I hope this clears things up a bit, and I will ping this thread when the fix PR is posted and then once more when it's merged.

mstoops commented 6 days ago

In regards to your mention of the label field, I added the array because I was getting an error otherwise.

When I use the following (without wrapping the map in an array)

     "labels": {
         "app.open-xchange.com": "gitlab",
         "ingress-node.open-xchange.com": "true",
         "env.open-xchange.com": "test"
       }

I get the following error

Error: failed unmarshalling json properties into object: 3 error(s) decoding:

* 'Properties.Labels[app]' expected type 'string', got unconvertible type 'map[string]interface {}', value: 'map[open-xchange:map[com:gitlab]]'
* 'Properties.Labels[env]' expected type 'string', got unconvertible type 'map[string]interface {}', value: 'map[open-xchange:map[com:test]]'
* 'Properties.Labels[ingress-node]' expected type 'string', got unconvertible type 'map[string]interface {}', value: 'map[open-xchange:map[com:true]]'

I didn't get the complains once I wrapped the object in an array.

mstoops commented 6 days ago

Now I see the reason that's happening, in that it's not taking the key name as a string, but instead is treating the '.'s as dot operators. Not sure how to deal with that though.

glimberea commented 20 minutes ago

I don't think that error is something that we can do much about, it's simply how the go/json package seems to handle such naming schemes. We have merged the fix PR https://github.com/ionos-cloud/ionosctl/pull/464 into master and will be releasing a new version of ionosctl soon.

If there are no more issues, I will be closing this thread.