-
Notifications
You must be signed in to change notification settings - Fork 138
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added Extension Controller and StatsD containers to the ActiveGate po…
…d on reconciliation Added StatsD UDP port to the ActiveGate service Hide StatsD and EEC containers under feature flag 'enable-statsd' Added feature flag 'use-activegate-image-for-statsd' to control whether custom entry points are needed for StatsD/EEC containers
- Loading branch information
Showing
16 changed files
with
660 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,11 @@ | ||
package consts | ||
|
||
const ( | ||
ServicePortName = "https" | ||
ServicePort = 443 | ||
ServiceTargetPort = "ag-https" | ||
|
||
StatsDIngestPortName = "statsd" | ||
StatsDIngestPort = 18125 | ||
StatsDIngestTargetPort = "statsd-port" | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
controllers/activegate/reconciler/statefulset/container_builder.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package statefulset | ||
|
||
import corev1 "k8s.io/api/core/v1" | ||
|
||
type ContainerBuilder interface { | ||
BuildContainer() corev1.Container | ||
BuildVolumes() []corev1.Volume | ||
} | ||
|
||
type GenericContainer struct { | ||
StsProperties *statefulSetProperties | ||
} | ||
|
||
func NewGenericContainer(stsProperties *statefulSetProperties) *GenericContainer { | ||
return &GenericContainer{StsProperties: stsProperties} | ||
} |
141 changes: 141 additions & 0 deletions
141
controllers/activegate/reconciler/statefulset/container_eec.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,141 @@ | ||
package statefulset | ||
|
||
import ( | ||
"fmt" | ||
"net/url" | ||
"strings" | ||
|
||
dynatracev1beta1 "github.com/Dynatrace/dynatrace-operator/api/v1beta1" | ||
"github.com/pkg/errors" | ||
corev1 "k8s.io/api/core/v1" | ||
"k8s.io/apimachinery/pkg/util/intstr" | ||
) | ||
|
||
const eecIngestPortName = "eec-http" | ||
const eecIngestPort = 14599 | ||
|
||
const activeGateInternalCommunicationPort = 9999 | ||
|
||
var _ ContainerBuilder = (*ExtensionController)(nil) | ||
|
||
type ExtensionController struct { | ||
GenericContainer | ||
} | ||
|
||
func NewExtensionController(stsProperties *statefulSetProperties) *ExtensionController { | ||
return &ExtensionController{ | ||
GenericContainer: *NewGenericContainer(stsProperties), | ||
} | ||
} | ||
|
||
func (eec *ExtensionController) BuildContainer() corev1.Container { | ||
return corev1.Container{ | ||
Name: fmt.Sprintf("%s-eec", dynatracev1beta1.OperatorName), | ||
Image: eec.StsProperties.DynaKube.ActiveGateImage(), | ||
ImagePullPolicy: corev1.PullAlways, | ||
Env: eec.buildEnvs(), | ||
VolumeMounts: eec.buildVolumeMounts(), | ||
Command: eec.buildCommand(), | ||
Ports: eec.buildPorts(), | ||
ReadinessProbe: &corev1.Probe{ | ||
Handler: corev1.Handler{ | ||
HTTPGet: &corev1.HTTPGetAction{ | ||
Path: "/readyz", | ||
Port: intstr.IntOrString{IntVal: eecIngestPort}, | ||
}, | ||
}, | ||
InitialDelaySeconds: 30, | ||
PeriodSeconds: 15, | ||
FailureThreshold: 3, | ||
SuccessThreshold: 1, | ||
TimeoutSeconds: 1, | ||
}, | ||
} | ||
} | ||
|
||
func (eec *ExtensionController) BuildVolumes() []corev1.Volume { | ||
return []corev1.Volume{ | ||
{ | ||
Name: "auth-tokens", | ||
VolumeSource: corev1.VolumeSource{ | ||
EmptyDir: &corev1.EmptyDirVolumeSource{}, | ||
}, | ||
}, | ||
{ | ||
Name: "eec-ds-shared", | ||
VolumeSource: corev1.VolumeSource{ | ||
EmptyDir: &corev1.EmptyDirVolumeSource{}, | ||
}, | ||
}, | ||
{ | ||
Name: "dsauthtokendir", | ||
VolumeSource: corev1.VolumeSource{ | ||
EmptyDir: &corev1.EmptyDirVolumeSource{}, | ||
}, | ||
}, | ||
{ | ||
Name: "eec-config", | ||
VolumeSource: corev1.VolumeSource{ | ||
// TODO | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func (eec *ExtensionController) buildPorts() []corev1.ContainerPort { | ||
return []corev1.ContainerPort{ | ||
{Name: eecIngestPortName, ContainerPort: eecIngestPort}, | ||
} | ||
} | ||
|
||
func (eec *ExtensionController) buildCommand() []string { | ||
if eec.StsProperties.DynaKube.FeatureUseActiveGateImageForStatsD() { | ||
return []string{ | ||
"/bin/bash", "/dt/eec/entrypoint.sh", | ||
} | ||
} | ||
return nil | ||
} | ||
|
||
func (eec *ExtensionController) buildVolumeMounts() []corev1.VolumeMount { | ||
return []corev1.VolumeMount{ | ||
{Name: "auth-tokens", MountPath: "/var/lib/dynatrace/gateway/config"}, | ||
{Name: "eec-ds-shared", MountPath: "/mnt/dsexecargs"}, | ||
{Name: "dsauthtokendir", MountPath: "/var/lib/dynatrace/remotepluginmodule/agent/runtime/datasources"}, | ||
{Name: "eec-config", MountPath: "/var/lib/dynatrace/remotepluginmodule/agent/conf/runtime"}, | ||
{Name: "ds-metadata", MountPath: "/opt/dynatrace/remotepluginmodule/agent/datasources/statsd", ReadOnly: true}, | ||
} | ||
} | ||
|
||
func (eec *ExtensionController) buildEnvs() []corev1.EnvVar { | ||
tenantId, err := getTenantId(eec.StsProperties.Spec.APIURL) | ||
if err != nil { | ||
eec.StsProperties.log.Error(err, "Problem getting tenant id from api url") | ||
} | ||
return []corev1.EnvVar{ | ||
{Name: "TenantId", Value: tenantId}, | ||
{Name: "ServerUrl", Value: fmt.Sprintf("https://localhost:%d/communication", activeGateInternalCommunicationPort)}, | ||
{Name: "EecIngestPort", Value: fmt.Sprintf("%d", eecIngestPort)}, | ||
} | ||
} | ||
|
||
func getTenantId(apiUrl string) (string, error) { | ||
if !strings.HasSuffix(apiUrl, "/api") { | ||
return "", fmt.Errorf("api url %s does not end with /api", apiUrl) | ||
} | ||
|
||
parsedUrl, err := url.Parse(apiUrl) | ||
if err != nil { | ||
return "", errors.WithMessagef(err, "problem parsing tenant id from url %s", apiUrl) | ||
} | ||
|
||
fqdn := parsedUrl.Hostname() | ||
hostnameWithDomains := strings.FieldsFunc(fqdn, | ||
func(r rune) bool { return r == '.' }, | ||
) | ||
if len(hostnameWithDomains) < 1 { | ||
return "", fmt.Errorf("problem getting tenant id from fqdn '%s'", fqdn) | ||
} | ||
|
||
return hostnameWithDomains[0], nil | ||
} |
Oops, something went wrong.