github.com/IBM-Cloud/bluemix-go@v0.0.0-20240314082800-4e02a69b84b2/api/container/containerv2/clusters_test.go (about) 1 package containerv2 2 3 import ( 4 "log" 5 "net/http" 6 7 bluemix "github.com/IBM-Cloud/bluemix-go" 8 "github.com/IBM-Cloud/bluemix-go/client" 9 bluemixHttp "github.com/IBM-Cloud/bluemix-go/http" 10 "github.com/IBM-Cloud/bluemix-go/session" 11 12 "github.com/onsi/gomega/ghttp" 13 14 . "github.com/onsi/ginkgo" 15 . "github.com/onsi/gomega" 16 ) 17 18 var _ = Describe("Clusters", func() { 19 var server *ghttp.Server 20 AfterEach(func() { 21 server.Close() 22 }) 23 24 //List 25 Describe("List", func() { 26 Context("When read of clusters is successful", func() { 27 BeforeEach(func() { 28 server = ghttp.NewServer() 29 server.AppendHandlers( 30 ghttp.CombineHandlers( 31 ghttp.VerifyRequest(http.MethodGet, ContainSubstring("/v2/vpc/getClusters")), 32 ghttp.RespondWith(http.StatusOK, `[{ 33 "CreatedDate": "", 34 "DataCenter": "dal10", 35 "Entitlement": "", 36 "ID": "f91adfe2-76c9-4649-939e-b01c37a3704", 37 "IngressHostname": "", 38 "IngressSecretName": "", 39 "Location": "", 40 "MasterKubeVersion": "1.8.1", 41 "Prefix": "worker", 42 "ModifiedDate": "", 43 "Name": "test", 44 "Region": "abc", 45 "ServerURL": "", 46 "State": "normal", 47 "IsPaid": false, 48 "IsTrusted": true, 49 "WorkerCount": 1 50 }]`), 51 ), 52 53 ghttp.CombineHandlers( 54 ghttp.VerifyRequest(http.MethodGet, ContainSubstring("/v2/satellite/getClusters")), 55 ghttp.RespondWith(http.StatusOK, `[{ 56 "CreatedDate": "", 57 "DataCenter": "dal10", 58 "Entitlement": "", 59 "ID": "d91adfe2-76c9-4649-939e-b01c37a3704", 60 "IngressHostname": "", 61 "IngressSecretName": "", 62 "Location": "", 63 "MasterKubeVersion": "1.8.1", 64 "Prefix": "worker", 65 "ModifiedDate": "", 66 "Name": "test", 67 "Region": "abc", 68 "ServerURL": "", 69 "State": "normal", 70 "IsPaid": false, 71 "IsTrusted": true, 72 "WorkerCount": 1 73 }]`), 74 ), 75 ) 76 }) 77 78 It("should return cluster list", func() { 79 target := ClusterTargetHeader{} 80 myCluster, err := newCluster(server.URL()).List(target) 81 Expect(myCluster).ShouldNot(BeNil()) 82 Expect(err).NotTo(HaveOccurred()) 83 Expect(len(myCluster)).Should(Equal(2)) 84 Expect(myCluster[0].ID).Should(Equal("f91adfe2-76c9-4649-939e-b01c37a3704")) 85 Expect(myCluster[0].WorkerCount).Should(Equal(1)) 86 Expect(myCluster[0].MasterKubeVersion).Should(Equal("1.8.1")) 87 Expect(myCluster[1].ID).Should(Equal("d91adfe2-76c9-4649-939e-b01c37a3704")) 88 Expect(myCluster[1].WorkerCount).Should(Equal(1)) 89 Expect(myCluster[1].MasterKubeVersion).Should(Equal("1.8.1")) 90 }) 91 }) 92 93 Context("When provider is satellite", func() { 94 BeforeEach(func() { 95 server = ghttp.NewServer() 96 server.AppendHandlers( 97 ghttp.CombineHandlers( 98 ghttp.VerifyRequest(http.MethodGet, ContainSubstring("/v2/satellite/getClusters")), 99 ghttp.RespondWith(http.StatusOK, `[{ 100 "CreatedDate": "", 101 "DataCenter": "dal10", 102 "Entitlement": "", 103 "ID": "d91adfe2-76c9-4649-939e-b01c37a3704", 104 "IngressHostname": "", 105 "IngressSecretName": "", 106 "Location": "", 107 "MasterKubeVersion": "1.8.1", 108 "Prefix": "worker", 109 "ModifiedDate": "", 110 "Name": "test-satellite", 111 "Region": "abc", 112 "ServerURL": "", 113 "State": "normal", 114 "IsPaid": false, 115 "IsTrusted": true, 116 "WorkerCount": 1 117 }]`), 118 ), 119 ) 120 }) 121 122 It("should return only satellite cluster list", func() { 123 target := ClusterTargetHeader{} 124 target.Provider = "satellite" 125 myCluster, err := newCluster(server.URL()).List(target) 126 Expect(myCluster).ShouldNot(BeNil()) 127 Expect(err).NotTo(HaveOccurred()) 128 Expect(len(myCluster)).Should(Equal(1)) 129 Expect(myCluster[0].ID).Should(Equal("d91adfe2-76c9-4649-939e-b01c37a3704")) 130 Expect(myCluster[0].Name).Should(Equal("test-satellite")) 131 Expect(myCluster[0].WorkerCount).Should(Equal(1)) 132 Expect(myCluster[0].MasterKubeVersion).Should(Equal("1.8.1")) 133 }) 134 }) 135 136 Context("When provider is vpc-classic", func() { 137 BeforeEach(func() { 138 server = ghttp.NewServer() 139 server.AppendHandlers( 140 ghttp.CombineHandlers( 141 ghttp.VerifyRequest(http.MethodGet, "/v2/vpc/getClusters", "provider=vpc-classic"), 142 ghttp.RespondWith(http.StatusOK, `[{ 143 "CreatedDate": "", 144 "DataCenter": "dal10", 145 "Entitlement": "", 146 "ID": "c91adfe2-76c9-4649-939e-b01c37a3704", 147 "IngressHostname": "", 148 "IngressSecretName": "", 149 "Location": "", 150 "MasterKubeVersion": "1.8.1", 151 "Prefix": "worker", 152 "ModifiedDate": "", 153 "Name": "test-vpc-classic", 154 "Region": "abc", 155 "ServerURL": "", 156 "State": "normal", 157 "IsPaid": false, 158 "IsTrusted": true, 159 "WorkerCount": 1 160 }]`), 161 ), 162 ) 163 }) 164 165 It("should return only vpc-classic cluster list", func() { 166 target := ClusterTargetHeader{} 167 target.Provider = "vpc-classic" 168 myCluster, err := newCluster(server.URL()).List(target) 169 Expect(myCluster).ShouldNot(BeNil()) 170 Expect(err).NotTo(HaveOccurred()) 171 Expect(len(myCluster)).Should(Equal(1)) 172 Expect(myCluster[0].ID).Should(Equal("c91adfe2-76c9-4649-939e-b01c37a3704")) 173 Expect(myCluster[0].Name).Should(Equal("test-vpc-classic")) 174 Expect(myCluster[0].WorkerCount).Should(Equal(1)) 175 Expect(myCluster[0].MasterKubeVersion).Should(Equal("1.8.1")) 176 }) 177 }) 178 Context("When read of clusters is unsuccessful", func() { 179 BeforeEach(func() { 180 181 server = ghttp.NewServer() 182 server.SetAllowUnhandledRequests(true) 183 server.AppendHandlers( 184 ghttp.CombineHandlers( 185 ghttp.VerifyRequest(http.MethodGet, ContainSubstring("/v2/")), 186 ghttp.RespondWith(http.StatusInternalServerError, `Failed to retrieve clusters`), 187 ), 188 ) 189 }) 190 191 It("should return error when cluster are retrieved", func() { 192 target := ClusterTargetHeader{} 193 myCluster, err := newCluster(server.URL()).List(target) 194 Expect(err).To(HaveOccurred()) 195 Expect(myCluster).Should(BeNil()) 196 }) 197 }) 198 }) 199 200 //Create 201 Describe("Create", func() { 202 Context("When creation is successful", func() { 203 BeforeEach(func() { 204 server = ghttp.NewServer() 205 server.AppendHandlers( 206 ghttp.CombineHandlers( 207 ghttp.VerifyRequest(http.MethodPost, "/v2/vpc/createCluster"), 208 ghttp.VerifyJSON(`{"disablePublicServiceEndpoint": false, "defaultWorkerPoolEntitlement": "", "kubeVersion": "", "podSubnet": "podnet", "provider": "abc", "serviceSubnet": "svcnet", "name": "abcd", "cosInstanceCRN": "", "workerPool": {"flavor": "", "hostPoolID": "hostpoolid", "name": "", "vpcID": "", "workerCount": 0, "zones": null, "entitlement": ""}, "securityGroupIDs": ["cluster"]}`), 209 ghttp.RespondWith(http.StatusCreated, `{ 210 "clusterID": "f91adfe2-76c9-4649-939e-b01c37a3704c" 211 }`), 212 ), 213 ) 214 }) 215 216 It("should return cluster created", func() { 217 WPools := WorkerPoolConfig{ 218 CommonWorkerPoolConfig: CommonWorkerPoolConfig{Flavor: "", WorkerCount: 0, VpcID: "", Name: ""}, 219 HostPoolID: "hostpoolid", 220 } 221 params := ClusterCreateRequest{ 222 DisablePublicServiceEndpoint: false, KubeVersion: "", PodSubnet: "podnet", Provider: "abc", ServiceSubnet: "svcnet", Name: "abcd", WorkerPools: WPools, CosInstanceCRN: "", SecurityGroupIDs: []string{"cluster"}, 223 } 224 target := ClusterTargetHeader{} 225 myCluster, err := newCluster(server.URL()).Create(params, target) 226 Expect(err).NotTo(HaveOccurred()) 227 Expect(myCluster).ShouldNot(BeNil()) 228 Expect(myCluster.ID).Should(Equal("f91adfe2-76c9-4649-939e-b01c37a3704c")) 229 }) 230 }) 231 Context("When creation is successful, securityGroupIDs set with multiple values", func() { 232 BeforeEach(func() { 233 server = ghttp.NewServer() 234 server.AppendHandlers( 235 ghttp.CombineHandlers( 236 ghttp.VerifyRequest(http.MethodPost, "/v2/vpc/createCluster"), 237 ghttp.VerifyJSON(`{"disablePublicServiceEndpoint": false, "defaultWorkerPoolEntitlement": "", "kubeVersion": "", "podSubnet": "podnet", "provider": "abc", "serviceSubnet": "svcnet", "name": "abcd", "cosInstanceCRN": "", "workerPool": {"flavor": "", "hostPoolID": "hostpoolid", "name": "", "vpcID": "", "workerCount": 0, "zones": null, "entitlement": ""}, "securityGroupIDs": ["cluster", "r134-ee951766-31e7-4fdb-bde8-0f08315b0cc6", "r134-dab9930e-cf2d-46d5-9808-9e52955f15f2", "r134-4f29f2fb-979d-451b-bac7-1e6c773e63d7"]}`), 238 ghttp.RespondWith(http.StatusCreated, `{ 239 "clusterID": "f91adfe2-76c9-4649-939e-b01c37a3704c" 240 }`), 241 ), 242 ) 243 }) 244 245 It("should return cluster created", func() { 246 WPools := WorkerPoolConfig{ 247 CommonWorkerPoolConfig: CommonWorkerPoolConfig{Flavor: "", WorkerCount: 0, VpcID: "", Name: ""}, 248 HostPoolID: "hostpoolid", 249 } 250 params := ClusterCreateRequest{ 251 DisablePublicServiceEndpoint: false, KubeVersion: "", PodSubnet: "podnet", Provider: "abc", ServiceSubnet: "svcnet", Name: "abcd", WorkerPools: WPools, CosInstanceCRN: "", SecurityGroupIDs: []string{"cluster", "r134-ee951766-31e7-4fdb-bde8-0f08315b0cc6", "r134-dab9930e-cf2d-46d5-9808-9e52955f15f2", "r134-4f29f2fb-979d-451b-bac7-1e6c773e63d7"}, 252 } 253 target := ClusterTargetHeader{} 254 myCluster, err := newCluster(server.URL()).Create(params, target) 255 Expect(err).NotTo(HaveOccurred()) 256 Expect(myCluster).ShouldNot(BeNil()) 257 Expect(myCluster.ID).Should(Equal("f91adfe2-76c9-4649-939e-b01c37a3704c")) 258 }) 259 }) 260 Context("When creation is successful, securityGroupIDs set to null", func() { 261 BeforeEach(func() { 262 server = ghttp.NewServer() 263 server.AppendHandlers( 264 ghttp.CombineHandlers( 265 ghttp.VerifyRequest(http.MethodPost, "/v2/vpc/createCluster"), 266 ghttp.VerifyJSON(`{"disablePublicServiceEndpoint": false, "defaultWorkerPoolEntitlement": "", "kubeVersion": "", "podSubnet": "podnet", "provider": "abc", "serviceSubnet": "svcnet", "name": "abcd", "cosInstanceCRN": "", "workerPool": {"flavor": "", "hostPoolID": "hostpoolid", "name": "", "vpcID": "", "workerCount": 0, "zones": null, "entitlement": ""}}`), 267 ghttp.RespondWith(http.StatusCreated, `{ 268 "clusterID": "f91adfe2-76c9-4649-939e-b01c37a3704c" 269 }`), 270 ), 271 ) 272 }) 273 274 It("should return cluster created", func() { 275 WPools := WorkerPoolConfig{ 276 CommonWorkerPoolConfig: CommonWorkerPoolConfig{Flavor: "", WorkerCount: 0, VpcID: "", Name: ""}, 277 HostPoolID: "hostpoolid", 278 } 279 params := ClusterCreateRequest{ 280 DisablePublicServiceEndpoint: false, KubeVersion: "", PodSubnet: "podnet", Provider: "abc", ServiceSubnet: "svcnet", Name: "abcd", WorkerPools: WPools, CosInstanceCRN: "", SecurityGroupIDs: nil, 281 } 282 target := ClusterTargetHeader{} 283 myCluster, err := newCluster(server.URL()).Create(params, target) 284 Expect(err).NotTo(HaveOccurred()) 285 Expect(myCluster).ShouldNot(BeNil()) 286 Expect(myCluster.ID).Should(Equal("f91adfe2-76c9-4649-939e-b01c37a3704c")) 287 }) 288 }) 289 Context("When creation is successful, securityGroupIDs is empty", func() { 290 BeforeEach(func() { 291 server = ghttp.NewServer() 292 server.AppendHandlers( 293 ghttp.CombineHandlers( 294 ghttp.VerifyRequest(http.MethodPost, "/v2/vpc/createCluster"), 295 ghttp.VerifyJSON(`{"disablePublicServiceEndpoint": false, "defaultWorkerPoolEntitlement": "", "kubeVersion": "", "podSubnet": "podnet", "provider": "abc", "serviceSubnet": "svcnet", "name": "abcd", "cosInstanceCRN": "", "workerPool": {"flavor": "", "hostPoolID": "hostpoolid", "name": "", "vpcID": "", "workerCount": 0, "zones": null, "entitlement": ""}}`), 296 ghttp.RespondWith(http.StatusCreated, `{ 297 "clusterID": "f91adfe2-76c9-4649-939e-b01c37a3704c" 298 }`), 299 ), 300 ) 301 }) 302 303 It("should return cluster created", func() { 304 WPools := WorkerPoolConfig{ 305 CommonWorkerPoolConfig: CommonWorkerPoolConfig{Flavor: "", WorkerCount: 0, VpcID: "", Name: ""}, 306 HostPoolID: "hostpoolid", 307 } 308 params := ClusterCreateRequest{ 309 DisablePublicServiceEndpoint: false, KubeVersion: "", PodSubnet: "podnet", Provider: "abc", ServiceSubnet: "svcnet", Name: "abcd", WorkerPools: WPools, CosInstanceCRN: "", SecurityGroupIDs: []string{}, 310 } 311 target := ClusterTargetHeader{} 312 myCluster, err := newCluster(server.URL()).Create(params, target) 313 Expect(err).NotTo(HaveOccurred()) 314 Expect(myCluster).ShouldNot(BeNil()) 315 Expect(myCluster.ID).Should(Equal("f91adfe2-76c9-4649-939e-b01c37a3704c")) 316 }) 317 }) 318 Context("When creation with OS is successful", func() { 319 BeforeEach(func() { 320 server = ghttp.NewServer() 321 server.AppendHandlers( 322 ghttp.CombineHandlers( 323 ghttp.VerifyRequest(http.MethodPost, "/v2/vpc/createCluster"), 324 ghttp.VerifyJSON(`{"disablePublicServiceEndpoint": false, "defaultWorkerPoolEntitlement": "", "kubeVersion": "", "podSubnet": "podnet", "provider": "abc", "serviceSubnet": "svcnet", "name": "abcd", "cosInstanceCRN": "", "workerPool": {"flavor": "", "hostPoolID": "hostpoolid", "name": "", "vpcID": "", "workerCount": 0, "zones": null, "entitlement": "", "operatingSystem":"REDHAT_7_64"}, "securityGroupIDs": ["cluster"]}`), 325 ghttp.RespondWith(http.StatusCreated, `{ 326 "clusterID": "f91adfe2-76c9-4649-939e-b01c37a3704c" 327 }`), 328 ), 329 ) 330 }) 331 332 It("should return cluster created", func() { 333 WPools := WorkerPoolConfig{ 334 CommonWorkerPoolConfig: CommonWorkerPoolConfig{ 335 Flavor: "", 336 WorkerCount: 0, 337 VpcID: "", 338 Name: "", 339 OperatingSystem: "REDHAT_7_64", 340 }, 341 HostPoolID: "hostpoolid", 342 } 343 params := ClusterCreateRequest{ 344 DisablePublicServiceEndpoint: false, KubeVersion: "", PodSubnet: "podnet", Provider: "abc", ServiceSubnet: "svcnet", Name: "abcd", WorkerPools: WPools, CosInstanceCRN: "", SecurityGroupIDs: []string{"cluster"}, 345 } 346 target := ClusterTargetHeader{} 347 myCluster, err := newCluster(server.URL()).Create(params, target) 348 Expect(err).NotTo(HaveOccurred()) 349 Expect(myCluster).ShouldNot(BeNil()) 350 Expect(myCluster.ID).Should(Equal("f91adfe2-76c9-4649-939e-b01c37a3704c")) 351 }) 352 }) 353 Context("When creation with SecondaryStorageOption is successful", func() { 354 BeforeEach(func() { 355 server = ghttp.NewServer() 356 server.AppendHandlers( 357 ghttp.CombineHandlers( 358 ghttp.VerifyRequest(http.MethodPost, "/v2/vpc/createCluster"), 359 ghttp.VerifyJSON(`{"disablePublicServiceEndpoint": false, "defaultWorkerPoolEntitlement": "", "kubeVersion": "", "podSubnet": "podnet", "provider": "abc", "serviceSubnet": "svcnet", "name": "abcd", "cosInstanceCRN": "", "workerPool": {"flavor": "", "hostPoolID": "hostpoolid", "name": "", "vpcID": "", "workerCount": 0, "zones": null, "entitlement": "", "secondaryStorageOption": "secondarystoragename1"}, "securityGroupIDs": ["cluster"]}`), 360 ghttp.RespondWith(http.StatusCreated, `{ 361 "clusterID": "f91adfe2-76c9-4649-939e-b01c37a3704c" 362 }`), 363 ), 364 ) 365 }) 366 367 It("should return cluster created", func() { 368 WPools := WorkerPoolConfig{ 369 CommonWorkerPoolConfig: CommonWorkerPoolConfig{ 370 Flavor: "", 371 WorkerCount: 0, 372 VpcID: "", 373 Name: "", 374 SecondaryStorageOption: "secondarystoragename1", 375 }, 376 HostPoolID: "hostpoolid", 377 } 378 params := ClusterCreateRequest{ 379 DisablePublicServiceEndpoint: false, KubeVersion: "", PodSubnet: "podnet", Provider: "abc", ServiceSubnet: "svcnet", Name: "abcd", WorkerPools: WPools, CosInstanceCRN: "", SecurityGroupIDs: []string{"cluster"}, 380 } 381 target := ClusterTargetHeader{} 382 myCluster, err := newCluster(server.URL()).Create(params, target) 383 Expect(err).NotTo(HaveOccurred()) 384 Expect(myCluster).ShouldNot(BeNil()) 385 Expect(myCluster.ID).Should(Equal("f91adfe2-76c9-4649-939e-b01c37a3704c")) 386 }) 387 }) 388 389 Context("When creation is unsuccessful", func() { 390 BeforeEach(func() { 391 server = ghttp.NewServer() 392 server.SetAllowUnhandledRequests(true) 393 server.AppendHandlers( 394 ghttp.CombineHandlers( 395 ghttp.VerifyRequest(http.MethodPost, "/v2/vpc/createCluster"), 396 ghttp.VerifyJSON(`{"disablePublicServiceEndpoint": false, "defaultWorkerPoolEntitlement": "", "kubeVersion": "", "podSubnet": "podnet", "provider": "abc", "serviceSubnet": "svcnet", "name": "abcd", "cosInstanceCRN": "", "workerPool": {"flavor": "", "name": "", "vpcID": "", "workerCount": 0, "zones": null, "entitlement": ""}, "securityGroupIDs": ["cluster"]}`), 397 ghttp.RespondWith(http.StatusInternalServerError, `Failed to create cluster`), 398 ), 399 ) 400 }) 401 It("should return error during cluster creation", func() { 402 WPools := WorkerPoolConfig{ 403 CommonWorkerPoolConfig: CommonWorkerPoolConfig{Flavor: "", WorkerCount: 0, VpcID: "", Name: "", Entitlement: ""}, 404 } 405 params := ClusterCreateRequest{ 406 DisablePublicServiceEndpoint: false, KubeVersion: "", PodSubnet: "podnet", Provider: "abc", ServiceSubnet: "svcnet", Name: "abcd", WorkerPools: WPools, DefaultWorkerPoolEntitlement: "", CosInstanceCRN: "", SecurityGroupIDs: []string{"cluster"}, 407 } 408 target := ClusterTargetHeader{} 409 myCluster, err := newCluster(server.URL()).Create(params, target) 410 Expect(err).To(HaveOccurred()) 411 Expect(myCluster.ID).Should(Equal("")) 412 }) 413 }) 414 Context("When creating with kms enabled", func() { 415 BeforeEach(func() { 416 server = ghttp.NewServer() 417 server.AppendHandlers( 418 ghttp.CombineHandlers( 419 ghttp.VerifyRequest(http.MethodPost, "/v2/vpc/createCluster"), 420 ghttp.VerifyJSON(`{"disablePublicServiceEndpoint": false, "defaultWorkerPoolEntitlement": "", "kubeVersion": "", "podSubnet": "podnet", "provider": "abc", "serviceSubnet": "svcnet", "name": "abcd", "cosInstanceCRN": "", "workerPool": {"flavor": "", "name": "", "vpcID": "", "workerCount": 0, "zones": null, "entitlement": "", "workerVolumeEncryption": {"kmsInstanceID": "kmsid", "workerVolumeCRKID": "rootkeyid"}}, "securityGroupIDs": ["cluster"]}`), 421 ghttp.RespondWith(http.StatusCreated, `{ 422 "clusterID": "f91adfe2-76c9-4649-939e-b01c37a3704c" 423 }`), 424 ), 425 ) 426 }) 427 428 It("should return cluster created", func() { 429 WVE := WorkerVolumeEncryption{KmsInstanceID: "kmsid", WorkerVolumeCRKID: "rootkeyid"} 430 WPools := WorkerPoolConfig{ 431 CommonWorkerPoolConfig: CommonWorkerPoolConfig{Flavor: "", WorkerCount: 0, VpcID: "", Name: "", WorkerVolumeEncryption: &WVE}, 432 } 433 params := ClusterCreateRequest{ 434 DisablePublicServiceEndpoint: false, KubeVersion: "", PodSubnet: "podnet", Provider: "abc", ServiceSubnet: "svcnet", Name: "abcd", WorkerPools: WPools, CosInstanceCRN: "", SecurityGroupIDs: []string{"cluster"}, 435 } 436 target := ClusterTargetHeader{} 437 myCluster, err := newCluster(server.URL()).Create(params, target) 438 Expect(err).NotTo(HaveOccurred()) 439 Expect(myCluster).ShouldNot(BeNil()) 440 Expect(myCluster.ID).Should(Equal("f91adfe2-76c9-4649-939e-b01c37a3704c")) 441 }) 442 }) 443 Context("When creating with kms provided from different acount", func() { 444 BeforeEach(func() { 445 server = ghttp.NewServer() 446 server.AppendHandlers( 447 ghttp.CombineHandlers( 448 ghttp.VerifyRequest(http.MethodPost, "/v2/vpc/createCluster"), 449 ghttp.VerifyJSON(`{"disablePublicServiceEndpoint": false, "defaultWorkerPoolEntitlement": "", "kubeVersion": "", "podSubnet": "podnet", "provider": "abc", "serviceSubnet": "svcnet", "name": "abcd", "cosInstanceCRN": "", "workerPool": {"flavor": "", "name": "", "vpcID": "", "workerCount": 0, "zones": null, "entitlement": "", "workerVolumeEncryption": {"kmsInstanceID": "kmsid", "workerVolumeCRKID": "rootkeyid", "kmsAccountID":"OtherAccountID"}}, "securityGroupIDs": ["cluster"]}`), 450 ghttp.RespondWith(http.StatusCreated, `{ 451 "clusterID": "f91adfe2-76c9-4649-939e-b01c37a3704c" 452 }`), 453 ), 454 ) 455 }) 456 457 It("should return cluster created", func() { 458 WVE := WorkerVolumeEncryption{KmsInstanceID: "kmsid", WorkerVolumeCRKID: "rootkeyid", KMSAccountID: "OtherAccountID"} 459 WPools := WorkerPoolConfig{ 460 CommonWorkerPoolConfig: CommonWorkerPoolConfig{Flavor: "", WorkerCount: 0, VpcID: "", Name: "", WorkerVolumeEncryption: &WVE}, 461 } 462 params := ClusterCreateRequest{ 463 DisablePublicServiceEndpoint: false, KubeVersion: "", PodSubnet: "podnet", Provider: "abc", ServiceSubnet: "svcnet", Name: "abcd", WorkerPools: WPools, CosInstanceCRN: "", SecurityGroupIDs: []string{"cluster"}, 464 } 465 target := ClusterTargetHeader{} 466 myCluster, err := newCluster(server.URL()).Create(params, target) 467 Expect(err).NotTo(HaveOccurred()) 468 Expect(myCluster).ShouldNot(BeNil()) 469 Expect(myCluster.ID).Should(Equal("f91adfe2-76c9-4649-939e-b01c37a3704c")) 470 }) 471 }) 472 Context("When creating with kms provided from different acount", func() { 473 BeforeEach(func() { 474 server = ghttp.NewServer() 475 server.AppendHandlers( 476 ghttp.CombineHandlers( 477 ghttp.VerifyRequest(http.MethodPost, "/v2/vpc/createCluster"), 478 ghttp.VerifyJSON(`{"disablePublicServiceEndpoint": false, "defaultWorkerPoolEntitlement": "", "kubeVersion": "", "podSubnet": "podnet", "provider": "abc", "serviceSubnet": "svcnet", "name": "abcd", "cosInstanceCRN": "", "workerPool": {"flavor": "", "name": "", "vpcID": "", "workerCount": 0, "zones": null, "entitlement": "", "workerVolumeEncryption": {"kmsInstanceID": "kmsid", "workerVolumeCRKID": "rootkeyid", "kmsAccountID":"OtherAccountID"}}, "securityGroupIDs": ["cluster"]}`), 479 ghttp.RespondWith(http.StatusCreated, `{ 480 "clusterID": "f91adfe2-76c9-4649-939e-b01c37a3704c" 481 }`), 482 ), 483 ) 484 }) 485 486 It("should return cluster created", func() { 487 WVE := WorkerVolumeEncryption{KmsInstanceID: "kmsid", WorkerVolumeCRKID: "rootkeyid", KMSAccountID: "OtherAccountID"} 488 WPools := WorkerPoolConfig{ 489 CommonWorkerPoolConfig: CommonWorkerPoolConfig{Flavor: "", WorkerCount: 0, VpcID: "", Name: "", WorkerVolumeEncryption: &WVE}, 490 } 491 params := ClusterCreateRequest{ 492 DisablePublicServiceEndpoint: false, KubeVersion: "", PodSubnet: "podnet", Provider: "abc", ServiceSubnet: "svcnet", Name: "abcd", WorkerPools: WPools, CosInstanceCRN: "", SecurityGroupIDs: []string{"cluster"}, 493 } 494 target := ClusterTargetHeader{} 495 myCluster, err := newCluster(server.URL()).Create(params, target) 496 Expect(err).NotTo(HaveOccurred()) 497 Expect(myCluster).ShouldNot(BeNil()) 498 Expect(myCluster.ID).Should(Equal("f91adfe2-76c9-4649-939e-b01c37a3704c")) 499 }) 500 }) 501 }) 502 }) 503 504 func newCluster(url string) Clusters { 505 506 sess, err := session.New() 507 if err != nil { 508 log.Fatal(err) 509 } 510 conf := sess.Config.Copy() 511 conf.HTTPClient = bluemixHttp.NewHTTPClient(conf) 512 conf.Endpoint = &url 513 514 client := client.Client{ 515 Config: conf, 516 ServiceName: bluemix.VpcContainerService, 517 } 518 return newClusterAPI(&client) 519 }