Skip to content

Commit 3a2efc9

Browse files
authored
added labels to ingress, fixed erroneous tls secret check #263 (#264)
1 parent e92c17a commit 3a2efc9

11 files changed

Lines changed: 67 additions & 17 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.2
55+
IMG_TAG ?= 0.4.1-rc.3
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.2**
231+
- Latest version: **0.4.1-rc.3**
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_ingress.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ type IngressSpec struct {
2727
// +kubebuilder:validation:Optional
2828
ServiceAnnotations map[string]string `json:"serviceAnnotations,omitempty"`
2929

30+
// +optional
31+
Labels map[string]string `json:"labels,omitempty"`
32+
33+
// +optional
3034
Annotations map[string]string `json:"annotations,omitempty"`
3135

3236
// +optional

api/v1alpha1/zz_generated.deepcopy.go

Lines changed: 7 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.2
17+
version: 0.4.1-rc.3
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.2"
22+
appVersion: "0.4.1-rc.3"
2323

2424
maintainers:
2525
- name: Kyriakos Akriotis

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1262,6 +1262,10 @@ spec:
12621262
type: string
12631263
ingressClassName:
12641264
type: string
1265+
labels:
1266+
additionalProperties:
1267+
type: string
1268+
type: object
12651269
locationDirectives:
12661270
type: string
12671271
path:

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.2
15+
tag: 0.4.1-rc.3
1616
imagePullPolicy: IfNotPresent
1717
resources:
1818
limits:

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1262,6 +1262,10 @@ spec:
12621262
type: string
12631263
ingressClassName:
12641264
type: string
1265+
labels:
1266+
additionalProperties:
1267+
type: string
1268+
type: object
12651269
locationDirectives:
12661270
type: string
12671271
path:

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.2
8+
newTag: 0.4.1-rc.3

internal/controller/typesensecluster_ingress.go

Lines changed: 27 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -93,9 +93,13 @@ func (r *TypesenseClusterReconciler) ReconcileIngress(ctx context.Context, ts *t
9393
return err
9494
}
9595
} else {
96+
lbls := r.getIngressLabels(ig, ts, ingressObjectKey)
97+
anons := r.getIngressAnnotations(ig, ts)
98+
9699
if ts.Spec.Ingress.Host != ig.Spec.Rules[0].Host ||
97100
(ts.Spec.Ingress.ClusterIssuer != nil && *ts.Spec.Ingress.ClusterIssuer != ig.Annotations[clusterIssuerAnnotationKey]) ||
98-
!apiequality.Semantic.DeepEqual(ts.Spec.Ingress.Annotations, r.getIngressAnnotations(ig, ts)) ||
101+
!apiequality.Semantic.DeepEqual(ts.Spec.Ingress.Labels, lbls) ||
102+
!apiequality.Semantic.DeepEqual(ts.Spec.Ingress.Annotations, anons) ||
99103
(ts.Spec.Ingress.TLSSecretName != nil && *ts.Spec.Ingress.TLSSecretName != ig.Spec.TLS[0].SecretName) ||
100104
ts.Spec.Ingress.IngressClassName != *ig.Spec.IngressClassName ||
101105
ts.Spec.Ingress.Path != ig.Spec.Rules[0].IngressRuleValue.HTTP.Paths[0].Path ||
@@ -278,10 +282,7 @@ func (r *TypesenseClusterReconciler) ReconcileIngress(ctx context.Context, ts *t
278282
}
279283

280284
func (r *TypesenseClusterReconciler) createIngress(ctx context.Context, key client.ObjectKey, ts *tsv1alpha1.TypesenseCluster) (*networkingv1.Ingress, error) {
281-
if ts.Spec.Ingress.ClusterIssuer != nil && ts.Spec.Ingress.TLSSecretName == nil {
282-
return nil, fmt.Errorf("tls secret name is required, skipping ingress creation")
283-
}
284-
285+
labels := map[string]string{}
285286
annotations := map[string]string{}
286287
var tlsSecretName string
287288

@@ -290,6 +291,10 @@ func (r *TypesenseClusterReconciler) createIngress(ctx context.Context, key clie
290291
tlsSecretName = fmt.Sprintf("%s-reverse-proxy-%s-certificate-tls", ts.Name, *ts.Spec.Ingress.ClusterIssuer)
291292
}
292293

294+
if ts.Spec.Ingress.Labels != nil {
295+
maps.Copy(labels, ts.Spec.Ingress.Labels)
296+
}
297+
293298
if ts.Spec.Ingress.Annotations != nil {
294299
maps.Copy(annotations, ts.Spec.Ingress.Annotations)
295300
}
@@ -299,7 +304,7 @@ func (r *TypesenseClusterReconciler) createIngress(ctx context.Context, key clie
299304
}
300305

301306
ingress := &networkingv1.Ingress{
302-
ObjectMeta: getObjectMeta(ts, &key.Name, annotations),
307+
ObjectMeta: getIngressObjectMeta(ts, &key.Name, ts.Spec.Ingress.Labels, ts.Spec.Ingress.Annotations),
303308
Spec: networkingv1.IngressSpec{
304309
IngressClassName: ptr.To(ts.Spec.Ingress.IngressClassName),
305310
TLS: []networkingv1.IngressTLS{
@@ -348,9 +353,6 @@ func (r *TypesenseClusterReconciler) createIngress(ctx context.Context, key clie
348353
}
349354

350355
func (r *TypesenseClusterReconciler) updateIngress(ctx context.Context, ig networkingv1.Ingress, ts *tsv1alpha1.TypesenseCluster) (*networkingv1.Ingress, error) {
351-
if ts.Spec.Ingress.ClusterIssuer != nil && ts.Spec.Ingress.TLSSecretName == nil {
352-
return nil, fmt.Errorf("tls secret name is required, skipping ingress update")
353-
}
354356
patch := client.MergeFrom(ig.DeepCopy())
355357

356358
ig.Spec.Rules[0].Host = ts.Spec.Ingress.Host
@@ -366,10 +368,13 @@ func (r *TypesenseClusterReconciler) updateIngress(ctx context.Context, ig netwo
366368
tlsSecretName = fmt.Sprintf("%s-reverse-proxy-%s-certificate-tls", ts.Name, *ts.Spec.Ingress.ClusterIssuer)
367369
}
368370

371+
if ts.Spec.Ingress.Labels != nil {
372+
maps.Copy(ig.Labels, ts.Spec.Ingress.Labels)
373+
}
374+
369375
if ts.Spec.Ingress.Annotations != nil {
370-
maps.Copy(annotations, ts.Spec.Ingress.Annotations)
376+
maps.Copy(ig.Annotations, ts.Spec.Ingress.Annotations)
371377
}
372-
ig.Annotations = annotations
373378

374379
if ts.Spec.Ingress.TLSSecretName != nil {
375380
tlsSecretName = *ts.Spec.Ingress.TLSSecretName
@@ -392,6 +397,17 @@ func (r *TypesenseClusterReconciler) deleteIngress(ctx context.Context, ig *netw
392397
return nil
393398
}
394399

400+
func (r *TypesenseClusterReconciler) getIngressLabels(ig *networkingv1.Ingress, ts *tsv1alpha1.TypesenseCluster, key client.ObjectKey) map[string]string {
401+
var filters []string
402+
defaultLabels := getIngressObjectMeta(ts, &key.Name, nil, nil).Labels
403+
for k := range defaultLabels {
404+
filters = append(filters, k)
405+
}
406+
407+
filtered := filterMap(ig.Labels, filters...)
408+
return filtered
409+
}
410+
395411
func (r *TypesenseClusterReconciler) getIngressAnnotations(ig *networkingv1.Ingress, ts *tsv1alpha1.TypesenseCluster) map[string]string {
396412
filters := append([]string{clusterIssuerAnnotationKey, rancherDomainAnnotationKey}, ts.Spec.IgnoreAnnotationsFromExternalMutations...)
397413
filtered := filterMap(ig.Annotations, filters...)

0 commit comments

Comments
 (0)