Skip to content

Commit

Permalink
create dedicated ingress type
Browse files Browse the repository at this point in the history
Signed-off-by: Benedikt Bongartz <bongartz@klimlive.de>
  • Loading branch information
frzifus committed Oct 10, 2022
1 parent 25792a5 commit 19b8f41
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 7 deletions.
30 changes: 30 additions & 0 deletions apis/v1alpha1/ingress_type.go
Original file line number Diff line number Diff line change
@@ -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"
)
4 changes: 3 additions & 1 deletion apis/v1alpha1/opentelemetrycollector_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion apis/v1alpha1/opentelemetrycollector_webhook.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
)
Expand Down
2 changes: 1 addition & 1 deletion pkg/collector/reconcile/ingress.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 4 additions & 4 deletions pkg/collector/reconcile/ingress_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ func TestDesiredIngresses(t *testing.T) {
Instance: v1alpha1.OpenTelemetryCollector{
Spec: v1alpha1.OpenTelemetryCollectorSpec{
Ingress: v1alpha1.Ingress{
Type: "unknown",
Type: v1alpha1.IngressType("unknown"),
},
},
},
Expand All @@ -62,7 +62,7 @@ func TestDesiredIngresses(t *testing.T) {
Spec: v1alpha1.OpenTelemetryCollectorSpec{
Config: "!!!",
Ingress: v1alpha1.Ingress{
Type: "ingress",
Type: v1alpha1.IngressTypeNginx,
},
},
},
Expand All @@ -81,7 +81,7 @@ func TestDesiredIngresses(t *testing.T) {
Spec: v1alpha1.OpenTelemetryCollectorSpec{
Config: "---",
Ingress: v1alpha1.Ingress{
Type: "ingress",
Type: v1alpha1.IngressTypeNginx,
},
},
},
Expand All @@ -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"},
}
Expand Down

0 comments on commit 19b8f41

Please sign in to comment.