github.com/IBM-Cloud/bluemix-go@v0.0.0-20240423071914-9e96525baef4/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 is successful, disableOutboundTrafficProtection is set", 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": ""}, "securityGroupIDs": ["cluster"], "disableOutboundTrafficProtection": true}`),
   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{Flavor: "", WorkerCount: 0, VpcID: "", Name: ""},
   335  					HostPoolID:             "hostpoolid",
   336  				}
   337  				params := ClusterCreateRequest{
   338  					DisablePublicServiceEndpoint: false, KubeVersion: "", PodSubnet: "podnet", Provider: "abc", ServiceSubnet: "svcnet", Name: "abcd", WorkerPools: WPools, CosInstanceCRN: "", SecurityGroupIDs: []string{"cluster"}, DisableOutboundTrafficProtection: true,
   339  				}
   340  				target := ClusterTargetHeader{}
   341  				myCluster, err := newCluster(server.URL()).Create(params, target)
   342  				Expect(err).NotTo(HaveOccurred())
   343  				Expect(myCluster).ShouldNot(BeNil())
   344  				Expect(myCluster.ID).Should(Equal("f91adfe2-76c9-4649-939e-b01c37a3704c"))
   345  			})
   346  		})
   347  		Context("When creation with OS is successful", func() {
   348  			BeforeEach(func() {
   349  				server = ghttp.NewServer()
   350  				server.AppendHandlers(
   351  					ghttp.CombineHandlers(
   352  						ghttp.VerifyRequest(http.MethodPost, "/v2/vpc/createCluster"),
   353  						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"]}`),
   354  						ghttp.RespondWith(http.StatusCreated, `{
   355  							 "clusterID": "f91adfe2-76c9-4649-939e-b01c37a3704c"
   356  						}`),
   357  					),
   358  				)
   359  			})
   360  
   361  			It("should return cluster created", func() {
   362  				WPools := WorkerPoolConfig{
   363  					CommonWorkerPoolConfig: CommonWorkerPoolConfig{
   364  						Flavor:          "",
   365  						WorkerCount:     0,
   366  						VpcID:           "",
   367  						Name:            "",
   368  						OperatingSystem: "REDHAT_7_64",
   369  					},
   370  					HostPoolID: "hostpoolid",
   371  				}
   372  				params := ClusterCreateRequest{
   373  					DisablePublicServiceEndpoint: false, KubeVersion: "", PodSubnet: "podnet", Provider: "abc", ServiceSubnet: "svcnet", Name: "abcd", WorkerPools: WPools, CosInstanceCRN: "", SecurityGroupIDs: []string{"cluster"},
   374  				}
   375  				target := ClusterTargetHeader{}
   376  				myCluster, err := newCluster(server.URL()).Create(params, target)
   377  				Expect(err).NotTo(HaveOccurred())
   378  				Expect(myCluster).ShouldNot(BeNil())
   379  				Expect(myCluster.ID).Should(Equal("f91adfe2-76c9-4649-939e-b01c37a3704c"))
   380  			})
   381  		})
   382  		Context("When creation with SecondaryStorageOption is successful", func() {
   383  			BeforeEach(func() {
   384  				server = ghttp.NewServer()
   385  				server.AppendHandlers(
   386  					ghttp.CombineHandlers(
   387  						ghttp.VerifyRequest(http.MethodPost, "/v2/vpc/createCluster"),
   388  						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"]}`),
   389  						ghttp.RespondWith(http.StatusCreated, `{
   390  							 "clusterID": "f91adfe2-76c9-4649-939e-b01c37a3704c"
   391  						}`),
   392  					),
   393  				)
   394  			})
   395  
   396  			It("should return cluster created", func() {
   397  				WPools := WorkerPoolConfig{
   398  					CommonWorkerPoolConfig: CommonWorkerPoolConfig{
   399  						Flavor:                 "",
   400  						WorkerCount:            0,
   401  						VpcID:                  "",
   402  						Name:                   "",
   403  						SecondaryStorageOption: "secondarystoragename1",
   404  					},
   405  					HostPoolID: "hostpoolid",
   406  				}
   407  				params := ClusterCreateRequest{
   408  					DisablePublicServiceEndpoint: false, KubeVersion: "", PodSubnet: "podnet", Provider: "abc", ServiceSubnet: "svcnet", Name: "abcd", WorkerPools: WPools, CosInstanceCRN: "", SecurityGroupIDs: []string{"cluster"},
   409  				}
   410  				target := ClusterTargetHeader{}
   411  				myCluster, err := newCluster(server.URL()).Create(params, target)
   412  				Expect(err).NotTo(HaveOccurred())
   413  				Expect(myCluster).ShouldNot(BeNil())
   414  				Expect(myCluster.ID).Should(Equal("f91adfe2-76c9-4649-939e-b01c37a3704c"))
   415  			})
   416  		})
   417  
   418  		Context("When creation is unsuccessful", func() {
   419  			BeforeEach(func() {
   420  				server = ghttp.NewServer()
   421  				server.SetAllowUnhandledRequests(true)
   422  				server.AppendHandlers(
   423  					ghttp.CombineHandlers(
   424  						ghttp.VerifyRequest(http.MethodPost, "/v2/vpc/createCluster"),
   425  						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"]}`),
   426  						ghttp.RespondWith(http.StatusInternalServerError, `Failed to create cluster`),
   427  					),
   428  				)
   429  			})
   430  			It("should return error during cluster creation", func() {
   431  				WPools := WorkerPoolConfig{
   432  					CommonWorkerPoolConfig: CommonWorkerPoolConfig{Flavor: "", WorkerCount: 0, VpcID: "", Name: "", Entitlement: ""},
   433  				}
   434  				params := ClusterCreateRequest{
   435  					DisablePublicServiceEndpoint: false, KubeVersion: "", PodSubnet: "podnet", Provider: "abc", ServiceSubnet: "svcnet", Name: "abcd", WorkerPools: WPools, DefaultWorkerPoolEntitlement: "", CosInstanceCRN: "", SecurityGroupIDs: []string{"cluster"},
   436  				}
   437  				target := ClusterTargetHeader{}
   438  				myCluster, err := newCluster(server.URL()).Create(params, target)
   439  				Expect(err).To(HaveOccurred())
   440  				Expect(myCluster.ID).Should(Equal(""))
   441  			})
   442  		})
   443  		Context("When creating with kms enabled", 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"}}, "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"}
   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  		Context("When creating with kms provided from different acount", func() {
   502  			BeforeEach(func() {
   503  				server = ghttp.NewServer()
   504  				server.AppendHandlers(
   505  					ghttp.CombineHandlers(
   506  						ghttp.VerifyRequest(http.MethodPost, "/v2/vpc/createCluster"),
   507  						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"]}`),
   508  						ghttp.RespondWith(http.StatusCreated, `{
   509  							 "clusterID": "f91adfe2-76c9-4649-939e-b01c37a3704c"
   510  						}`),
   511  					),
   512  				)
   513  			})
   514  
   515  			It("should return cluster created", func() {
   516  				WVE := WorkerVolumeEncryption{KmsInstanceID: "kmsid", WorkerVolumeCRKID: "rootkeyid", KMSAccountID: "OtherAccountID"}
   517  				WPools := WorkerPoolConfig{
   518  					CommonWorkerPoolConfig: CommonWorkerPoolConfig{Flavor: "", WorkerCount: 0, VpcID: "", Name: "", WorkerVolumeEncryption: &WVE},
   519  				}
   520  				params := ClusterCreateRequest{
   521  					DisablePublicServiceEndpoint: false, KubeVersion: "", PodSubnet: "podnet", Provider: "abc", ServiceSubnet: "svcnet", Name: "abcd", WorkerPools: WPools, CosInstanceCRN: "", SecurityGroupIDs: []string{"cluster"},
   522  				}
   523  				target := ClusterTargetHeader{}
   524  				myCluster, err := newCluster(server.URL()).Create(params, target)
   525  				Expect(err).NotTo(HaveOccurred())
   526  				Expect(myCluster).ShouldNot(BeNil())
   527  				Expect(myCluster.ID).Should(Equal("f91adfe2-76c9-4649-939e-b01c37a3704c"))
   528  			})
   529  		})
   530  	})
   531  })
   532  
   533  func newCluster(url string) Clusters {
   534  
   535  	sess, err := session.New()
   536  	if err != nil {
   537  		log.Fatal(err)
   538  	}
   539  	conf := sess.Config.Copy()
   540  	conf.HTTPClient = bluemixHttp.NewHTTPClient(conf)
   541  	conf.Endpoint = &url
   542  
   543  	client := client.Client{
   544  		Config:      conf,
   545  		ServiceName: bluemix.VpcContainerService,
   546  	}
   547  	return newClusterAPI(&client)
   548  }