github.com/IBM-Blockchain/fabric-operator@v1.0.4/integration/console/console_test.go (about)

     1  /*
     2   * Copyright contributors to the Hyperledger Fabric Operator project
     3   *
     4   * SPDX-License-Identifier: Apache-2.0
     5   *
     6   * Licensed under the Apache License, Version 2.0 (the "License");
     7   * you may not use this file except in compliance with the License.
     8   * You may obtain a copy of the License at:
     9   *
    10   * 	  http://www.apache.org/licenses/LICENSE-2.0
    11   *
    12   * Unless required by applicable law or agreed to in writing, software
    13   * distributed under the License is distributed on an "AS IS" BASIS,
    14   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    15   * See the License for the specific language governing permissions and
    16   * limitations under the License.
    17   */
    18  
    19  package console_test
    20  
    21  import (
    22  	"context"
    23  	"encoding/json"
    24  	"math/rand"
    25  	"time"
    26  
    27  	. "github.com/onsi/ginkgo/v2"
    28  	. "github.com/onsi/gomega"
    29  	appsv1 "k8s.io/api/apps/v1"
    30  	corev1 "k8s.io/api/core/v1"
    31  	"k8s.io/apimachinery/pkg/api/resource"
    32  	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
    33  	"k8s.io/apimachinery/pkg/types"
    34  	"k8s.io/apimachinery/pkg/util/wait"
    35  
    36  	current "github.com/IBM-Blockchain/fabric-operator/api/v1beta1"
    37  	"github.com/IBM-Blockchain/fabric-operator/integration"
    38  )
    39  
    40  var (
    41  	console  *Console
    42  	console2 *Console // DISABLED
    43  	console3 *Console
    44  )
    45  
    46  var (
    47  	defaultRequestsConsole = corev1.ResourceList{
    48  		corev1.ResourceCPU:              resource.MustParse("30m"),
    49  		corev1.ResourceMemory:           resource.MustParse("60M"),
    50  		corev1.ResourceEphemeralStorage: resource.MustParse("100Mi"),
    51  	}
    52  
    53  	defaultLimitsConsole = corev1.ResourceList{
    54  		corev1.ResourceCPU:              resource.MustParse("300m"),
    55  		corev1.ResourceMemory:           resource.MustParse("600M"),
    56  		corev1.ResourceEphemeralStorage: resource.MustParse("1Gi"),
    57  	}
    58  
    59  	defaultRequestsConfigtxlator = corev1.ResourceList{
    60  		corev1.ResourceCPU:              resource.MustParse("25m"),
    61  		corev1.ResourceMemory:           resource.MustParse("50M"),
    62  		corev1.ResourceEphemeralStorage: resource.MustParse("100Mi"),
    63  	}
    64  
    65  	defaultLimitsConfigtxlator = corev1.ResourceList{
    66  		corev1.ResourceCPU:              resource.MustParse("25m"),
    67  		corev1.ResourceMemory:           resource.MustParse("50M"),
    68  		corev1.ResourceEphemeralStorage: resource.MustParse("1Gi"),
    69  	}
    70  
    71  	defaultRequestsCouchdb = corev1.ResourceList{
    72  		corev1.ResourceCPU:              resource.MustParse("30m"),
    73  		corev1.ResourceMemory:           resource.MustParse("60M"),
    74  		corev1.ResourceEphemeralStorage: resource.MustParse("100Mi"),
    75  	}
    76  
    77  	defaultLimitsCouchdb = corev1.ResourceList{
    78  		corev1.ResourceCPU:              resource.MustParse("300m"),
    79  		corev1.ResourceMemory:           resource.MustParse("600M"),
    80  		corev1.ResourceEphemeralStorage: resource.MustParse("1Gi"),
    81  	}
    82  
    83  	defaultRequestsDeployer = corev1.ResourceList{
    84  		corev1.ResourceCPU:              resource.MustParse("10m"),
    85  		corev1.ResourceMemory:           resource.MustParse("20M"),
    86  		corev1.ResourceEphemeralStorage: resource.MustParse("100Mi"),
    87  	}
    88  
    89  	defaultLimitsDeployer = corev1.ResourceList{
    90  		corev1.ResourceCPU:              resource.MustParse("100m"),
    91  		corev1.ResourceMemory:           resource.MustParse("200M"),
    92  		corev1.ResourceEphemeralStorage: resource.MustParse("1Gi"),
    93  	}
    94  
    95  	useTagsFlag = true
    96  )
    97  
    98  var _ = Describe("Interaction between IBP-Operator and Kubernetes cluster", func() {
    99  	SetDefaultEventuallyTimeout(240 * time.Second)
   100  	SetDefaultEventuallyPollingInterval(time.Second)
   101  
   102  	AfterEach(func() {
   103  		// Set flag if a test falls
   104  		if CurrentGinkgoTestDescription().Failed {
   105  			testFailed = true
   106  		}
   107  	})
   108  
   109  	Context("IBPConsole controller", func() {
   110  		Context("applying incorrectly configured third instance of IBPConsole CR", func() {
   111  			It("should set the CR status to error", func() {
   112  				Eventually(console3.pollForCRStatus).Should((Equal(current.Error)))
   113  
   114  				crStatus := &current.IBPConsole{}
   115  				result := ibpCRClient.Get().Namespace(namespace).Resource("ibpconsoles").Name(console3.Name).Do(context.TODO())
   116  				result.Into(crStatus)
   117  
   118  				Expect(crStatus.Status.Message).To(ContainSubstring("Service account name not provided"))
   119  			})
   120  
   121  			It("should delete the third instance of IBPConsole CR", func() {
   122  				result := ibpCRClient.Delete().Namespace(namespace).Resource("ibpconsoles").Name(console3.Name).Do(context.TODO())
   123  				Expect(result.Error()).NotTo(HaveOccurred())
   124  			})
   125  		})
   126  
   127  		// This test is disabled as it doesn't test anything interesting AND it consumes
   128  		// too many resources on the GHA pipeline, causing the primary test flow to starve
   129  		// and eventually time out.
   130  		PContext("applying the second instance of IBPConsole CR", func() {
   131  			var (
   132  				err error
   133  				dep *appsv1.Deployment
   134  			)
   135  
   136  			It("creates a second IBPConsole custom resource", func() {
   137  				By("starting a pod", func() {
   138  					Eventually(console2.PodIsRunning).Should((Equal(true)))
   139  				})
   140  			})
   141  
   142  			PIt("should find zone and region", func() {
   143  				// Wait for new deployment before querying deployment for updates
   144  				err = wait.Poll(500*time.Millisecond, 60*time.Second, func() (bool, error) {
   145  					dep, err = kclient.AppsV1().Deployments(namespace).Get(context.TODO(), console2.Name, metav1.GetOptions{})
   146  					if dep != nil {
   147  						if dep.Status.UpdatedReplicas == 1 && dep.Status.Conditions[0].Type == appsv1.DeploymentAvailable {
   148  							return true, nil
   149  						}
   150  					}
   151  					return false, nil
   152  				})
   153  				Expect(err).NotTo(HaveOccurred())
   154  				dep, err = kclient.AppsV1().Deployments(namespace).Get(context.TODO(), console2.Name, metav1.GetOptions{})
   155  				Expect(err).NotTo(HaveOccurred())
   156  
   157  				By("checking zone", func() {
   158  					Expect(console2.TestAffinityZone(dep)).To((Equal(true)))
   159  				})
   160  
   161  				By("checking region", func() {
   162  					Expect(console2.TestAffinityRegion(dep)).To((Equal(true)))
   163  				})
   164  			})
   165  
   166  			It("should delete the second instance of IBPConsole CR", func() {
   167  				result := ibpCRClient.Delete().Namespace(namespace).Resource("ibpconsoles").Name(console2.Name).Do(context.TODO())
   168  				Expect(result.Error()).NotTo(HaveOccurred())
   169  			})
   170  		})
   171  
   172  		Context("applying the first instance of IBPConsole CR", func() {
   173  			var (
   174  				err error
   175  				dep *appsv1.Deployment
   176  			)
   177  
   178  			It("creates a IBPConsole custom resource", func() {
   179  				By("setting the CR status to deploying", func() {
   180  					Eventually(console.pollForCRStatus).Should(Equal(current.Deploying))
   181  				})
   182  
   183  				By("creating a service", func() {
   184  					Eventually(console.ServiceExists).Should((Equal(true)))
   185  				})
   186  
   187  				By("creating a pvc", func() {
   188  					Eventually(console.PVCExists).Should((Equal(true)))
   189  				})
   190  
   191  				By("creating a configmap", func() {
   192  					Eventually(console.ConfigMapExists).Should((Equal(true)))
   193  				})
   194  
   195  				By("starting a ingress", func() {
   196  					Eventually(console.IngressExists).Should((Equal(true)))
   197  				})
   198  
   199  				By("creating a deployment", func() {
   200  					Eventually(console.DeploymentExists).Should((Equal(true)))
   201  				})
   202  
   203  				By("starting a pod", func() {
   204  					Eventually(console.PodIsRunning).Should((Equal(true)))
   205  				})
   206  
   207  				By("setting the CR status to deployed when pod is running", func() {
   208  					Eventually(console.pollForCRStatus).Should((Equal(current.Deployed)))
   209  				})
   210  			})
   211  
   212  			It("should not find zone and region", func() {
   213  				// Wait for new deployment before querying deployment for updates
   214  				err = wait.Poll(500*time.Millisecond, 60*time.Second, func() (bool, error) {
   215  					dep, err = kclient.AppsV1().Deployments(namespace).Get(context.TODO(), console.Name, metav1.GetOptions{})
   216  					if dep != nil {
   217  						if dep.Status.UpdatedReplicas == 1 && dep.Status.Conditions[0].Type == appsv1.DeploymentAvailable {
   218  							return true, nil
   219  						}
   220  					}
   221  					return false, nil
   222  				})
   223  				Expect(err).NotTo(HaveOccurred())
   224  				dep, err = kclient.AppsV1().Deployments(namespace).Get(context.TODO(), console.Name, metav1.GetOptions{})
   225  				Expect(err).NotTo(HaveOccurred())
   226  
   227  				By("checking zone", func() {
   228  					Expect(console.TestAffinityZone(dep)).Should((Equal(false)))
   229  				})
   230  
   231  				By("checking region", func() {
   232  					Expect(console.TestAffinityRegion(dep)).Should((Equal(false)))
   233  				})
   234  			})
   235  
   236  			When("the custom resource is updated", func() {
   237  				var (
   238  					err                              error
   239  					dep                              *appsv1.Deployment
   240  					newResourceRequestsConsole       corev1.ResourceList
   241  					newResourceLimitsConsole         corev1.ResourceList
   242  					newResourceRequestsConfigtxlator corev1.ResourceList
   243  					newResourceLimitsConfigtxlator   corev1.ResourceList
   244  					newResourceRequestsCouchdb       corev1.ResourceList
   245  					newResourceLimitsCouchdb         corev1.ResourceList
   246  					newResourceRequestsDeployer      corev1.ResourceList
   247  					newResourceLimitsDeployer        corev1.ResourceList
   248  				)
   249  
   250  				BeforeEach(func() {
   251  					newResourceRequestsConsole = map[corev1.ResourceName]resource.Quantity{
   252  						corev1.ResourceCPU:              resource.MustParse("25m"),
   253  						corev1.ResourceMemory:           resource.MustParse("50M"),
   254  						corev1.ResourceEphemeralStorage: resource.MustParse("100M"),
   255  					}
   256  					newResourceLimitsConsole = map[corev1.ResourceName]resource.Quantity{
   257  						corev1.ResourceCPU:              resource.MustParse("250m"),
   258  						corev1.ResourceMemory:           resource.MustParse("500M"),
   259  						corev1.ResourceEphemeralStorage: resource.MustParse("1G"),
   260  					}
   261  
   262  					newResourceRequestsConfigtxlator = map[corev1.ResourceName]resource.Quantity{
   263  						corev1.ResourceCPU:              resource.MustParse("30m"),
   264  						corev1.ResourceMemory:           resource.MustParse("60M"),
   265  						corev1.ResourceEphemeralStorage: resource.MustParse("100M"),
   266  					}
   267  					newResourceLimitsConfigtxlator = map[corev1.ResourceName]resource.Quantity{
   268  						corev1.ResourceCPU:              resource.MustParse("30m"),
   269  						corev1.ResourceMemory:           resource.MustParse("60M"),
   270  						corev1.ResourceEphemeralStorage: resource.MustParse("1G"),
   271  					}
   272  
   273  					newResourceRequestsCouchdb = map[corev1.ResourceName]resource.Quantity{
   274  						corev1.ResourceCPU:              resource.MustParse("35m"),
   275  						corev1.ResourceMemory:           resource.MustParse("70M"),
   276  						corev1.ResourceEphemeralStorage: resource.MustParse("100M"),
   277  					}
   278  					newResourceLimitsCouchdb = map[corev1.ResourceName]resource.Quantity{
   279  						corev1.ResourceCPU:              resource.MustParse("350m"),
   280  						corev1.ResourceMemory:           resource.MustParse("700M"),
   281  						corev1.ResourceEphemeralStorage: resource.MustParse("1G"),
   282  					}
   283  
   284  					newResourceRequestsDeployer = map[corev1.ResourceName]resource.Quantity{
   285  						corev1.ResourceCPU:              resource.MustParse("9m"),
   286  						corev1.ResourceMemory:           resource.MustParse("18M"),
   287  						corev1.ResourceEphemeralStorage: resource.MustParse("100M"),
   288  					}
   289  					newResourceLimitsDeployer = map[corev1.ResourceName]resource.Quantity{
   290  						corev1.ResourceCPU:              resource.MustParse("90m"),
   291  						corev1.ResourceMemory:           resource.MustParse("180M"),
   292  						corev1.ResourceEphemeralStorage: resource.MustParse("1G"),
   293  					}
   294  
   295  					Eventually(console.DeploymentExists).Should((Equal(true)))
   296  					dep, err = kclient.AppsV1().Deployments(namespace).Get(context.TODO(), console.Name, metav1.GetOptions{})
   297  					Expect(err).NotTo(HaveOccurred())
   298  				})
   299  
   300  				It("updates the instance of IBPConsole if resources are updated in CR", func() {
   301  					consoleResources := dep.Spec.Template.Spec.Containers[0].Resources
   302  					Expect(consoleResources.Requests).To(Equal(defaultRequestsConsole))
   303  					Expect(consoleResources.Limits).To(Equal(defaultLimitsConsole))
   304  
   305  					deployerResources := dep.Spec.Template.Spec.Containers[1].Resources
   306  					Expect(deployerResources.Requests).To(Equal(defaultRequestsDeployer))
   307  					Expect(deployerResources.Limits).To(Equal(defaultLimitsDeployer))
   308  
   309  					configtxResources := dep.Spec.Template.Spec.Containers[2].Resources
   310  					Expect(configtxResources.Requests).To(Equal(defaultRequestsConfigtxlator))
   311  					Expect(configtxResources.Limits).To(Equal(defaultLimitsConfigtxlator))
   312  
   313  					couchdbResources := dep.Spec.Template.Spec.Containers[3].Resources
   314  					Expect(couchdbResources.Requests).To(Equal(defaultRequestsCouchdb))
   315  					Expect(couchdbResources.Limits).To(Equal(defaultLimitsCouchdb))
   316  
   317  					console.CR.Spec.Resources = &current.ConsoleResources{
   318  						Console: &corev1.ResourceRequirements{
   319  							Requests: newResourceRequestsConsole,
   320  							Limits:   newResourceLimitsConsole,
   321  						},
   322  						Configtxlator: &corev1.ResourceRequirements{
   323  							Requests: newResourceRequestsConfigtxlator,
   324  							Limits:   newResourceLimitsConfigtxlator,
   325  						},
   326  						CouchDB: &corev1.ResourceRequirements{
   327  							Requests: newResourceRequestsCouchdb,
   328  							Limits:   newResourceLimitsCouchdb,
   329  						},
   330  						Deployer: &corev1.ResourceRequirements{
   331  							Requests: newResourceRequestsDeployer,
   332  							Limits:   newResourceLimitsDeployer,
   333  						},
   334  					}
   335  					console.CR.Spec.Password = ""
   336  					bytes, err := json.Marshal(console.CR)
   337  					Expect(err).NotTo(HaveOccurred())
   338  
   339  					result := ibpCRClient.Patch(types.MergePatchType).Namespace(namespace).Resource("ibpconsoles").Name(console.Name).Body(bytes).Do(context.TODO())
   340  					Expect(result.Error()).NotTo(HaveOccurred())
   341  
   342  					// Wait for new deployment before querying deployment for updates
   343  					err = wait.Poll(500*time.Millisecond, 60*time.Second, func() (bool, error) {
   344  						dep, err = kclient.AppsV1().Deployments(namespace).Get(context.TODO(), console.Name, metav1.GetOptions{})
   345  						if dep != nil {
   346  							if dep.Status.UpdatedReplicas == 1 && dep.Status.Conditions[0].Type == appsv1.DeploymentAvailable {
   347  								if dep.Spec.Template.Spec.Containers[0].Resources.Requests.Cpu().MilliValue() == newResourceRequestsConsole.Cpu().MilliValue() {
   348  									return true, nil
   349  								}
   350  							}
   351  						}
   352  						return false, nil
   353  					})
   354  					Expect(err).NotTo(HaveOccurred())
   355  
   356  					dep, err = kclient.AppsV1().Deployments(namespace).Get(context.TODO(), console.Name, metav1.GetOptions{})
   357  					Expect(err).NotTo(HaveOccurred())
   358  
   359  					updatedConsoleResources := dep.Spec.Template.Spec.Containers[0].Resources
   360  					Expect(updatedConsoleResources.Requests).To(Equal(newResourceRequestsConsole))
   361  					Expect(updatedConsoleResources.Limits).To(Equal(newResourceLimitsConsole))
   362  
   363  					updatedDeployerResources := dep.Spec.Template.Spec.Containers[1].Resources
   364  					Expect(updatedDeployerResources.Requests).To(Equal(newResourceRequestsDeployer))
   365  					Expect(updatedDeployerResources.Limits).To(Equal(newResourceLimitsDeployer))
   366  
   367  					updatedConfigtxResources := dep.Spec.Template.Spec.Containers[2].Resources
   368  					Expect(updatedConfigtxResources.Requests).To(Equal(newResourceRequestsConfigtxlator))
   369  					Expect(updatedConfigtxResources.Limits).To(Equal(newResourceLimitsConfigtxlator))
   370  
   371  					updatedCouchDBResources := dep.Spec.Template.Spec.Containers[3].Resources
   372  					Expect(updatedCouchDBResources.Requests).To(Equal(newResourceRequestsCouchdb))
   373  					Expect(updatedCouchDBResources.Limits).To(Equal(newResourceLimitsCouchdb))
   374  				})
   375  			})
   376  
   377  			When("a deployment managed by operator is manually edited", func() {
   378  				var (
   379  					err error
   380  					dep *appsv1.Deployment
   381  				)
   382  
   383  				BeforeEach(func() {
   384  					Eventually(console.DeploymentExists).Should((Equal(true)))
   385  					dep, err = kclient.AppsV1().Deployments(namespace).Get(context.TODO(), console.Name, metav1.GetOptions{})
   386  					Expect(err).NotTo(HaveOccurred())
   387  				})
   388  
   389  				It("restores states", func() {
   390  					origRequests := dep.Spec.Template.Spec.Containers[0].Resources.Requests
   391  					dep.Spec.Template.Spec.Containers[0].Resources.Requests = map[corev1.ResourceName]resource.Quantity{
   392  						corev1.ResourceCPU:    resource.MustParse("107m"),
   393  						corev1.ResourceMemory: resource.MustParse("107M"),
   394  					}
   395  
   396  					depBytes, err := json.Marshal(dep)
   397  					Expect(err).NotTo(HaveOccurred())
   398  
   399  					_, err = kclient.AppsV1().Deployments(namespace).Patch(context.TODO(), console.Name, types.MergePatchType, depBytes, metav1.PatchOptions{})
   400  					Expect(err).NotTo(HaveOccurred())
   401  
   402  					// Wait for new deployment before querying deployment for updates
   403  					err = wait.Poll(500*time.Millisecond, 60*time.Second, func() (bool, error) {
   404  						dep, err = kclient.AppsV1().Deployments(namespace).Get(context.TODO(), console.Name, metav1.GetOptions{})
   405  						if dep != nil {
   406  							if dep.Status.UpdatedReplicas == 1 && dep.Status.Conditions[0].Type == appsv1.DeploymentAvailable {
   407  								if dep.Spec.Template.Spec.Containers[0].Resources.Requests.Cpu().MilliValue() == origRequests.Cpu().MilliValue() {
   408  									return true, nil
   409  								}
   410  							}
   411  						}
   412  						return false, nil
   413  					})
   414  					Expect(err).NotTo(HaveOccurred())
   415  					dep, err = kclient.AppsV1().Deployments(namespace).Get(context.TODO(), console.Name, metav1.GetOptions{})
   416  					Expect(err).NotTo(HaveOccurred())
   417  
   418  					Expect(dep.Spec.Template.Spec.Containers[0].Resources.Requests).To(Equal(origRequests))
   419  				})
   420  			})
   421  
   422  			It("should delete the first instance of IBPConsole CR", func() {
   423  				result := ibpCRClient.Delete().Namespace(namespace).Resource("ibpconsoles").Name(console.Name).Do(context.TODO())
   424  				Expect(result.Error()).NotTo(HaveOccurred())
   425  			})
   426  		})
   427  	})
   428  })
   429  
   430  func shuf(min, max int) int32 {
   431  	rand.Seed(time.Now().UnixNano())
   432  	return int32(rand.Intn(max-min+1) + min)
   433  }
   434  
   435  func GetConsole() *Console {
   436  	consolePort := shuf(30000, 32768)
   437  	proxyPort := shuf(30000, 32768)
   438  
   439  	name := "ibpconsole1"
   440  	cr := &current.IBPConsole{
   441  		Spec: current.IBPConsoleSpec{
   442  			License: current.License{
   443  				Accept: true,
   444  			},
   445  			ConnectionString:   "http://localhost:5984",
   446  			ServiceAccountName: "ibpconsole1",
   447  			NetworkInfo: &current.NetworkInfo{
   448  				Domain:      integration.TestAutomation1IngressDomain,
   449  				ConsolePort: consolePort,
   450  				ProxyPort:   proxyPort,
   451  			},
   452  			Email:    "admin@ibm.com",
   453  			Password: "cGFzc3dvcmQ=",
   454  			Resources: &current.ConsoleResources{
   455  				Console: &corev1.ResourceRequirements{
   456  					Requests: defaultRequestsConsole,
   457  					Limits:   defaultLimitsConsole,
   458  				},
   459  				Configtxlator: &corev1.ResourceRequirements{
   460  					Requests: defaultRequestsConfigtxlator,
   461  					Limits:   defaultLimitsConfigtxlator,
   462  				},
   463  				CouchDB: &corev1.ResourceRequirements{
   464  					Requests: defaultRequestsCouchdb,
   465  					Limits:   defaultLimitsCouchdb,
   466  				},
   467  				Deployer: &corev1.ResourceRequirements{
   468  					Requests: defaultRequestsDeployer,
   469  					Limits:   defaultLimitsDeployer,
   470  				},
   471  			},
   472  			ImagePullSecrets: []string{"regcred"},
   473  			Images: &current.ConsoleImages{
   474  				ConfigtxlatorImage: integration.ConfigtxlatorImage,
   475  				ConfigtxlatorTag:   integration.ConfigtxlatorTag,
   476  				ConsoleImage:       integration.ConsoleImage,
   477  				ConsoleTag:         integration.ConsoleTag,
   478  				ConsoleInitImage:   integration.InitImage,
   479  				ConsoleInitTag:     integration.InitTag,
   480  				CouchDBImage:       integration.CouchdbImage,
   481  				CouchDBTag:         integration.CouchdbTag,
   482  				DeployerImage:      integration.DeployerImage,
   483  				DeployerTag:        integration.DeployerTag,
   484  			},
   485  			Versions: &current.Versions{
   486  				CA: map[string]current.VersionCA{
   487  					integration.FabricCAVersion: current.VersionCA{
   488  						Default: true,
   489  						Version: integration.FabricCAVersion,
   490  						Image: current.CAImages{
   491  							CAInitImage: integration.InitImage,
   492  							CAInitTag:   integration.InitTag,
   493  							CAImage:     integration.CaImage,
   494  							CATag:       integration.CaTag,
   495  						},
   496  					},
   497  				},
   498  				Peer: map[string]current.VersionPeer{
   499  					integration.FabricVersion: current.VersionPeer{
   500  						Default: true,
   501  						Version: integration.FabricVersion,
   502  						Image: current.PeerImages{
   503  							PeerInitImage: integration.InitImage,
   504  							PeerInitTag:   integration.InitTag,
   505  							PeerImage:     integration.PeerImage,
   506  							PeerTag:       integration.PeerTag,
   507  							GRPCWebImage:  integration.GrpcwebImage,
   508  							GRPCWebTag:    integration.GrpcwebTag,
   509  							CouchDBImage:  integration.CouchdbImage,
   510  							CouchDBTag:    integration.CouchdbTag,
   511  						},
   512  					},
   513  				},
   514  				Orderer: map[string]current.VersionOrderer{
   515  					integration.FabricVersion: current.VersionOrderer{
   516  						Default: true,
   517  						Version: integration.FabricVersion,
   518  						Image: current.OrdererImages{
   519  							OrdererInitImage: integration.InitImage,
   520  							OrdererInitTag:   integration.InitTag,
   521  							OrdererImage:     integration.OrdererImage,
   522  							OrdererTag:       integration.OrdererTag,
   523  							GRPCWebImage:     integration.GrpcwebImage,
   524  							GRPCWebTag:       integration.GrpcwebTag,
   525  						},
   526  					},
   527  				},
   528  			},
   529  			UseTags: &useTagsFlag,
   530  		},
   531  	}
   532  	cr.Name = name
   533  
   534  	return &Console{
   535  		Name: name,
   536  		CR:   cr,
   537  		NativeResourcePoller: integration.NativeResourcePoller{
   538  			Name:      name,
   539  			Namespace: namespace,
   540  			Client:    kclient,
   541  		},
   542  	}
   543  }
   544  
   545  // DISABLED
   546  func GetConsole2() *Console {
   547  	consolePort := shuf(30000, 32768)
   548  	proxyPort := shuf(30000, 32768)
   549  
   550  	name := "ibpconsole2"
   551  	cr := &current.IBPConsole{
   552  		Spec: current.IBPConsoleSpec{
   553  			License: current.License{
   554  				Accept: true,
   555  			},
   556  			ConnectionString:   "http://localhost:5984",
   557  			ServiceAccountName: "ibpconsole1",
   558  			NetworkInfo: &current.NetworkInfo{
   559  				Domain:      integration.TestAutomation1IngressDomain,
   560  				ConsolePort: consolePort,
   561  				ProxyPort:   proxyPort,
   562  			},
   563  			Email:            "admin@ibm.com",
   564  			Password:         "cGFzc3dvcmQ=",
   565  			Zone:             "select",
   566  			Region:           "select",
   567  			ImagePullSecrets: []string{"regcred"},
   568  			Images: &current.ConsoleImages{
   569  				ConfigtxlatorImage: integration.ConfigtxlatorImage,
   570  				ConfigtxlatorTag:   integration.ConfigtxlatorTag,
   571  				ConsoleImage:       integration.ConsoleImage,
   572  				ConsoleTag:         integration.ConsoleTag,
   573  				ConsoleInitImage:   integration.InitImage,
   574  				ConsoleInitTag:     integration.InitTag,
   575  				CouchDBImage:       integration.CouchdbImage,
   576  				CouchDBTag:         integration.CouchdbTag,
   577  				DeployerImage:      integration.DeployerImage,
   578  				DeployerTag:        integration.DeployerTag,
   579  			},
   580  			Versions: &current.Versions{
   581  				CA: map[string]current.VersionCA{
   582  					integration.FabricCAVersion: current.VersionCA{
   583  						Default: true,
   584  						Version: integration.FabricCAVersion,
   585  						Image: current.CAImages{
   586  							CAInitImage: integration.InitImage,
   587  							CAInitTag:   integration.InitTag,
   588  							CAImage:     integration.CaImage,
   589  							CATag:       integration.CaTag,
   590  						},
   591  					},
   592  				},
   593  				Peer: map[string]current.VersionPeer{
   594  					integration.FabricVersion: current.VersionPeer{
   595  						Default: true,
   596  						Version: integration.FabricVersion,
   597  						Image: current.PeerImages{
   598  							PeerInitImage: integration.InitImage,
   599  							PeerInitTag:   integration.InitTag,
   600  							PeerImage:     integration.PeerImage,
   601  							PeerTag:       integration.PeerTag,
   602  							GRPCWebImage:  integration.GrpcwebImage,
   603  							GRPCWebTag:    integration.GrpcwebTag,
   604  							CouchDBImage:  integration.CouchdbImage,
   605  							CouchDBTag:    integration.CouchdbTag,
   606  						},
   607  					},
   608  				},
   609  				Orderer: map[string]current.VersionOrderer{
   610  					integration.FabricVersion: current.VersionOrderer{
   611  						Default: true,
   612  						Version: integration.FabricVersion,
   613  						Image: current.OrdererImages{
   614  							OrdererInitImage: integration.InitImage,
   615  							OrdererInitTag:   integration.InitTag,
   616  							OrdererImage:     integration.OrdererImage,
   617  							OrdererTag:       integration.OrdererTag,
   618  							GRPCWebImage:     integration.GrpcwebImage,
   619  							GRPCWebTag:       integration.GrpcwebTag,
   620  						},
   621  					},
   622  				},
   623  			},
   624  			UseTags: &useTagsFlag,
   625  		},
   626  	}
   627  	cr.Name = name
   628  
   629  	return &Console{
   630  		Name: name,
   631  		CR:   cr,
   632  		NativeResourcePoller: integration.NativeResourcePoller{
   633  			Name:      name,
   634  			Namespace: namespace,
   635  			Client:    kclient,
   636  		},
   637  	}
   638  }
   639  
   640  func GetConsole3() *Console {
   641  	consolePort := shuf(30000, 32768)
   642  	proxyPort := shuf(30000, 32768)
   643  
   644  	name := "ibpconsole3"
   645  	cr := &current.IBPConsole{
   646  		Spec: current.IBPConsoleSpec{
   647  			License: current.License{
   648  				Accept: true,
   649  			},
   650  			ServiceAccountName: "", // Will cause error
   651  			NetworkInfo: &current.NetworkInfo{
   652  				Domain:      integration.TestAutomation1IngressDomain,
   653  				ConsolePort: consolePort,
   654  				ProxyPort:   proxyPort,
   655  			},
   656  			Images: &current.ConsoleImages{
   657  				CouchDBImage: integration.CouchdbImage,
   658  				CouchDBTag:   integration.CouchdbTag,
   659  			},
   660  			UseTags: &useTagsFlag,
   661  		},
   662  	}
   663  	cr.Name = name
   664  
   665  	return &Console{
   666  		Name: name,
   667  		CR:   cr,
   668  		NativeResourcePoller: integration.NativeResourcePoller{
   669  			Name:      name,
   670  			Namespace: namespace,
   671  			Client:    kclient,
   672  		},
   673  	}
   674  }
   675  
   676  type Console struct {
   677  	Name string
   678  	CR   *current.IBPConsole
   679  	integration.NativeResourcePoller
   680  }
   681  
   682  func (console *Console) pollForCRStatus() current.IBPCRStatusType {
   683  	crStatus := &current.IBPConsole{}
   684  
   685  	result := ibpCRClient.Get().Namespace(namespace).Resource("ibpconsoles").Name(console.Name).Do(context.TODO())
   686  	result.Into(crStatus)
   687  
   688  	return crStatus.Status.Type
   689  }