/
authtoken.go
60 lines (52 loc) · 1.91 KB
/
authtoken.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
package modifiers
import (
dynatracev1beta1 "github.com/Dynatrace/dynatrace-operator/pkg/api/v1beta1/dynakube"
"github.com/Dynatrace/dynatrace-operator/pkg/controllers/dynakube/activegate/consts"
"github.com/Dynatrace/dynatrace-operator/pkg/controllers/dynakube/activegate/internal/authtoken"
"github.com/Dynatrace/dynatrace-operator/pkg/controllers/dynakube/activegate/internal/statefulset/builder"
"github.com/Dynatrace/dynatrace-operator/pkg/util/kubeobjects/container"
appsv1 "k8s.io/api/apps/v1"
corev1 "k8s.io/api/core/v1"
)
var _ volumeModifier = AuthTokenModifier{}
var _ volumeMountModifier = AuthTokenModifier{}
var _ builder.Modifier = AuthTokenModifier{}
func NewAuthTokenModifier(dynakube dynatracev1beta1.DynaKube) AuthTokenModifier {
return AuthTokenModifier{
dynakube: dynakube,
}
}
type AuthTokenModifier struct {
dynakube dynatracev1beta1.DynaKube
}
func (mod AuthTokenModifier) Enabled() bool {
return true // TODO: Investigate moving this package to the default statefulset
}
func (mod AuthTokenModifier) Modify(sts *appsv1.StatefulSet) error {
baseContainer := container.FindContainerInPodSpec(&sts.Spec.Template.Spec, consts.ActiveGateContainerName)
sts.Spec.Template.Spec.Volumes = append(sts.Spec.Template.Spec.Volumes, mod.getVolumes()...)
baseContainer.VolumeMounts = append(baseContainer.VolumeMounts, mod.getVolumeMounts()...)
return nil
}
func (mod AuthTokenModifier) getVolumes() []corev1.Volume {
return []corev1.Volume{
{
Name: consts.AuthTokenSecretVolumeName,
VolumeSource: corev1.VolumeSource{
Secret: &corev1.SecretVolumeSource{
SecretName: mod.dynakube.ActiveGateAuthTokenSecret(),
},
},
},
}
}
func (mod AuthTokenModifier) getVolumeMounts() []corev1.VolumeMount {
return []corev1.VolumeMount{
{
Name: consts.AuthTokenSecretVolumeName,
ReadOnly: true,
MountPath: consts.AuthTokenMountPoint,
SubPath: authtoken.ActiveGateAuthTokenName,
},
}
}