diff --git a/.commitlintrc.json b/.commitlintrc.json index 233ff603a802..2aef88f0584f 100644 --- a/.commitlintrc.json +++ b/.commitlintrc.json @@ -15,8 +15,7 @@ "core", "docs", "nfs", - "test", - "yugabytedb" + "test" ] ], "body-leading-blank": [ diff --git a/CODE-OWNERS b/CODE-OWNERS index 7f33280226e6..8ae1d8a80ab1 100644 --- a/CODE-OWNERS +++ b/CODE-OWNERS @@ -25,7 +25,3 @@ areas: nfs: reviewers: - rohan47 - yugabytedb: - reviewers: - - Arnav15 - - samkulkarni20 diff --git a/Documentation/development-flow.md b/Documentation/development-flow.md index 6c287f1c5890..3e743928606b 100644 --- a/Documentation/development-flow.md +++ b/Documentation/development-flow.md @@ -280,7 +280,6 @@ The `component` **MUST** be one of the following: - docs - nfs - test -- yugabytedb Note: sometimes you will feel like there is not so much to say, for instance if you are fixing a typo in a text. In that case, it is acceptable to shorten the commit message. diff --git a/Documentation/quickstart.md b/Documentation/quickstart.md index 18442c00b5d2..c04e1d484c28 100644 --- a/Documentation/quickstart.md +++ b/Documentation/quickstart.md @@ -14,9 +14,8 @@ Rook provides a growing number of storage providers to a Kubernetes cluster, eac **Follow these guides to get started with each provider**: -| Storage Provider | Status | Description | -| --------------------------- | ----------- | ------------------------------------------------------------------------------------------------------------------------------------------------------ | -| [Ceph](ceph-quickstart.md) | Stable / V1 | Ceph is a highly scalable distributed storage solution for block storage, object storage, and shared filesystems with years of production deployments. | -| [Cassandra](cassandra.md) | Alpha | Cassandra is a highly available NoSQL database featuring lightning fast performance, tunable consistency and massive scalability. | -| [NFS](nfs.md) | Alpha | NFS allows remote hosts to mount filesystems over a network and interact with those filesystems as though they are mounted locally. | -| [YugabyteDB](yugabytedb.md) | Alpha | YugaByteDB is a high-performance, cloud-native distributed SQL database which can tolerate disk, node, zone and region failures automatically. | +| Storage Provider | Status | Description | +| -------------------------- | ----------- | ------------------------------------------------------------------------------------------------------------------------------------------------------ | +| [Ceph](ceph-quickstart.md) | Stable / V1 | Ceph is a highly scalable distributed storage solution for block storage, object storage, and shared filesystems with years of production deployments. | +| [Cassandra](cassandra.md) | Alpha | Cassandra is a highly available NoSQL database featuring lightning fast performance, tunable consistency and massive scalability. | +| [NFS](nfs.md) | Alpha | NFS allows remote hosts to mount filesystems over a network and interact with those filesystems as though they are mounted locally. | diff --git a/Documentation/yugabytedb-cluster-crd.md b/Documentation/yugabytedb-cluster-crd.md deleted file mode 100644 index 57e6e59c048e..000000000000 --- a/Documentation/yugabytedb-cluster-crd.md +++ /dev/null @@ -1,121 +0,0 @@ ---- -title: YugabyteDB Cluster CRD -weight: 9000 ---- -# YugabyteDB Cluster CRD - -YugabyteDB clusters can be created/configured by creating/updating the custom resource object `ybclusters.yugabytedb.rook.io`. -Please follow instructions in the [YugabyteDB Operator Quikstart](yugabytedb.md) to create a YugabyteDB cluster. - -The configuration options provided by the custom resource are explained here. - -## Sample - -```yaml -apiVersion: yugabytedb.rook.io/v1alpha1 -kind: YBCluster -metadata: - name: rook-yugabytedb - namespace: rook-yugabytedb -spec: - master: - # Replica count for Master. - replicas: 3 - # optional. Default values for resource are as below - resource: - requests: - cpu: 2 - memory: 2Gi - limits: - cpu: 2 - memory: 2Gi - # Mentioning network ports is optional. If some or all ports are not specified, then they will be defaulted to below-mentioned values, except for tserver-ui. - network: - ports: - - name: yb-master-ui - port: 7000 # default value - - name: yb-master-rpc - port: 7100 # default value - # Volume claim template for Master - volumeClaimTemplate: - metadata: - name: datadir - spec: - accessModes: [ "ReadWriteOnce" ] - resources: - requests: - storage: 1Gi - storageClassName: standard # Modify this field with required storage class name. - tserver: - # Replica count for TServer - replicas: 3 - # optional. Default values for resource are as below - resource: - requests: - cpu: 2 - memory: 4Gi - limits: - cpu: 2 - memory: 4Gi - # Mentioning network ports is optional. If some or all ports are not specified, then they will be defaulted to below-mentioned values, except for tserver-ui. - # For tserver-ui a cluster ip service will be created if the yb-tserver-ui port is explicitly mentioned. If it is not specified, only StatefulSet & headless service will be created for TServer. TServer ClusterIP service creation will be skipped. Whereas for Master, all 3 kubernetes objects will always be created. - network: - ports: - - name: yb-tserver-ui - port: 9000 - - name: yb-tserver-rpc - port: 9100 # default value - - name: ycql - port: 9042 # default value - - name: yedis - port: 6379 # default value - - name: ysql - port: 5433 # default value - # Volume claim template for TServer - volumeClaimTemplate: - metadata: - name: datadir - spec: - accessModes: [ "ReadWriteOnce" ] - resources: - requests: - storage: 1Gi - storageClassName: standard # Modify this field with required storage class name. -``` - -## Configuration options - -### Master/TServer - -Master & TServer are two essential components of a YugabyteDB cluster. Master is responsible for recording and maintaining system metadata & for admin activities. TServers are mainly responsible for data I/O. -Specify Master/TServer specific attributes under `master`/`tserver`. The valid attributes are `replicas`, `network` & `volumeClaimTemplate`. - -### Replica Count - -Specify replica count for `master` & `tserver` pods under `replicas` field. This is a **required** field. - -### Resource - -Specify resource requests and limits for CPU & Memory. If provided, the given resource values will be used. If omitted the default CPU request & limit will be 2, whereas default memory request & limit will be 2Gi & 4Gi for Master & TServer, respectively. You may override these values for dev environments where the cluster doesn't have CPU/Memory as per the defaults. -**Though it is recommended to use the defaults for production-like deployments.** - -### Network - -`network` field accepts `NetworkSpec` to be specified which describes YugabyteDB network settings. This is an **optional** field. Default network settings will be used, if any or all of the acceptable values are absent. - -A ClusterIP service will be created when `yb-tserver-ui` port is explicitly specified. If it is not specified, only StatefulSet & headless service will be created for TServer. ClusterIP service creation will be skipped. Whereas for Master, all 3 kubernetes objects will always be created. - -The acceptable port names & their default values are as follows: - -| Name | Default Value | -| ---------------- | ------------- | -| `yb-master-ui` | `7000` | -| `yb-master-rpc` | `7100` | -| `yb-tserver-rpc` | `9100` | -| `ycql` | `9042` | -| `yedis` | `6379` | -| `ysql` | `5433` | - -### Volume Claim Templates - -Specify a `PersistentVolumeClaim` template under the `volumeClaimTemplate` field for `master` & `tserver` each. This is a **required** field. diff --git a/Documentation/yugabytedb.md b/Documentation/yugabytedb.md deleted file mode 100644 index b1d90b1eedf5..000000000000 --- a/Documentation/yugabytedb.md +++ /dev/null @@ -1,114 +0,0 @@ ---- -title: YugabyteDB -weight: 900 -indent: true ---- - -# YugabyteDB operator Quikstart - -YugaByte DB is a high-performance distributed SQL database (more information [here](https://docs.yugabyte.com/latest/introduction/)). Rook provides an operator that can create and manage YugabyteDB clusters. - -## Prerequisites - -Follow [these instructions](k8s-pre-reqs.md) to make your kubernetes cluster ready for `Rook`. - -## TL;DR - -You can create a simple YugabyteDB cluster with below commands. For more detailed instructions, please skip to the [Deploy Rook YugabyteDB Operator](#Deploy-Rook-YugabyteDB-Operator) section. - -```console -cd cluster/examples/kubernetes/yugabytedb -kubectl create -f operator.yaml -kubectl create -f cluster.yaml -``` - -Use below commands to observe the created cluster. - -```console -kubectl -n rook-yugabytedb-system get pods -``` - -## Deploy Rook YugabyteDB Operator - -To begin with, deploy the Rook YugabyteDB operator, which can create/manage the YugabyteDB cluster. Use following commands to do the same. - -```console -cd cluster/examples/kubernetes/yugabytedb -kubectl create -f operator.yaml -``` - -Observe the rook operator using below command. - -```console -kubectl -n rook-yugabytedb-system get pods -``` - -## Create a simple YugabyteDB cluster - -After the Rook YugabyteDB operator is up and running, you can create an object of the custom resource type `ybclusters.yugabytedb.rook.io`. A sample resource specs are present in `cluster.yaml`. You can also browse/modify the contents of `cluster.yaml` according to the configuration options available. Refer [YugabyteDB CRD documentation](yugabytedb-cluster-crd.md) for details on available configuration options. - -To create a YugabyteDB cluster, run - -```console -kubectl create -f cluster.yaml -``` - -Verify the created custom resource object using - -```console -kubectl -n rook-yugabytedb get ybclusters.yugabytedb.rook.io -``` - -Check if the required replicas of Master & TServer are running, run the following command. Tally the Master & TServer pod count against the corresponding replica count you have in `cluster.yaml`. With no change to the replica count, you should see 3 pods each for Master & TServer. - -```console -kubectl -n rook-yugabytedb get pods -``` - -## Troubleshooting - -Skip this section, if the cluster is up & running. Continue to the [Access the Database](#access-the-database) section to access `ysql` api. - -If the cluster does not come up, first run following command to take a look at operator logs. - -```console -kubectl -n rook-yugabytedb-system logs -l app=rook-yugabytedb-operator -``` - -If everything is OK in the operator logs, check the YugabyteDB Master & TServer logs next. - -```console -kubectl -n rook-yugabytedb logs -l app=yb-master-hello-ybdb-cluster -kubectl -n rook-yugabytedb logs -l app=yb-tserver-hello-ybdb-cluster -``` - -## Access the Database - -After all the pods in YugabyteDB cluster are running, you can access the YugabyteDB's postgres compliant `ysql` api. Run following command to access it. - -```console -kubectl -n rook-yugabytedb exec -it yb-tserver-hello-ybdb-cluster-0 /home/yugabyte/bin/ysqlsh -- -h yb-tserver-hello-ybdb-cluster-0 --echo-queries -``` - -Refer the [YugabyteDB documentation](https://docs.yugabyte.com/latest/quick-start/explore-ysql/#kubernetes) for more details on the `ysql` api. - -You can also access the YugabyteDB dashboard using port-forwarding. - -```console -kubectl port-forward -n rook-yugabytedb svc/yb-master-ui-hello-ybdb-cluster 7000:7000 -``` - -> **NOTE**: You should now be able to navigate to `127.0.0.1:7000` to visualize your cluster. - -## Cleanup - -Run the commands below to clean up all resources created above. - -> **NOTE**: This will destroy your database and delete all of its data. - -```console -kubectl delete -f cluster.yaml -kubectl delete -f operator.yaml -``` - -Manually delete any Persistent Volumes that were created for this YugabyteDB cluster. diff --git a/Jenkinsfile b/Jenkinsfile index de6599e54fa2..ecde9c0f35c0 100644 --- a/Jenkinsfile +++ b/Jenkinsfile @@ -66,8 +66,6 @@ pipeline { } } else if (body.contains("[test nfs]") || title.contains("nfs:")) { env.testProvider = "nfs" - } else if (body.contains("[test yugabytedb]") || title.contains("yugabytedb:")) { - env.testProvider = "yugabytedb" } else if (body.contains("[test]")) { env.shouldBuild = "true" } else if (!changed_files.contains(".go")) { @@ -152,7 +150,7 @@ pipeline { } steps { sh 'cat _output/version | xargs tests/scripts/makeTestImages.sh save amd64' - stash name: 'repo-amd64',includes: 'ceph-amd64.tar,cassandra-amd64.tar,nfs-amd64.tar,yugabytedb-amd64.tar,build/common.sh,_output/tests/linux_amd64/,_output/charts/,tests/scripts/,cluster/charts/' + stash name: 'repo-amd64',includes: 'ceph-amd64.tar,cassandra-amd64.tar,nfs-amd64.tar,build/common.sh,_output/tests/linux_amd64/,_output/charts/,tests/scripts/,cluster/charts/' script { def data = [ "aws_1.15.x": "v1.15.12", diff --git a/README.md b/README.md index 1096e3d55ba4..5f5bc9cf10d1 100644 --- a/README.md +++ b/README.md @@ -81,11 +81,12 @@ More details about API versioning and status in Kubernetes can be found on the K | Ceph | [Ceph](https://ceph.com/) is a distributed storage system that provides file, block and object storage and is deployed in large scale production clusters. | ceph.rook.io/v1 | Stable | | Cassandra | [Cassandra](http://cassandra.apache.org/) is a highly available NoSQL database featuring lightning fast performance, tunable consistency and massive scalability. [Scylla](https://www.scylladb.com) is a close-to-the-hardware rewrite of Cassandra in C++, which enables much lower latencies and higher throughput. | cassandra.rook.io/v1alpha1 | Alpha | | NFS | [Network File System (NFS)](https://github.com/nfs-ganesha/nfs-ganesha/wiki) allows remote hosts to mount file systems over a network and interact with those file systems as though they are mounted locally. | nfs.rook.io/v1alpha1 | Alpha | -| YugabyteDB | [YugabyteDB](https://docs.yugabyte.com/latest/introduction/) is a high-performance, cloud-native distributed SQL database which can tolerate disk, node, zone and region failures automatically. | yugabytedb.rook.io/v1alpha1 | Alpha | | CockroachDB | [CockroachDB](https://www.cockroachlabs.com/product/cockroachdb/) is a cloud-native SQL database for building global, scalable cloud services that survive disasters. | cockroachdb.rook.io/v1alpha1 | [Deprecated](https://github.com/rook/rook/issues/6990)* | | EdgeFS | [EdgeFS](http://edgefs.io) is high-performance and fault-tolerant decentralized data fabric with access to object, file, NoSQL and block. | edgefs.rook.io/v1 | [Deprecated](https://github.com/rook/rook/issues/5823#issuecomment-703834989)* | +| YugabyteDB | [YugabyteDB](https://docs.yugabyte.com/latest/introduction/) is a high-performance, cloud-native distributed SQL database which can tolerate disk, node, zone and region failures automatically. | yugabytedb.rook.io/v1alpha1 | [Deprecated](https://github.com/rook/rook/issues/6992#issuecomment-771297708)* | -\* EdgeFS and CockroachDB were removed from Rook in v1.6. See [Rook v1.5](https://rook.github.io/docs/rook/v1.5/) docs if still interested. +\* CockroachDB, EdgeFS, and YugabyteDB were removed from Rook in v1.6. See [Rook v1.5](https://rook.github.io/docs/rook/v1.5/) docs if still interested. + For YugabyteDB, see the replacement operator [here](https://github.com/yugabyte/yugabyte-operator). ### Official Releases diff --git a/build/codegen/codegen.sh b/build/codegen/codegen.sh index 8e6317cc3791..be9f932beea3 100755 --- a/build/codegen/codegen.sh +++ b/build/codegen/codegen.sh @@ -14,7 +14,7 @@ # See the License for the specific language governing permissions and # limitations under the License. -GROUP_VERSIONS="rook.io:v1 rook.io:v1alpha2 ceph.rook.io:v1 nfs.rook.io:v1alpha1 cassandra.rook.io:v1alpha1 yugabytedb.rook.io:v1alpha1" +GROUP_VERSIONS="rook.io:v1 rook.io:v1alpha2 ceph.rook.io:v1 nfs.rook.io:v1alpha1 cassandra.rook.io:v1alpha1" scriptdir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" codegendir="${scriptdir}/../../vendor/k8s.io/code-generator" diff --git a/build/makelib/common.mk b/build/makelib/common.mk index 14ce58c03803..ced429ee924f 100644 --- a/build/makelib/common.mk +++ b/build/makelib/common.mk @@ -109,7 +109,7 @@ endif echo.%: ; @echo $* = $($*) # Select which images (backends) to make; default to all possible images -IMAGES ?= ceph nfs cassandra yugabytedb +IMAGES ?= ceph nfs cassandra COMMA := , SPACE := diff --git a/build/release/README.md b/build/release/README.md index 3bf1e1516068..16427b0d3a7b 100644 --- a/build/release/README.md +++ b/build/release/README.md @@ -113,5 +113,6 @@ Containers go to docker hub where we have the following repos: ``` rook/ceph -rook/yugabytedb +rook/nfs +rook/cassandra ``` diff --git a/cluster/examples/kubernetes/yugabytedb/cluster.yaml b/cluster/examples/kubernetes/yugabytedb/cluster.yaml deleted file mode 100644 index 3abc714fa8c5..000000000000 --- a/cluster/examples/kubernetes/yugabytedb/cluster.yaml +++ /dev/null @@ -1,72 +0,0 @@ -apiVersion: v1 -kind: Namespace -metadata: - name: rook-yugabytedb ---- -apiVersion: yugabytedb.rook.io/v1alpha1 -kind: YBCluster -metadata: - name: hello-ybdb-cluster - namespace: rook-yugabytedb -spec: - master: - # Replica count for Master. - replicas: 3 - resource: - requests: - cpu: 2 - memory: 2Gi - limits: - cpu: 2 - memory: 2Gi - # Mentioning network ports is optional. If some or all ports are not specified, then they will be defaulted to below-mentioned values, except for tserver-ui. - network: - ports: - - name: yb-master-ui - port: 7000 # default value - - name: yb-master-rpc - port: 7100 # default value - # Volume claim template for Master - volumeClaimTemplate: - metadata: - name: datadir - spec: - accessModes: [ "ReadWriteOnce" ] - resources: - requests: - storage: 1Gi - storageClassName: standard - tserver: - # Replica count for TServer - replicas: 3 - resource: - requests: - cpu: 2 - memory: 4Gi - limits: - cpu: 2 - memory: 4Gi - # Mentioning network ports is optional. If some or all ports are not specified, then they will be defaulted to below-mentioned values, except for tserver-ui. - # For tserver-ui a cluster ip service will be created if the yb-tserver-ui port is explicitly mentioned. If it is not specified, only StatefulSet & headless service will be created for TServer. TServer ClusterIP service creation will be skipped. Whereas for Master, all 3 kubernetes objects will always be created. - network: - ports: - - name: yb-tserver-ui - port: 9000 - - name: yb-tserver-rpc - port: 9100 # default value - - name: ycql - port: 9042 # default value - - name: yedis - port: 6379 # default value - - name: ysql - port: 5433 # default value - # Volume claim template for TServer - volumeClaimTemplate: - metadata: - name: datadir - spec: - accessModes: [ "ReadWriteOnce" ] - resources: - requests: - storage: 1Gi - storageClassName: standard diff --git a/cluster/examples/kubernetes/yugabytedb/operator.yaml b/cluster/examples/kubernetes/yugabytedb/operator.yaml deleted file mode 100644 index 4a0c583924dd..000000000000 --- a/cluster/examples/kubernetes/yugabytedb/operator.yaml +++ /dev/null @@ -1,112 +0,0 @@ -apiVersion: v1 -kind: Namespace -metadata: - name: rook-yugabytedb-system ---- -apiVersion: apiextensions.k8s.io/v1beta1 -kind: CustomResourceDefinition -metadata: - name: ybclusters.yugabytedb.rook.io -spec: - group: yugabytedb.rook.io - names: - kind: YBCluster - listKind: YBClusterList - singular: ybcluster - plural: ybclusters - scope: Namespaced - version: v1alpha1 ---- -apiVersion: rbac.authorization.k8s.io/v1 -kind: ClusterRole -metadata: - name: rook-yugabytedb-operator -rules: -- apiGroups: - - "" - resources: - - pods - verbs: - - get - - list -- apiGroups: - - "" - resources: - - services - verbs: - - get - - list - - watch - - create - - update - - patch - - delete -- apiGroups: - - apps - resources: - - statefulsets - verbs: - - get - - list - - watch - - create - - update - - patch - - delete -- apiGroups: - - yugabytedb.rook.io - resources: - - "*" - verbs: - - "*" ---- -apiVersion: v1 -kind: ServiceAccount -metadata: - name: rook-yugabytedb-operator - namespace: rook-yugabytedb-system ---- -apiVersion: rbac.authorization.k8s.io/v1 -kind: ClusterRoleBinding -metadata: - name: rook-yugabytedb-operator -roleRef: - apiGroup: rbac.authorization.k8s.io - kind: ClusterRole - name: rook-yugabytedb-operator -subjects: -- kind: ServiceAccount - name: rook-yugabytedb-operator - namespace: rook-yugabytedb-system ---- -apiVersion: apps/v1 -kind: Deployment -metadata: - name: rook-yugabytedb-operator - namespace: rook-yugabytedb-system - labels: - app: rook-yugabytedb-operator -spec: - selector: - matchLabels: - app: rook-yugabytedb-operator - replicas: 1 - template: - metadata: - labels: - app: rook-yugabytedb-operator - spec: - serviceAccountName: rook-yugabytedb-operator - containers: - - name: rook-yugabytedb-operator - image: rook/yugabytedb:master - args: ["yugabytedb", "operator"] - env: - - name: POD_NAME - valueFrom: - fieldRef: - fieldPath: metadata.name - - name: POD_NAMESPACE - valueFrom: - fieldRef: - fieldPath: metadata.namespace diff --git a/cmd/rook/main.go b/cmd/rook/main.go index 2e7b0914facb..2d7699d4b941 100644 --- a/cmd/rook/main.go +++ b/cmd/rook/main.go @@ -24,7 +24,6 @@ import ( rook "github.com/rook/rook/cmd/rook/rook" "github.com/rook/rook/cmd/rook/util" "github.com/rook/rook/cmd/rook/version" - "github.com/rook/rook/cmd/rook/yugabytedb" ) func main() { @@ -42,7 +41,6 @@ func addCommands() { ceph.Cmd, nfs.Cmd, cassandra.Cmd, - yugabytedb.Cmd, // util commands util.CmdReporterCmd, diff --git a/cmd/rook/yugabytedb/operator.go b/cmd/rook/yugabytedb/operator.go deleted file mode 100644 index 17e0617c89aa..000000000000 --- a/cmd/rook/yugabytedb/operator.go +++ /dev/null @@ -1,54 +0,0 @@ -/* -Copyright 2018 The Rook Authors. All rights reserved. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package yugabytedb - -import ( - "github.com/rook/rook/cmd/rook/rook" - operator "github.com/rook/rook/pkg/operator/yugabytedb" - "github.com/rook/rook/pkg/util/flags" - "github.com/spf13/cobra" -) - -const containerName = "rook-yugabytedb-operator" - -var operatorCmd = &cobra.Command{ - Use: "operator", - Short: "Runs the yugabytedb operator to deploy and manage yugabytedb in kubernetes cluster.", - Long: `Runs the yugabytedb operator to deploy and manage yugabytedb in kubernetes cluster. -https://github.com/rook/rook`, -} - -func init() { - flags.SetFlagsFromEnv(operatorCmd.Flags(), rook.RookEnvVarPrefix) - flags.SetLoggingFlags(operatorCmd.Flags()) - - operatorCmd.RunE = startOperator -} - -func startOperator(cmd *cobra.Command, args []string) error { - rook.SetLogLevel() - rook.LogStartupInfo(operatorCmd.Flags()) - - logger.Infof("starting yugabytedb operator") - context := rook.NewContext() - rookImage := rook.GetOperatorImage(context.Clientset, containerName) - op := operator.New(context, rookImage) - err := op.Run() - rook.TerminateOnError(err, "failed to run operator") - - return nil -} diff --git a/cmd/rook/yugabytedb/yugabytedb.go b/cmd/rook/yugabytedb/yugabytedb.go deleted file mode 100644 index 04e6f3379009..000000000000 --- a/cmd/rook/yugabytedb/yugabytedb.go +++ /dev/null @@ -1,36 +0,0 @@ -/* -Copyright 2018 The Rook Authors. All rights reserved. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package yugabytedb - -import ( - "github.com/coreos/pkg/capnslog" - "github.com/spf13/cobra" -) - -var Cmd = &cobra.Command{ - Use: "yugabytedb", - Short: "Main command for yugabytedb operator and daemons.", - Hidden: false, -} - -var ( - logger = capnslog.NewPackageLogger("github.com/rook/rook", "yugabytedbcmd") -) - -func init() { - Cmd.AddCommand(operatorCmd) -} diff --git a/design/yugabyte/yugabytedb-rook-design.md b/design/yugabyte/yugabytedb-rook-design.md deleted file mode 100644 index 2b3067a1fac7..000000000000 --- a/design/yugabyte/yugabytedb-rook-design.md +++ /dev/null @@ -1,105 +0,0 @@ -YugaByte DB is a high-performance distributed SQL database. (More information [here](https://docs.yugabyte.com/latest/introduction/)). This document outlines design and interfaces for a Rook YugaByte operator for running YugaByte on Kubernetes with Rook as the underlying storage engine. - -**What is use case behind this feature:** - -A cluster of YugaByte DB backed by Rook should be created using the `ybcluster.yugabytedb.rook.io` custom resource definition. Below is a sample custom resource spec for creating a 3-master, 3 t-servers cluster using the CRD. The sample is followed by an explanation of different configuration options available on the YugaByte DB CRD. - -## Sample - -```yaml -apiVersion: yugabytedb.rook.io/v1alpha1 -kind: YBCluster -metadata: - name: rook-yugabytedb - namespace: rook-yugabytedb -spec: - master: - # Replica count for Master. - replicas: 3 - # Mentioning network ports is optional. If some or all ports are not specified, then they will be defaulted to below-mentioned values, except for tserver-ui. - network: - ports: - - name: yb-master-ui - port: 7000 # default value - - name: yb-master-rpc - port: 7100 # default value - # Volume claim template for Master - volumeClaimTemplate: - metadata: - name: datadir - spec: - accessModes: [ "ReadWriteOnce" ] - resources: - requests: - storage: 1Gi - storageClassName: standard - tserver: - # Replica count for TServer - replicas: 3 - # Mentioning network ports is optional. If some or all ports are not specified, then they will be defaulted to below-mentioned values, except for tserver-ui. - # For tserver-ui a cluster ip service will be created if the yb-tserver-ui port is explicitly mentioned. If it is not specified, only StatefulSet & headless service will be created for TServer. TServer ClusterIP service creation will be skipped. Whereas for Master, all 3 kubernetes objects will always be created. - network: - ports: - - name: yb-tserver-ui - port: 9000 - - name: yb-tserver-rpc - port: 9100 # default value - - name: ycql - port: 9042 # default value - - name: yedis - port: 6379 # default value - - name: ysql - port: 5433 # default value - # Volume claim template for TServer - volumeClaimTemplate: - metadata: - name: datadir - spec: - accessModes: [ "ReadWriteOnce" ] - resources: - requests: - storage: 1Gi - storageClassName: standard -``` -# Cluster Settings - -### Master/TServer -Master & TServer are two essential components of a YugabyteDB cluster. Master is responsible for recording and maintaining system metadata & for admin activities. TServers are mainly responsible for data I/O. -Specify Master/TServer specific attributes under `master`/`tserver`. The valid attributes are `replicas`, `network` & `volumeClaimTemplate`. - -### Replica Count -Specify replica count for `master` & `tserver` pods under `replicas` field. This is a **required** field. - -### Network -`network` field accepts `NetworkSpec` to be specified which describes YugabyteDB network settings. This is an **optional** field. Default network settings will be used, if any or all of the acceptable values are absent. - -A ClusterIP service will be created when `yb-tserver-ui` port is explicitly specified. If it is not specified, only StatefulSet & headless service will be created for TServer. ClusterIP service creation will be skipped. Whereas for Master, all 3 kubernetes objects will always be created. - -The acceptable port names & their default values are as follows: - -| Name | Default Value | -| ---- | ------------- | -| yb-master-ui | 7000 | -| yb-master-rpc | 7100 | -| yb-tserver-rpc | 9100 | -| ycql | 9042 | -| yedis | 6379 | -| ysql | 5433 | - -### Volume Claim Templates -Specify a `PersistentVolumeClaim` template under the `volumeClaimTemplate` field for `master` & `tserver` each. This is a **required** field. - - -# Expected result -Above sample will result in creation on a 3 Master 3 TServer YugabyteDB cluster. The YugabyteDB cluster is backed by following Kubernetes objects, which will be managed by the Rook-YugabyteDB operator. - -|Object|Count| -|------|-----| -|Master UI Service| 1 | -|TServer UI Service| 1 | -|Master Headless Service| 1 | -|TServer Headless Service| 1 | -|Master StatefulSet| 1 | -|TServer StatefulSet| 1 | -|Master Pods| 3 | -|TServer Pods| 3 | \ No newline at end of file diff --git a/images/Makefile b/images/Makefile index 8e55a1c6f7a6..6dd5e3e33d93 100644 --- a/images/Makefile +++ b/images/Makefile @@ -35,9 +35,6 @@ nfs.%: cassandra.%: @$(MAKE) -C cassandra PLATFORM=$* -yugabytedb.%: - @$(MAKE) -C yugabytedb PLATFORM=$* - do.build.images.%: $(foreach i,$(IMAGES), $(i).%); diff --git a/images/yugabytedb/Dockerfile b/images/yugabytedb/Dockerfile deleted file mode 100644 index 78ac9c0db512..000000000000 --- a/images/yugabytedb/Dockerfile +++ /dev/null @@ -1,20 +0,0 @@ -# Copyright 2019 The Rook Authors. All rights reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -FROM yugabytedb/yugabyte:1.3.1.0-b16 - -COPY rook /usr/local/bin/ - -ENTRYPOINT ["/usr/local/bin/rook"] -CMD [""] diff --git a/images/yugabytedb/Makefile b/images/yugabytedb/Makefile deleted file mode 100755 index 4cd9873d06ec..000000000000 --- a/images/yugabytedb/Makefile +++ /dev/null @@ -1,34 +0,0 @@ -# Copyright 2019 The Rook Authors. All rights reserved. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. - -include ../image.mk - -# ==================================================================================== -# Image Build Options - -YUGABYTEDB_IMAGE = $(BUILD_REGISTRY)/yugabytedb-$(GOARCH) - -TEMP := $(shell mktemp -d) - -# ==================================================================================== -# Build Rook YugabyteDB - -do.build: - @echo === container build $(YUGABYTEDB_IMAGE) - @cp Dockerfile $(TEMP) - @cp $(OUTPUT_DIR)/bin/linux_$(GOARCH)/rook $(TEMP) - @$(DOCKERCMD) build $(BUILD_ARGS) \ - -t $(YUGABYTEDB_IMAGE) \ - $(TEMP) - @rm -fr $(TEMP) diff --git a/pkg/apis/yugabytedb.rook.io/register.go b/pkg/apis/yugabytedb.rook.io/register.go deleted file mode 100644 index 25fe8a9f1df1..000000000000 --- a/pkg/apis/yugabytedb.rook.io/register.go +++ /dev/null @@ -1,20 +0,0 @@ -/* -Copyright 2019 The Rook Authors. All rights reserved. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ -package yugabytedbrookio - -const ( - CustomResourceGroupName = "yugabytedb.rook.io" -) diff --git a/pkg/apis/yugabytedb.rook.io/v1alpha1/doc.go b/pkg/apis/yugabytedb.rook.io/v1alpha1/doc.go deleted file mode 100644 index 54df1a537b00..000000000000 --- a/pkg/apis/yugabytedb.rook.io/v1alpha1/doc.go +++ /dev/null @@ -1,21 +0,0 @@ -/* -Copyright 2019 The Rook Authors. All rights reserved. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -// +k8s:deepcopy-gen=package,register - -// Package v1alpha1 is the v1alpha1 version of the API. -// +groupName=yugabytedb.rook.io -package v1alpha1 diff --git a/pkg/apis/yugabytedb.rook.io/v1alpha1/register.go b/pkg/apis/yugabytedb.rook.io/v1alpha1/register.go deleted file mode 100644 index 2b293ef72226..000000000000 --- a/pkg/apis/yugabytedb.rook.io/v1alpha1/register.go +++ /dev/null @@ -1,61 +0,0 @@ -/* -Copyright 2019 The Rook Authors. All rights reserved. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ -package v1alpha1 - -import ( - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/runtime" - "k8s.io/apimachinery/pkg/runtime/schema" - - yugabytedbrookio "github.com/rook/rook/pkg/apis/yugabytedb.rook.io" -) - -const ( - CustomResourceGroup = "yugabytedb.rook.io" - Version = "v1alpha1" -) - -// Group version used to register these objects -var SchemeGroupVersion = schema.GroupVersion{Group: yugabytedbrookio.CustomResourceGroupName, Version: Version} - -// Resource takes an unqualified resource and returns a Group qualified GroupResource -func Resource(resource string) schema.GroupResource { - return SchemeGroupVersion.WithResource(resource).GroupResource() -} - -var ( - // SchemeBuilder and AddToScheme will stay in k8s.io/kubernetes. - SchemeBuilder runtime.SchemeBuilder - localSchemeBuilder = &SchemeBuilder - AddToScheme = localSchemeBuilder.AddToScheme -) - -func init() { - // We only register manually written functions here. The registration of the - // generated functions takes place in the generated files. The separation - // makes the code compile even when the generated files are missing. - localSchemeBuilder.Register(addKnownTypes) -} - -// Adds the list of known types to api.Scheme. -func addKnownTypes(scheme *runtime.Scheme) error { - scheme.AddKnownTypes(SchemeGroupVersion, - &YBCluster{}, - &YBClusterList{}, - ) - metav1.AddToGroupVersion(scheme, SchemeGroupVersion) - return nil -} diff --git a/pkg/apis/yugabytedb.rook.io/v1alpha1/types.go b/pkg/apis/yugabytedb.rook.io/v1alpha1/types.go deleted file mode 100644 index 60dd6d77f34b..000000000000 --- a/pkg/apis/yugabytedb.rook.io/v1alpha1/types.go +++ /dev/null @@ -1,74 +0,0 @@ -/* -Copyright 2019 The Rook Authors. All rights reserved. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ -package v1alpha1 - -import ( - v1 "k8s.io/api/core/v1" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - - rook "github.com/rook/rook/pkg/apis/rook.io/v1" -) - -// *************************************************************************** -// IMPORTANT FOR CODE GENERATION -// If the types in this file are updated, you will need to run -// `make codegen` to generate the new types under the client/clientset folder. -// *************************************************************************** - -// +genclient -// +genclient:noStatus -// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object - -type YBCluster struct { - metav1.TypeMeta `json:",inline"` - metav1.ObjectMeta `json:"metadata"` - Spec YBClusterSpec `json:"spec"` -} - -// +k8s:deepcopy-gen:interfaces=k8s.io/apimachinery/pkg/runtime.Object - -type YBClusterList struct { - metav1.TypeMeta `json:",inline"` - metav1.ListMeta `json:"metadata"` - Items []YBCluster `json:"items"` -} - -type YBClusterSpec struct { - Annotations rook.Annotations `json:"annotations,omitempty"` - Master ServerSpec `json:"master"` - TServer ServerSpec `json:"tserver"` -} - -type ServerSpec struct { - Replicas int32 `json:"replicas,omitempty"` - Resource v1.ResourceRequirements `json:"resource,omitempty"` - Network NetworkSpec `json:"network,omitempty"` - VolumeClaimTemplate v1.PersistentVolumeClaim `json:"volumeClaimTemplate,omitempty"` -} - -// NetworkSpec describes network related settings of the cluster -type NetworkSpec struct { - // Set of named ports that can be configured for this resource - Ports []PortSpec `json:"ports,omitempty"` -} - -// PortSpec is named port -type PortSpec struct { - // Name of port - Name string `json:"name,omitempty"` - // Port number - Port int32 `json:"port,omitempty"` -} diff --git a/pkg/apis/yugabytedb.rook.io/v1alpha1/zz_generated.deepcopy.go b/pkg/apis/yugabytedb.rook.io/v1alpha1/zz_generated.deepcopy.go deleted file mode 100644 index 10220a7d5df0..000000000000 --- a/pkg/apis/yugabytedb.rook.io/v1alpha1/zz_generated.deepcopy.go +++ /dev/null @@ -1,167 +0,0 @@ -// +build !ignore_autogenerated - -/* -Copyright The Kubernetes Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -// Code generated by deepcopy-gen. DO NOT EDIT. - -package v1alpha1 - -import ( - v1 "github.com/rook/rook/pkg/apis/rook.io/v1" - runtime "k8s.io/apimachinery/pkg/runtime" -) - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *NetworkSpec) DeepCopyInto(out *NetworkSpec) { - *out = *in - if in.Ports != nil { - in, out := &in.Ports, &out.Ports - *out = make([]PortSpec, len(*in)) - copy(*out, *in) - } - return -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new NetworkSpec. -func (in *NetworkSpec) DeepCopy() *NetworkSpec { - if in == nil { - return nil - } - out := new(NetworkSpec) - in.DeepCopyInto(out) - return out -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *PortSpec) DeepCopyInto(out *PortSpec) { - *out = *in - return -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new PortSpec. -func (in *PortSpec) DeepCopy() *PortSpec { - if in == nil { - return nil - } - out := new(PortSpec) - in.DeepCopyInto(out) - return out -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *ServerSpec) DeepCopyInto(out *ServerSpec) { - *out = *in - in.Resource.DeepCopyInto(&out.Resource) - in.Network.DeepCopyInto(&out.Network) - in.VolumeClaimTemplate.DeepCopyInto(&out.VolumeClaimTemplate) - return -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new ServerSpec. -func (in *ServerSpec) DeepCopy() *ServerSpec { - if in == nil { - return nil - } - out := new(ServerSpec) - in.DeepCopyInto(out) - return out -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *YBCluster) DeepCopyInto(out *YBCluster) { - *out = *in - out.TypeMeta = in.TypeMeta - in.ObjectMeta.DeepCopyInto(&out.ObjectMeta) - in.Spec.DeepCopyInto(&out.Spec) - return -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new YBCluster. -func (in *YBCluster) DeepCopy() *YBCluster { - if in == nil { - return nil - } - out := new(YBCluster) - in.DeepCopyInto(out) - return out -} - -// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. -func (in *YBCluster) DeepCopyObject() runtime.Object { - if c := in.DeepCopy(); c != nil { - return c - } - return nil -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *YBClusterList) DeepCopyInto(out *YBClusterList) { - *out = *in - out.TypeMeta = in.TypeMeta - in.ListMeta.DeepCopyInto(&out.ListMeta) - if in.Items != nil { - in, out := &in.Items, &out.Items - *out = make([]YBCluster, len(*in)) - for i := range *in { - (*in)[i].DeepCopyInto(&(*out)[i]) - } - } - return -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new YBClusterList. -func (in *YBClusterList) DeepCopy() *YBClusterList { - if in == nil { - return nil - } - out := new(YBClusterList) - in.DeepCopyInto(out) - return out -} - -// DeepCopyObject is an autogenerated deepcopy function, copying the receiver, creating a new runtime.Object. -func (in *YBClusterList) DeepCopyObject() runtime.Object { - if c := in.DeepCopy(); c != nil { - return c - } - return nil -} - -// DeepCopyInto is an autogenerated deepcopy function, copying the receiver, writing into out. in must be non-nil. -func (in *YBClusterSpec) DeepCopyInto(out *YBClusterSpec) { - *out = *in - if in.Annotations != nil { - in, out := &in.Annotations, &out.Annotations - *out = make(v1.Annotations, len(*in)) - for key, val := range *in { - (*out)[key] = val - } - } - in.Master.DeepCopyInto(&out.Master) - in.TServer.DeepCopyInto(&out.TServer) - return -} - -// DeepCopy is an autogenerated deepcopy function, copying the receiver, creating a new YBClusterSpec. -func (in *YBClusterSpec) DeepCopy() *YBClusterSpec { - if in == nil { - return nil - } - out := new(YBClusterSpec) - in.DeepCopyInto(out) - return out -} diff --git a/pkg/client/clientset/versioned/clientset.go b/pkg/client/clientset/versioned/clientset.go index a1547134a9ec..e04076da4cc7 100644 --- a/pkg/client/clientset/versioned/clientset.go +++ b/pkg/client/clientset/versioned/clientset.go @@ -26,7 +26,6 @@ import ( nfsv1alpha1 "github.com/rook/rook/pkg/client/clientset/versioned/typed/nfs.rook.io/v1alpha1" rookv1 "github.com/rook/rook/pkg/client/clientset/versioned/typed/rook.io/v1" rookv1alpha2 "github.com/rook/rook/pkg/client/clientset/versioned/typed/rook.io/v1alpha2" - yugabytedbv1alpha1 "github.com/rook/rook/pkg/client/clientset/versioned/typed/yugabytedb.rook.io/v1alpha1" discovery "k8s.io/client-go/discovery" rest "k8s.io/client-go/rest" flowcontrol "k8s.io/client-go/util/flowcontrol" @@ -39,19 +38,17 @@ type Interface interface { NfsV1alpha1() nfsv1alpha1.NfsV1alpha1Interface RookV1() rookv1.RookV1Interface RookV1alpha2() rookv1alpha2.RookV1alpha2Interface - YugabytedbV1alpha1() yugabytedbv1alpha1.YugabytedbV1alpha1Interface } // Clientset contains the clients for groups. Each group has exactly one // version included in a Clientset. type Clientset struct { *discovery.DiscoveryClient - cassandraV1alpha1 *cassandrav1alpha1.CassandraV1alpha1Client - cephV1 *cephv1.CephV1Client - nfsV1alpha1 *nfsv1alpha1.NfsV1alpha1Client - rookV1 *rookv1.RookV1Client - rookV1alpha2 *rookv1alpha2.RookV1alpha2Client - yugabytedbV1alpha1 *yugabytedbv1alpha1.YugabytedbV1alpha1Client + cassandraV1alpha1 *cassandrav1alpha1.CassandraV1alpha1Client + cephV1 *cephv1.CephV1Client + nfsV1alpha1 *nfsv1alpha1.NfsV1alpha1Client + rookV1 *rookv1.RookV1Client + rookV1alpha2 *rookv1alpha2.RookV1alpha2Client } // CassandraV1alpha1 retrieves the CassandraV1alpha1Client @@ -79,11 +76,6 @@ func (c *Clientset) RookV1alpha2() rookv1alpha2.RookV1alpha2Interface { return c.rookV1alpha2 } -// YugabytedbV1alpha1 retrieves the YugabytedbV1alpha1Client -func (c *Clientset) YugabytedbV1alpha1() yugabytedbv1alpha1.YugabytedbV1alpha1Interface { - return c.yugabytedbV1alpha1 -} - // Discovery retrieves the DiscoveryClient func (c *Clientset) Discovery() discovery.DiscoveryInterface { if c == nil { @@ -125,10 +117,6 @@ func NewForConfig(c *rest.Config) (*Clientset, error) { if err != nil { return nil, err } - cs.yugabytedbV1alpha1, err = yugabytedbv1alpha1.NewForConfig(&configShallowCopy) - if err != nil { - return nil, err - } cs.DiscoveryClient, err = discovery.NewDiscoveryClientForConfig(&configShallowCopy) if err != nil { @@ -146,7 +134,6 @@ func NewForConfigOrDie(c *rest.Config) *Clientset { cs.nfsV1alpha1 = nfsv1alpha1.NewForConfigOrDie(c) cs.rookV1 = rookv1.NewForConfigOrDie(c) cs.rookV1alpha2 = rookv1alpha2.NewForConfigOrDie(c) - cs.yugabytedbV1alpha1 = yugabytedbv1alpha1.NewForConfigOrDie(c) cs.DiscoveryClient = discovery.NewDiscoveryClientForConfigOrDie(c) return &cs @@ -160,7 +147,6 @@ func New(c rest.Interface) *Clientset { cs.nfsV1alpha1 = nfsv1alpha1.New(c) cs.rookV1 = rookv1.New(c) cs.rookV1alpha2 = rookv1alpha2.New(c) - cs.yugabytedbV1alpha1 = yugabytedbv1alpha1.New(c) cs.DiscoveryClient = discovery.NewDiscoveryClient(c) return &cs diff --git a/pkg/client/clientset/versioned/fake/clientset_generated.go b/pkg/client/clientset/versioned/fake/clientset_generated.go index 7202f412a087..084d6415b996 100644 --- a/pkg/client/clientset/versioned/fake/clientset_generated.go +++ b/pkg/client/clientset/versioned/fake/clientset_generated.go @@ -30,8 +30,6 @@ import ( fakerookv1 "github.com/rook/rook/pkg/client/clientset/versioned/typed/rook.io/v1/fake" rookv1alpha2 "github.com/rook/rook/pkg/client/clientset/versioned/typed/rook.io/v1alpha2" fakerookv1alpha2 "github.com/rook/rook/pkg/client/clientset/versioned/typed/rook.io/v1alpha2/fake" - yugabytedbv1alpha1 "github.com/rook/rook/pkg/client/clientset/versioned/typed/yugabytedb.rook.io/v1alpha1" - fakeyugabytedbv1alpha1 "github.com/rook/rook/pkg/client/clientset/versioned/typed/yugabytedb.rook.io/v1alpha1/fake" "k8s.io/apimachinery/pkg/runtime" "k8s.io/apimachinery/pkg/watch" "k8s.io/client-go/discovery" @@ -110,8 +108,3 @@ func (c *Clientset) RookV1() rookv1.RookV1Interface { func (c *Clientset) RookV1alpha2() rookv1alpha2.RookV1alpha2Interface { return &fakerookv1alpha2.FakeRookV1alpha2{Fake: &c.Fake} } - -// YugabytedbV1alpha1 retrieves the YugabytedbV1alpha1Client -func (c *Clientset) YugabytedbV1alpha1() yugabytedbv1alpha1.YugabytedbV1alpha1Interface { - return &fakeyugabytedbv1alpha1.FakeYugabytedbV1alpha1{Fake: &c.Fake} -} diff --git a/pkg/client/clientset/versioned/fake/register.go b/pkg/client/clientset/versioned/fake/register.go index 70d2a4ef99d1..9f8b8807f298 100644 --- a/pkg/client/clientset/versioned/fake/register.go +++ b/pkg/client/clientset/versioned/fake/register.go @@ -24,7 +24,6 @@ import ( nfsv1alpha1 "github.com/rook/rook/pkg/apis/nfs.rook.io/v1alpha1" rookv1 "github.com/rook/rook/pkg/apis/rook.io/v1" rookv1alpha2 "github.com/rook/rook/pkg/apis/rook.io/v1alpha2" - yugabytedbv1alpha1 "github.com/rook/rook/pkg/apis/yugabytedb.rook.io/v1alpha1" v1 "k8s.io/apimachinery/pkg/apis/meta/v1" runtime "k8s.io/apimachinery/pkg/runtime" schema "k8s.io/apimachinery/pkg/runtime/schema" @@ -41,7 +40,6 @@ var localSchemeBuilder = runtime.SchemeBuilder{ nfsv1alpha1.AddToScheme, rookv1.AddToScheme, rookv1alpha2.AddToScheme, - yugabytedbv1alpha1.AddToScheme, } // AddToScheme adds all types of this clientset into the given scheme. This allows composition diff --git a/pkg/client/clientset/versioned/scheme/register.go b/pkg/client/clientset/versioned/scheme/register.go index 7fd90189b1c3..ef495bb2bb64 100644 --- a/pkg/client/clientset/versioned/scheme/register.go +++ b/pkg/client/clientset/versioned/scheme/register.go @@ -24,7 +24,6 @@ import ( nfsv1alpha1 "github.com/rook/rook/pkg/apis/nfs.rook.io/v1alpha1" rookv1 "github.com/rook/rook/pkg/apis/rook.io/v1" rookv1alpha2 "github.com/rook/rook/pkg/apis/rook.io/v1alpha2" - yugabytedbv1alpha1 "github.com/rook/rook/pkg/apis/yugabytedb.rook.io/v1alpha1" v1 "k8s.io/apimachinery/pkg/apis/meta/v1" runtime "k8s.io/apimachinery/pkg/runtime" schema "k8s.io/apimachinery/pkg/runtime/schema" @@ -41,7 +40,6 @@ var localSchemeBuilder = runtime.SchemeBuilder{ nfsv1alpha1.AddToScheme, rookv1.AddToScheme, rookv1alpha2.AddToScheme, - yugabytedbv1alpha1.AddToScheme, } // AddToScheme adds all types of this clientset into the given scheme. This allows composition diff --git a/pkg/client/clientset/versioned/typed/yugabytedb.rook.io/v1alpha1/doc.go b/pkg/client/clientset/versioned/typed/yugabytedb.rook.io/v1alpha1/doc.go deleted file mode 100644 index df51baa4d4c1..000000000000 --- a/pkg/client/clientset/versioned/typed/yugabytedb.rook.io/v1alpha1/doc.go +++ /dev/null @@ -1,20 +0,0 @@ -/* -Copyright The Kubernetes Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -// Code generated by client-gen. DO NOT EDIT. - -// This package has the automatically generated typed clients. -package v1alpha1 diff --git a/pkg/client/clientset/versioned/typed/yugabytedb.rook.io/v1alpha1/fake/doc.go b/pkg/client/clientset/versioned/typed/yugabytedb.rook.io/v1alpha1/fake/doc.go deleted file mode 100644 index 16f44399065e..000000000000 --- a/pkg/client/clientset/versioned/typed/yugabytedb.rook.io/v1alpha1/fake/doc.go +++ /dev/null @@ -1,20 +0,0 @@ -/* -Copyright The Kubernetes Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -// Code generated by client-gen. DO NOT EDIT. - -// Package fake has the automatically generated clients. -package fake diff --git a/pkg/client/clientset/versioned/typed/yugabytedb.rook.io/v1alpha1/fake/fake_ybcluster.go b/pkg/client/clientset/versioned/typed/yugabytedb.rook.io/v1alpha1/fake/fake_ybcluster.go deleted file mode 100644 index 2cfde6230900..000000000000 --- a/pkg/client/clientset/versioned/typed/yugabytedb.rook.io/v1alpha1/fake/fake_ybcluster.go +++ /dev/null @@ -1,130 +0,0 @@ -/* -Copyright The Kubernetes Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -// Code generated by client-gen. DO NOT EDIT. - -package fake - -import ( - "context" - - v1alpha1 "github.com/rook/rook/pkg/apis/yugabytedb.rook.io/v1alpha1" - v1 "k8s.io/apimachinery/pkg/apis/meta/v1" - labels "k8s.io/apimachinery/pkg/labels" - schema "k8s.io/apimachinery/pkg/runtime/schema" - types "k8s.io/apimachinery/pkg/types" - watch "k8s.io/apimachinery/pkg/watch" - testing "k8s.io/client-go/testing" -) - -// FakeYBClusters implements YBClusterInterface -type FakeYBClusters struct { - Fake *FakeYugabytedbV1alpha1 - ns string -} - -var ybclustersResource = schema.GroupVersionResource{Group: "yugabytedb.rook.io", Version: "v1alpha1", Resource: "ybclusters"} - -var ybclustersKind = schema.GroupVersionKind{Group: "yugabytedb.rook.io", Version: "v1alpha1", Kind: "YBCluster"} - -// Get takes name of the yBCluster, and returns the corresponding yBCluster object, and an error if there is any. -func (c *FakeYBClusters) Get(ctx context.Context, name string, options v1.GetOptions) (result *v1alpha1.YBCluster, err error) { - obj, err := c.Fake. - Invokes(testing.NewGetAction(ybclustersResource, c.ns, name), &v1alpha1.YBCluster{}) - - if obj == nil { - return nil, err - } - return obj.(*v1alpha1.YBCluster), err -} - -// List takes label and field selectors, and returns the list of YBClusters that match those selectors. -func (c *FakeYBClusters) List(ctx context.Context, opts v1.ListOptions) (result *v1alpha1.YBClusterList, err error) { - obj, err := c.Fake. - Invokes(testing.NewListAction(ybclustersResource, ybclustersKind, c.ns, opts), &v1alpha1.YBClusterList{}) - - if obj == nil { - return nil, err - } - - label, _, _ := testing.ExtractFromListOptions(opts) - if label == nil { - label = labels.Everything() - } - list := &v1alpha1.YBClusterList{ListMeta: obj.(*v1alpha1.YBClusterList).ListMeta} - for _, item := range obj.(*v1alpha1.YBClusterList).Items { - if label.Matches(labels.Set(item.Labels)) { - list.Items = append(list.Items, item) - } - } - return list, err -} - -// Watch returns a watch.Interface that watches the requested yBClusters. -func (c *FakeYBClusters) Watch(ctx context.Context, opts v1.ListOptions) (watch.Interface, error) { - return c.Fake. - InvokesWatch(testing.NewWatchAction(ybclustersResource, c.ns, opts)) - -} - -// Create takes the representation of a yBCluster and creates it. Returns the server's representation of the yBCluster, and an error, if there is any. -func (c *FakeYBClusters) Create(ctx context.Context, yBCluster *v1alpha1.YBCluster, opts v1.CreateOptions) (result *v1alpha1.YBCluster, err error) { - obj, err := c.Fake. - Invokes(testing.NewCreateAction(ybclustersResource, c.ns, yBCluster), &v1alpha1.YBCluster{}) - - if obj == nil { - return nil, err - } - return obj.(*v1alpha1.YBCluster), err -} - -// Update takes the representation of a yBCluster and updates it. Returns the server's representation of the yBCluster, and an error, if there is any. -func (c *FakeYBClusters) Update(ctx context.Context, yBCluster *v1alpha1.YBCluster, opts v1.UpdateOptions) (result *v1alpha1.YBCluster, err error) { - obj, err := c.Fake. - Invokes(testing.NewUpdateAction(ybclustersResource, c.ns, yBCluster), &v1alpha1.YBCluster{}) - - if obj == nil { - return nil, err - } - return obj.(*v1alpha1.YBCluster), err -} - -// Delete takes name of the yBCluster and deletes it. Returns an error if one occurs. -func (c *FakeYBClusters) Delete(ctx context.Context, name string, opts v1.DeleteOptions) error { - _, err := c.Fake. - Invokes(testing.NewDeleteAction(ybclustersResource, c.ns, name), &v1alpha1.YBCluster{}) - - return err -} - -// DeleteCollection deletes a collection of objects. -func (c *FakeYBClusters) DeleteCollection(ctx context.Context, opts v1.DeleteOptions, listOpts v1.ListOptions) error { - action := testing.NewDeleteCollectionAction(ybclustersResource, c.ns, listOpts) - - _, err := c.Fake.Invokes(action, &v1alpha1.YBClusterList{}) - return err -} - -// Patch applies the patch and returns the patched yBCluster. -func (c *FakeYBClusters) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts v1.PatchOptions, subresources ...string) (result *v1alpha1.YBCluster, err error) { - obj, err := c.Fake. - Invokes(testing.NewPatchSubresourceAction(ybclustersResource, c.ns, name, pt, data, subresources...), &v1alpha1.YBCluster{}) - - if obj == nil { - return nil, err - } - return obj.(*v1alpha1.YBCluster), err -} diff --git a/pkg/client/clientset/versioned/typed/yugabytedb.rook.io/v1alpha1/fake/fake_yugabytedb.rook.io_client.go b/pkg/client/clientset/versioned/typed/yugabytedb.rook.io/v1alpha1/fake/fake_yugabytedb.rook.io_client.go deleted file mode 100644 index e29e6c29f745..000000000000 --- a/pkg/client/clientset/versioned/typed/yugabytedb.rook.io/v1alpha1/fake/fake_yugabytedb.rook.io_client.go +++ /dev/null @@ -1,40 +0,0 @@ -/* -Copyright The Kubernetes Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -// Code generated by client-gen. DO NOT EDIT. - -package fake - -import ( - v1alpha1 "github.com/rook/rook/pkg/client/clientset/versioned/typed/yugabytedb.rook.io/v1alpha1" - rest "k8s.io/client-go/rest" - testing "k8s.io/client-go/testing" -) - -type FakeYugabytedbV1alpha1 struct { - *testing.Fake -} - -func (c *FakeYugabytedbV1alpha1) YBClusters(namespace string) v1alpha1.YBClusterInterface { - return &FakeYBClusters{c, namespace} -} - -// RESTClient returns a RESTClient that is used to communicate -// with API server by this client implementation. -func (c *FakeYugabytedbV1alpha1) RESTClient() rest.Interface { - var ret *rest.RESTClient - return ret -} diff --git a/pkg/client/clientset/versioned/typed/yugabytedb.rook.io/v1alpha1/generated_expansion.go b/pkg/client/clientset/versioned/typed/yugabytedb.rook.io/v1alpha1/generated_expansion.go deleted file mode 100644 index 861e36933ebf..000000000000 --- a/pkg/client/clientset/versioned/typed/yugabytedb.rook.io/v1alpha1/generated_expansion.go +++ /dev/null @@ -1,21 +0,0 @@ -/* -Copyright The Kubernetes Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -// Code generated by client-gen. DO NOT EDIT. - -package v1alpha1 - -type YBClusterExpansion interface{} diff --git a/pkg/client/clientset/versioned/typed/yugabytedb.rook.io/v1alpha1/ybcluster.go b/pkg/client/clientset/versioned/typed/yugabytedb.rook.io/v1alpha1/ybcluster.go deleted file mode 100644 index ccc9094adec3..000000000000 --- a/pkg/client/clientset/versioned/typed/yugabytedb.rook.io/v1alpha1/ybcluster.go +++ /dev/null @@ -1,178 +0,0 @@ -/* -Copyright The Kubernetes Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -// Code generated by client-gen. DO NOT EDIT. - -package v1alpha1 - -import ( - "context" - "time" - - v1alpha1 "github.com/rook/rook/pkg/apis/yugabytedb.rook.io/v1alpha1" - scheme "github.com/rook/rook/pkg/client/clientset/versioned/scheme" - v1 "k8s.io/apimachinery/pkg/apis/meta/v1" - types "k8s.io/apimachinery/pkg/types" - watch "k8s.io/apimachinery/pkg/watch" - rest "k8s.io/client-go/rest" -) - -// YBClustersGetter has a method to return a YBClusterInterface. -// A group's client should implement this interface. -type YBClustersGetter interface { - YBClusters(namespace string) YBClusterInterface -} - -// YBClusterInterface has methods to work with YBCluster resources. -type YBClusterInterface interface { - Create(ctx context.Context, yBCluster *v1alpha1.YBCluster, opts v1.CreateOptions) (*v1alpha1.YBCluster, error) - Update(ctx context.Context, yBCluster *v1alpha1.YBCluster, opts v1.UpdateOptions) (*v1alpha1.YBCluster, error) - Delete(ctx context.Context, name string, opts v1.DeleteOptions) error - DeleteCollection(ctx context.Context, opts v1.DeleteOptions, listOpts v1.ListOptions) error - Get(ctx context.Context, name string, opts v1.GetOptions) (*v1alpha1.YBCluster, error) - List(ctx context.Context, opts v1.ListOptions) (*v1alpha1.YBClusterList, error) - Watch(ctx context.Context, opts v1.ListOptions) (watch.Interface, error) - Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts v1.PatchOptions, subresources ...string) (result *v1alpha1.YBCluster, err error) - YBClusterExpansion -} - -// yBClusters implements YBClusterInterface -type yBClusters struct { - client rest.Interface - ns string -} - -// newYBClusters returns a YBClusters -func newYBClusters(c *YugabytedbV1alpha1Client, namespace string) *yBClusters { - return &yBClusters{ - client: c.RESTClient(), - ns: namespace, - } -} - -// Get takes name of the yBCluster, and returns the corresponding yBCluster object, and an error if there is any. -func (c *yBClusters) Get(ctx context.Context, name string, options v1.GetOptions) (result *v1alpha1.YBCluster, err error) { - result = &v1alpha1.YBCluster{} - err = c.client.Get(). - Namespace(c.ns). - Resource("ybclusters"). - Name(name). - VersionedParams(&options, scheme.ParameterCodec). - Do(ctx). - Into(result) - return -} - -// List takes label and field selectors, and returns the list of YBClusters that match those selectors. -func (c *yBClusters) List(ctx context.Context, opts v1.ListOptions) (result *v1alpha1.YBClusterList, err error) { - var timeout time.Duration - if opts.TimeoutSeconds != nil { - timeout = time.Duration(*opts.TimeoutSeconds) * time.Second - } - result = &v1alpha1.YBClusterList{} - err = c.client.Get(). - Namespace(c.ns). - Resource("ybclusters"). - VersionedParams(&opts, scheme.ParameterCodec). - Timeout(timeout). - Do(ctx). - Into(result) - return -} - -// Watch returns a watch.Interface that watches the requested yBClusters. -func (c *yBClusters) Watch(ctx context.Context, opts v1.ListOptions) (watch.Interface, error) { - var timeout time.Duration - if opts.TimeoutSeconds != nil { - timeout = time.Duration(*opts.TimeoutSeconds) * time.Second - } - opts.Watch = true - return c.client.Get(). - Namespace(c.ns). - Resource("ybclusters"). - VersionedParams(&opts, scheme.ParameterCodec). - Timeout(timeout). - Watch(ctx) -} - -// Create takes the representation of a yBCluster and creates it. Returns the server's representation of the yBCluster, and an error, if there is any. -func (c *yBClusters) Create(ctx context.Context, yBCluster *v1alpha1.YBCluster, opts v1.CreateOptions) (result *v1alpha1.YBCluster, err error) { - result = &v1alpha1.YBCluster{} - err = c.client.Post(). - Namespace(c.ns). - Resource("ybclusters"). - VersionedParams(&opts, scheme.ParameterCodec). - Body(yBCluster). - Do(ctx). - Into(result) - return -} - -// Update takes the representation of a yBCluster and updates it. Returns the server's representation of the yBCluster, and an error, if there is any. -func (c *yBClusters) Update(ctx context.Context, yBCluster *v1alpha1.YBCluster, opts v1.UpdateOptions) (result *v1alpha1.YBCluster, err error) { - result = &v1alpha1.YBCluster{} - err = c.client.Put(). - Namespace(c.ns). - Resource("ybclusters"). - Name(yBCluster.Name). - VersionedParams(&opts, scheme.ParameterCodec). - Body(yBCluster). - Do(ctx). - Into(result) - return -} - -// Delete takes name of the yBCluster and deletes it. Returns an error if one occurs. -func (c *yBClusters) Delete(ctx context.Context, name string, opts v1.DeleteOptions) error { - return c.client.Delete(). - Namespace(c.ns). - Resource("ybclusters"). - Name(name). - Body(&opts). - Do(ctx). - Error() -} - -// DeleteCollection deletes a collection of objects. -func (c *yBClusters) DeleteCollection(ctx context.Context, opts v1.DeleteOptions, listOpts v1.ListOptions) error { - var timeout time.Duration - if listOpts.TimeoutSeconds != nil { - timeout = time.Duration(*listOpts.TimeoutSeconds) * time.Second - } - return c.client.Delete(). - Namespace(c.ns). - Resource("ybclusters"). - VersionedParams(&listOpts, scheme.ParameterCodec). - Timeout(timeout). - Body(&opts). - Do(ctx). - Error() -} - -// Patch applies the patch and returns the patched yBCluster. -func (c *yBClusters) Patch(ctx context.Context, name string, pt types.PatchType, data []byte, opts v1.PatchOptions, subresources ...string) (result *v1alpha1.YBCluster, err error) { - result = &v1alpha1.YBCluster{} - err = c.client.Patch(pt). - Namespace(c.ns). - Resource("ybclusters"). - Name(name). - SubResource(subresources...). - VersionedParams(&opts, scheme.ParameterCodec). - Body(data). - Do(ctx). - Into(result) - return -} diff --git a/pkg/client/clientset/versioned/typed/yugabytedb.rook.io/v1alpha1/yugabytedb.rook.io_client.go b/pkg/client/clientset/versioned/typed/yugabytedb.rook.io/v1alpha1/yugabytedb.rook.io_client.go deleted file mode 100644 index cc1b403b2a2a..000000000000 --- a/pkg/client/clientset/versioned/typed/yugabytedb.rook.io/v1alpha1/yugabytedb.rook.io_client.go +++ /dev/null @@ -1,89 +0,0 @@ -/* -Copyright The Kubernetes Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -// Code generated by client-gen. DO NOT EDIT. - -package v1alpha1 - -import ( - v1alpha1 "github.com/rook/rook/pkg/apis/yugabytedb.rook.io/v1alpha1" - "github.com/rook/rook/pkg/client/clientset/versioned/scheme" - rest "k8s.io/client-go/rest" -) - -type YugabytedbV1alpha1Interface interface { - RESTClient() rest.Interface - YBClustersGetter -} - -// YugabytedbV1alpha1Client is used to interact with features provided by the yugabytedb.rook.io group. -type YugabytedbV1alpha1Client struct { - restClient rest.Interface -} - -func (c *YugabytedbV1alpha1Client) YBClusters(namespace string) YBClusterInterface { - return newYBClusters(c, namespace) -} - -// NewForConfig creates a new YugabytedbV1alpha1Client for the given config. -func NewForConfig(c *rest.Config) (*YugabytedbV1alpha1Client, error) { - config := *c - if err := setConfigDefaults(&config); err != nil { - return nil, err - } - client, err := rest.RESTClientFor(&config) - if err != nil { - return nil, err - } - return &YugabytedbV1alpha1Client{client}, nil -} - -// NewForConfigOrDie creates a new YugabytedbV1alpha1Client for the given config and -// panics if there is an error in the config. -func NewForConfigOrDie(c *rest.Config) *YugabytedbV1alpha1Client { - client, err := NewForConfig(c) - if err != nil { - panic(err) - } - return client -} - -// New creates a new YugabytedbV1alpha1Client for the given RESTClient. -func New(c rest.Interface) *YugabytedbV1alpha1Client { - return &YugabytedbV1alpha1Client{c} -} - -func setConfigDefaults(config *rest.Config) error { - gv := v1alpha1.SchemeGroupVersion - config.GroupVersion = &gv - config.APIPath = "/apis" - config.NegotiatedSerializer = scheme.Codecs.WithoutConversion() - - if config.UserAgent == "" { - config.UserAgent = rest.DefaultKubernetesUserAgent() - } - - return nil -} - -// RESTClient returns a RESTClient that is used to communicate -// with API server by this client implementation. -func (c *YugabytedbV1alpha1Client) RESTClient() rest.Interface { - if c == nil { - return nil - } - return c.restClient -} diff --git a/pkg/client/informers/externalversions/factory.go b/pkg/client/informers/externalversions/factory.go index 1cc5bacd50db..ca31ecada5ad 100644 --- a/pkg/client/informers/externalversions/factory.go +++ b/pkg/client/informers/externalversions/factory.go @@ -29,7 +29,6 @@ import ( internalinterfaces "github.com/rook/rook/pkg/client/informers/externalversions/internalinterfaces" nfsrookio "github.com/rook/rook/pkg/client/informers/externalversions/nfs.rook.io" rookio "github.com/rook/rook/pkg/client/informers/externalversions/rook.io" - yugabytedbrookio "github.com/rook/rook/pkg/client/informers/externalversions/yugabytedb.rook.io" v1 "k8s.io/apimachinery/pkg/apis/meta/v1" runtime "k8s.io/apimachinery/pkg/runtime" schema "k8s.io/apimachinery/pkg/runtime/schema" @@ -180,7 +179,6 @@ type SharedInformerFactory interface { Ceph() cephrookio.Interface Nfs() nfsrookio.Interface Rook() rookio.Interface - Yugabytedb() yugabytedbrookio.Interface } func (f *sharedInformerFactory) Cassandra() cassandrarookio.Interface { @@ -198,7 +196,3 @@ func (f *sharedInformerFactory) Nfs() nfsrookio.Interface { func (f *sharedInformerFactory) Rook() rookio.Interface { return rookio.New(f, f.namespace, f.tweakListOptions) } - -func (f *sharedInformerFactory) Yugabytedb() yugabytedbrookio.Interface { - return yugabytedbrookio.New(f, f.namespace, f.tweakListOptions) -} diff --git a/pkg/client/informers/externalversions/generic.go b/pkg/client/informers/externalversions/generic.go index 1002b4d7527d..98a981182151 100644 --- a/pkg/client/informers/externalversions/generic.go +++ b/pkg/client/informers/externalversions/generic.go @@ -25,7 +25,6 @@ import ( v1 "github.com/rook/rook/pkg/apis/ceph.rook.io/v1" nfsrookiov1alpha1 "github.com/rook/rook/pkg/apis/nfs.rook.io/v1alpha1" v1alpha2 "github.com/rook/rook/pkg/apis/rook.io/v1alpha2" - yugabytedbrookiov1alpha1 "github.com/rook/rook/pkg/apis/yugabytedb.rook.io/v1alpha1" schema "k8s.io/apimachinery/pkg/runtime/schema" cache "k8s.io/client-go/tools/cache" ) @@ -94,10 +93,6 @@ func (f *sharedInformerFactory) ForResource(resource schema.GroupVersionResource case v1alpha2.SchemeGroupVersion.WithResource("volumes"): return &genericInformer{resource: resource.GroupResource(), informer: f.Rook().V1alpha2().Volumes().Informer()}, nil - // Group=yugabytedb.rook.io, Version=v1alpha1 - case yugabytedbrookiov1alpha1.SchemeGroupVersion.WithResource("ybclusters"): - return &genericInformer{resource: resource.GroupResource(), informer: f.Yugabytedb().V1alpha1().YBClusters().Informer()}, nil - } return nil, fmt.Errorf("no informer found for %v", resource) diff --git a/pkg/client/informers/externalversions/yugabytedb.rook.io/interface.go b/pkg/client/informers/externalversions/yugabytedb.rook.io/interface.go deleted file mode 100644 index 2425aa9cb725..000000000000 --- a/pkg/client/informers/externalversions/yugabytedb.rook.io/interface.go +++ /dev/null @@ -1,46 +0,0 @@ -/* -Copyright The Kubernetes Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -// Code generated by informer-gen. DO NOT EDIT. - -package yugabytedb - -import ( - internalinterfaces "github.com/rook/rook/pkg/client/informers/externalversions/internalinterfaces" - v1alpha1 "github.com/rook/rook/pkg/client/informers/externalversions/yugabytedb.rook.io/v1alpha1" -) - -// Interface provides access to each of this group's versions. -type Interface interface { - // V1alpha1 provides access to shared informers for resources in V1alpha1. - V1alpha1() v1alpha1.Interface -} - -type group struct { - factory internalinterfaces.SharedInformerFactory - namespace string - tweakListOptions internalinterfaces.TweakListOptionsFunc -} - -// New returns a new Interface. -func New(f internalinterfaces.SharedInformerFactory, namespace string, tweakListOptions internalinterfaces.TweakListOptionsFunc) Interface { - return &group{factory: f, namespace: namespace, tweakListOptions: tweakListOptions} -} - -// V1alpha1 returns a new v1alpha1.Interface. -func (g *group) V1alpha1() v1alpha1.Interface { - return v1alpha1.New(g.factory, g.namespace, g.tweakListOptions) -} diff --git a/pkg/client/informers/externalversions/yugabytedb.rook.io/v1alpha1/interface.go b/pkg/client/informers/externalversions/yugabytedb.rook.io/v1alpha1/interface.go deleted file mode 100644 index 0674e9f20609..000000000000 --- a/pkg/client/informers/externalversions/yugabytedb.rook.io/v1alpha1/interface.go +++ /dev/null @@ -1,45 +0,0 @@ -/* -Copyright The Kubernetes Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -// Code generated by informer-gen. DO NOT EDIT. - -package v1alpha1 - -import ( - internalinterfaces "github.com/rook/rook/pkg/client/informers/externalversions/internalinterfaces" -) - -// Interface provides access to all the informers in this group version. -type Interface interface { - // YBClusters returns a YBClusterInformer. - YBClusters() YBClusterInformer -} - -type version struct { - factory internalinterfaces.SharedInformerFactory - namespace string - tweakListOptions internalinterfaces.TweakListOptionsFunc -} - -// New returns a new Interface. -func New(f internalinterfaces.SharedInformerFactory, namespace string, tweakListOptions internalinterfaces.TweakListOptionsFunc) Interface { - return &version{factory: f, namespace: namespace, tweakListOptions: tweakListOptions} -} - -// YBClusters returns a YBClusterInformer. -func (v *version) YBClusters() YBClusterInformer { - return &yBClusterInformer{factory: v.factory, namespace: v.namespace, tweakListOptions: v.tweakListOptions} -} diff --git a/pkg/client/informers/externalversions/yugabytedb.rook.io/v1alpha1/ybcluster.go b/pkg/client/informers/externalversions/yugabytedb.rook.io/v1alpha1/ybcluster.go deleted file mode 100644 index 016a6962842a..000000000000 --- a/pkg/client/informers/externalversions/yugabytedb.rook.io/v1alpha1/ybcluster.go +++ /dev/null @@ -1,90 +0,0 @@ -/* -Copyright The Kubernetes Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -// Code generated by informer-gen. DO NOT EDIT. - -package v1alpha1 - -import ( - "context" - time "time" - - yugabytedbrookiov1alpha1 "github.com/rook/rook/pkg/apis/yugabytedb.rook.io/v1alpha1" - versioned "github.com/rook/rook/pkg/client/clientset/versioned" - internalinterfaces "github.com/rook/rook/pkg/client/informers/externalversions/internalinterfaces" - v1alpha1 "github.com/rook/rook/pkg/client/listers/yugabytedb.rook.io/v1alpha1" - v1 "k8s.io/apimachinery/pkg/apis/meta/v1" - runtime "k8s.io/apimachinery/pkg/runtime" - watch "k8s.io/apimachinery/pkg/watch" - cache "k8s.io/client-go/tools/cache" -) - -// YBClusterInformer provides access to a shared informer and lister for -// YBClusters. -type YBClusterInformer interface { - Informer() cache.SharedIndexInformer - Lister() v1alpha1.YBClusterLister -} - -type yBClusterInformer struct { - factory internalinterfaces.SharedInformerFactory - tweakListOptions internalinterfaces.TweakListOptionsFunc - namespace string -} - -// NewYBClusterInformer constructs a new informer for YBCluster type. -// Always prefer using an informer factory to get a shared informer instead of getting an independent -// one. This reduces memory footprint and number of connections to the server. -func NewYBClusterInformer(client versioned.Interface, namespace string, resyncPeriod time.Duration, indexers cache.Indexers) cache.SharedIndexInformer { - return NewFilteredYBClusterInformer(client, namespace, resyncPeriod, indexers, nil) -} - -// NewFilteredYBClusterInformer constructs a new informer for YBCluster type. -// Always prefer using an informer factory to get a shared informer instead of getting an independent -// one. This reduces memory footprint and number of connections to the server. -func NewFilteredYBClusterInformer(client versioned.Interface, namespace string, resyncPeriod time.Duration, indexers cache.Indexers, tweakListOptions internalinterfaces.TweakListOptionsFunc) cache.SharedIndexInformer { - return cache.NewSharedIndexInformer( - &cache.ListWatch{ - ListFunc: func(options v1.ListOptions) (runtime.Object, error) { - if tweakListOptions != nil { - tweakListOptions(&options) - } - return client.YugabytedbV1alpha1().YBClusters(namespace).List(context.TODO(), options) - }, - WatchFunc: func(options v1.ListOptions) (watch.Interface, error) { - if tweakListOptions != nil { - tweakListOptions(&options) - } - return client.YugabytedbV1alpha1().YBClusters(namespace).Watch(context.TODO(), options) - }, - }, - &yugabytedbrookiov1alpha1.YBCluster{}, - resyncPeriod, - indexers, - ) -} - -func (f *yBClusterInformer) defaultInformer(client versioned.Interface, resyncPeriod time.Duration) cache.SharedIndexInformer { - return NewFilteredYBClusterInformer(client, f.namespace, resyncPeriod, cache.Indexers{cache.NamespaceIndex: cache.MetaNamespaceIndexFunc}, f.tweakListOptions) -} - -func (f *yBClusterInformer) Informer() cache.SharedIndexInformer { - return f.factory.InformerFor(&yugabytedbrookiov1alpha1.YBCluster{}, f.defaultInformer) -} - -func (f *yBClusterInformer) Lister() v1alpha1.YBClusterLister { - return v1alpha1.NewYBClusterLister(f.Informer().GetIndexer()) -} diff --git a/pkg/client/listers/yugabytedb.rook.io/v1alpha1/expansion_generated.go b/pkg/client/listers/yugabytedb.rook.io/v1alpha1/expansion_generated.go deleted file mode 100644 index b36b9de69dfb..000000000000 --- a/pkg/client/listers/yugabytedb.rook.io/v1alpha1/expansion_generated.go +++ /dev/null @@ -1,27 +0,0 @@ -/* -Copyright The Kubernetes Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -// Code generated by lister-gen. DO NOT EDIT. - -package v1alpha1 - -// YBClusterListerExpansion allows custom methods to be added to -// YBClusterLister. -type YBClusterListerExpansion interface{} - -// YBClusterNamespaceListerExpansion allows custom methods to be added to -// YBClusterNamespaceLister. -type YBClusterNamespaceListerExpansion interface{} diff --git a/pkg/client/listers/yugabytedb.rook.io/v1alpha1/ybcluster.go b/pkg/client/listers/yugabytedb.rook.io/v1alpha1/ybcluster.go deleted file mode 100644 index 60264e2f07d3..000000000000 --- a/pkg/client/listers/yugabytedb.rook.io/v1alpha1/ybcluster.go +++ /dev/null @@ -1,99 +0,0 @@ -/* -Copyright The Kubernetes Authors. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -// Code generated by lister-gen. DO NOT EDIT. - -package v1alpha1 - -import ( - v1alpha1 "github.com/rook/rook/pkg/apis/yugabytedb.rook.io/v1alpha1" - "k8s.io/apimachinery/pkg/api/errors" - "k8s.io/apimachinery/pkg/labels" - "k8s.io/client-go/tools/cache" -) - -// YBClusterLister helps list YBClusters. -// All objects returned here must be treated as read-only. -type YBClusterLister interface { - // List lists all YBClusters in the indexer. - // Objects returned here must be treated as read-only. - List(selector labels.Selector) (ret []*v1alpha1.YBCluster, err error) - // YBClusters returns an object that can list and get YBClusters. - YBClusters(namespace string) YBClusterNamespaceLister - YBClusterListerExpansion -} - -// yBClusterLister implements the YBClusterLister interface. -type yBClusterLister struct { - indexer cache.Indexer -} - -// NewYBClusterLister returns a new YBClusterLister. -func NewYBClusterLister(indexer cache.Indexer) YBClusterLister { - return &yBClusterLister{indexer: indexer} -} - -// List lists all YBClusters in the indexer. -func (s *yBClusterLister) List(selector labels.Selector) (ret []*v1alpha1.YBCluster, err error) { - err = cache.ListAll(s.indexer, selector, func(m interface{}) { - ret = append(ret, m.(*v1alpha1.YBCluster)) - }) - return ret, err -} - -// YBClusters returns an object that can list and get YBClusters. -func (s *yBClusterLister) YBClusters(namespace string) YBClusterNamespaceLister { - return yBClusterNamespaceLister{indexer: s.indexer, namespace: namespace} -} - -// YBClusterNamespaceLister helps list and get YBClusters. -// All objects returned here must be treated as read-only. -type YBClusterNamespaceLister interface { - // List lists all YBClusters in the indexer for a given namespace. - // Objects returned here must be treated as read-only. - List(selector labels.Selector) (ret []*v1alpha1.YBCluster, err error) - // Get retrieves the YBCluster from the indexer for a given namespace and name. - // Objects returned here must be treated as read-only. - Get(name string) (*v1alpha1.YBCluster, error) - YBClusterNamespaceListerExpansion -} - -// yBClusterNamespaceLister implements the YBClusterNamespaceLister -// interface. -type yBClusterNamespaceLister struct { - indexer cache.Indexer - namespace string -} - -// List lists all YBClusters in the indexer for a given namespace. -func (s yBClusterNamespaceLister) List(selector labels.Selector) (ret []*v1alpha1.YBCluster, err error) { - err = cache.ListAllByNamespace(s.indexer, s.namespace, selector, func(m interface{}) { - ret = append(ret, m.(*v1alpha1.YBCluster)) - }) - return ret, err -} - -// Get retrieves the YBCluster from the indexer for a given namespace and name. -func (s yBClusterNamespaceLister) Get(name string) (*v1alpha1.YBCluster, error) { - obj, exists, err := s.indexer.GetByKey(s.namespace + "/" + name) - if err != nil { - return nil, err - } - if !exists { - return nil, errors.NewNotFound(v1alpha1.Resource("ybcluster"), name) - } - return obj.(*v1alpha1.YBCluster), nil -} diff --git a/pkg/operator/yugabytedb/controller.go b/pkg/operator/yugabytedb/controller.go deleted file mode 100644 index 205503015fbb..000000000000 --- a/pkg/operator/yugabytedb/controller.go +++ /dev/null @@ -1,517 +0,0 @@ -/* -Copyright 2019 The Rook Authors. All rights reserved. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package yugabytedb - -import ( - "fmt" - "reflect" - "strings" - - "github.com/pkg/errors" - rookv1 "github.com/rook/rook/pkg/apis/rook.io/v1" - yugabytedbv1alpha1 "github.com/rook/rook/pkg/apis/yugabytedb.rook.io/v1alpha1" - "github.com/rook/rook/pkg/clusterd" - "github.com/rook/rook/pkg/operator/k8sutil" - v1 "k8s.io/api/core/v1" - "k8s.io/apimachinery/pkg/api/resource" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/types" - "k8s.io/apimachinery/pkg/util/intstr" - "k8s.io/client-go/tools/cache" -) - -const ( - customResourceName = "ybcluster" - customResourceNamePlural = "ybclusters" - masterName = "yb-master" - masterNamePlural = "yb-masters" - tserverName = "yb-tserver" - tserverNamePlural = "yb-tservers" - masterUIServiceName = "yb-master-ui" - tserverUIServiceName = "yb-tserver-ui" - masterUIPortDefault = int32(7000) - masterUIPortName = "yb-master-ui" - masterRPCPortDefault = int32(7100) - masterRPCPortName = "yb-master-rpc" - tserverUIPortDefault = int32(9000) - tserverUIPortName = "yb-tserver-ui" - tserverRPCPortDefault = int32(9100) - tserverRPCPortName = "yb-tserver-rpc" - tserverCassandraPortDefault = int32(9042) - tserverCassandraPortName = "ycql" - tserverRedisPortDefault = int32(6379) - tserverRedisPortName = "yedis" - tserverPostgresPortDefault = int32(5433) - tserverPostgresPortName = "ysql" - masterContainerUIPortName = "master-ui" - masterContainerRPCPortName = "master-rpc" - tserverContainerUIPortName = "tserver-ui" - tserverContainerRPCPortName = "tserver-rpc" - uiPortName = "ui" - rpcPortName = "rpc-port" - cassandraPortName = "cassandra" - redisPortName = "redis" - postgresPortName = "postgres" - volumeMountPath = "/mnt/data0" - envGetHostsFrom = "GET_HOSTS_FROM" - envGetHostsFromVal = "dns" - envPodIP = "POD_IP" - envPodIPVal = "status.podIP" - envPodNameVal = "metadata.name" - yugabyteDBImageName = "yugabytedb/yugabyte:2.2.2.0-b15" - podCPULimitDefault = "2" - masterMemLimitDefault = "2Gi" - tserverMemLimitDefault = "4Gi" -) - -var ClusterResource = k8sutil.CustomResource{ - Name: customResourceName, - Plural: customResourceNamePlural, - Group: yugabytedbv1alpha1.CustomResourceGroup, - Version: yugabytedbv1alpha1.Version, - Kind: reflect.TypeOf(yugabytedbv1alpha1.YBCluster{}).Name(), -} - -type ClusterController struct { - context *clusterd.Context - containerImage string -} - -func NewClusterController(context *clusterd.Context, containerImage string) *ClusterController { - return &ClusterController{ - context: context, - containerImage: containerImage, - } -} - -type cluster struct { - context *clusterd.Context - name string - namespace string - spec yugabytedbv1alpha1.YBClusterSpec - annotations rookv1.Annotations - ownerRef metav1.OwnerReference -} - -type clusterPorts struct { - masterPorts, tserverPorts serverPorts -} - -type serverPorts struct { - ui, rpc, cassandra, redis, postgres int32 -} - -func NewCluster(c *yugabytedbv1alpha1.YBCluster, context *clusterd.Context) *cluster { - return &cluster{ - context: context, - name: c.Name, - namespace: c.Namespace, - spec: c.Spec, - annotations: c.Spec.Annotations, - ownerRef: clusterOwnerRef(c.Name, string(c.UID)), - } -} - -func clusterOwnerRef(name, clusterID string) metav1.OwnerReference { - blockOwner := true - return metav1.OwnerReference{ - APIVersion: fmt.Sprintf("%s/%s", ClusterResource.Group, ClusterResource.Version), - Kind: ClusterResource.Kind, - Name: name, - UID: types.UID(clusterID), - BlockOwnerDeletion: &blockOwner, - } -} - -func (c *ClusterController) StartWatch(namespace string, stopCh chan struct{}) { - resourceHandlerFuncs := cache.ResourceEventHandlerFuncs{ - AddFunc: c.OnAdd, - UpdateFunc: c.OnUpdate, - DeleteFunc: c.onDelete, - } - - logger.Infof("start watching yugabytedb clusters in all namespaces") - go k8sutil.WatchCR(ClusterResource, namespace, resourceHandlerFuncs, c.context.RookClientset.YugabytedbV1alpha1().RESTClient(), &yugabytedbv1alpha1.YBCluster{}, stopCh) -} - -func (c *ClusterController) onDelete(obj interface{}) { - cluster, ok := obj.(*yugabytedbv1alpha1.YBCluster) - if !ok { - return - } - cluster = cluster.DeepCopy() - logger.Infof("cluster %s deleted from namespace %s", cluster.Name, cluster.Namespace) -} - -func validateClusterSpec(spec yugabytedbv1alpha1.YBClusterSpec) error { - - if spec.Master.Replicas < 1 { - return fmt.Errorf("invalid Master replica count: %d. Must be at least 1", spec.Master.Replicas) - } - - if spec.TServer.Replicas < 1 { - return fmt.Errorf("invalid TServer replica count: %d. Must be at least 1", spec.TServer.Replicas) - } - - if _, err := getPortsFromSpec(spec.Master.Network); err != nil { - return err - } - - if _, err := getPortsFromSpec(spec.TServer.Network); err != nil { - return err - } - - if &spec.Master.VolumeClaimTemplate == nil { //nolint, ok to ignore this test - return fmt.Errorf("VolumeClaimTemplate unavailable in Master spec.") - } - - if &spec.TServer.VolumeClaimTemplate == nil { //nolint, ok to ignore this test - return fmt.Errorf("VolumeClaimTemplate unavailable in TServer spec.") - } - - if err := validateResourceSpec(spec.Master.Resource, false); err != nil { - return errors.Wrap(err, "failed to validate resource spec") - } - - if err := validateResourceSpec(spec.TServer.Resource, true); err != nil { - return errors.Wrap(err, "failed to validate resource spec") - } - - return nil -} - -func validateResourceSpec(resourceSpec v1.ResourceRequirements, isTServer bool) error { - if (&resourceSpec.Requests == nil || len(resourceSpec.Requests) != 0) && (&resourceSpec.Limits == nil || len(resourceSpec.Limits) != 0) { //nolint, ok to ignore this test - reqCPU, reqOk := resourceSpec.Requests[v1.ResourceCPU] - limCPU, limOk := resourceSpec.Limits[v1.ResourceCPU] - podName := "Master" - - if isTServer { - podName = "TServer" - } - - // q.Cmp(y Quantity) returns -1 if q < y - if reqOk && limOk && (&reqCPU).Cmp(limCPU) < 0 { - return fmt.Errorf("%s Requested CPU cannot be greater than CPU limit", podName) - } - - reqMem, reqOk := resourceSpec.Requests[v1.ResourceMemory] - limMem, limOk := resourceSpec.Limits[v1.ResourceMemory] - // q.Cmp(y Quantity) returns -1 if q < y - if reqOk && limOk && (&reqMem).Cmp(limMem) < 0 { - return fmt.Errorf("%s Requested Memory cannot be greater than Memory limit", podName) - } - } - - return nil -} - -func createAppLabels(label string) map[string]string { - return map[string]string{ - k8sutil.AppAttr: label, - } -} - -func createServicePorts(cluster *cluster, isTServerService bool) []v1.ServicePort { - var servicePorts []v1.ServicePort - - if !isTServerService { - ports, _ := getPortsFromSpec(cluster.spec.Master.Network) - - servicePorts = []v1.ServicePort{ - { - Name: uiPortName, - Port: ports.masterPorts.ui, - TargetPort: intstr.FromInt(int(ports.masterPorts.ui)), - }, - { - Name: rpcPortName, - Port: ports.masterPorts.rpc, - TargetPort: intstr.FromInt(int(ports.masterPorts.rpc)), - }, - } - } else { - ports, _ := getPortsFromSpec(cluster.spec.TServer.Network) - - tserverUIPort := ports.tserverPorts.ui - - if tserverUIPort <= 0 { - tserverUIPort = tserverUIPortDefault - } - - servicePorts = []v1.ServicePort{ - { - Name: uiPortName, - Port: tserverUIPort, - TargetPort: intstr.FromInt(int(tserverUIPort)), - }, - { - Name: rpcPortName, - Port: ports.tserverPorts.rpc, - TargetPort: intstr.FromInt(int(ports.tserverPorts.rpc)), - }, - { - Name: cassandraPortName, - Port: ports.tserverPorts.cassandra, - TargetPort: intstr.FromInt(int(ports.tserverPorts.cassandra)), - }, - { - Name: redisPortName, - Port: ports.tserverPorts.redis, - TargetPort: intstr.FromInt(int(ports.tserverPorts.redis)), - }, - { - Name: postgresPortName, - Port: ports.tserverPorts.postgres, - TargetPort: intstr.FromInt(int(ports.tserverPorts.postgres)), - }, - } - } - - return servicePorts -} - -func createUIServicePorts(ports *clusterPorts, isTServerService bool) []v1.ServicePort { - var servicePorts []v1.ServicePort - - if !isTServerService { - servicePorts = []v1.ServicePort{ - { - Name: uiPortName, - Port: ports.masterPorts.ui, - TargetPort: intstr.FromInt(int(ports.masterPorts.ui)), - }, - } - } else { - if ports.tserverPorts.ui > 0 { - servicePorts = []v1.ServicePort{ - { - Name: uiPortName, - Port: ports.tserverPorts.ui, - TargetPort: intstr.FromInt(int(ports.tserverPorts.ui)), - }, - } - } else { - servicePorts = nil - } - } - - return servicePorts -} - -func getPortsFromSpec(networkSpec yugabytedbv1alpha1.NetworkSpec) (clusterPort *clusterPorts, err error) { - ports := clusterPorts{} - - for _, p := range networkSpec.Ports { - switch p.Name { - case masterUIPortName: - ports.masterPorts.ui = p.Port - case masterRPCPortName: - ports.masterPorts.rpc = p.Port - case tserverUIPortName: - ports.tserverPorts.ui = p.Port - case tserverRPCPortName: - ports.tserverPorts.rpc = p.Port - case tserverCassandraPortName: - ports.tserverPorts.cassandra = p.Port - case tserverRedisPortName: - ports.tserverPorts.redis = p.Port - case tserverPostgresPortName: - ports.tserverPorts.postgres = p.Port - default: - return &clusterPorts{}, fmt.Errorf("Invalid port name: %s. Must be one of: [%s, %s, %s, %s, %s, %s, %s]", p.Name, - masterUIPortName, masterRPCPortName, tserverUIPortName, tserverRPCPortName, tserverCassandraPortName, - tserverRedisPortName, tserverPostgresPortName) - } - } - - if ports.masterPorts.ui == 0 { - ports.masterPorts.ui = masterUIPortDefault - } - - if ports.masterPorts.rpc == 0 { - ports.masterPorts.rpc = masterRPCPortDefault - } - - if ports.tserverPorts.rpc == 0 { - ports.tserverPorts.rpc = tserverRPCPortDefault - } - - if ports.tserverPorts.cassandra == 0 { - ports.tserverPorts.cassandra = tserverCassandraPortDefault - } - - if ports.tserverPorts.redis == 0 { - ports.tserverPorts.redis = tserverRedisPortDefault - } - - if ports.tserverPorts.postgres == 0 { - ports.tserverPorts.postgres = tserverPostgresPortDefault - } - - return &ports, nil -} - -func createMasterContainerCommand(namespace, serviceName string, masterCompleteName string, grpcPort, replicas int32, resources v1.ResourceRequirements) []string { - command := []string{ - "/home/yugabyte/bin/yb-master", - fmt.Sprintf("--fs_data_dirs=%s", volumeMountPath), - fmt.Sprintf("--rpc_bind_addresses=$(POD_IP):%d", grpcPort), - fmt.Sprintf("--server_broadcast_addresses=$(POD_NAME).%s:%d", serviceName, grpcPort), - "--use_private_ip=never", - fmt.Sprintf("--master_addresses=%s", getMasterAddresses(masterCompleteName, serviceName, namespace, replicas, grpcPort)), - "--enable_ysql=true", - fmt.Sprintf("--replication_factor=%d", replicas), - "--logtostderr", - } - - if &resources.Limits != nil { //nolint, ok to ignore this test - if memLimit, ok := getMemoryLimitBytes(resources); ok { - command = append(command, fmt.Sprintf("--memory_limit_hard_bytes=%d", memLimit)) - } - } - - return command -} - -func createTServerContainerCommand(namespace, serviceName, masterServiceName string, masterCompleteName string, masterGRPCPort, tserverGRPCPort, pgsqlPort, replicas int32, resources v1.ResourceRequirements) []string { - command := []string{ - "/home/yugabyte/bin/yb-tserver", - fmt.Sprintf("--fs_data_dirs=%s", volumeMountPath), - fmt.Sprintf("--rpc_bind_addresses=$(POD_IP):%d", tserverGRPCPort), - fmt.Sprintf("--server_broadcast_addresses=$(POD_NAME).%s:%d", serviceName, tserverGRPCPort), - fmt.Sprintf("--pgsql_proxy_bind_address=$(POD_IP):%d", pgsqlPort), - "--use_private_ip=never", - fmt.Sprintf("--tserver_master_addrs=%s", getMasterAddresses(masterCompleteName, masterServiceName, namespace, replicas, masterGRPCPort)), - "--enable_ysql=true", - "--logtostderr", - } - - if &resources.Limits != nil { //nolint, ok to ignore this test - if memLimit, ok := getMemoryLimitBytes(resources); ok { - command = append(command, fmt.Sprintf("--memory_limit_hard_bytes=%d", memLimit)) - } - } - - return command -} - -func getMemoryLimitBytes(resources v1.ResourceRequirements) (int64, bool) { - if memLimit, ok := resources.Limits[v1.ResourceMemory]; ok { - memBytes, _ := (&memLimit).AsInt64() - // Set DB mem limit at 85% of pod memory. 1024 * 85% ~= 870 - memBytesAdjusted := memBytes * 870 / 1024 - return memBytesAdjusted, true - } - - return int64(0), false -} - -func getMasterAddresses(masterCompleteName string, serviceName string, namespace string, replicas int32, masterGRPCPort int32) string { - masterAddrs := []string{} - for i := int32(0); i < replicas; i++ { - masterAddrs = append(masterAddrs, fmt.Sprintf("%s-%d.%s.%s.svc.cluster.local:%d", masterCompleteName, i, serviceName, namespace, masterGRPCPort)) - } - return strings.Join(masterAddrs, ",") -} - -func createMasterContainerPortsList(clusterPortsSpec *clusterPorts) []v1.ContainerPort { - ports := []v1.ContainerPort{ - { - Name: masterContainerUIPortName, - ContainerPort: int32(clusterPortsSpec.masterPorts.ui), - }, - { - Name: masterContainerRPCPortName, - ContainerPort: int32(clusterPortsSpec.masterPorts.rpc), - }, - } - - return ports -} - -func createTServerContainerPortsList(clusterPortsSpec *clusterPorts) []v1.ContainerPort { - tserverUIPort := int32(clusterPortsSpec.tserverPorts.ui) - - if tserverUIPort <= 0 { - tserverUIPort = tserverUIPortDefault - } - - ports := []v1.ContainerPort{ - { - Name: tserverContainerUIPortName, - ContainerPort: tserverUIPort, - }, - { - Name: tserverContainerRPCPortName, - ContainerPort: int32(clusterPortsSpec.tserverPorts.rpc), - }, - { - Name: cassandraPortName, - ContainerPort: int32(clusterPortsSpec.tserverPorts.cassandra), - }, - { - Name: redisPortName, - ContainerPort: int32(clusterPortsSpec.tserverPorts.redis), - }, - { - Name: postgresPortName, - ContainerPort: int32(clusterPortsSpec.tserverPorts.postgres), - }, - } - - return ports -} - -func (c *cluster) addCRNameSuffix(str string) string { - return fmt.Sprintf("%s-%s", str, c.name) -} - -func getResourceSpec(resourceSpec v1.ResourceRequirements, isTServerStatefulset bool) v1.ResourceRequirements { - resources := resourceSpec - - if &resources == nil { //nolint, ok to ignore this test - resources = v1.ResourceRequirements{ - Requests: make(map[v1.ResourceName]resource.Quantity), - Limits: make(map[v1.ResourceName]resource.Quantity), - } - } - - if len(resources.Requests) != 0 || len(resources.Limits) != 0 { - return resources - } - - memoryLimit := masterMemLimitDefault - - if isTServerStatefulset { - memoryLimit = tserverMemLimitDefault - } - - if &resources.Requests == nil || len(resources.Requests) == 0 { //nolint, ok to ignore this test - resources.Requests = make(map[v1.ResourceName]resource.Quantity) - resources.Requests[v1.ResourceCPU] = resource.MustParse(podCPULimitDefault) - resources.Requests[v1.ResourceMemory] = resource.MustParse(memoryLimit) - } - - if &resources.Limits == nil || len(resources.Limits) == 0 { //nolint, ok to ignore this test - resources.Limits = make(map[v1.ResourceName]resource.Quantity) - resources.Limits[v1.ResourceCPU] = resource.MustParse(podCPULimitDefault) - resources.Limits[v1.ResourceMemory] = resource.MustParse(memoryLimit) - } - - return resources -} diff --git a/pkg/operator/yugabytedb/controller_test.go b/pkg/operator/yugabytedb/controller_test.go deleted file mode 100644 index 85551938ceaf..000000000000 --- a/pkg/operator/yugabytedb/controller_test.go +++ /dev/null @@ -1,1317 +0,0 @@ -/* -Copyright 2019 The Rook Authors. All rights reserved. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ -package yugabytedb - -import ( - "context" - "fmt" - "strings" - "testing" - "time" - - yugabytedbv1alpha1 "github.com/rook/rook/pkg/apis/yugabytedb.rook.io/v1alpha1" - - "github.com/rook/rook/pkg/clusterd" - "github.com/rook/rook/pkg/operator/k8sutil" - testop "github.com/rook/rook/pkg/operator/test" - "github.com/stretchr/testify/assert" - v1 "k8s.io/api/core/v1" - "k8s.io/apimachinery/pkg/api/errors" - "k8s.io/apimachinery/pkg/api/resource" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" - "k8s.io/apimachinery/pkg/util/intstr" - "k8s.io/apimachinery/pkg/util/wait" - "k8s.io/client-go/kubernetes/fake" -) - -const ( - CustomPortShift = 100 - ClusterName = "ybdb-cluster" - VolumeDataName = "datadir" - PodCreationWaitInterval = 100 * time.Millisecond - PodCreationWaitTimeout = 30 * time.Second -) - -func TestValidateClusterSpec(t *testing.T) { - // invalid master & tserver replica count - spec := yugabytedbv1alpha1.YBClusterSpec{ - Master: yugabytedbv1alpha1.ServerSpec{ - Replicas: 0, - Network: yugabytedbv1alpha1.NetworkSpec{ - Ports: []yugabytedbv1alpha1.PortSpec{ - {Name: masterUIPortName, Port: 123}, - {Name: masterRPCPortName, Port: 456}, - }, - }, - VolumeClaimTemplate: v1.PersistentVolumeClaim{}, - }, - TServer: yugabytedbv1alpha1.ServerSpec{ - Replicas: 0, - Network: yugabytedbv1alpha1.NetworkSpec{}, - VolumeClaimTemplate: v1.PersistentVolumeClaim{}, - }, - } - err := validateClusterSpec(spec) - assert.NotNil(t, err) - assert.True(t, strings.Contains(err.Error(), "invalid Master replica count")) - - // invalid master replica count - spec = yugabytedbv1alpha1.YBClusterSpec{ - Master: yugabytedbv1alpha1.ServerSpec{ - Replicas: 0, - Network: yugabytedbv1alpha1.NetworkSpec{ - Ports: []yugabytedbv1alpha1.PortSpec{ - {Name: masterUIPortName, Port: 123}, - {Name: masterRPCPortName, Port: 456}, - }, - }, - VolumeClaimTemplate: v1.PersistentVolumeClaim{}, - }, - TServer: yugabytedbv1alpha1.ServerSpec{ - Replicas: 1, - Network: yugabytedbv1alpha1.NetworkSpec{}, - VolumeClaimTemplate: v1.PersistentVolumeClaim{}, - }, - } - err = validateClusterSpec(spec) - assert.NotNil(t, err) - assert.True(t, strings.Contains(err.Error(), "invalid Master replica count")) - - // invalid tserver replica count - spec = yugabytedbv1alpha1.YBClusterSpec{ - Master: yugabytedbv1alpha1.ServerSpec{ - Replicas: 1, - Network: yugabytedbv1alpha1.NetworkSpec{ - Ports: []yugabytedbv1alpha1.PortSpec{ - {Name: masterUIPortName, Port: 123}, - {Name: masterRPCPortName, Port: 456}, - }, - }, - VolumeClaimTemplate: v1.PersistentVolumeClaim{}, - }, - TServer: yugabytedbv1alpha1.ServerSpec{ - Replicas: 0, - Network: yugabytedbv1alpha1.NetworkSpec{}, - VolumeClaimTemplate: v1.PersistentVolumeClaim{}, - }, - } - err = validateClusterSpec(spec) - assert.NotNil(t, err) - assert.True(t, strings.Contains(err.Error(), "invalid TServer replica count")) - - // invalid master network spec - spec = yugabytedbv1alpha1.YBClusterSpec{ - Master: yugabytedbv1alpha1.ServerSpec{ - Replicas: 1, - Network: yugabytedbv1alpha1.NetworkSpec{ - Ports: []yugabytedbv1alpha1.PortSpec{ - {Name: "http", Port: 123}, - }, - }, - VolumeClaimTemplate: v1.PersistentVolumeClaim{}, - }, - TServer: yugabytedbv1alpha1.ServerSpec{ - Replicas: 1, - Network: yugabytedbv1alpha1.NetworkSpec{}, - VolumeClaimTemplate: v1.PersistentVolumeClaim{}, - }, - } - err = validateClusterSpec(spec) - assert.NotNil(t, err) - assert.True(t, strings.Contains(err.Error(), "Invalid port name")) - - // invalid tserver network spec - spec = yugabytedbv1alpha1.YBClusterSpec{ - Master: yugabytedbv1alpha1.ServerSpec{ - Replicas: 1, - Network: yugabytedbv1alpha1.NetworkSpec{}, - VolumeClaimTemplate: v1.PersistentVolumeClaim{}, - }, - TServer: yugabytedbv1alpha1.ServerSpec{ - Replicas: 1, - Network: yugabytedbv1alpha1.NetworkSpec{ - Ports: []yugabytedbv1alpha1.PortSpec{ - {Name: "http", Port: 123}, - }, - }, - VolumeClaimTemplate: v1.PersistentVolumeClaim{}, - }, - } - err = validateClusterSpec(spec) - assert.NotNil(t, err) - assert.True(t, strings.Contains(err.Error(), "Invalid port name")) - - // Valid spec. - spec = yugabytedbv1alpha1.YBClusterSpec{ - Master: yugabytedbv1alpha1.ServerSpec{ - Replicas: 1, - Network: yugabytedbv1alpha1.NetworkSpec{ - Ports: []yugabytedbv1alpha1.PortSpec{ - {Name: masterUIPortName, Port: 123}, - {Name: masterRPCPortName, Port: 456}, - }, - }, - VolumeClaimTemplate: v1.PersistentVolumeClaim{}, - }, - TServer: yugabytedbv1alpha1.ServerSpec{ - Replicas: 1, - Network: yugabytedbv1alpha1.NetworkSpec{}, - VolumeClaimTemplate: v1.PersistentVolumeClaim{}, - }, - } - err = validateClusterSpec(spec) - assert.Nil(t, err) - - // Valid spec, absent network attribute. - spec = yugabytedbv1alpha1.YBClusterSpec{ - Master: yugabytedbv1alpha1.ServerSpec{ - Replicas: 1, - VolumeClaimTemplate: v1.PersistentVolumeClaim{}, - }, - TServer: yugabytedbv1alpha1.ServerSpec{ - Replicas: 1, - VolumeClaimTemplate: v1.PersistentVolumeClaim{}, - }, - } - err = validateClusterSpec(spec) - assert.Nil(t, err) - -} - -func TestGetPortsFromSpec(t *testing.T) { - - // All ports unspecified. Get all default ports - spec := yugabytedbv1alpha1.NetworkSpec{} - ports, err := getPortsFromSpec(spec) - assert.Nil(t, err) - assert.Equal(t, masterUIPortDefault, ports.masterPorts.ui) - assert.Equal(t, masterRPCPortDefault, ports.masterPorts.rpc) - assert.Equal(t, int32(0), ports.tserverPorts.ui) - assert.Equal(t, tserverRPCPortDefault, ports.tserverPorts.rpc) - assert.Equal(t, tserverCassandraPortDefault, ports.tserverPorts.cassandra) - assert.Equal(t, tserverRedisPortDefault, ports.tserverPorts.redis) - assert.Equal(t, tserverPostgresPortDefault, ports.tserverPorts.postgres) - - // All ports specified. Get all custom ports - mUIPort := int32(123) - mRPCPort := int32(456) - tsUIPort := int32(789) - tsRPCPort := int32(012) - tsCassandraPort := int32(345) - tsRedisPort := int32(678) - tsPostgresPort := int32(901) - - spec = yugabytedbv1alpha1.NetworkSpec{ - Ports: []yugabytedbv1alpha1.PortSpec{ - {Name: masterUIPortName, Port: mUIPort}, - {Name: masterRPCPortName, Port: mRPCPort}, - {Name: tserverUIPortName, Port: tsUIPort}, - {Name: tserverRPCPortName, Port: tsRPCPort}, - {Name: tserverCassandraPortName, Port: tsCassandraPort}, - {Name: tserverRedisPortName, Port: tsRedisPort}, - {Name: tserverPostgresPortName, Port: tsPostgresPort}, - }, - } - - ports, err = getPortsFromSpec(spec) - assert.Nil(t, err) - assert.Equal(t, mUIPort, ports.masterPorts.ui) - assert.Equal(t, mRPCPort, ports.masterPorts.rpc) - assert.Equal(t, tsUIPort, ports.tserverPorts.ui) - assert.Equal(t, tsRPCPort, ports.tserverPorts.rpc) - assert.Equal(t, tsCassandraPort, ports.tserverPorts.cassandra) - assert.Equal(t, tsRedisPort, ports.tserverPorts.redis) - assert.Equal(t, tsPostgresPort, ports.tserverPorts.postgres) - - // All ports specified, except TServer-UI. Get all custom ports, except TServer-UI being 0. - spec = yugabytedbv1alpha1.NetworkSpec{ - Ports: []yugabytedbv1alpha1.PortSpec{ - {Name: masterUIPortName, Port: mUIPort}, - {Name: masterRPCPortName, Port: mRPCPort}, - {Name: tserverRPCPortName, Port: tsRPCPort}, - {Name: tserverCassandraPortName, Port: tsCassandraPort}, - {Name: tserverRedisPortName, Port: tsRedisPort}, - {Name: tserverPostgresPortName, Port: tsPostgresPort}, - }, - } - - ports, err = getPortsFromSpec(spec) - assert.Nil(t, err) - assert.Equal(t, mUIPort, ports.masterPorts.ui) - assert.Equal(t, mRPCPort, ports.masterPorts.rpc) - assert.Equal(t, int32(0), ports.tserverPorts.ui) - assert.Equal(t, tsRPCPort, ports.tserverPorts.rpc) - assert.Equal(t, tsCassandraPort, ports.tserverPorts.cassandra) - assert.Equal(t, tsRedisPort, ports.tserverPorts.redis) - assert.Equal(t, tsPostgresPort, ports.tserverPorts.postgres) -} - -func TestCreateMasterContainerCommand(t *testing.T) { - replicationFactor := int32(3) - resources := v1.ResourceRequirements{} - - expectedCommand := getMasterContainerCommand(replicationFactor) - actualCommand := createMasterContainerCommand("default", masterNamePlural, masterName, int32(7100), replicationFactor, resources) - - assert.Equal(t, expectedCommand, actualCommand) -} - -func TestCreateTServerContainerCommand(t *testing.T) { - replicationFactor := int32(3) - resources := v1.ResourceRequirements{} - - expectedCommand := getTserverContainerCommand(replicationFactor) - actualCommand := createTServerContainerCommand("default", tserverNamePlural, masterNamePlural, masterName, int32(7100), int32(9100), int32(5433), replicationFactor, resources) - - assert.Equal(t, expectedCommand, actualCommand) -} - -func TestCreateMasterContainerCommandRF1(t *testing.T) { - replicationFactor := int32(1) - resources := v1.ResourceRequirements{} - - expectedCommand := getMasterContainerCommand(replicationFactor) - actualCommand := createMasterContainerCommand("default", masterNamePlural, masterName, int32(7100), replicationFactor, resources) - - assert.Equal(t, expectedCommand, actualCommand) -} - -func TestCreateTServerContainerCommandRF1(t *testing.T) { - replicationFactor := int32(1) - resources := v1.ResourceRequirements{} - - expectedCommand := getTserverContainerCommand(replicationFactor) - actualCommand := createTServerContainerCommand("default", tserverNamePlural, masterNamePlural, masterName, int32(7100), int32(9100), int32(5433), replicationFactor, resources) - - assert.Equal(t, expectedCommand, actualCommand) -} - -func getMasterContainerCommand(replicationFactor int32) []string { - expectedCommand := []string{ - "/home/yugabyte/bin/yb-master", - "--fs_data_dirs=/mnt/data0", - fmt.Sprintf("--rpc_bind_addresses=$(POD_IP):%d", masterRPCPortDefault), - fmt.Sprintf("--server_broadcast_addresses=$(POD_NAME).yb-masters:%d", masterRPCPortDefault), - "--use_private_ip=never", - fmt.Sprintf("--master_addresses=%s", getMasterAddresses(masterName, masterNamePlural, "default", replicationFactor, int32(7100))), - "--enable_ysql=true", - fmt.Sprintf("--replication_factor=%d", replicationFactor), - "--logtostderr", - } - return expectedCommand -} - -func getTserverContainerCommand(replicationFactor int32) []string { - expectedCommand := []string{ - "/home/yugabyte/bin/yb-tserver", - "--fs_data_dirs=/mnt/data0", - fmt.Sprintf("--rpc_bind_addresses=$(POD_IP):%d", tserverRPCPortDefault), - fmt.Sprintf("--server_broadcast_addresses=$(POD_NAME).yb-tservers:%d", tserverRPCPortDefault), - fmt.Sprintf("--pgsql_proxy_bind_address=$(POD_IP):%d", tserverPostgresPortDefault), - "--use_private_ip=never", - fmt.Sprintf("--tserver_master_addrs=%s", getMasterAddresses(masterName, masterNamePlural, "default", replicationFactor, int32(7100))), - "--enable_ysql=true", - "--logtostderr", - } - return expectedCommand -} - -func TestOnAdd(t *testing.T) { - ctx := context.TODO() - namespace := "rook-yugabytedb" - - // initialize the controller and its dependencies - clientset := testop.New(t, 3) - context := &clusterd.Context{Clientset: clientset} - controller := NewClusterController(context, "rook/yugabytedb:mockTag") - controllerSet := &ControllerSet{ - ClientSet: clientset, - Context: context, - Controller: controller, - } - - cluster := simulateARunningYugabyteCluster(ctx, t, controllerSet, namespace, int32(3), false) - - expectedServicePorts := []v1.ServicePort{ - {Name: uiPortName, Port: masterUIPortDefault, TargetPort: intstr.FromInt(int(masterUIPortDefault))}, - } - - // verify Master UI service is created - clientService, err := clientset.CoreV1().Services(namespace).Get(ctx, addCRNameSuffix(masterUIServiceName), metav1.GetOptions{}) - assert.Nil(t, err) - assert.NotNil(t, clientService) - assert.Equal(t, v1.ServiceTypeClusterIP, clientService.Spec.Type) - assert.Equal(t, expectedServicePorts, clientService.Spec.Ports) - - // verify TServer UI service is NOT created - clientService, err = clientset.CoreV1().Services(namespace).Get(ctx, addCRNameSuffix(tserverUIServiceName), metav1.GetOptions{}) - assert.Nil(t, clientService) - assert.NotNil(t, err) - assert.True(t, errors.IsNotFound(err)) - - // verify Master headless Service is created - expectedServicePorts = []v1.ServicePort{ - {Name: uiPortName, Port: masterUIPortDefault, TargetPort: intstr.FromInt(int(masterUIPortDefault))}, - {Name: rpcPortName, Port: masterRPCPortDefault, TargetPort: intstr.FromInt(int(masterRPCPortDefault))}, - } - - headlessService, err := clientset.CoreV1().Services(namespace).Get(ctx, addCRNameSuffix(masterNamePlural), metav1.GetOptions{}) - assert.Nil(t, err) - assert.NotNil(t, headlessService) - assert.Equal(t, "None", headlessService.Spec.ClusterIP) - assert.Equal(t, expectedServicePorts, headlessService.Spec.Ports) - - // verify TServer headless Service is created - expectedServicePorts = []v1.ServicePort{ - {Name: uiPortName, Port: tserverUIPortDefault, TargetPort: intstr.FromInt(int(tserverUIPortDefault))}, - {Name: rpcPortName, Port: tserverRPCPortDefault, TargetPort: intstr.FromInt(int(tserverRPCPortDefault))}, - {Name: cassandraPortName, Port: tserverCassandraPortDefault, TargetPort: intstr.FromInt(int(tserverCassandraPortDefault))}, - {Name: redisPortName, Port: tserverRedisPortDefault, TargetPort: intstr.FromInt(int(tserverRedisPortDefault))}, - {Name: postgresPortName, Port: tserverPostgresPortDefault, TargetPort: intstr.FromInt(int(tserverPostgresPortDefault))}, - } - - headlessService, err = clientset.CoreV1().Services(namespace).Get(ctx, addCRNameSuffix(tserverNamePlural), metav1.GetOptions{}) - assert.Nil(t, err) - assert.NotNil(t, headlessService) - assert.Equal(t, "None", headlessService.Spec.ClusterIP) - assert.Equal(t, expectedServicePorts, headlessService.Spec.Ports) - - // verify Master statefulSet is created - statefulSets, err := clientset.AppsV1().StatefulSets(namespace).Get(ctx, addCRNameSuffix(masterName), metav1.GetOptions{}) - assert.Nil(t, err) - assert.NotNil(t, statefulSets) - assert.Equal(t, int32(3), *statefulSets.Spec.Replicas) - assert.Equal(t, 1, len(statefulSets.Spec.VolumeClaimTemplates)) - - vct := *cluster.Spec.Master.VolumeClaimTemplate.DeepCopy() - vct.Name = addCRNameSuffix(vct.Name) - expectedVolumeClaimTemplates := []v1.PersistentVolumeClaim{vct} - assert.Equal(t, expectedVolumeClaimTemplates, statefulSets.Spec.VolumeClaimTemplates) - assert.Equal(t, 1, len(statefulSets.Spec.Template.Spec.Containers)) - - container := statefulSets.Spec.Template.Spec.Containers[0] - expectedContainerPorts := []v1.ContainerPort{ - {Name: masterContainerUIPortName, ContainerPort: masterUIPortDefault}, - {Name: masterContainerRPCPortName, ContainerPort: masterRPCPortDefault}, - } - assert.Equal(t, expectedContainerPorts, container.Ports) - assert.NotNil(t, container.Resources) - assert.Equal(t, 2, len(container.Resources.Requests)) - assert.Equal(t, 2, len(container.Resources.Limits)) - - reqCPU, reqOk := container.Resources.Requests[v1.ResourceCPU] - limCPU, limOk := container.Resources.Limits[v1.ResourceCPU] - assert.True(t, reqOk) - assert.True(t, limOk) - assert.Equal(t, 0, (&reqCPU).Cmp(resource.MustParse(podCPULimitDefault))) - assert.Equal(t, 0, (&limCPU).Cmp(resource.MustParse(podCPULimitDefault))) - - reqMem, reqOk := container.Resources.Requests[v1.ResourceMemory] - limMem := container.Resources.Limits[v1.ResourceMemory] - assert.True(t, reqOk) - assert.True(t, reqOk) - assert.Equal(t, 0, (&reqMem).Cmp(resource.MustParse(masterMemLimitDefault))) - assert.Equal(t, 0, (&limMem).Cmp(resource.MustParse(masterMemLimitDefault))) - - volumeMountName := addCRNameSuffix(cluster.Spec.Master.VolumeClaimTemplate.Name) - expectedVolumeMounts := []v1.VolumeMount{{Name: volumeMountName, MountPath: volumeMountPath}} - assert.Equal(t, expectedVolumeMounts, container.VolumeMounts) - - expectedEnvVars := []v1.EnvVar{ - { - Name: envGetHostsFrom, - Value: envGetHostsFromVal}, - { - Name: envPodIP, - ValueFrom: &v1.EnvVarSource{ - FieldRef: &v1.ObjectFieldSelector{ - FieldPath: envPodIPVal, - }, - }, - }, - { - Name: k8sutil.PodNameEnvVar, - ValueFrom: &v1.EnvVarSource{ - FieldRef: &v1.ObjectFieldSelector{ - FieldPath: envPodNameVal, - }, - }, - }, - } - assert.Equal(t, expectedEnvVars, container.Env) - - expectedCommand := []string{ - "/home/yugabyte/bin/yb-master", - "--fs_data_dirs=/mnt/data0", - "--rpc_bind_addresses=$(POD_IP):7100", - fmt.Sprintf("--server_broadcast_addresses=$(POD_NAME).%s:7100", addCRNameSuffix(masterNamePlural)), - "--use_private_ip=never", - fmt.Sprintf("--master_addresses=%s", getMasterAddresses(addCRNameSuffix(masterName), addCRNameSuffix(masterNamePlural), namespace, int32(3), int32(7100))), - "--enable_ysql=true", - "--replication_factor=3", - "--logtostderr", - "--memory_limit_hard_bytes=1824522240", - } - assert.Equal(t, expectedCommand, container.Command) - - // verify Master pods are created - pods, err := clientset.CoreV1().Pods(namespace).List(ctx, metav1.ListOptions{ - LabelSelector: fmt.Sprintf("%s=%s", k8sutil.AppAttr, addCRNameSuffix(masterName)), - }) - assert.Nil(t, err) - assert.NotNil(t, pods) - assert.Equal(t, 3, len(pods.Items)) - - // verify TServer statefulSet is created - statefulSets, err = clientset.AppsV1().StatefulSets(namespace).Get(ctx, addCRNameSuffix(tserverName), metav1.GetOptions{}) - assert.Nil(t, err) - assert.NotNil(t, statefulSets) - assert.Equal(t, int32(3), *statefulSets.Spec.Replicas) - assert.Equal(t, 1, len(statefulSets.Spec.VolumeClaimTemplates)) - - vct = *cluster.Spec.TServer.VolumeClaimTemplate.DeepCopy() - vct.Name = addCRNameSuffix(vct.Name) - expectedVolumeClaimTemplates = []v1.PersistentVolumeClaim{vct} - assert.Equal(t, expectedVolumeClaimTemplates, statefulSets.Spec.VolumeClaimTemplates) - assert.Equal(t, 1, len(statefulSets.Spec.Template.Spec.Containers)) - - container = statefulSets.Spec.Template.Spec.Containers[0] - expectedContainerPorts = []v1.ContainerPort{ - {Name: tserverContainerUIPortName, ContainerPort: tserverUIPortDefault}, - {Name: tserverContainerRPCPortName, ContainerPort: tserverRPCPortDefault}, - {Name: cassandraPortName, ContainerPort: tserverCassandraPortDefault}, - {Name: redisPortName, ContainerPort: tserverRedisPortDefault}, - {Name: postgresPortName, ContainerPort: tserverPostgresPortDefault}, - } - assert.Equal(t, expectedContainerPorts, container.Ports) - assert.NotNil(t, container.Resources) - assert.Equal(t, 2, len(container.Resources.Requests)) - assert.Equal(t, 2, len(container.Resources.Limits)) - - reqCPU, reqOk = container.Resources.Requests[v1.ResourceCPU] - limCPU, limOk = container.Resources.Limits[v1.ResourceCPU] - assert.True(t, reqOk) - assert.True(t, limOk) - assert.Equal(t, 0, (&reqCPU).Cmp(resource.MustParse(podCPULimitDefault))) - assert.Equal(t, 0, (&limCPU).Cmp(resource.MustParse(podCPULimitDefault))) - - reqMem, reqOk = container.Resources.Requests[v1.ResourceMemory] - limMem, limOk = container.Resources.Limits[v1.ResourceMemory] - assert.True(t, limOk) - assert.True(t, reqOk) - assert.Equal(t, 0, (&reqMem).Cmp(resource.MustParse(tserverMemLimitDefault))) - assert.Equal(t, 0, (&limMem).Cmp(resource.MustParse(tserverMemLimitDefault))) - - volumeMountName = addCRNameSuffix(cluster.Spec.TServer.VolumeClaimTemplate.Name) - expectedVolumeMounts = []v1.VolumeMount{{Name: volumeMountName, MountPath: volumeMountPath}} - assert.Equal(t, expectedVolumeMounts, container.VolumeMounts) - - expectedEnvVars = []v1.EnvVar{ - { - Name: envGetHostsFrom, - Value: envGetHostsFromVal}, - { - Name: envPodIP, - ValueFrom: &v1.EnvVarSource{ - FieldRef: &v1.ObjectFieldSelector{ - FieldPath: envPodIPVal, - }, - }, - }, - { - Name: k8sutil.PodNameEnvVar, - ValueFrom: &v1.EnvVarSource{ - FieldRef: &v1.ObjectFieldSelector{ - FieldPath: envPodNameVal, - }, - }, - }, - } - assert.Equal(t, expectedEnvVars, container.Env) - - expectedCommand = []string{ - "/home/yugabyte/bin/yb-tserver", - "--fs_data_dirs=/mnt/data0", - "--rpc_bind_addresses=$(POD_IP):9100", - fmt.Sprintf("--server_broadcast_addresses=$(POD_NAME).%s:9100", addCRNameSuffix(tserverNamePlural)), - "--pgsql_proxy_bind_address=$(POD_IP):5433", - "--use_private_ip=never", - fmt.Sprintf("--tserver_master_addrs=%s", getMasterAddresses(addCRNameSuffix(masterName), addCRNameSuffix(masterNamePlural), namespace, int32(3), int32(7100))), - "--enable_ysql=true", - "--logtostderr", - "--memory_limit_hard_bytes=3649044480", - } - assert.Equal(t, expectedCommand, container.Command) - - // verify TServer pods are created - pods, err = clientset.CoreV1().Pods(namespace).List(ctx, metav1.ListOptions{ - LabelSelector: fmt.Sprintf("%s=%s", k8sutil.AppAttr, addCRNameSuffix(tserverName)), - }) - assert.Nil(t, err) - assert.NotNil(t, pods) - assert.Equal(t, 3, len(pods.Items)) -} - -func TestOnAddWithTServerUI(t *testing.T) { - ctx := context.TODO() - namespace := "rook-yugabytedb" - - // initialize the controller and its dependencies - clientset := testop.New(t, 3) - context := &clusterd.Context{Clientset: clientset} - controller := NewClusterController(context, "rook/yugabytedb:mockTag") - controllerSet := &ControllerSet{ - ClientSet: clientset, - Context: context, - Controller: controller, - } - - simulateARunningYugabyteCluster(ctx, t, controllerSet, namespace, int32(1), true) - - expectedServicePorts := []v1.ServicePort{ - {Name: uiPortName, Port: masterUIPortDefault, TargetPort: intstr.FromInt(int(masterUIPortDefault))}, - } - - // verify Master UI service is created - clientService, err := clientset.CoreV1().Services(namespace).Get(ctx, addCRNameSuffix(masterUIServiceName), metav1.GetOptions{}) - assert.Nil(t, err) - assert.NotNil(t, clientService) - assert.Equal(t, v1.ServiceTypeClusterIP, clientService.Spec.Type) - assert.Equal(t, expectedServicePorts, clientService.Spec.Ports) - - // verify TServer UI service is ALSO created - expectedServicePorts = []v1.ServicePort{ - {Name: uiPortName, Port: tserverUIPortDefault, TargetPort: intstr.FromInt(int(tserverUIPortDefault))}, - } - - clientService, err = clientset.CoreV1().Services(namespace).Get(ctx, addCRNameSuffix(tserverUIServiceName), metav1.GetOptions{}) - assert.Nil(t, err) - assert.NotNil(t, clientService) - assert.Equal(t, v1.ServiceTypeClusterIP, clientService.Spec.Type) - assert.Equal(t, expectedServicePorts, clientService.Spec.Ports) - -} - -type ControllerSet struct { - ClientSet *fake.Clientset - Context *clusterd.Context - Controller *ClusterController -} - -func TestOnUpdate_replicaCount(t *testing.T) { - ctx := context.TODO() - // initialize the controller and its dependencies - namespace := "rook-yugabytedb" - initialReplicatCount := 3 - clientset := testop.New(t, initialReplicatCount) - context := &clusterd.Context{Clientset: clientset} - controller := NewClusterController(context, "rook/yugabytedb:mockTag") - controllerSet := &ControllerSet{ - ClientSet: clientset, - Context: context, - Controller: controller, - } - - cluster := simulateARunningYugabyteCluster(ctx, t, controllerSet, namespace, int32(initialReplicatCount), false) - - // Verify all must-have components exist before updation. - verifyAllComponentsExist(ctx, t, clientset, namespace) - - // verify TServer UI service is NOT present - clientService, _ := clientset.CoreV1().Services(namespace).Get(ctx, addCRNameSuffix(tserverUIServiceName), metav1.GetOptions{}) - assert.Nil(t, clientService) - - // verify Master pods count matches initial count. - pods, _ := clientset.CoreV1().Pods(namespace).List(ctx, metav1.ListOptions{ - LabelSelector: fmt.Sprintf("%s=%s", k8sutil.AppAttr, addCRNameSuffix(masterName)), - }) - assert.NotNil(t, pods) - assert.Equal(t, initialReplicatCount, len(pods.Items)) - - // verify TServer pods count matches initial count. - pods, _ = clientset.CoreV1().Pods(namespace).List(ctx, metav1.ListOptions{ - LabelSelector: fmt.Sprintf("%s=%s", k8sutil.AppAttr, addCRNameSuffix(tserverName)), - }) - assert.NotNil(t, pods) - assert.Equal(t, initialReplicatCount, len(pods.Items)) - - // Update replica size - updatedMasterReplicaCount := 1 - updatedTServerReplicaCount := 2 - - newCluster := cluster.DeepCopy() - - newCluster.Spec.Master.Replicas = int32(updatedMasterReplicaCount) - newCluster.Spec.TServer.Replicas = int32(updatedTServerReplicaCount) - - controller.OnUpdate(cluster, newCluster) - - // Verify all must-have components exist after updation. - verifyAllComponentsExist(ctx, t, clientset, namespace) - - // verify TServer UI service is NOT present - clientService, _ = clientset.CoreV1().Services(namespace).Get(ctx, addCRNameSuffix(tserverUIServiceName), metav1.GetOptions{}) - assert.Nil(t, clientService) - - // verify Master pods count matches updated count. - pods, _ = clientset.CoreV1().Pods(namespace).List(ctx, metav1.ListOptions{ - LabelSelector: fmt.Sprintf("%s=%s", k8sutil.AppAttr, addCRNameSuffix(masterName)), - }) - assert.NotNil(t, pods) - assert.Equal(t, initialReplicatCount, len(pods.Items)) - - // verify TServer pods count matches updated count. - pods, _ = clientset.CoreV1().Pods(namespace).List(ctx, metav1.ListOptions{ - LabelSelector: fmt.Sprintf("%s=%s", k8sutil.AppAttr, addCRNameSuffix(tserverName)), - }) - assert.NotNil(t, pods) - assert.Equal(t, initialReplicatCount, len(pods.Items)) -} - -func TestOnUpdate_volumeClaimTemplate(t *testing.T) { - ctx := context.TODO() - // initialize the controller and its dependencies - namespace := "rook-yugabytedb" - initialReplicatCount := 3 - clientset := testop.New(t, initialReplicatCount) - context := &clusterd.Context{Clientset: clientset} - controller := NewClusterController(context, "rook/yugabytedb:mockTag") - controllerSet := &ControllerSet{ - ClientSet: clientset, - Context: context, - Controller: controller, - } - - cluster := simulateARunningYugabyteCluster(ctx, t, controllerSet, namespace, int32(initialReplicatCount), false) - - // Verify all must-have components exist before updation. - verifyAllComponentsExist(ctx, t, clientset, namespace) - - // verify TServer UI service is NOT present - clientService, _ := clientset.CoreV1().Services(namespace).Get(ctx, addCRNameSuffix(tserverUIServiceName), metav1.GetOptions{}) - assert.Nil(t, clientService) - - // verify Master VolumeClaimTemplate size is as set initially. - statefulSet, _ := clientset.AppsV1().StatefulSets(namespace).Get(ctx, addCRNameSuffix(masterName), metav1.GetOptions{}) - assert.NotNil(t, statefulSet) - vct := statefulSet.Spec.VolumeClaimTemplates[0] - assert.NotNil(t, vct) - assert.Equal(t, resource.MustParse("1Mi"), vct.Spec.Resources.Requests[v1.ResourceStorage]) - - // verify TServer VolumeClaimTemplate size is as set initially. - statefulSet, _ = clientset.AppsV1().StatefulSets(namespace).Get(ctx, addCRNameSuffix(tserverName), metav1.GetOptions{}) - assert.NotNil(t, statefulSet) - vct = statefulSet.Spec.VolumeClaimTemplates[0] - assert.NotNil(t, vct) - assert.Equal(t, resource.MustParse("1Mi"), vct.Spec.Resources.Requests[v1.ResourceStorage]) - - // Update volumeclaimtemplates size - newCluster := cluster.DeepCopy() - - newCluster.Spec.Master.VolumeClaimTemplate.Spec.Resources.Requests = v1.ResourceList{ - v1.ResourceStorage: resource.MustParse("10Mi"), - } - newCluster.Spec.TServer.VolumeClaimTemplate.Spec.Resources.Requests = v1.ResourceList{ - v1.ResourceStorage: resource.MustParse("20Mi"), - } - - controller.OnUpdate(cluster, newCluster) - - // Verify all must-have components exist after updation. - verifyAllComponentsExist(ctx, t, clientset, namespace) - - // verify TServer UI service is NOT present - clientService, _ = clientset.CoreV1().Services(namespace).Get(ctx, addCRNameSuffix(tserverUIServiceName), metav1.GetOptions{}) - assert.Nil(t, clientService) - - // verify Master VolumeClaimTemplate is updated. - statefulSet, _ = clientset.AppsV1().StatefulSets(namespace).Get(ctx, addCRNameSuffix(masterName), metav1.GetOptions{}) - assert.NotNil(t, statefulSet) - vct = statefulSet.Spec.VolumeClaimTemplates[0] - assert.NotNil(t, vct) - assert.Equal(t, resource.MustParse("10Mi"), vct.Spec.Resources.Requests[v1.ResourceStorage]) - - // verify TServer VolumeClaimTemplate is updated. - statefulSet, _ = clientset.AppsV1().StatefulSets(namespace).Get(ctx, addCRNameSuffix(tserverName), metav1.GetOptions{}) - assert.NotNil(t, statefulSet) - vct = statefulSet.Spec.VolumeClaimTemplates[0] - assert.NotNil(t, vct) - assert.Equal(t, resource.MustParse("20Mi"), vct.Spec.Resources.Requests[v1.ResourceStorage]) -} - -func TestOnUpdate_updateNetworkPorts(t *testing.T) { - ctx := context.TODO() - // initialize the controller and its dependencies - namespace := "rook-yugabytedb" - initialReplicatCount := 3 - clientset := testop.New(t, initialReplicatCount) - context := &clusterd.Context{Clientset: clientset} - controller := NewClusterController(context, "rook/yugabytedb:mockTag") - controllerSet := &ControllerSet{ - ClientSet: clientset, - Context: context, - Controller: controller, - } - - cluster := simulateARunningYugabyteCluster(ctx, t, controllerSet, namespace, int32(initialReplicatCount), false) - - verifyAllComponentsExist(ctx, t, clientset, namespace) - - // verify Master UI service ports - expectedMUIServicePorts := getMasterUIServicePortsList(false) - - clientService, _ := clientset.CoreV1().Services(namespace).Get(ctx, addCRNameSuffix(masterUIServiceName), metav1.GetOptions{}) - assert.NotNil(t, clientService) - assert.Equal(t, v1.ServiceTypeClusterIP, clientService.Spec.Type) - assert.Equal(t, expectedMUIServicePorts, clientService.Spec.Ports) - - // verify TServer UI service is NOT created - clientService, _ = clientset.CoreV1().Services(namespace).Get(ctx, addCRNameSuffix(tserverUIServiceName), metav1.GetOptions{}) - assert.Nil(t, clientService) - - // verify Master headless Service ports - expectedMHServicePorts := getMasterHeadlessServicePortsList(false) - - headlessService, _ := clientset.CoreV1().Services(namespace).Get(ctx, addCRNameSuffix(masterNamePlural), metav1.GetOptions{}) - assert.NotNil(t, headlessService) - assert.Equal(t, "None", headlessService.Spec.ClusterIP) - assert.Equal(t, expectedMHServicePorts, headlessService.Spec.Ports) - - // verify TServer headless Service ports - expectedTHServicePorts := getTServerHeadlessServicePortsList(false) - - headlessService, _ = clientset.CoreV1().Services(namespace).Get(ctx, addCRNameSuffix(tserverNamePlural), metav1.GetOptions{}) - assert.NotNil(t, headlessService) - assert.Equal(t, "None", headlessService.Spec.ClusterIP) - assert.Equal(t, expectedTHServicePorts, headlessService.Spec.Ports) - - // Update network ports - newCluster := cluster.DeepCopy() - - newCluster.Spec.Master.Network = getUpdatedMasterNetworkSpec() - newCluster.Spec.TServer.Network = getUpdatedTServerNetworkSpec() - - controller.OnUpdate(cluster, newCluster) - - verifyAllComponentsExist(ctx, t, clientset, namespace) - - // verify Master UI service ports - expectedMUIServicePorts = getMasterUIServicePortsList(true) - - clientService, _ = clientset.CoreV1().Services(namespace).Get(ctx, addCRNameSuffix(masterUIServiceName), metav1.GetOptions{}) - assert.NotNil(t, clientService) - assert.Equal(t, v1.ServiceTypeClusterIP, clientService.Spec.Type) - assert.Equal(t, expectedMUIServicePorts, clientService.Spec.Ports) - - // verify TServer UI service is NOT created - clientService, _ = clientset.CoreV1().Services(namespace).Get(ctx, addCRNameSuffix(tserverUIServiceName), metav1.GetOptions{}) - assert.Nil(t, clientService) - - // verify Master headless Service ports - expectedMHServicePorts = getMasterHeadlessServicePortsList(true) - - headlessService, _ = clientset.CoreV1().Services(namespace).Get(ctx, addCRNameSuffix(masterNamePlural), metav1.GetOptions{}) - assert.NotNil(t, headlessService) - assert.Equal(t, "None", headlessService.Spec.ClusterIP) - assert.Equal(t, expectedMHServicePorts, headlessService.Spec.Ports) - - // verify TServer headless Service ports - expectedTHServicePorts = getTServerHeadlessServicePortsList(true) - - // Since updated YBDB cluster spec doesn't have TServer UI port specified, the port on TServer Headless service will be of default value. - expectedTHServicePorts[0].Port = tserverUIPortDefault - expectedTHServicePorts[0].TargetPort = intstr.FromInt(int(tserverUIPortDefault)) - - headlessService, _ = clientset.CoreV1().Services(namespace).Get(ctx, addCRNameSuffix(tserverNamePlural), metav1.GetOptions{}) - assert.NotNil(t, headlessService) - assert.Equal(t, "None", headlessService.Spec.ClusterIP) - assert.Equal(t, expectedTHServicePorts, headlessService.Spec.Ports) -} - -func TestOnUpdate_addTServerUIPort(t *testing.T) { - ctx := context.TODO() - // initialize the controller and its dependencies - namespace := "rook-yugabytedb" - initialReplicatCount := 3 - clientset := testop.New(t, initialReplicatCount) - context := &clusterd.Context{Clientset: clientset} - controller := NewClusterController(context, "rook/yugabytedb:mockTag") - controllerSet := &ControllerSet{ - ClientSet: clientset, - Context: context, - Controller: controller, - } - - cluster := simulateARunningYugabyteCluster(ctx, t, controllerSet, namespace, int32(initialReplicatCount), false) - - verifyAllComponentsExist(ctx, t, clientset, namespace) - - // verify Master UI service ports - expectedMUIServicePorts := getMasterUIServicePortsList(false) - - clientService, _ := clientset.CoreV1().Services(namespace).Get(ctx, addCRNameSuffix(masterUIServiceName), metav1.GetOptions{}) - assert.NotNil(t, clientService) - assert.Equal(t, v1.ServiceTypeClusterIP, clientService.Spec.Type) - assert.Equal(t, expectedMUIServicePorts, clientService.Spec.Ports) - - // verify TServer UI service is NOT created - clientService, _ = clientset.CoreV1().Services(namespace).Get(ctx, addCRNameSuffix(tserverUIServiceName), metav1.GetOptions{}) - assert.Nil(t, clientService) - - // verify Master headless Service ports - expectedMHServicePorts := getMasterHeadlessServicePortsList(false) - - headlessService, _ := clientset.CoreV1().Services(namespace).Get(ctx, addCRNameSuffix(masterNamePlural), metav1.GetOptions{}) - assert.NotNil(t, headlessService) - assert.Equal(t, "None", headlessService.Spec.ClusterIP) - assert.Equal(t, expectedMHServicePorts, headlessService.Spec.Ports) - - // verify TServer headless Service ports - expectedTHServicePorts := getTServerHeadlessServicePortsList(false) - - headlessService, _ = clientset.CoreV1().Services(namespace).Get(ctx, addCRNameSuffix(tserverNamePlural), metav1.GetOptions{}) - assert.NotNil(t, headlessService) - assert.Equal(t, "None", headlessService.Spec.ClusterIP) - assert.Equal(t, expectedTHServicePorts, headlessService.Spec.Ports) - - // Update network ports, which contain TServer UI Port number - newCluster := cluster.DeepCopy() - - updatedTServerNetworkSpec := getUpdatedTServerNetworkSpec() - updatedTServerNetworkSpec.Ports = append(updatedTServerNetworkSpec.Ports, yugabytedbv1alpha1.PortSpec{ - Name: tserverUIPortName, - Port: tserverUIPortDefault + int32(CustomPortShift), - }) - - newCluster.Spec.Master.Network = getUpdatedMasterNetworkSpec() - newCluster.Spec.TServer.Network = updatedTServerNetworkSpec - - logger.Info("Updated TServer network specs: ", newCluster.Spec.TServer.Network) - - controller.OnUpdate(cluster, newCluster) - - verifyAllComponentsExist(ctx, t, clientset, namespace) - - // verify Master UI service ports - expectedMUIServicePorts = getMasterUIServicePortsList(true) - - clientService, _ = clientset.CoreV1().Services(namespace).Get(ctx, addCRNameSuffix(masterUIServiceName), metav1.GetOptions{}) - assert.NotNil(t, clientService) - assert.Equal(t, v1.ServiceTypeClusterIP, clientService.Spec.Type) - assert.Equal(t, expectedMUIServicePorts, clientService.Spec.Ports) - - // verify TServer UI service IS created - expectedTUIServicePorts := getTServerUIServicePortsList(true) - - clientService2, err := clientset.CoreV1().Services(namespace).Get(ctx, addCRNameSuffix(tserverUIServiceName), metav1.GetOptions{}) - assert.Nil(t, err) - assert.NotNil(t, clientService2) - assert.Equal(t, v1.ServiceTypeClusterIP, clientService2.Spec.Type) - assert.Equal(t, expectedTUIServicePorts, clientService2.Spec.Ports) - - // verify Master headless Service ports - expectedMHServicePorts = getMasterHeadlessServicePortsList(true) - - headlessService, _ = clientset.CoreV1().Services(namespace).Get(ctx, addCRNameSuffix(masterNamePlural), metav1.GetOptions{}) - assert.NotNil(t, headlessService) - assert.Equal(t, "None", headlessService.Spec.ClusterIP) - assert.Equal(t, expectedMHServicePorts, headlessService.Spec.Ports) - - // verify TServer headless Service ports - expectedTHServicePorts = getTServerHeadlessServicePortsList(true) - - headlessService, _ = clientset.CoreV1().Services(namespace).Get(ctx, addCRNameSuffix(tserverNamePlural), metav1.GetOptions{}) - assert.NotNil(t, headlessService) - assert.Equal(t, "None", headlessService.Spec.ClusterIP) - assert.Equal(t, expectedTHServicePorts, headlessService.Spec.Ports) -} - -func TestOnUpdate_removeTServerUIPort(t *testing.T) { - ctx := context.TODO() - // initialize the controller and its dependencies - namespace := "rook-yugabytedb" - initialReplicatCount := 3 - clientset := testop.New(t, initialReplicatCount) - context := &clusterd.Context{Clientset: clientset} - controller := NewClusterController(context, "rook/yugabytedb:mockTag") - controllerSet := &ControllerSet{ - ClientSet: clientset, - Context: context, - Controller: controller, - } - - cluster := simulateARunningYugabyteCluster(ctx, t, controllerSet, namespace, int32(initialReplicatCount), true) - - verifyAllComponentsExist(ctx, t, clientset, namespace) - - // verify Master UI service ports - expectedMUIServicePorts := getMasterUIServicePortsList(false) - - clientService, _ := clientset.CoreV1().Services(namespace).Get(ctx, addCRNameSuffix(masterUIServiceName), metav1.GetOptions{}) - assert.NotNil(t, clientService) - assert.Equal(t, v1.ServiceTypeClusterIP, clientService.Spec.Type) - assert.Equal(t, expectedMUIServicePorts, clientService.Spec.Ports) - - // verify TServer UI service IS created - expectedTUIServicePorts := getTServerUIServicePortsList(false) - - clientService2, err := clientset.CoreV1().Services(namespace).Get(ctx, addCRNameSuffix(tserverUIServiceName), metav1.GetOptions{}) - assert.Nil(t, err) - assert.NotNil(t, clientService2) - assert.Equal(t, v1.ServiceTypeClusterIP, clientService2.Spec.Type) - assert.Equal(t, expectedTUIServicePorts, clientService2.Spec.Ports) - - // verify Master headless Service ports - expectedMHServicePorts := getMasterHeadlessServicePortsList(false) - - headlessService, _ := clientset.CoreV1().Services(namespace).Get(ctx, addCRNameSuffix(masterNamePlural), metav1.GetOptions{}) - assert.NotNil(t, headlessService) - assert.Equal(t, "None", headlessService.Spec.ClusterIP) - assert.Equal(t, expectedMHServicePorts, headlessService.Spec.Ports) - - // verify TServer headless Service ports - expectedTHServicePorts := getTServerHeadlessServicePortsList(false) - - headlessService, _ = clientset.CoreV1().Services(namespace).Get(ctx, addCRNameSuffix(tserverNamePlural), metav1.GetOptions{}) - assert.NotNil(t, headlessService) - assert.Equal(t, "None", headlessService.Spec.ClusterIP) - assert.Equal(t, expectedTHServicePorts, headlessService.Spec.Ports) - - // Update network ports, which lack TServer UI Port number - newCluster := cluster.DeepCopy() - - newCluster.Spec.Master.Network = getUpdatedMasterNetworkSpec() - newCluster.Spec.TServer.Network = getUpdatedTServerNetworkSpec() - - controller.OnUpdate(cluster, newCluster) - - verifyAllComponentsExist(ctx, t, clientset, namespace) - - // verify Master UI service ports - expectedMUIServicePorts = getMasterUIServicePortsList(true) - - clientService, _ = clientset.CoreV1().Services(namespace).Get(ctx, addCRNameSuffix(masterUIServiceName), metav1.GetOptions{}) - assert.NotNil(t, clientService) - assert.Equal(t, v1.ServiceTypeClusterIP, clientService.Spec.Type) - assert.Equal(t, expectedMUIServicePorts, clientService.Spec.Ports) - - // verify TServer UI service IS DELETED - clientService2, err = clientset.CoreV1().Services(namespace).Get(ctx, addCRNameSuffix(tserverUIServiceName), metav1.GetOptions{}) - assert.NotNil(t, err) - assert.True(t, errors.IsNotFound(err)) - assert.Nil(t, clientService2) - - // verify Master headless Service ports - expectedMHServicePorts = getMasterHeadlessServicePortsList(true) - - headlessService, _ = clientset.CoreV1().Services(namespace).Get(ctx, addCRNameSuffix(masterNamePlural), metav1.GetOptions{}) - assert.NotNil(t, headlessService) - assert.Equal(t, "None", headlessService.Spec.ClusterIP) - assert.Equal(t, expectedMHServicePorts, headlessService.Spec.Ports) - - // verify TServer headless Service ports - expectedTHServicePorts = getTServerHeadlessServicePortsList(true) - - // Since updated YBDB cluster spec doesn't have TServer UI port specified, the port on TServer Headless service will be of default value. - expectedTHServicePorts[0].Port = tserverUIPortDefault - expectedTHServicePorts[0].TargetPort = intstr.FromInt(int(tserverUIPortDefault)) - - headlessService, _ = clientset.CoreV1().Services(namespace).Get(ctx, addCRNameSuffix(tserverNamePlural), metav1.GetOptions{}) - assert.NotNil(t, headlessService) - assert.Equal(t, "None", headlessService.Spec.ClusterIP) - assert.Equal(t, expectedTHServicePorts, headlessService.Spec.Ports) -} - -// Verify all must-have components exist after updation. -func verifyAllComponentsExist(ctx context.Context, t *testing.T, clientset *fake.Clientset, namespace string) { - // verify Master UI service is created - clientService, err := clientset.CoreV1().Services(namespace).Get(ctx, addCRNameSuffix(masterUIServiceName), metav1.GetOptions{}) - assert.Nil(t, err) - assert.NotNil(t, clientService) - - // verify Master headless Service is created - headlessService, err := clientset.CoreV1().Services(namespace).Get(ctx, addCRNameSuffix(masterNamePlural), metav1.GetOptions{}) - assert.Nil(t, err) - assert.NotNil(t, headlessService) - - // verify TServer headless Service is created - headlessService, err = clientset.CoreV1().Services(namespace).Get(ctx, addCRNameSuffix(tserverNamePlural), metav1.GetOptions{}) - assert.Nil(t, err) - assert.NotNil(t, headlessService) - - // verify Master statefulSet is created - statefulSets, err := clientset.AppsV1().StatefulSets(namespace).Get(ctx, addCRNameSuffix(masterName), metav1.GetOptions{}) - assert.NoError(t, err) - assert.NotNil(t, statefulSets) - - // verify Master pods are created - pods, err := clientset.CoreV1().Pods(namespace).List(ctx, metav1.ListOptions{ - LabelSelector: fmt.Sprintf("%s=%s", k8sutil.AppAttr, addCRNameSuffix(masterName)), - }) - assert.Nil(t, err) - assert.NotNil(t, pods) - - // verify TServer statefulSet is created - statefulSets, err = clientset.AppsV1().StatefulSets(namespace).Get(ctx, addCRNameSuffix(tserverName), metav1.GetOptions{}) - assert.Nil(t, err) - assert.NotNil(t, statefulSets) - - // verify TServer pods are created - pods, err = clientset.CoreV1().Pods(namespace).List(ctx, metav1.ListOptions{ - LabelSelector: fmt.Sprintf("%s=%s", k8sutil.AppAttr, addCRNameSuffix(tserverName)), - }) - assert.Nil(t, err) - assert.NotNil(t, pods) -} - -func simulateARunningYugabyteCluster(ctx context.Context, t *testing.T, controllerSet *ControllerSet, namespace string, replicaCount int32, addTServerUIService bool) *yugabytedbv1alpha1.YBCluster { - cluster := &yugabytedbv1alpha1.YBCluster{ - ObjectMeta: metav1.ObjectMeta{ - Name: ClusterName, - Namespace: namespace, - }, - Spec: yugabytedbv1alpha1.YBClusterSpec{ - Master: yugabytedbv1alpha1.ServerSpec{ - Replicas: replicaCount, - VolumeClaimTemplate: v1.PersistentVolumeClaim{ - ObjectMeta: metav1.ObjectMeta{ - Name: VolumeDataName, - }, - Spec: v1.PersistentVolumeClaimSpec{ - AccessModes: []v1.PersistentVolumeAccessMode{ - v1.ReadWriteOnce, - }, - Resources: v1.ResourceRequirements{ - Requests: v1.ResourceList{ - v1.ResourceStorage: resource.MustParse("1Mi"), - }, - }, - }, - }, - }, - TServer: yugabytedbv1alpha1.ServerSpec{ - Replicas: replicaCount, - VolumeClaimTemplate: v1.PersistentVolumeClaim{ - ObjectMeta: metav1.ObjectMeta{ - Name: VolumeDataName, - }, - Spec: v1.PersistentVolumeClaimSpec{ - AccessModes: []v1.PersistentVolumeAccessMode{ - v1.ReadWriteOnce, - }, - Resources: v1.ResourceRequirements{ - Requests: v1.ResourceList{ - v1.ResourceStorage: resource.MustParse("1Mi"), - }, - }, - }, - }, - }, - }, - } - - if addTServerUIService { - cluster.Spec.TServer.Network.Ports = append(cluster.Spec.TServer.Network.Ports, yugabytedbv1alpha1.PortSpec{ - Name: tserverUIPortName, - Port: tserverUIPortDefault, - }) - } - - // in a background thread, simulate running pods for Master & TServer processes. (fake statefulsets don't automatically do that) - go simulateMasterPodsRunning(ctx, t, controllerSet.ClientSet, namespace, replicaCount) - go simulateTServerPodsRunning(ctx, t, controllerSet.ClientSet, namespace, replicaCount) - - // Wait for Pods to start & go to running state - waitForPodsToStart(ctx, controllerSet.ClientSet, namespace, replicaCount) - - // call OnAdd given the specified cluster - controllerSet.Controller.OnAdd(cluster) - - return cluster -} - -func simulateMasterPodsRunning(ctx context.Context, t *testing.T, clientset *fake.Clientset, namespace string, podCount int32) { - simulatePodsRunning(ctx, t, clientset, namespace, podCount, addCRNameSuffix(masterName)) -} - -func simulateTServerPodsRunning(ctx context.Context, t *testing.T, clientset *fake.Clientset, namespace string, podCount int32) { - simulatePodsRunning(ctx, t, clientset, namespace, podCount, addCRNameSuffix(tserverName)) -} - -func waitForPodsToStart(ctx context.Context, clientset *fake.Clientset, namespace string, podCount int32) { - logger.Info("Waiting for Master & TServer pods to start & go to running state") - err := wait.Poll(PodCreationWaitInterval, PodCreationWaitTimeout, func() (bool, error) { - // Check if Master Pods are running - if err := isPodsRunning(ctx, clientset, namespace, masterName, podCount); err != nil { - logger.Warningf("Master pods are not yet running: %+v", err) - return false, nil - } - - // Check if TServer Pods are running - if err := isPodsRunning(ctx, clientset, namespace, tserverName, podCount); err != nil { - logger.Warningf("TServer pods are not yet running: %+v", err) - return false, nil - } - - return true, nil - }) - - if err != nil { - logger.Errorf("failed to start Master & TServer pods in namespace %s: %+v", namespace, err) - return - } -} - -func isPodsRunning(ctx context.Context, clientset *fake.Clientset, namespace, label string, podCount int32) error { - pods, err := clientset.CoreV1().Pods(namespace).List(ctx, metav1.ListOptions{ - LabelSelector: fmt.Sprintf("%s=%s", k8sutil.AppAttr, addCRNameSuffix(label)), - }) - if err != nil { - return fmt.Errorf("failed to list %s pods. error: %+v", label, err) - } - - runningPods := len(k8sutil.GetPodPhaseMap(pods)[v1.PodRunning]) - if runningPods != int(podCount) { - return fmt.Errorf("need %d %s pods & found %d ", podCount, label, runningPods) - } - - return nil -} - -func simulatePodsRunning(ctx context.Context, t *testing.T, clientset *fake.Clientset, namespace string, podCount int32, podName string) { - for i := 0; i < int(podCount); i++ { - pod := &v1.Pod{ - ObjectMeta: metav1.ObjectMeta{ - Name: fmt.Sprintf("%s-%d", podName, i), - Namespace: namespace, - Labels: map[string]string{k8sutil.AppAttr: podName}, - }, - Status: v1.PodStatus{Phase: v1.PodRunning}, - } - _, err := clientset.CoreV1().Pods(namespace).Create(ctx, pod, metav1.CreateOptions{}) - if err != nil { - assert.NoError(t, err) - } - } -} - -func getMasterUIServicePortsList(returnCustomPorts bool) []v1.ServicePort { - if returnCustomPorts { - return []v1.ServicePort{ - getServicePort(uiPortName, int(masterUIPortDefault)+CustomPortShift), - } - } - - return []v1.ServicePort{ - getServicePort(uiPortName, int(masterUIPortDefault)), - } -} - -func getTServerUIServicePortsList(returnCustomPorts bool) []v1.ServicePort { - if returnCustomPorts { - return []v1.ServicePort{ - getServicePort(uiPortName, int(tserverUIPortDefault)+CustomPortShift), - } - } - - return []v1.ServicePort{ - getServicePort(uiPortName, int(tserverUIPortDefault)), - } -} - -func getMasterHeadlessServicePortsList(returnCustomPorts bool) []v1.ServicePort { - if returnCustomPorts { - return []v1.ServicePort{ - getServicePort(uiPortName, int(masterUIPortDefault)+CustomPortShift), - getServicePort(rpcPortName, int(masterRPCPortDefault)+CustomPortShift), - } - } - - return []v1.ServicePort{ - getServicePort(uiPortName, int(masterUIPortDefault)), - getServicePort(rpcPortName, int(masterRPCPortDefault)), - } -} - -func getTServerHeadlessServicePortsList(returnCustomPorts bool) []v1.ServicePort { - if returnCustomPorts { - return []v1.ServicePort{ - getServicePort(uiPortName, int(tserverUIPortDefault)+CustomPortShift), - getServicePort(rpcPortName, int(tserverRPCPortDefault)+CustomPortShift), - getServicePort(cassandraPortName, int(tserverCassandraPortDefault)+CustomPortShift), - getServicePort(redisPortName, int(tserverRedisPortDefault)+CustomPortShift), - getServicePort(postgresPortName, int(tserverPostgresPortDefault)+CustomPortShift), - } - } - - return []v1.ServicePort{ - getServicePort(uiPortName, int(tserverUIPortDefault)), - getServicePort(rpcPortName, int(tserverRPCPortDefault)), - getServicePort(cassandraPortName, int(tserverCassandraPortDefault)), - getServicePort(redisPortName, int(tserverRedisPortDefault)), - getServicePort(postgresPortName, int(tserverPostgresPortDefault)), - } -} - -func getServicePort(portName string, portNum int) v1.ServicePort { - return v1.ServicePort{ - Name: portName, - Port: int32(portNum), - TargetPort: intstr.FromInt(portNum), - } -} - -func getUpdatedMasterNetworkSpec() yugabytedbv1alpha1.NetworkSpec { - return yugabytedbv1alpha1.NetworkSpec{ - Ports: []yugabytedbv1alpha1.PortSpec{ - { - Name: masterUIPortName, - Port: masterUIPortDefault + int32(CustomPortShift), - }, - { - Name: masterRPCPortName, - Port: masterRPCPortDefault + int32(CustomPortShift), - }, - }, - } -} - -func getUpdatedTServerNetworkSpec() yugabytedbv1alpha1.NetworkSpec { - return yugabytedbv1alpha1.NetworkSpec{ - Ports: []yugabytedbv1alpha1.PortSpec{ - { - Name: tserverRPCPortName, - Port: tserverRPCPortDefault + int32(CustomPortShift), - }, - { - Name: tserverCassandraPortName, - Port: tserverCassandraPortDefault + int32(CustomPortShift), - }, - { - Name: tserverPostgresPortName, - Port: tserverPostgresPortDefault + int32(CustomPortShift), - }, - { - Name: tserverRedisPortName, - Port: tserverRedisPortDefault + int32(CustomPortShift), - }, - }, - } -} - -func addCRNameSuffix(str string) string { - return fmt.Sprintf("%s-%s", str, ClusterName) -} diff --git a/pkg/operator/yugabytedb/create_controller.go b/pkg/operator/yugabytedb/create_controller.go deleted file mode 100644 index d986710baf5f..000000000000 --- a/pkg/operator/yugabytedb/create_controller.go +++ /dev/null @@ -1,357 +0,0 @@ -/* -Copyright 2019 The Rook Authors. All rights reserved. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package yugabytedb - -import ( - "context" - - yugabytedbv1alpha1 "github.com/rook/rook/pkg/apis/yugabytedb.rook.io/v1alpha1" - "github.com/rook/rook/pkg/operator/k8sutil" - appsv1 "k8s.io/api/apps/v1" - v1 "k8s.io/api/core/v1" - "k8s.io/apimachinery/pkg/api/errors" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" -) - -func (c *ClusterController) OnAdd(obj interface{}) { - clusterObj, ok := obj.(*yugabytedbv1alpha1.YBCluster) - if !ok { - return - } - clusterObj = clusterObj.DeepCopy() - logger.Infof("new cluster %s added to namespace %s", clusterObj.Name, clusterObj.Namespace) - - cluster := NewCluster(clusterObj, c.context) - - if err := validateClusterSpec(cluster.spec); err != nil { - logger.Errorf("invalid cluster spec: %+v", err) - return - } - - if err := c.createMasterHeadlessService(cluster); err != nil { - logger.Errorf("failed to create master headless service: %+v", err) - return - } - - if err := c.createTServerHeadlessService(cluster); err != nil { - logger.Errorf("failed to create TServer headless service: %+v", err) - return - } - - if err := c.createMasterUIService(cluster); err != nil { - logger.Errorf("failed to create Master UI service: %+v", err) - return - } - - if err := c.createTServerUIService(cluster); err != nil { - logger.Errorf("failed to create replica service: %+v", err) - return - } - - if err := c.createMasterStatefulset(cluster); err != nil { - logger.Errorf("failed to create master stateful set: %+v", err) - return - } - - if err := c.createTServerStatefulset(cluster); err != nil { - logger.Errorf("failed to create tserver stateful set: %+v", err) - return - } - - logger.Infof("succeeded creating and initializing cluster in namespace %s", cluster.namespace) -} - -func (c *ClusterController) createMasterUIService(cluster *cluster) error { - return c.createUIService(cluster, false) -} - -// Create UI service for TServer, if user has specified a UI port for it. Do not create it implicitly, with default port. -func (c *ClusterController) createTServerUIService(cluster *cluster) error { - return c.createUIService(cluster, true) -} - -func (c *ClusterController) createUIService(cluster *cluster, isTServerService bool) error { - ctx := context.TODO() - ports, err := getPortsFromSpec(cluster.spec.Master.Network) - if err != nil { - return err - } - - serviceName := masterUIServiceName - label := masterName - - if isTServerService { - ports, err = getPortsFromSpec(cluster.spec.TServer.Network) - if err != nil { - return err - } - // If user hasn't specified TServer UI port, do not create a UI service for it. - if ports.tserverPorts.ui <= 0 { - return nil - } - - serviceName = tserverUIServiceName - label = tserverName - } - - // Append CR name suffix to make the service name & label unique in current namespace. - serviceName = cluster.addCRNameSuffix(serviceName) - label = cluster.addCRNameSuffix(label) - - // This service is meant to be used by clients of the database. It exposes a ClusterIP that will - // automatically load balance connections to the different database pods. - uiService := &v1.Service{ - ObjectMeta: metav1.ObjectMeta{ - Name: serviceName, - Namespace: cluster.namespace, - Labels: createAppLabels(label), - }, - Spec: v1.ServiceSpec{ - Selector: createAppLabels(label), - Type: v1.ServiceTypeClusterIP, - Ports: createUIServicePorts(ports, isTServerService), - }, - } - k8sutil.SetOwnerRef(&uiService.ObjectMeta, &cluster.ownerRef) - - if _, err := c.context.Clientset.CoreV1().Services(cluster.namespace).Create(ctx, uiService, metav1.CreateOptions{}); err != nil { - if !errors.IsAlreadyExists(err) { - return err - } - logger.Infof("client service %s already exists in namespace %s", uiService.Name, uiService.Namespace) - } else { - logger.Infof("client service %s started in namespace %s", uiService.Name, uiService.Namespace) - } - - return nil -} - -func (c *ClusterController) createMasterHeadlessService(cluster *cluster) error { - return c.createHeadlessService(cluster, false) -} - -func (c *ClusterController) createTServerHeadlessService(cluster *cluster) error { - return c.createHeadlessService(cluster, true) -} - -func (c *ClusterController) createHeadlessService(cluster *cluster, isTServerService bool) error { - serviceName := masterNamePlural - label := masterName - ctx := context.TODO() - - if isTServerService { - serviceName = tserverNamePlural - label = tserverName - } - - // Append CR name suffix to make the service name & label unique in current namespace. - serviceName = cluster.addCRNameSuffix(serviceName) - label = cluster.addCRNameSuffix(label) - - // This service only exists to create DNS entries for each pod in the stateful - // set such that they can resolve each other's IP addresses. It does not - // create a load-balanced ClusterIP and should not be used directly by clients - // in most circumstances. - headlessService := &v1.Service{ - ObjectMeta: metav1.ObjectMeta{ - Name: serviceName, - Namespace: cluster.namespace, - Labels: createAppLabels(label), - }, - Spec: v1.ServiceSpec{ - Selector: createAppLabels(label), - // We want all pods in the StatefulSet to have their addresses published for - // the sake of the other YugabyteDB pods even before they're ready, since they - // have to be able to talk to each other in order to become ready. - ClusterIP: "None", - Ports: createServicePorts(cluster, isTServerService), - }, - } - - k8sutil.SetOwnerRef(&headlessService.ObjectMeta, &cluster.ownerRef) - - if _, err := c.context.Clientset.CoreV1().Services(cluster.namespace).Create(ctx, headlessService, metav1.CreateOptions{}); err != nil { - if !errors.IsAlreadyExists(err) { - return err - } - logger.Infof("headless service %s already exists in namespace %s", headlessService.Name, headlessService.Namespace) - } else { - logger.Infof("headless service %s started in namespace %s", headlessService.Name, headlessService.Namespace) - } - - return nil -} - -func (c *ClusterController) createMasterStatefulset(cluster *cluster) error { - return c.createStatefulSet(cluster, false) -} - -func (c *ClusterController) createTServerStatefulset(cluster *cluster) error { - return c.createStatefulSet(cluster, true) -} - -func (c *ClusterController) createStatefulSet(cluster *cluster, isTServerStatefulset bool) error { - replicas := int32(cluster.spec.Master.Replicas) - name := masterName - label := masterName - serviceName := masterNamePlural - ctx := context.TODO() - volumeClaimTemplates := []v1.PersistentVolumeClaim{ - cluster.spec.Master.VolumeClaimTemplate, - } - - if isTServerStatefulset { - replicas = int32(cluster.spec.TServer.Replicas) - name = tserverName - label = tserverName - serviceName = tserverNamePlural - volumeClaimTemplates = []v1.PersistentVolumeClaim{ - cluster.spec.TServer.VolumeClaimTemplate, - } - } - - // Append CR name suffix to make the service name & label unique in current namespace. - name = cluster.addCRNameSuffix(name) - label = cluster.addCRNameSuffix(label) - serviceName = cluster.addCRNameSuffix(serviceName) - volumeClaimTemplates[0].Name = cluster.addCRNameSuffix(volumeClaimTemplates[0].Name) - - statefulSet := &appsv1.StatefulSet{ - ObjectMeta: metav1.ObjectMeta{ - Name: name, - Namespace: cluster.namespace, - Labels: createAppLabels(label), - }, - Spec: appsv1.StatefulSetSpec{ - ServiceName: serviceName, - PodManagementPolicy: appsv1.ParallelPodManagement, - Replicas: &replicas, - Selector: &metav1.LabelSelector{ - MatchLabels: createAppLabels(label), - }, - Template: v1.PodTemplateSpec{ - ObjectMeta: metav1.ObjectMeta{ - Namespace: cluster.namespace, - Labels: createAppLabels(label), - }, - Spec: createPodSpec(cluster, c.containerImage, isTServerStatefulset, name, serviceName), - }, - UpdateStrategy: appsv1.StatefulSetUpdateStrategy{ - Type: appsv1.RollingUpdateStatefulSetStrategyType, - }, - VolumeClaimTemplates: volumeClaimTemplates, - }, - } - cluster.annotations.ApplyToObjectMeta(&statefulSet.Spec.Template.ObjectMeta) - cluster.annotations.ApplyToObjectMeta(&statefulSet.ObjectMeta) - k8sutil.SetOwnerRef(&statefulSet.ObjectMeta, &cluster.ownerRef) - - if _, err := c.context.Clientset.AppsV1().StatefulSets(cluster.namespace).Create(ctx, statefulSet, metav1.CreateOptions{}); err != nil { - if !errors.IsAlreadyExists(err) { - return err - } - logger.Infof("stateful set %s already exists in namespace %s", statefulSet.Name, statefulSet.Namespace) - } else { - logger.Infof("stateful set %s created in namespace %s", statefulSet.Name, statefulSet.Namespace) - } - - return nil -} - -func createPodSpec(cluster *cluster, containerImage string, isTServerStatefulset bool, name, serviceName string) v1.PodSpec { - return v1.PodSpec{ - Affinity: &v1.Affinity{ - PodAntiAffinity: &v1.PodAntiAffinity{ - PreferredDuringSchedulingIgnoredDuringExecution: []v1.WeightedPodAffinityTerm{ - { - Weight: int32(100), - PodAffinityTerm: v1.PodAffinityTerm{ - LabelSelector: &metav1.LabelSelector{ - MatchExpressions: []metav1.LabelSelectorRequirement{ - { - Key: k8sutil.AppAttr, - Operator: metav1.LabelSelectorOpIn, - Values: []string{name}, - }, - }, - }, - TopologyKey: v1.LabelHostname, - }, - }, - }, - }, - }, - Containers: []v1.Container{createContainer(cluster, containerImage, isTServerStatefulset, name, serviceName)}, - } -} - -func createContainer(cluster *cluster, containerImage string, isTServerStatefulset bool, name, serviceName string) v1.Container { - resources := getResourceSpec(cluster.spec.Master.Resource, isTServerStatefulset) - ports, _ := getPortsFromSpec(cluster.spec.Master.Network) - masterCompleteName := cluster.addCRNameSuffix(masterName) - command := createMasterContainerCommand(cluster.namespace, serviceName, masterCompleteName, ports.masterPorts.rpc, cluster.spec.Master.Replicas, resources) - containerPorts := createMasterContainerPortsList(ports) - volumeMountName := cluster.addCRNameSuffix(cluster.spec.Master.VolumeClaimTemplate.Name) - - if isTServerStatefulset { - masterServiceName := cluster.addCRNameSuffix(masterNamePlural) - masterCompleteName := cluster.addCRNameSuffix(masterName) - masterRPCPort := ports.masterPorts.rpc - ports, _ = getPortsFromSpec(cluster.spec.TServer.Network) - resources = getResourceSpec(cluster.spec.TServer.Resource, isTServerStatefulset) - command = createTServerContainerCommand(cluster.namespace, serviceName, masterServiceName, masterCompleteName, masterRPCPort, ports.tserverPorts.rpc, ports.tserverPorts.postgres, cluster.spec.TServer.Replicas, resources) - containerPorts = createTServerContainerPortsList(ports) - volumeMountName = cluster.addCRNameSuffix(cluster.spec.TServer.VolumeClaimTemplate.Name) - } - - return v1.Container{ - Name: name, - Image: yugabyteDBImageName, - ImagePullPolicy: v1.PullAlways, - Env: []v1.EnvVar{ - { - Name: envGetHostsFrom, - Value: envGetHostsFromVal, - }, - { - Name: envPodIP, - ValueFrom: &v1.EnvVarSource{ - FieldRef: &v1.ObjectFieldSelector{ - FieldPath: envPodIPVal, - }, - }, - }, - { - Name: k8sutil.PodNameEnvVar, - ValueFrom: &v1.EnvVarSource{ - FieldRef: &v1.ObjectFieldSelector{ - FieldPath: envPodNameVal, - }, - }, - }, - }, - Resources: resources, - Command: command, - Ports: containerPorts, - VolumeMounts: []v1.VolumeMount{ - { - Name: volumeMountName, - MountPath: volumeMountPath, - }, - }, - } -} diff --git a/pkg/operator/yugabytedb/operator.go b/pkg/operator/yugabytedb/operator.go deleted file mode 100644 index 0e90716fd49a..000000000000 --- a/pkg/operator/yugabytedb/operator.go +++ /dev/null @@ -1,67 +0,0 @@ -/* -Copyright 2019 The Rook Authors. All rights reserved. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -// Package operator to manage Kubernetes storage. -package yugabytedb - -import ( - "os" - "os/signal" - "syscall" - - "github.com/coreos/pkg/capnslog" - "github.com/rook/rook/pkg/clusterd" - "github.com/rook/rook/pkg/operator/k8sutil" - v1 "k8s.io/api/core/v1" -) - -var logger = capnslog.NewPackageLogger("github.com/rook/rook", "yugabytedb-operator") - -type Operator struct { - context *clusterd.Context - resources []k8sutil.CustomResource - rookImage string - clusterController *ClusterController -} - -// New creates an operator instance -func New(context *clusterd.Context, rookImage string) *Operator { - clusterController := NewClusterController(context, rookImage) - - schemes := []k8sutil.CustomResource{ClusterResource} - return &Operator{ - context: context, - clusterController: clusterController, - resources: schemes, - rookImage: rookImage, - } -} - -// Run the operator instance -func (o *Operator) Run() error { - - signalChan := make(chan os.Signal, 1) - stopChan := make(chan struct{}) - signal.Notify(signalChan, syscall.SIGINT, syscall.SIGTERM) - - // watch for changes to the yugabytedb clusters - o.clusterController.StartWatch(v1.NamespaceAll, stopChan) - - <-signalChan - logger.Infof("shutdown signal received, exiting...") - close(stopChan) - return nil -} diff --git a/pkg/operator/yugabytedb/update_controller.go b/pkg/operator/yugabytedb/update_controller.go deleted file mode 100644 index 25f4432378c6..000000000000 --- a/pkg/operator/yugabytedb/update_controller.go +++ /dev/null @@ -1,257 +0,0 @@ -/* -Copyright 2019 The Rook Authors. All rights reserved. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package yugabytedb - -import ( - "context" - - yugabytedbv1alpha1 "github.com/rook/rook/pkg/apis/yugabytedb.rook.io/v1alpha1" - v1 "k8s.io/api/core/v1" - "k8s.io/apimachinery/pkg/api/errors" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" -) - -func (c *ClusterController) OnUpdate(oldObj, newObj interface{}) { - // TODO Create the cluster if previous attempt to create has failed. - oldYBCluster, ok := oldObj.(*yugabytedbv1alpha1.YBCluster) - if !ok { - return - } - _ = oldYBCluster.DeepCopy() - newObjCluster, ok := newObj.(*yugabytedbv1alpha1.YBCluster) - if !ok { - return - } - newYBCluster := NewCluster(newObjCluster, c.context) - - // Validate new spec - if err := validateClusterSpec(newYBCluster.spec); err != nil { - logger.Errorf("invalid cluster spec: %+v", err) - return - } - - // Update headless service ports - if err := c.updateMasterHeadlessService(newYBCluster); err != nil { - logger.Errorf("failed to update Master headless service: %+v", err) - return - } - - if err := c.updateTServerHeadlessService(newYBCluster); err != nil { - logger.Errorf("failed to update TServer headless service: %+v", err) - return - } - - // Create/update/delete UI services (create/delete would apply for TServer UI services) - if err := c.updateMasterUIService(newYBCluster); err != nil { - logger.Errorf("failed to update Master UI service: %+v", err) - return - } - - if err := c.updateTServerUIService(newYBCluster); err != nil { - logger.Errorf("failed to update TServer UI service: %+v", err) - return - } - - // Update StatefulSets replica count, command, ports & PVCs. - if err := c.updateMasterStatefulset(newYBCluster); err != nil { - logger.Errorf("failed to update Master statefulsets: %+v", err) - return - } - - if err := c.updateTServerStatefulset(newYBCluster); err != nil { - logger.Errorf("failed to update TServer statefulsets: %+v", err) - return - } - - logger.Infof("cluster %s updated in namespace %s", newObjCluster.Name, newObjCluster.Namespace) -} - -func (c *ClusterController) updateMasterHeadlessService(newCluster *cluster) error { - return c.updateHeadlessService(newCluster, false) -} - -func (c *ClusterController) updateTServerHeadlessService(newCluster *cluster) error { - return c.updateHeadlessService(newCluster, true) -} - -func (c *ClusterController) updateHeadlessService(newCluster *cluster, isTServerService bool) error { - ctx := context.TODO() - serviceName := masterNamePlural - - if isTServerService { - serviceName = tserverNamePlural - } - - serviceName = newCluster.addCRNameSuffix(serviceName) - - service, err := c.context.Clientset.CoreV1().Services(newCluster.namespace).Get(ctx, serviceName, metav1.GetOptions{}) - - if err != nil { - return err - } - - service.Spec.Ports = createServicePorts(newCluster, isTServerService) - - if _, err := c.context.Clientset.CoreV1().Services(newCluster.namespace).Update(ctx, service, metav1.UpdateOptions{}); err != nil { - return err - } - - logger.Infof("headless service %s updated in namespace %s", service.Name, service.Namespace) - - return nil -} - -func (c *ClusterController) updateMasterUIService(newCluster *cluster) error { - return c.updateUIService(newCluster, false) -} - -// Update/Delete UI service for TServer, if user has specified/removed a UI port for it. -func (c *ClusterController) updateTServerUIService(newCluster *cluster) error { - return c.updateUIService(newCluster, true) -} - -func (c *ClusterController) updateUIService(newCluster *cluster, isTServerService bool) error { - ctx := context.TODO() - ports, err := getPortsFromSpec(newCluster.spec.Master.Network) - if err != nil { - return err - } - - serviceName := masterUIServiceName - - if isTServerService { - ports, err = getPortsFromSpec(newCluster.spec.TServer.Network) - if err != nil { - return err - } - - serviceName = tserverUIServiceName - } - - serviceName = newCluster.addCRNameSuffix(serviceName) - - service, err := c.context.Clientset.CoreV1().Services(newCluster.namespace).Get(ctx, serviceName, metav1.GetOptions{}) - - if err != nil { - // Create TServer UI Service, if it wasn't present & new spec needs one. - if errors.IsNotFound(err) && isTServerService { - // The below condition is not clubbed with other two above, so as to - // report the error if any of above conditions is false; irrespective of TServer UI port value in the new spec. - if ports.tserverPorts.ui > 0 { - return c.createTServerUIService(newCluster) - } - - // Return if TServer UI service did not exist previously & new spec also doesn't need one to be created. - return nil - } - - return err - } - - // Delete the TServer UI service if existed, but new spec doesn't need one. - if isTServerService && service != nil && ports.tserverPorts.ui <= 0 { - if err := c.context.Clientset.CoreV1().Services(newCluster.namespace).Delete(ctx, serviceName, metav1.DeleteOptions{}); err != nil { - return err - } - - logger.Infof("UI service %s deleted in namespace %s", service.Name, service.Namespace) - - return nil - } - - // Update the UI service for Master or TServer, otherwise. - service.Spec.Ports = createUIServicePorts(ports, isTServerService) - - if _, err := c.context.Clientset.CoreV1().Services(newCluster.namespace).Update(ctx, service, metav1.UpdateOptions{}); err != nil { - return err - } - - logger.Infof("client service %s updated in namespace %s", service.Name, service.Namespace) - - return nil -} - -func (c *ClusterController) updateMasterStatefulset(newCluster *cluster) error { - return c.updateStatefulSet(newCluster, false) -} - -func (c *ClusterController) updateTServerStatefulset(newCluster *cluster) error { - return c.updateStatefulSet(newCluster, true) -} - -func (c *ClusterController) updateStatefulSet(newCluster *cluster, isTServerStatefulset bool) error { - ctx := context.TODO() - ports, err := getPortsFromSpec(newCluster.spec.Master.Network) - - if err != nil { - return err - } - - replicas := int32(newCluster.spec.Master.Replicas) - sfsName := newCluster.addCRNameSuffix(masterName) - masterServiceName := newCluster.addCRNameSuffix(masterNamePlural) - masterCompleteName := newCluster.addCRNameSuffix(masterName) - vct := *newCluster.spec.Master.VolumeClaimTemplate.DeepCopy() - vct.Name = newCluster.addCRNameSuffix(vct.Name) - volumeClaimTemplates := []v1.PersistentVolumeClaim{vct} - resources := getResourceSpec(newCluster.spec.Master.Resource, isTServerStatefulset) - command := createMasterContainerCommand(newCluster.namespace, masterServiceName, masterCompleteName, ports.masterPorts.rpc, newCluster.spec.Master.Replicas, resources) - containerPorts := createMasterContainerPortsList(ports) - - if isTServerStatefulset { - masterRPCPort := ports.masterPorts.rpc - ports, err := getPortsFromSpec(newCluster.spec.TServer.Network) - - if err != nil { - return err - } - - replicas = int32(newCluster.spec.TServer.Replicas) - sfsName = newCluster.addCRNameSuffix(tserverName) - masterServiceName = newCluster.addCRNameSuffix(masterNamePlural) - masterCompleteName := newCluster.addCRNameSuffix(masterName) - tserverServiceName := newCluster.addCRNameSuffix(tserverNamePlural) - vct = *newCluster.spec.TServer.VolumeClaimTemplate.DeepCopy() - vct.Name = newCluster.addCRNameSuffix(vct.Name) - volumeClaimTemplates = []v1.PersistentVolumeClaim{vct} - resources = getResourceSpec(newCluster.spec.Master.Resource, isTServerStatefulset) - command = createTServerContainerCommand(newCluster.namespace, tserverServiceName, masterServiceName, masterCompleteName, - masterRPCPort, ports.tserverPorts.rpc, ports.tserverPorts.postgres, newCluster.spec.TServer.Replicas, resources) - containerPorts = createTServerContainerPortsList(ports) - } - - sfs, err := c.context.Clientset.AppsV1().StatefulSets(newCluster.namespace).Get(ctx, sfsName, metav1.GetOptions{}) - - if err != nil { - return err - } - - sfs.Spec.Replicas = &replicas - sfs.Spec.Template.Spec.Containers[0].Command = command - sfs.Spec.Template.Spec.Containers[0].Resources = resources - sfs.Spec.Template.Spec.Containers[0].Ports = containerPorts - sfs.Spec.Template.Spec.Containers[0].VolumeMounts[0].Name = vct.Name - sfs.Spec.VolumeClaimTemplates = volumeClaimTemplates - - if _, err := c.context.Clientset.AppsV1().StatefulSets(newCluster.namespace).Update(ctx, sfs, metav1.UpdateOptions{}); err != nil { - return err - } - - logger.Infof("stateful set %s updated in namespace %s", sfs.Name, sfs.Namespace) - - return nil -} diff --git a/tests/framework/installer/installer.go b/tests/framework/installer/installer.go index 8fa3055a2d7c..4c7d0f673ec9 100644 --- a/tests/framework/installer/installer.go +++ b/tests/framework/installer/installer.go @@ -32,10 +32,9 @@ const ( VersionMaster = "master" // test suite names - CassandraTestSuite = "cassandra" - CephTestSuite = "ceph" - NFSTestSuite = "nfs" - YugabyteDBTestSuite = "yugabytedb" + CassandraTestSuite = "cassandra" + CephTestSuite = "ceph" + NFSTestSuite = "nfs" ) var ( diff --git a/tests/framework/installer/yugabytedb_installer.go b/tests/framework/installer/yugabytedb_installer.go deleted file mode 100644 index b415b3c2f159..000000000000 --- a/tests/framework/installer/yugabytedb_installer.go +++ /dev/null @@ -1,174 +0,0 @@ -/* -Copyright 2019 The Rook Authors. All rights reserved. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package installer - -import ( - "context" - "fmt" - "testing" - - "github.com/rook/rook/tests/framework/utils" - "github.com/stretchr/testify/assert" - metav1 "k8s.io/apimachinery/pkg/apis/meta/v1" -) - -const ( - CRDFullyQualifiedName = "ybclusters.yugabytedb.rook.io" - CRDFullyQualifiedNameSingular = "ybcluster.yugabytedb.rook.io" -) - -type YugabyteDBInstaller struct { - T func() *testing.T - k8sHelper *utils.K8sHelper - manifests *YugabyteDBManifests - hostPathProvisionerInstalled bool -} - -func NewYugabyteDBInstaller(t func() *testing.T, k8shelper *utils.K8sHelper) *YugabyteDBInstaller { - return &YugabyteDBInstaller{t, k8shelper, &YugabyteDBManifests{}, false} -} - -func (y *YugabyteDBInstaller) InstallYugabyteDB(systemNS, ns string, count int) error { - logger.Info("Yugabytedb cluster install started") - y.k8sHelper.CreateAnonSystemClusterBinding() - - if isDefStorageClassPresent, err := y.k8sHelper.IsDefaultStorageClassPresent(); err != nil { - return err - } else if !isDefStorageClassPresent { - logger.Info("Default storage class not set. Creating one.") - - // Mark the installation attempt of a host path provisioner, for removal later. - y.hostPathProvisionerInstalled = true - - if err := CreateHostPathPVs(y.k8sHelper, 3, true, "5Gi"); err != nil { - return err - } - } else { - logger.Info("Default storage class found.") - } - - if err := y.CreateOperator(systemNS); err != nil { - return err - } - - // install yugabytedb cluster instance - if err := y.CreateYugabyteDBCluster(ns, count); err != nil { - return err - } - - return nil -} - -func (y *YugabyteDBInstaller) CreateOperator(SystemNamespace string) error { - logger.Info("Starting YugabyteDB operator") - - logger.Info("Creating CRDs.") - if _, err := y.k8sHelper.KubectlWithStdin(y.manifests.GetYugabyteDBCRDSpecs(), createFromStdinArgs...); err != nil { - return err - } - - logger.Info("Creating RBAC & deployment for operator.") - if _, err := y.k8sHelper.KubectlWithStdin(y.manifests.GetYugabyteDBOperatorSpecs(SystemNamespace), createFromStdinArgs...); err != nil { - return err - } - - logger.Info("Checking if CRD definition persisted.") - if !y.k8sHelper.IsCRDPresent(CRDFullyQualifiedName) { - logger.Errorf("YugabyteDB CRD %s creation failed!", CRDFullyQualifiedName) - } - - logger.Info("Checking if operator pod is created") - if !y.k8sHelper.IsPodInExpectedState("rook-yugabytedb-operator", SystemNamespace, "Running") { - return fmt.Errorf("YugabyteDB operator isn't running!") - } - - logger.Infof("yugabytedb operator started") - return nil -} - -func (y *YugabyteDBInstaller) CreateYugabyteDBCluster(namespace string, replicaCount int) error { - logger.Info("Creating cluster namespace") - if err := y.k8sHelper.CreateNamespace(namespace); err != nil { - return err - } - - logger.Info("Creating yugabytedb cluster") - if _, err := y.k8sHelper.KubectlWithStdin(y.manifests.GetYugabyteDBClusterSpecs(namespace, replicaCount), createFromStdinArgs...); err != nil { - logger.Errorf("Failed to create YugabyteDB cluster") - return err - } - - if err := y.k8sHelper.WaitForPodCount("app=yb-master-rook-yugabytedb", namespace, replicaCount); err != nil { - logger.Error("YugabyteDB cluster master pods are not running") - return err - } - - if err := y.k8sHelper.WaitForPodCount("app=yb-tserver-rook-yugabytedb", namespace, replicaCount); err != nil { - logger.Error("YugabyteDB cluster tserver pods are not running") - return err - } - - logger.Infof("Yugabytedb cluster has started") - return nil -} - -func (y *YugabyteDBInstaller) RemoveAllYugabyteDBResources(systemNS, namespace string) error { - ctx := context.TODO() - logger.Info("Removing YugabyteDB cluster") - err := y.k8sHelper.DeleteResourceAndWait(false, "-n", namespace, CRDFullyQualifiedNameSingular, namespace) - checkError(y.T(), err, fmt.Sprintf("cannot remove cluster %s", namespace)) - - crdCheckerFunc := func() error { - _, err := y.k8sHelper.RookClientset.YugabytedbV1alpha1().YBClusters(namespace).Get(ctx, namespace, metav1.GetOptions{}) - return err - } - err = y.k8sHelper.WaitForCustomResourceDeletion(namespace, crdCheckerFunc) - checkError(y.T(), err, fmt.Sprintf("failed to wait for crd %s deletion", namespace)) - - logger.Info("Removing yugabytedb cluster namespace") - err = y.k8sHelper.DeleteResourceAndWait(false, "namespace", namespace) - checkError(y.T(), err, fmt.Sprintf("cannot delete namespace %s", namespace)) - - logger.Infof("removing the operator from namespace %s", systemNS) - err = y.k8sHelper.DeleteResource("crd", CRDFullyQualifiedName) - checkError(y.T(), err, "cannot delete CRDs") - - logger.Info("Removing yugabytedb operator system namespace") - _, err = y.k8sHelper.KubectlWithStdin(y.manifests.GetYugabyteDBOperatorSpecs(systemNS), deleteFromStdinArgs...) - checkError(y.T(), err, "cannot uninstall rook-yugabytedb-operator") - - // Remove host path provisioner resources, if installed. - if y.hostPathProvisionerInstalled { - err = DeleteHostPathPVs(y.k8sHelper) - checkError(y.T(), err, "cannot uninstall hostpath provisioner") - } - - err = y.k8sHelper.Clientset.RbacV1().ClusterRoleBindings().Delete(ctx, "anon-user-access", metav1.DeleteOptions{}) - assert.NoError(y.T(), err) - logger.Infof("done removing the operator from namespace %s", systemNS) - - return nil -} - -func (y *YugabyteDBInstaller) GatherAllLogs(systemNS, namespace, testName string) { - if !y.T().Failed() && TestLogCollectionLevel() != "all" { - return - } - logger.Infof("Gathering all logs from yugabytedb cluster %s", namespace) - y.k8sHelper.GetLogsFromNamespace(systemNS, testName, utils.TestEnvName()) - y.k8sHelper.GetLogsFromNamespace(namespace, testName, utils.TestEnvName()) -} diff --git a/tests/framework/installer/yugabytedb_manifests.go b/tests/framework/installer/yugabytedb_manifests.go deleted file mode 100644 index f84bff64682c..000000000000 --- a/tests/framework/installer/yugabytedb_manifests.go +++ /dev/null @@ -1,200 +0,0 @@ -/* -Copyright 2019 The Rook Authors. All rights reserved. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package installer - -import "strconv" - -type YugabyteDBManifests struct { -} - -func (_ *YugabyteDBManifests) GetYugabyteDBOperatorSpecs(namespace string) string { - return `apiVersion: v1 -kind: Namespace -metadata: - name: ` + namespace + ` ---- -apiVersion: rbac.authorization.k8s.io/v1 -kind: ClusterRole -metadata: - name: rook-yugabytedb-operator -rules: -- apiGroups: - - "" - resources: - - pods - verbs: - - get - - list -- apiGroups: - - "" - resources: - - services - verbs: - - get - - list - - watch - - create - - update - - patch - - delete -- apiGroups: - - apps - resources: - - statefulsets - verbs: - - get - - list - - watch - - create - - update - - patch - - delete -- apiGroups: - - yugabytedb.rook.io - resources: - - "*" - verbs: - - "*" ---- -apiVersion: v1 -kind: ServiceAccount -metadata: - name: rook-yugabytedb-operator - namespace: ` + namespace + ` ---- -apiVersion: rbac.authorization.k8s.io/v1 -kind: ClusterRoleBinding -metadata: - name: rook-yugabytedb-operator -roleRef: - apiGroup: rbac.authorization.k8s.io - kind: ClusterRole - name: rook-yugabytedb-operator -subjects: -- kind: ServiceAccount - name: rook-yugabytedb-operator - namespace: ` + namespace + ` ---- -apiVersion: apps/v1 -kind: Deployment -metadata: - name: rook-yugabytedb-operator - namespace: ` + namespace + ` - labels: - app: rook-yugabytedb-operator -spec: - selector: - matchLabels: - app: rook-yugabytedb-operator - replicas: 1 - template: - metadata: - labels: - app: rook-yugabytedb-operator - spec: - serviceAccountName: rook-yugabytedb-operator - containers: - - name: rook-yugabytedb-operator - image: rook/yugabytedb:master - args: ["yugabytedb", "operator"] - env: - - name: POD_NAME - valueFrom: - fieldRef: - fieldPath: metadata.name - - name: POD_NAMESPACE - valueFrom: - fieldRef: - fieldPath: metadata.namespace` -} - -func (_ *YugabyteDBManifests) GetYugabyteDBCRDSpecs() string { - return `apiVersion: apiextensions.k8s.io/v1beta1 -kind: CustomResourceDefinition -metadata: - name: ybclusters.yugabytedb.rook.io -spec: - group: yugabytedb.rook.io - names: - kind: YBCluster - listKind: YBClusterList - singular: ybcluster - plural: ybclusters - scope: Namespaced - version: v1alpha1` -} - -func (_ *YugabyteDBManifests) GetYugabyteDBClusterSpecs(namespace string, replicaCount int) string { - return `apiVersion: yugabytedb.rook.io/v1alpha1 -kind: YBCluster -metadata: - name: rook-yugabytedb - namespace: ` + namespace + ` -spec: - master: - replicas: ` + strconv.Itoa(replicaCount) + ` - resource: - requests: - cpu: 300m - memory: 256Mi - limits: - cpu: 300m - memory: 256Mi - network: - ports: - - name: yb-master-ui - port: 7000 - - name: yb-master-rpc - port: 7100 - volumeClaimTemplate: - metadata: - name: datadir - spec: - accessModes: [ "ReadWriteOnce" ] - resources: - requests: - storage: 10Mi - tserver: - replicas: ` + strconv.Itoa(replicaCount) + ` - resource: - requests: - cpu: 300m - memory: 256Mi - limits: - cpu: 300m - memory: 256Mi - network: - ports: - - name: yb-tserver-ui - port: 9000 - - name: yb-tserver-rpc - port: 9100 - - name: ycql - port: 9042 - - name: yedis - port: 6379 - - name: ysql - port: 5433 - volumeClaimTemplate: - metadata: - name: datadir - spec: - accessModes: [ "ReadWriteOnce" ] - resources: - requests: - storage: 10Mi` -} diff --git a/tests/integration/yugabytedb_test.go b/tests/integration/yugabytedb_test.go deleted file mode 100644 index b411ea015b44..000000000000 --- a/tests/integration/yugabytedb_test.go +++ /dev/null @@ -1,103 +0,0 @@ -/* -Copyright 2019 The Rook Authors. All rights reserved. - -Licensed under the Apache License, Version 2.0 (the "License"); -you may not use this file except in compliance with the License. -You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - -Unless required by applicable law or agreed to in writing, software -distributed under the License is distributed on an "AS IS" BASIS, -WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -See the License for the specific language governing permissions and -limitations under the License. -*/ - -package integration - -import ( - "fmt" - "testing" - - "github.com/rook/rook/tests/framework/installer" - "github.com/rook/rook/tests/framework/utils" - "github.com/stretchr/testify/assert" - "github.com/stretchr/testify/require" - "github.com/stretchr/testify/suite" -) - -type YugabyteDBSuite struct { - k8sHelper *utils.K8sHelper - ybdbInstaller *installer.YugabyteDBInstaller - namespace string - systemNS string - replicaCount int - suite.Suite -} - -func TestYugabyteDBSuite(t *testing.T) { - if installer.SkipTestSuite(installer.YugabyteDBTestSuite) { - t.Skip() - } - - y := new(YugabyteDBSuite) - defer func(y *YugabyteDBSuite) { - HandlePanics(recover(), y, y.T) - }(y) - suite.Run(t, y) -} - -func (y *YugabyteDBSuite) SetupSuite() { - y.Setup() -} - -func (y *YugabyteDBSuite) TearDownSuite() { - y.Teardown() -} - -func (y *YugabyteDBSuite) Setup() { - k8sHelperObj, err := utils.CreateK8sHelper(y.T) - require.NoError(y.T(), err) - y.k8sHelper = k8sHelperObj - - logger.Info("YugabyteDB integration test setup started.") - y.namespace = "rook-yugabytedb" - y.systemNS = installer.SystemNamespace(y.namespace) - y.replicaCount = 1 - - k8sversion := y.k8sHelper.GetK8sServerVersion() - logger.Infof("Installing yugabytedb on kubernetes %s", k8sversion) - - y.ybdbInstaller = installer.NewYugabyteDBInstaller(y.T, k8sHelperObj) - - err = y.ybdbInstaller.InstallYugabyteDB(y.systemNS, y.namespace, y.replicaCount) - if err != nil { - logger.Errorf("yugabytedb installation failed with error: %+v", err) - y.T().Fail() - y.Teardown() - y.T().FailNow() - } -} - -func (y *YugabyteDBSuite) Teardown() { - y.ybdbInstaller.GatherAllLogs(y.systemNS, y.namespace, y.T().Name()) - err := y.ybdbInstaller.RemoveAllYugabyteDBResources(y.systemNS, y.namespace) - assert.NoError(y.T(), err) -} - -func (y *YugabyteDBSuite) TestYBClusterComponents() { - logger.Info("Verifying yugabytedb cluster is created & has all required components") - - // verify operator pod is running - assert.True(y.T(), y.k8sHelper.CheckPodCountAndState("rook-yugabytedb-operator", y.systemNS, 1, "Running"), - "1 rook-yugabytedb-operator must be in Running state") - - // verify master pod is running - assert.True(y.T(), y.k8sHelper.CheckPodCountAndState("yb-master-rook-yugabytedb", y.namespace, y.replicaCount, "Running"), - fmt.Sprintf("%d yb-master must be in Running state", y.replicaCount)) - - // verify master pod is running - assert.True(y.T(), y.k8sHelper.CheckPodCountAndState("yb-tserver-rook-yugabytedb", y.namespace, y.replicaCount, "Running"), - fmt.Sprintf("%d yb-tserver must be in Running state", y.replicaCount)) -} diff --git a/tests/pipeline/Jenkinsfile.k8sSetup b/tests/pipeline/Jenkinsfile.k8sSetup index 565401ea0508..eb3680266b6e 100644 --- a/tests/pipeline/Jenkinsfile.k8sSetup +++ b/tests/pipeline/Jenkinsfile.k8sSetup @@ -30,19 +30,17 @@ pipeline { sh "wget -O ceph.tar.gz https://release.rook.io/build/pr/${params.PR}/${params.version}/images/linux_amd64/ceph.tar.gz" sh "wget -O cassandra.tar.gz https://release.rook.io/build/pr/${params.PR}/${params.version}/images/linux_amd64/cassandra.tar.gz" sh "wget -O nfs.tar.gz https://release.rook.io/build/pr/${params.PR}/${params.version}/images/linux_amd64/nfs.tar.gz" - sh "wget -O yugabytedb.tar.gz https://release.rook.io/build/pr/${params.PR}/${params.version}/images/linux_amd64/yugabytedb.tar.gz" sh "wget -O version https://release.rook.io/build/pr/${params.PR}/${params.version}/version" }else { sh "wget -O ceph.tar.gz https://release.rook.io/build/master/${params.version}/images/linux_amd64/ceph.tar.gz" sh "wget -O cassandra.tar.gz https://release.rook.io/build/master/${params.version}/images/linux_amd64/cassandra.tar.gz" sh "wget -O nfs.tar.gz https://release.rook.io/build/master/${params.version}/images/linux_amd64/nfs.tar.gz" - sh "wget -O yugabytedb.tar.gz https://release.rook.io/build/master/${params.version}/images/linux_amd64/yugabytedb.tar.gz" sh "wget -O version https://release.rook.io/build/master/${params.version}/version" } stash name: 'test-scripts',includes: 'tests/scripts/' - stash name: 'test-images', includes: 'ceph.tar.gz,cassandra.tar.gz,nfs.tar.gz,yugabytedb.tar.gz,version' + stash name: 'test-images', includes: 'ceph.tar.gz,cassandra.tar.gz,nfs.tar.gz,version' } } } @@ -103,7 +101,6 @@ def setUpRookImages(){ docker load -i ceph.tar.gz docker load -i cassandra.tar.gz docker load -i nfs.tar.gz - docker load -i yugabytedb.tar.gz docker images rookImg=$(docker images |grep rook | awk '{print $1}') echo $rookImg @@ -115,6 +112,4 @@ def setUpRookImages(){ docker tag $rookImg rook/cassandra:${versionId} docker tag $rookImg rook/nfs:master docker tag $rookImg rook/nfs:${versionId} - docker tag $rookImg rook/yugabytedb:master - docker tag $rookImg rook/yugabytedb:${versionId} } diff --git a/tests/scripts/makeTestImages.sh b/tests/scripts/makeTestImages.sh index 0868cc62d40d..dd669f37421e 100755 --- a/tests/scripts/makeTestImages.sh +++ b/tests/scripts/makeTestImages.sh @@ -12,7 +12,6 @@ case "${1:-}" in docker tag "${BUILD_REGISTRY}/ceph-$2:latest" rook/ceph:master docker tag "${BUILD_REGISTRY}/cassandra-$2:latest" rook/cassandra:master docker tag "${BUILD_REGISTRY}/nfs-$2:latest" rook/nfs:master - docker tag "${BUILD_REGISTRY}/yugabytedb-$2:latest" rook/yugabytedb:master if [ ! -z "$3" ] then docker tag "${BUILD_REGISTRY}/ceph-$2:latest" "rook/ceph:$3" @@ -21,13 +20,10 @@ case "${1:-}" in docker save -o "cassandra-$2.tar" rook/cassandra:master "rook/cassandra:$3" docker tag "${BUILD_REGISTRY}/nfs-$2:latest" "rook/nfs:$3" docker save -o "nfs-$2.tar" rook/nfs:master "rook/nfs:$3" - docker tag "${BUILD_REGISTRY}/yugabytedb-$2:latest" "rook/yugabytedb:$3" - docker save -o "yugabytedb-$2.tar" rook/yugabytedb:master "rook/yugabytedb:$3" else docker save -o "ceph-$2.tar" rook/ceph:master docker save -o "cassandra-$2.tar" rook/cassandra:master docker save -o "nfs-$2.tar" rook/nfs:master - docker save -o "yugabytedb-$2.tar" rook/yugabytedb:master fi echo "Saved docker images in archives: $(ls | grep tar)" @@ -45,7 +41,6 @@ case "${1:-}" in docker load -i "ceph-$2.tar" docker load -i "cassandra-$2.tar" docker load -i "nfs-$2.tar" - docker load -i "yugabytedb-$2.tar" ;; *) echo "usage :" >&2 @@ -60,7 +55,6 @@ case "${1:-}" in docker tag "${BUILD_REGISTRY}/ceph-$2:latest" "rook/ceph:${tag_version}" docker tag "${BUILD_REGISTRY}/cassandra-$2:latest" "rook/cassandra:${tag_version}" docker tag "${BUILD_REGISTRY}/nfs-$2:latest" "rook/nfs:${tag_version}" - docker tag "${BUILD_REGISTRY}/yugabytedb-$2:latest" "rook/yugabytedb:${tag_version}" ;; *) echo "usage :" >&2 diff --git a/tests/scripts/minikube.sh b/tests/scripts/minikube.sh index 68b1159147bb..d1ee0deee2c7 100755 --- a/tests/scripts/minikube.sh +++ b/tests/scripts/minikube.sh @@ -44,11 +44,6 @@ function copy_images() { echo "copying nfs image" copy_image_to_cluster "${BUILD_REGISTRY}/nfs-amd64" rook/nfs:master fi - - if [[ "$1" == "" || "$1" == "yugabytedb" ]]; then - echo "copying yugabytedb image" - copy_image_to_cluster "${BUILD_REGISTRY}/yugabytedb-amd64" rook/yugabytedb:master - fi } # configure minikube @@ -96,11 +91,11 @@ case "${1:-}" in ;; *) echo "usage:" >&2 - echo " $0 up [ceph | cassandra | nfs | yugabytedb]" >&2 + echo " $0 up [ceph | cassandra | nfs]" >&2 echo " $0 down" >&2 echo " $0 clean" >&2 echo " $0 ssh" >&2 - echo " $0 update [ceph | cassandra | nfs | yugabytedb]" >&2 + echo " $0 update [ceph | cassandra | nfs]" >&2 echo " $0 wordpress" >&2 echo " $0 helm" >&2 esac