Skip to content

Commit

Permalink
feat: allow customizing cluster domain
Browse files Browse the repository at this point in the history
Signed-off-by: GitHub <[email protected]>
  • Loading branch information
aslafy-z authored Sep 7, 2022
1 parent bf44280 commit 549a1d9
Show file tree
Hide file tree
Showing 13 changed files with 43 additions and 11 deletions.
1 change: 1 addition & 0 deletions charts/logging-demo/templates/logging.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,5 @@ spec:
{{ toYaml .Values.loggingOperator.fluentbit | indent 4}}
{{- end}}

clusterDomain: {{ .Values.loggingOperator.clusterDomain }}
controlNamespace: {{ .Values.loggingOperator.controlNamespace | default .Release.Namespace }}
6 changes: 5 additions & 1 deletion charts/logging-demo/templates/secret_tls.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
{{- if .Values.loggingOperator.tls.enabled }}
{{ $ca := genCA "svc-cat-ca" 3650 }}
{{ $cn := printf "%s-%s.%s.svc.cluster.local" (include "logging-demo.name" .) "fluentd" .Release.Namespace }}
{{- if .Values.loggingOperator.clusterDomain }}
{{ $cn := printf "%s-%s.%s.svc.%s" (include "logging-demo.name" .) "fluentd" .Release.Namespace .Values.loggingOperator.clusterDomain }}
{{- else }}
{{ $cn := printf "%s-%s.%s.svc" (include "logging-demo.name" .) "fluentd" .Release.Namespace }}
{{- end }}
{{ $server := genSignedCert $cn nil nil 365 $ca }}
{{ $client := genSignedCert "" nil nil 365 $ca }}

Expand Down
1 change: 1 addition & 0 deletions charts/logging-demo/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ nameOverride: ""
fullnameOverride: ""

loggingOperator:
clusterDomain: cluster.local
controlNamespace:
fluentd: {}
# metrics:
Expand Down
1 change: 1 addition & 0 deletions charts/logging-operator-logging/templates/logging.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ spec:
watchNamespaces:
{{ toYaml .Values.watchNamespaces | indent 4 }}
{{- end }}
clusterDomain: {{ .Values.clusterDomain }}
controlNamespace: {{ .Values.controlNamespace | default .Release.Namespace }}
{{- if .Values.defaultFlow }}
defaultFlow:
Expand Down
6 changes: 5 additions & 1 deletion charts/logging-operator-logging/templates/secret.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
{{- if .Values.tls.enabled }}
{{ $ca := genCA "svc-cat-ca" 3650 }}
{{ $cn := printf "%s-%s.%s.svc.cluster.local" (include "logging-operator-logging.name" .) "fluentd" .Release.Namespace }}
{{- if .Values.clusterDomain }}
{{ $cn := printf "%s-%s.%s.svc.%s" (include "logging-operator-logging.name" .) "fluentd" .Release.Namespace .Values.clusterDomain }}
{{- else }}
{{ $cn := printf "%s-%s.%s.svc" (include "logging-operator-logging.name" .) "fluentd" .Release.Namespace }}
{{- end }}
{{ $server := genSignedCert $cn nil nil 365 $ca }}
{{ $client := genSignedCert "" nil nil 365 $ca }}

Expand Down
5 changes: 5 additions & 0 deletions charts/logging-operator-logging/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ flowConfigOverride: ""
nameOverride: ""
fullnameOverride: ""


# If an immutable field is changed, delete the existing resource
# and recreate it with the new configuration.
enableRecreateWorkloadOnImmutableFieldChange: false
Expand Down Expand Up @@ -68,6 +69,10 @@ skipInvalidResources: false

# Limit namespaces from where to read Flow and Output specs
watchNamespaces: []

# Cluster domain name to be used when templating URLs to services
clusterDomain: "cluster.local"

# Control namespace that contains ClusterOutput and ClusterFlow resources
controlNamespace: ""
# Allow configuration of cluster resources from any namespace
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ spec:
properties:
allowClusterResourcesFromAllNamespaces:
type: boolean
clusterDomain:
type: string
controlNamespace:
type: string
defaultFlow:
Expand Down
2 changes: 2 additions & 0 deletions config/crd/bases/logging.banzaicloud.io_loggings.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ spec:
properties:
allowClusterResourcesFromAllNamespaces:
type: boolean
clusterDomain:
type: string
controlNamespace:
type: string
defaultFlow:
Expand Down
7 changes: 4 additions & 3 deletions pkg/resources/fluentbit/configsecret.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ func (r *Reconciler) configSecret() (runtime.Object, reconciler.DesiredState, er

var fluentbitTargetHost string
if r.Logging.Spec.FluentdSpec != nil && r.Logging.Spec.FluentbitSpec.TargetHost == "" {
fluentbitTargetHost = fmt.Sprintf("%s.%s.svc.cluster.local", r.Logging.QualifiedName(fluentd.ServiceName), r.Logging.Spec.ControlNamespace)
fluentbitTargetHost = fmt.Sprintf("%s.%s.svc.%s", r.Logging.QualifiedName(fluentd.ServiceName), r.Logging.Spec.ControlNamespace, r.Logging.Spec.ClusterDomain)
} else {
fluentbitTargetHost = r.Logging.Spec.FluentbitSpec.TargetHost
}
Expand Down Expand Up @@ -360,10 +360,11 @@ func (r *Reconciler) generateUpstreamNode(index int32) upstreamNode {
podName := r.Logging.QualifiedName(fmt.Sprintf("%s-%d", fluentd.ComponentFluentd, index))
return upstreamNode{
Name: podName,
Host: fmt.Sprintf("%s.%s.%s.svc.cluster.local",
Host: fmt.Sprintf("%s.%s.%s.svc.%s",
podName,
r.Logging.QualifiedName(fluentd.ServiceName+"-headless"),
r.Logging.Spec.ControlNamespace),
r.Logging.Spec.ControlNamespace,
r.Logging.Spec.ClusterDomain),
Port: 24240,
}
}
7 changes: 4 additions & 3 deletions pkg/resources/nodeagent/configsecret.go
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ func (n *nodeAgentInstance) configSecret() (runtime.Object, reconciler.DesiredSt
SharedKey: n.nodeAgent.FluentbitSpec.TLS.SharedKey,
},
Monitor: monitor,
TargetHost: fmt.Sprintf("%s.%s.svc.cluster.local", n.FluentdQualifiedName(fluentd.ServiceName), n.logging.Spec.ControlNamespace),
TargetHost: fmt.Sprintf("%s.%s.svc.%s", n.FluentdQualifiedName(fluentd.ServiceName), n.logging.Spec.ControlNamespace, n.logging.Spec.ClusterDomain),
TargetPort: n.logging.Spec.FluentdSpec.Port,
Input: fluentbitInput,
DisableKubernetesFilter: disableKubernetesFilter,
Expand Down Expand Up @@ -317,10 +317,11 @@ func (n *nodeAgentInstance) generateUpstreamNode(index int32) upstreamNode {
podName := n.FluentdQualifiedName(fmt.Sprintf("%s-%d", fluentd.ComponentFluentd, index))
return upstreamNode{
Name: podName,
Host: fmt.Sprintf("%s.%s.%s.svc.cluster.local",
Host: fmt.Sprintf("%s.%s.%s.svc.%s",
podName,
n.FluentdQualifiedName(fluentd.ServiceName+"-headless"),
n.logging.Spec.ControlNamespace),
n.logging.Spec.ControlNamespace,
n.logging.Spec.ClusterDomain),
Port: 24240,
}
}
6 changes: 5 additions & 1 deletion pkg/resources/nodeagent/nodeagent.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ func NodeAgentFluentbitDefaults(userDefined **v1beta1.NodeAgent) (*v1beta1.NodeA
var NodeAgentFluentbitWindowsDefaults = &v1beta1.NodeAgent{
FluentbitSpec: &v1beta1.NodeAgentFluentbit{
FilterKubernetes: v1beta1.FilterKubernetes{
KubeURL: "https://kubernetes.default.svc.cluster.local:443",
KubeURL: "https://kubernetes.default.svc:443",
KubeCAFile: "c:\\var\\run\\secrets\\kubernetes.io\\serviceaccount\\ca.crt",
KubeTokenFile: "c:\\var\\run\\secrets\\kubernetes.io\\serviceaccount\\token",
KubeTagPrefix: "kubernetes.C.var.log.containers.",
Expand Down Expand Up @@ -304,6 +304,10 @@ func (r *Reconciler) Reconcile() (*reconcile.Result, error) {
if err != nil {
return nil, err
}

// Overwrite Kubernetes endpoint with a ClusterDomain templated value.
NodeAgentFluentbitDefaults.FluentbitSpec.FilterKubernetes.KubeURL = fmt.Sprintf("https://kubernetes.default.svc.%s:443", r.Logging.Spec.ClusterDomain)

default:
err := merge.Merge(NodeAgentFluentbitDefaults, NodeAgentFluentbitLinuxDefaults)
if err != nil {
Expand Down
6 changes: 6 additions & 0 deletions pkg/sdk/logging/api/v1beta1/logging_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ type LoggingSpec struct {
GlobalFilters []Filter `json:"globalFilters,omitempty"`
// Limit namespaces to watch Flow and Output custom resources.
WatchNamespaces []string `json:"watchNamespaces,omitempty"`
// Cluster domain name to be used when templating URLs to services (default: "cluster.local").
// +kubebuilder:validation:Optional
ClusterDomain string `json:"clusterDomain"`
// Namespace for cluster wide configuration resources like CLusterFlow and ClusterOutput.
// This should be a protected namespace from regular users.
// Resources like fluentbit and fluentd will run in this namespace as well.
Expand Down Expand Up @@ -137,6 +140,9 @@ const (

// SetDefaults fills empty attributes
func (l *Logging) SetDefaults() error {
if l.Spec.ClusterDomain == "" {
l.Spec.ClusterDomain = "cluster.local"
}
if !l.Spec.FlowConfigCheckDisabled && l.Status.ConfigCheckResults == nil {
l.Status.ConfigCheckResults = make(map[string]bool)
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/sdk/static/gen/crds/generated.go

Large diffs are not rendered by default.

0 comments on commit 549a1d9

Please sign in to comment.