From 19b8f41f523987df17414cc4e68e55a2e4d4ce2d Mon Sep 17 00:00:00 2001 From: Benedikt Bongartz Date: Mon, 10 Oct 2022 14:01:14 +0200 Subject: [PATCH] create dedicated ingress type Signed-off-by: Benedikt Bongartz --- apis/v1alpha1/ingress_type.go | 30 +++++++++++++++++++ apis/v1alpha1/opentelemetrycollector_types.go | 4 ++- .../opentelemetrycollector_webhook.go | 2 +- pkg/collector/reconcile/ingress.go | 2 +- pkg/collector/reconcile/ingress_test.go | 8 ++--- 5 files changed, 39 insertions(+), 7 deletions(-) create mode 100644 apis/v1alpha1/ingress_type.go diff --git a/apis/v1alpha1/ingress_type.go b/apis/v1alpha1/ingress_type.go new file mode 100644 index 0000000000..890c6a9b5f --- /dev/null +++ b/apis/v1alpha1/ingress_type.go @@ -0,0 +1,30 @@ +// Copyright The OpenTelemetry 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. + +package v1alpha1 + +type ( + // IngressType represents how a collector should be exposed (ingress vs route). + // +kubebuilder:validation:Enum=ingress + // TODO(frzifus): support route + IngressType string +) + +const ( + // IngressTypeNginx specifies that a ingress entry should be created. + IngressTypeNginx IngressType = "ingress" + + // IngressTypeRoute specifies that a route entry should be created. + IngressTypeRoute IngressType = "route" +) diff --git a/apis/v1alpha1/opentelemetrycollector_types.go b/apis/v1alpha1/opentelemetrycollector_types.go index d670006a42..3453be5d5f 100644 --- a/apis/v1alpha1/opentelemetrycollector_types.go +++ b/apis/v1alpha1/opentelemetrycollector_types.go @@ -27,9 +27,11 @@ import ( type Ingress struct { // Type default value is: none // Supported types are: ingress - Type string `json:"type,omitempty"` + // TODO(frzifus): support routes + Type IngressType `json:"type,omitempty"` // Hostname by which the ingress proxy can be reached. + // +optional Hostname string `json:"hostname,omitempty"` // Annotations to add to ingress. diff --git a/apis/v1alpha1/opentelemetrycollector_webhook.go b/apis/v1alpha1/opentelemetrycollector_webhook.go index 1cc9a1972f..c1ff89faf0 100644 --- a/apis/v1alpha1/opentelemetrycollector_webhook.go +++ b/apis/v1alpha1/opentelemetrycollector_webhook.go @@ -168,7 +168,7 @@ func (r *OpenTelemetryCollector) validateCRDSpec() error { } mode := strings.ToLower(string(r.Spec.Mode)) - if r.Spec.Ingress.Type != "" && (mode != "deployment" || mode != "daemonset" || mode != "statefulset") { + if r.Spec.Ingress.Type == IngressTypeNginx && (mode == "deployment" || mode == "daemonset" || mode == "statefulset") { return fmt.Errorf("the OptenTelemetry Spec Ingress configuiration is incorrect. Ingress can only be used in combination with the modes: %s, %s, %s", "deployment", "daemenset", "statefulset", ) diff --git a/pkg/collector/reconcile/ingress.go b/pkg/collector/reconcile/ingress.go index 5352fc8251..3d19d1214b 100644 --- a/pkg/collector/reconcile/ingress.go +++ b/pkg/collector/reconcile/ingress.go @@ -32,7 +32,7 @@ import ( ) func desiredIngresses(ctx context.Context, params Params) *networkingv1.Ingress { - if params.Instance.Spec.Ingress.Type != "ingress" { + if params.Instance.Spec.Ingress.Type != v1alpha1.IngressTypeNginx { return nil } svcTarget := naming.Service(params.Instance) diff --git a/pkg/collector/reconcile/ingress_test.go b/pkg/collector/reconcile/ingress_test.go index fec71fce83..36bd87a317 100644 --- a/pkg/collector/reconcile/ingress_test.go +++ b/pkg/collector/reconcile/ingress_test.go @@ -43,7 +43,7 @@ func TestDesiredIngresses(t *testing.T) { Instance: v1alpha1.OpenTelemetryCollector{ Spec: v1alpha1.OpenTelemetryCollectorSpec{ Ingress: v1alpha1.Ingress{ - Type: "unknown", + Type: v1alpha1.IngressType("unknown"), }, }, }, @@ -62,7 +62,7 @@ func TestDesiredIngresses(t *testing.T) { Spec: v1alpha1.OpenTelemetryCollectorSpec{ Config: "!!!", Ingress: v1alpha1.Ingress{ - Type: "ingress", + Type: v1alpha1.IngressTypeNginx, }, }, }, @@ -81,7 +81,7 @@ func TestDesiredIngresses(t *testing.T) { Spec: v1alpha1.OpenTelemetryCollectorSpec{ Config: "---", Ingress: v1alpha1.Ingress{ - Type: "ingress", + Type: v1alpha1.IngressTypeNginx, }, }, }, @@ -104,7 +104,7 @@ func TestDesiredIngresses(t *testing.T) { params.Instance.Namespace = ns params.Instance.Spec.Ingress = v1alpha1.Ingress{ - Type: "ingress", + Type: v1alpha1.IngressTypeNginx, Hostname: hostname, Annotations: map[string]string{"some.key": "some.value"}, }