Skip to content

Commit

Permalink
feat: add dnspolicy support to deployment and sts
Browse files Browse the repository at this point in the history
  • Loading branch information
gai6948 committed Feb 6, 2022
1 parent 450766b commit f8afe9c
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 5 deletions.
6 changes: 1 addition & 5 deletions pkg/collector/daemonset.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,6 @@ func DaemonSet(cfg config.Config, logger logr.Logger, otelcol v1alpha1.OpenTelem

annotations := Annotations(otelcol)
podAnnotations := PodAnnotations(otelcol)
dnsPolicy := corev1.DNSClusterFirst
if otelcol.Spec.HostNetwork {
dnsPolicy = corev1.DNSClusterFirstWithHostNet
}
return appsv1.DaemonSet{
ObjectMeta: metav1.ObjectMeta{
Name: naming.Collector(otelcol),
Expand All @@ -58,7 +54,7 @@ func DaemonSet(cfg config.Config, logger logr.Logger, otelcol v1alpha1.OpenTelem
Volumes: Volumes(cfg, otelcol),
Tolerations: otelcol.Spec.Tolerations,
HostNetwork: otelcol.Spec.HostNetwork,
DNSPolicy: dnsPolicy,
DNSPolicy: getDnsPolicy(otelcol),
SecurityContext: otelcol.Spec.PodSecurityContext,
},
},
Expand Down
1 change: 1 addition & 0 deletions pkg/collector/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ func Deployment(cfg config.Config, logger logr.Logger, otelcol v1alpha1.OpenTele
ServiceAccountName: ServiceAccountName(otelcol),
Containers: []corev1.Container{Container(cfg, logger, otelcol)},
Volumes: Volumes(cfg, otelcol),
DNSPolicy: getDnsPolicy(otelcol),
Tolerations: otelcol.Spec.Tolerations,
SecurityContext: otelcol.Spec.PodSecurityContext,
},
Expand Down
1 change: 1 addition & 0 deletions pkg/collector/statefulset.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ func StatefulSet(cfg config.Config, logger logr.Logger, otelcol v1alpha1.OpenTel
ServiceAccountName: ServiceAccountName(otelcol),
Containers: []corev1.Container{Container(cfg, logger, otelcol)},
Volumes: Volumes(cfg, otelcol),
DNSPolicy: getDnsPolicy(otelcol),
Tolerations: otelcol.Spec.Tolerations,
SecurityContext: otelcol.Spec.PodSecurityContext,
},
Expand Down
29 changes: 29 additions & 0 deletions pkg/collector/utils.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// 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 collector

import (
corev1 "k8s.io/api/core/v1"

"github.com/open-telemetry/opentelemetry-operator/apis/v1alpha1"
)

func getDnsPolicy(otelcol v1alpha1.OpenTelemetryCollector) corev1.DNSPolicy {
dnsPolicy := corev1.DNSClusterFirst
if otelcol.Spec.HostNetwork {
dnsPolicy = corev1.DNSClusterFirstWithHostNet
}
return dnsPolicy
}

0 comments on commit f8afe9c

Please sign in to comment.