Skip to content

Commit cc5e791

Browse files
authored
265 bring serviceannotations under servicespec (#266)
* fixed external traffic policy combinations invalidation, moved annotation under service specs #265 * bump charts and manifests #265
1 parent 3b6aefc commit cc5e791

11 files changed

Lines changed: 175 additions & 16 deletions

File tree

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ OPERATOR_SDK_VERSION ?= v1.39.0
5252
# Image URL to use all building/pushing image targets
5353
DOCKER_HUB_NAME ?= quay.io/akyriako#$(shell docker info | sed '/Username:/!d;s/.* //')
5454
IMG_NAME ?= typesense-operator
55-
IMG_TAG ?= 0.4.1-rc.3
55+
IMG_TAG ?= 0.4.1-rc.4
5656
IMG ?= $(DOCKER_HUB_NAME)/$(IMG_NAME):$(IMG_TAG)
5757

5858
# ENVTEST_K8S_VERSION refers to the version of kubebuilder assets to be downloaded by envtest binary.

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ Join the conversation:
228228
## 📦 Project Status
229229
230230
TyKO is an **independently maintained** project (not affiliated with Typesense, Inc.).
231-
- Latest version: **0.4.1-rc.3**
231+
- Latest version: **0.4.1-rc.4**
232232
- Tested on: Kubernetes 1.35 (earliest 1.26), Typesense 30.0 (earliest 26.0)
233233
- Contributions welcome! See [FAQ](https://akyriako.github.io/typesense-operator-docs/docs/faq) and [Development](https://akyriako.github.io/typesense-operator-docs/docs/development)
234234

api/v1alpha1/typesensecluster_types_service.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,9 @@ type ServiceSpec struct {
1111
Type corev1.ServiceType `json:"type"`
1212

1313
// +optional
14-
// +kubebuilder:default:="Cluster"
1514
// +kubebuilder:validation:Enum=Cluster;Local
16-
ExternalTrafficPolicy corev1.ServiceExternalTrafficPolicy `json:"externalTrafficPolicy,omitempty"`
15+
ExternalTrafficPolicy *corev1.ServiceExternalTrafficPolicyType `json:"externalTrafficPolicy,omitempty"`
16+
17+
// +kubebuilder:validation:Optional
18+
Annotations map[string]string `json:"annotations,omitempty"`
1719
}

api/v1alpha1/zz_generated.deepcopy.go

Lines changed: 32 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

charts/typesense-operator/Chart.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,12 @@ type: application
1414
# This is the chart version. This version number should be incremented each time you make changes
1515
# to the chart and its templates, including the app version.
1616
# Versions are expected to follow Semantic Versioning (https://semver.org/)
17-
version: 0.4.1-rc.3
17+
version: 0.4.1-rc.4
1818
# This is the version number of the application being deployed. This version number should be
1919
# incremented each time you make changes to the application. Versions are not expected to
2020
# follow Semantic Versioning. They should reflect the version the application is using.
2121
# It is recommended to use it with quotes.
22-
appVersion: "0.4.1-rc.3"
22+
appVersion: "0.4.1-rc.4"
2323

2424
maintainers:
2525
- name: Kyriakos Akriotis

charts/typesense-operator/templates/typesensecluster-crd.yaml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4542,6 +4542,27 @@ spec:
45424542
type: object
45434543
type: object
45444544
type: object
4545+
service:
4546+
properties:
4547+
annotations:
4548+
additionalProperties:
4549+
type: string
4550+
type: object
4551+
externalTrafficPolicy:
4552+
description: for backwards compat
4553+
enum:
4554+
- Cluster
4555+
- Local
4556+
type: string
4557+
type:
4558+
default: ClusterIP
4559+
description: Service Type string describes ingress methods for a
4560+
service
4561+
enum:
4562+
- ClusterIP
4563+
- LoadBalancer
4564+
type: string
4565+
type: object
45454566
serviceAnnotations:
45464567
additionalProperties:
45474568
type: string

charts/typesense-operator/values.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ controllerManager:
1212
- ALL
1313
image:
1414
repository: quay.io/akyriako/typesense-operator
15-
tag: 0.4.1-rc.3
15+
tag: 0.4.1-rc.4
1616
imagePullPolicy: IfNotPresent
1717
resources:
1818
limits:

config/crd/bases/ts.opentelekomcloud.com_typesenseclusters.yaml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4551,6 +4551,27 @@ spec:
45514551
type: object
45524552
type: object
45534553
type: object
4554+
service:
4555+
properties:
4556+
annotations:
4557+
additionalProperties:
4558+
type: string
4559+
type: object
4560+
externalTrafficPolicy:
4561+
description: for backwards compat
4562+
enum:
4563+
- Cluster
4564+
- Local
4565+
type: string
4566+
type:
4567+
default: ClusterIP
4568+
description: Service Type string describes ingress methods for
4569+
a service
4570+
enum:
4571+
- ClusterIP
4572+
- LoadBalancer
4573+
type: string
4574+
type: object
45544575
serviceAnnotations:
45554576
additionalProperties:
45564577
type: string

config/manager/kustomization.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@ kind: Kustomization
55
images:
66
- name: controller
77
newName: quay.io/akyriako/typesense-operator
8-
newTag: 0.4.1-rc.3
8+
newTag: 0.4.1-rc.4

internal/controller/typesensecluster_services.go

Lines changed: 61 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,22 @@ func (r *TypesenseClusterReconciler) ReconcileServices(ctx context.Context, ts t
8787
}
8888
}
8989

90-
if int32(ts.Spec.ApiPort) != svc.Spec.Ports[0].Port || !apiequality.Semantic.DeepEqual(svc.Annotations, ts.Spec.ServiceAnnotations) {
90+
// Remove in 0.5.0
91+
annotations := getMergedAnnotations(&ts)
92+
svcType := v1.ServiceTypeClusterIP
93+
if ts.Spec.Service != nil {
94+
svcType = ts.Spec.Service.Type
95+
}
96+
97+
svcExternalTrafficPolicy, err := r.invalidateExternalTrafficPolicy(svcType, ts.Spec.Service)
98+
if err != nil {
99+
return err
100+
}
101+
102+
if int32(ts.Spec.ApiPort) != svc.Spec.Ports[0].Port ||
103+
!apiequality.Semantic.DeepEqual(svc.Annotations, annotations) ||
104+
svc.Spec.Type != svcType ||
105+
!externalTrafficPolicyEqual(svc.Spec.ExternalTrafficPolicy, svcExternalTrafficPolicy) {
91106
r.logger.V(debugLevel).Info("updating resolver service", "service", svcObjectKey.Name)
92107

93108
err := r.updateService(ctx, svc, &ts)
@@ -144,7 +159,7 @@ func (r *TypesenseClusterReconciler) updateHeadlessService(ctx context.Context,
144159

145160
func (r *TypesenseClusterReconciler) createService(ctx context.Context, key client.ObjectKey, ts *tsv1alpha1.TypesenseCluster) (*v1.Service, error) {
146161
svc := &v1.Service{
147-
ObjectMeta: getObjectMeta(ts, &key.Name, ts.Spec.ServiceAnnotations),
162+
ObjectMeta: getObjectMeta(ts, &key.Name, getMergedAnnotations(ts)),
148163
Spec: v1.ServiceSpec{
149164
Type: v1.ServiceTypeClusterIP,
150165
Selector: getLabels(ts),
@@ -163,10 +178,17 @@ func (r *TypesenseClusterReconciler) createService(ctx context.Context, key clie
163178
},
164179
}
165180

166-
svcSpec := ts.Spec.Service
167-
if svcSpec != nil {
168-
svc.Spec.Type = svcSpec.Type
169-
svc.Spec.ExternalTrafficPolicy = svcSpec.ExternalTrafficPolicy
181+
if ts.Spec.Service != nil {
182+
svcType := ts.Spec.Service.Type
183+
svcExternalTrafficPolicy, err := r.invalidateExternalTrafficPolicy(svcType, ts.Spec.Service)
184+
if err != nil {
185+
return nil, err
186+
}
187+
188+
svc.Spec.Type = svcType
189+
if svcExternalTrafficPolicy != nil {
190+
svc.Spec.ExternalTrafficPolicy = *svcExternalTrafficPolicy
191+
}
170192
}
171193

172194
err := ctrl.SetControllerReference(ts, svc, r.Scheme)
@@ -184,12 +206,29 @@ func (r *TypesenseClusterReconciler) createService(ctx context.Context, key clie
184206

185207
func (r *TypesenseClusterReconciler) updateService(ctx context.Context, svc *v1.Service, ts *tsv1alpha1.TypesenseCluster) error {
186208
patch := client.MergeFrom(svc.DeepCopy())
209+
187210
svc.Spec.Ports[0].Port = int32(ts.Spec.ApiPort)
188211

212+
svcType := v1.ServiceTypeClusterIP
213+
if ts.Spec.Service != nil {
214+
svcType = ts.Spec.Service.Type
215+
}
216+
svc.Spec.Type = svcType
217+
218+
svcExternalTrafficPolicy, err := r.invalidateExternalTrafficPolicy(svcType, ts.Spec.Service)
219+
if err != nil {
220+
return err
221+
}
222+
223+
svc.Spec.ExternalTrafficPolicy = ""
224+
if svcExternalTrafficPolicy != nil {
225+
svc.Spec.ExternalTrafficPolicy = *svcExternalTrafficPolicy
226+
}
227+
189228
if svc.ObjectMeta.Annotations == nil {
190229
svc.ObjectMeta.Annotations = map[string]string{}
191230
}
192-
svc.ObjectMeta.Annotations = ts.Spec.ServiceAnnotations
231+
svc.ObjectMeta.Annotations = getMergedAnnotations(ts)
193232

194233
if err := r.Patch(ctx, svc, patch); err != nil {
195234
return err
@@ -206,3 +245,18 @@ func (r *TypesenseClusterReconciler) deleteService(ctx context.Context, svc *v1.
206245

207246
return nil
208247
}
248+
249+
func (r *TypesenseClusterReconciler) invalidateExternalTrafficPolicy(
250+
svcType v1.ServiceType,
251+
service *tsv1alpha1.ServiceSpec,
252+
) (*v1.ServiceExternalTrafficPolicyType, error) {
253+
if service == nil || service.ExternalTrafficPolicy == nil {
254+
return nil, nil
255+
}
256+
257+
if svcType == v1.ServiceTypeClusterIP {
258+
return nil, fmt.Errorf("externalTrafficPolicy may only be set for externally-accessible services")
259+
}
260+
261+
return service.ExternalTrafficPolicy, nil
262+
}

0 commit comments

Comments
 (0)