diff --git a/api/v1beta1/zookeepercluster_types.go b/api/v1beta1/zookeepercluster_types.go index f64474b4..a20c7de8 100644 --- a/api/v1beta1/zookeepercluster_types.go +++ b/api/v1beta1/zookeepercluster_types.go @@ -543,6 +543,8 @@ type ClientServicePolicy struct { // Annotations specifies the annotations to attach to client service the operator // creates. Annotations map[string]string `json:"annotations,omitempty"` + + External bool `json:"external,omitempty"` } type HeadlessServicePolicy struct { diff --git a/charts/zookeeper-operator/templates/zookeeper.pravega.io_zookeeperclusters_crd.yaml b/charts/zookeeper-operator/templates/zookeeper.pravega.io_zookeeperclusters_crd.yaml index d0f97931..9fcf527b 100644 --- a/charts/zookeeper-operator/templates/zookeeper.pravega.io_zookeeperclusters_crd.yaml +++ b/charts/zookeeper-operator/templates/zookeeper.pravega.io_zookeeperclusters_crd.yaml @@ -90,6 +90,8 @@ spec: description: Annotations specifies the annotations to attach to client service the operator creates. type: object + external: + type: boolean type: object config: description: Conf is the zookeeper configuration, which will be used diff --git a/charts/zookeeper/README.md b/charts/zookeeper/README.md index 95027a3a..07176e3d 100644 --- a/charts/zookeeper/README.md +++ b/charts/zookeeper/README.md @@ -86,6 +86,7 @@ The following table lists the configurable parameters of the zookeeper chart and | `pod.imagePullSecrets` | ImagePullSecrets is a list of references to secrets in the same namespace to use for pulling any images. | `[]` | | `clientService` | Defines the policy to create client Service for the zookeeper cluster. | {} | | `clientService.annotations` | Specifies the annotations to attach to client Service the operator creates. | {} | +| `clientService.external` | Specifies if LoadBalancer should be created for the Client. True means LoadBalancer will be created, false - only ClusterIP will be used. | false | | `headlessService` | Defines the policy to create headless Service for the zookeeper cluster. | {} | | `headlessService.annotations` | Specifies the annotations to attach to headless Service the operator creates. | {} | | `adminServerService` | Defines the policy to create AdminServer Service for the zookeeper cluster. | {} | diff --git a/charts/zookeeper/templates/zookeeper.yaml b/charts/zookeeper/templates/zookeeper.yaml index 902440e6..8dcf5f24 100644 --- a/charts/zookeeper/templates/zookeeper.yaml +++ b/charts/zookeeper/templates/zookeeper.yaml @@ -115,6 +115,9 @@ spec: annotations: {{ toYaml .Values.clientService.annotations | indent 6 }} {{- end }} + {{- if .Values.clientService.external }} + external: {{ .Values.clientService.external }} + {{- end }} {{- end }} {{- if .Values.headlessService }} headlessService: diff --git a/charts/zookeeper/values.yaml b/charts/zookeeper/values.yaml index 8a449f0b..d1f37c8b 100644 --- a/charts/zookeeper/values.yaml +++ b/charts/zookeeper/values.yaml @@ -52,6 +52,7 @@ adminServerService: {} clientService: {} # annotations: {} + # external: false headlessService: {} # annotations: {} diff --git a/config/crd/bases/zookeeper.pravega.io_zookeeperclusters.yaml b/config/crd/bases/zookeeper.pravega.io_zookeeperclusters.yaml index 0f2af6d2..2af9d0ca 100644 --- a/config/crd/bases/zookeeper.pravega.io_zookeeperclusters.yaml +++ b/config/crd/bases/zookeeper.pravega.io_zookeeperclusters.yaml @@ -89,6 +89,8 @@ spec: description: Annotations specifies the annotations to attach to client service the operator creates. type: object + external: + type: boolean type: object config: description: Conf is the zookeeper configuration, which will be used diff --git a/pkg/zk/generators.go b/pkg/zk/generators.go index f13ae37b..fd7691d9 100644 --- a/pkg/zk/generators.go +++ b/pkg/zk/generators.go @@ -198,7 +198,9 @@ func MakeClientService(z *v1beta1.ZookeeperCluster) *v1.Service { svcPorts := []v1.ServicePort{ {Name: "tcp-client", Port: ports.Client}, } - return makeService(z.GetClientServiceName(), svcPorts, true, false, z.Spec.ClientService.Annotations, z) + external := z.Spec.ClientService.External + annotations := z.Spec.ClientService.Annotations + return makeService(z.GetClientServiceName(), svcPorts, true, external, annotations, z) } // MakeAdminServerService returns a service which provides an interface diff --git a/pkg/zk/generators_test.go b/pkg/zk/generators_test.go index f545ddb5..714cd32f 100644 --- a/pkg/zk/generators_test.go +++ b/pkg/zk/generators_test.go @@ -378,6 +378,34 @@ var _ = Describe("Generators Spec", func() { "exampleAnnotation", "exampleValue")) }) + + It("should have no LoadBalancer attached by default", func() { + Ω(s.Spec.Type).NotTo(Equal(v1.ServiceTypeLoadBalancer)) + }) + }) + + Context("#MakeClientService external with LoadBalancer", func() { + var s *v1.Service + + BeforeEach(func() { + z := &v1beta1.ZookeeperCluster{ + ObjectMeta: metav1.ObjectMeta{ + Name: "example", + Namespace: "default", + }, + Spec: v1beta1.ZookeeperClusterSpec{ + ClientService: v1beta1.ClientServicePolicy{ + External: true, + }, + }, + } + z.WithDefaults() + s = zk.MakeClientService(z) + }) + + It("should have LoadBalancer attached", func() { + Ω(s.Spec.Type).To(Equal(v1.ServiceTypeLoadBalancer)) + }) }) Context("#MakeHeadlessService", func() {