IBM-Cloud / bluemix-go

Go library for accessing the Bluemix API
Apache License 2.0
37 stars 86 forks source link

add masterHealth field to cluster struct #442

Closed bhpratt closed 2 months ago

bhpratt commented 3 months ago

Using the API global/v2/getCluster?=cluster<id>&v1-compatible there are different return values depending on the provider.

For VPC clusters, masterHealth (and other master fields) can be checked in the lifecycle resource. Classic clusters don't have this resource and instead call masterHealth directly.

Downstream, the observability terraform provider needs to be able to check masterHealth to confirm the cluster is ready to deploy. So this PR is adding masterHealth to the cluster struct.

bhpratt commented 2 months ago

Current output for ClusterInfo using bluemix-go SDK:

classic cluster:

{
    "createdDate": "2024-04-22T17:21:20+0000",
    "dataCenter": "par01",
    "id": "coj9oqkf0pnpq7q70ap0",
    "location": "par01",
    "entitlement": "",
    "masterKubeVersion": "1.29.3_1531",
    "name": "paris-classic",
    "region": "eu-de",
    "resourceGroup": "a7ea1705c4e9479e8ea48cd4a13d657b",
    "state": "normal",
    "isPaid": true,
    "addons": null,
    "ownerEmail": "",
    "type": "kubernetes",
    "targetVersion": "1.29.3_1531",
    "serviceSubnet": "172.21.0.0/16",
    "resourceGroupName": "default",
    "provider": "",
    "podSubnet": "172.30.0.0/16",
    "multiAzCapable": false,
    "apiUser": "",
    "serverURL": "https://c126.eu-de.containers.cloud.ibm.com:30950",
    "masterURL": "",
    "masterStatus": "Ready",
    "disableAutoUpdate": false,
    "workerZones": [
        "par01"
    ],
    "vpcs": null,
    "crn": "crn:v1:bluemix:public:containers-kubernetes:eu-de:a/9e797f8a8592fed20ae7a775a1cd7e12:coj9oqkf0pnpq7q70ap0::",
    "versionEOS": "",
    "serviceEndpoints": {
        "privateServiceEndpointEnabled": false,
        "privateServiceEndpointURL": "",
        "publicServiceEndpointEnabled": false,
        "publicServiceEndpointURL": ""
    },
    "privateServiceEndpointEnabled": true,
    "privateServiceEndpointURL": "https://c126.private.eu-de.containers.cloud.ibm.com:30950",
    "publicServiceEndpointEnabled": true,
    "publicServiceEndpointURL": "https://c126.eu-de.containers.cloud.ibm.com:30950",
    "lifecycle": {
        "modifiedDate": "",
        "masterStatus": "",
        "masterStatusModifiedDate": "",
        "masterHealth": "",
        "masterState": ""
    },
    "workerCount": 3,
    "ingress": {
        "hostname": "",
        "secretName": ""
    },
    "features": {
        "keyProtectEnabled": false,
        "pullSecretApplied": false
    },
    "imageSecurityEnabled": false,
    "virtualPrivateEndpointURL": ""
}

vpc cluster:

{
    "createdDate": "2024-04-22T17:45:17+0000",
    "dataCenter": "lon04",
    "id": "coja4bpl00pm9c9e856g",
    "location": "London",
    "entitlement": "",
    "masterKubeVersion": "1.29.3_1531",
    "name": "iks-vpc-k8s",
    "region": "eu-gb",
    "resourceGroup": "a7ea1705c4e9479e8ea48cd4a13d657b",
    "state": "normal",
    "isPaid": true,
    "addons": null,
    "ownerEmail": "",
    "type": "kubernetes",
    "targetVersion": "1.29.3_1531",
    "serviceSubnet": "172.21.0.0/16",
    "resourceGroupName": "default",
    "provider": "vpc-gen2",
    "podSubnet": "172.17.0.0/18",
    "multiAzCapable": true,
    "apiUser": "",
    "serverURL": "",
    "masterURL": "https://c102.eu-gb.containers.cloud.ibm.com:31492",
    "masterStatus": "",
    "disableAutoUpdate": false,
    "workerZones": [
        "eu-gb-1"
    ],
    "vpcs": [
        "r018-e4a26dd6-9d46-4f29-b449-a722843fa4e0"
    ],
    "crn": "crn:v1:bluemix:public:containers-kubernetes:eu-gb:a/9e797f8a8592fed20ae7a775a1cd7e12:coja4bpl00pm9c9e856g::",
    "versionEOS": "",
    "serviceEndpoints": {
        "privateServiceEndpointEnabled": true,
        "privateServiceEndpointURL": "https://c102.private.eu-gb.containers.cloud.ibm.com:31492",
        "publicServiceEndpointEnabled": true,
        "publicServiceEndpointURL": "https://c102.eu-gb.containers.cloud.ibm.com:31492"
    },
    "privateServiceEndpointEnabled": false,
    "privateServiceEndpointURL": "",
    "publicServiceEndpointEnabled": false,
    "publicServiceEndpointURL": "",
    "lifecycle": {
        "modifiedDate": "2024-04-22T17:45:58+0000",
        "masterStatus": "Ready",
        "masterStatusModifiedDate": "2024-04-22T17:54:56+0000",
        "masterHealth": "normal",
        "masterState": "deployed"
    },
    "workerCount": 3,
    "ingress": {
        "hostname": "iks-vpc-k8s-d84d4d2137685d8446c88eacf59b5038-0000.eu-gb.containers.appdomain.cloud",
        "secretName": "iks-vpc-k8s-d84d4d2137685d8446c88eacf59b5038-0000"
    },
    "features": {
        "keyProtectEnabled": false,
        "pullSecretApplied": true
    },
    "imageSecurityEnabled": false,
    "virtualPrivateEndpointURL": "https://coja4bpl00pm9c9e856g.vpe.private.eu-gb.containers.cloud.ibm.com:31492"
}
bhpratt commented 2 months ago

after adding masterHealth field:

classic cluster:

{
    "createdDate": "2024-04-22T17:21:20+0000",
    "dataCenter": "par01",
    "id": "coj9oqkf0pnpq7q70ap0",
    "location": "par01",
    "entitlement": "",
    "masterKubeVersion": "1.29.3_1531",
    "name": "paris-classic",
    "region": "eu-de",
    "resourceGroup": "a7ea1705c4e9479e8ea48cd4a13d657b",
    "state": "normal",
    "isPaid": true,
    "addons": null,
    "ownerEmail": "",
    "type": "kubernetes",
    "targetVersion": "1.29.3_1531",
    "serviceSubnet": "172.21.0.0/16",
    "resourceGroupName": "default",
    "provider": "",
    "podSubnet": "172.30.0.0/16",
    "multiAzCapable": false,
    "apiUser": "",
    "serverURL": "https://c126.eu-de.containers.cloud.ibm.com:30950",
    "masterHealth": "normal",
    "masterURL": "",
    "masterStatus": "Ready",
    "disableAutoUpdate": false,
    "workerZones": [
        "par01"
    ],
    "vpcs": null,
    "crn": "crn:v1:bluemix:public:containers-kubernetes:eu-de:a/9e797f8a8592fed20ae7a775a1cd7e12:coj9oqkf0pnpq7q70ap0::",
    "versionEOS": "",
    "serviceEndpoints": {
        "privateServiceEndpointEnabled": false,
        "privateServiceEndpointURL": "",
        "publicServiceEndpointEnabled": false,
        "publicServiceEndpointURL": ""
    },
    "privateServiceEndpointEnabled": true,
    "privateServiceEndpointURL": "https://c126.private.eu-de.containers.cloud.ibm.com:30950",
    "publicServiceEndpointEnabled": true,
    "publicServiceEndpointURL": "https://c126.eu-de.containers.cloud.ibm.com:30950",
    "lifecycle": {
        "modifiedDate": "",
        "masterStatus": "",
        "masterStatusModifiedDate": "",
        "masterHealth": "",
        "masterState": ""
    },
    "workerCount": 3,
    "ingress": {
        "hostname": "",
        "secretName": ""
    },
    "features": {
        "keyProtectEnabled": false,
        "pullSecretApplied": false
    },
    "imageSecurityEnabled": false,
    "virtualPrivateEndpointURL": ""
}

vpc cluster:

{
    "createdDate": "2024-04-22T17:45:17+0000",
    "dataCenter": "lon04",
    "id": "coja4bpl00pm9c9e856g",
    "location": "London",
    "entitlement": "",
    "masterKubeVersion": "1.29.3_1531",
    "name": "iks-vpc-k8s",
    "region": "eu-gb",
    "resourceGroup": "a7ea1705c4e9479e8ea48cd4a13d657b",
    "state": "normal",
    "isPaid": true,
    "addons": null,
    "ownerEmail": "",
    "type": "kubernetes",
    "targetVersion": "1.29.3_1531",
    "serviceSubnet": "172.21.0.0/16",
    "resourceGroupName": "default",
    "provider": "vpc-gen2",
    "podSubnet": "172.17.0.0/18",
    "multiAzCapable": true,
    "apiUser": "",
    "serverURL": "",
    "masterHealth": "",
    "masterURL": "https://c102.eu-gb.containers.cloud.ibm.com:31492",
    "masterStatus": "",
    "disableAutoUpdate": false,
    "workerZones": [
        "eu-gb-1"
    ],
    "vpcs": [
        "r018-e4a26dd6-9d46-4f29-b449-a722843fa4e0"
    ],
    "crn": "crn:v1:bluemix:public:containers-kubernetes:eu-gb:a/9e797f8a8592fed20ae7a775a1cd7e12:coja4bpl00pm9c9e856g::",
    "versionEOS": "",
    "serviceEndpoints": {
        "privateServiceEndpointEnabled": true,
        "privateServiceEndpointURL": "https://c102.private.eu-gb.containers.cloud.ibm.com:31492",
        "publicServiceEndpointEnabled": true,
        "publicServiceEndpointURL": "https://c102.eu-gb.containers.cloud.ibm.com:31492"
    },
    "privateServiceEndpointEnabled": false,
    "privateServiceEndpointURL": "",
    "publicServiceEndpointEnabled": false,
    "publicServiceEndpointURL": "",
    "lifecycle": {
        "modifiedDate": "2024-04-22T17:45:58+0000",
        "masterStatus": "Ready",
        "masterStatusModifiedDate": "2024-04-22T17:54:56+0000",
        "masterHealth": "normal",
        "masterState": "deployed"
    },
    "workerCount": 3,
    "ingress": {
        "hostname": "iks-vpc-k8s-d84d4d2137685d8446c88eacf59b5038-0000.eu-gb.containers.appdomain.cloud",
        "secretName": "iks-vpc-k8s-d84d4d2137685d8446c88eacf59b5038-0000"
    },
    "features": {
        "keyProtectEnabled": false,
        "pullSecretApplied": true
    },
    "imageSecurityEnabled": false,
    "virtualPrivateEndpointURL": "https://coja4bpl00pm9c9e856g.vpe.private.eu-gb.containers.cloud.ibm.com:31492"
}

net effect - adds populated masterHealth field for classic cluster and unpopulated masterHealth field for VPC cluster.

bhpratt commented 2 months ago

After some internal discussion and further review - I've opted not to implement a new function. Instead I've update the struct to include a field that is needed for classic clusters.

bhpratt commented 2 months ago

make test

ok github.com/IBM-Cloud/bluemix-go/api/container/containerv2 1.478s