Skip to content

Commit a7d2014

Browse files
author
Dmitry Anisimov
committed
add containerSecurityContext, volumes, volumeMounts to Vector resource
1 parent 35755fe commit a7d2014

File tree

10 files changed

+3770
-141
lines changed

10 files changed

+3770
-141
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,3 +25,5 @@ testbin/*
2525
*~
2626
.vscode
2727
__debug_bin
28+
29+
vendor

api/v1alpha1/vector_types.go

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,9 +73,12 @@ type VectorAgent struct {
7373
// SecurityContext holds pod-level security attributes and common container settings.
7474
// This defaults to the default PodSecurityContext.
7575
// +optional
76-
// Tolerations If specified, the pod's tolerations.
76+
SecurityContext *v1.PodSecurityContext `json:"podSecurityContext,omitempty"`
77+
// SecurityContext holds security configuration that will be applied to a container.
78+
// Some fields are present in both SecurityContext and PodSecurityContext.
79+
// When both are set, the values in SecurityContext take precedence.
7780
// +optional
78-
SecurityContext *v1.PodSecurityContext `json:"securityContext,omitempty"`
81+
ContainerSecurityContext *v1.SecurityContext `json:"containerSecurityContext,omitempty"`
7982
// SchedulerName - defines kubernetes scheduler name
8083
// +optional
8184
SchedulerName string `json:"schedulerName,omitempty"`
@@ -107,6 +110,14 @@ type VectorAgent struct {
107110
// +optional
108111
InternalMetrics bool `json:"internalMetrics,omitempty"`
109112

113+
// List of volumes that can be mounted by containers belonging to the pod.
114+
// +optional
115+
Volumes []v1.Volume `json:"volumes,omitempty"`
116+
117+
// Pod volumes to mount into the container's filesystem.
118+
// +optional
119+
VolumeMounts []v1.VolumeMount `json:"volumeMounts,omitempty"`
120+
110121
ConfigCheck ConfigCheck `json:"configCheck,omitempty"`
111122
}
112123

api/v1alpha1/zz_generated.deepcopy.go

Lines changed: 19 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

config/crd/bases/observability.kaasops.io_vectors.yaml

Lines changed: 1829 additions & 44 deletions
Large diffs are not rendered by default.

controllers/factory/config/config.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ func New(vector *vectorv1alpha1.Vector) *VectorConfig {
4141
}
4242

4343
return &VectorConfig{
44-
DataDir: vector.Spec.Agent.DataDir,
44+
DataDir: "/vector-data-dir",
4545
Api: api,
4646
Sources: sources,
4747
Sinks: sinks,

controllers/factory/vector/vectoragent/vectoragent_daemonset.go

Lines changed: 10 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ func (ctrl *Controller) createVectorAgentDaemonSet() *appsv1.DaemonSet {
5858
},
5959
VolumeMounts: ctrl.generateVectorAgentVolumeMounts(),
6060
Resources: ctrl.Vector.Spec.Agent.Resources,
61-
SecurityContext: &corev1.SecurityContext{},
61+
SecurityContext: ctrl.Vector.Spec.Agent.ContainerSecurityContext,
6262
ImagePullPolicy: ctrl.Vector.Spec.Agent.ImagePullPolicy,
6363
},
6464
},
@@ -71,7 +71,9 @@ func (ctrl *Controller) createVectorAgentDaemonSet() *appsv1.DaemonSet {
7171
}
7272

7373
func (ctrl *Controller) generateVectorAgentVolume() []corev1.Volume {
74-
volume := []corev1.Volume{
74+
volume := ctrl.Vector.Spec.Agent.Volumes
75+
76+
volume = append(volume, []corev1.Volume{
7577
{
7678
Name: "config",
7779
VolumeSource: corev1.VolumeSource{
@@ -84,31 +86,7 @@ func (ctrl *Controller) generateVectorAgentVolume() []corev1.Volume {
8486
Name: "data",
8587
VolumeSource: corev1.VolumeSource{
8688
HostPath: &corev1.HostPathVolumeSource{
87-
Path: "/var/lib/vector",
88-
},
89-
},
90-
},
91-
{
92-
Name: "var-log",
93-
VolumeSource: corev1.VolumeSource{
94-
HostPath: &corev1.HostPathVolumeSource{
95-
Path: "/var/log/",
96-
},
97-
},
98-
},
99-
{
100-
Name: "journal",
101-
VolumeSource: corev1.VolumeSource{
102-
HostPath: &corev1.HostPathVolumeSource{
103-
Path: "/var/log/journal",
104-
},
105-
},
106-
},
107-
{
108-
Name: "var-lib",
109-
VolumeSource: corev1.VolumeSource{
110-
HostPath: &corev1.HostPathVolumeSource{
111-
Path: "/var/lib/",
89+
Path: ctrl.Vector.Spec.Agent.DataDir,
11290
},
11391
},
11492
},
@@ -128,13 +106,15 @@ func (ctrl *Controller) generateVectorAgentVolume() []corev1.Volume {
128106
},
129107
},
130108
},
131-
}
109+
}...)
132110

133111
return volume
134112
}
135113

136114
func (ctrl *Controller) generateVectorAgentVolumeMounts() []corev1.VolumeMount {
137-
volumeMount := []corev1.VolumeMount{
115+
volumeMount := ctrl.Vector.Spec.Agent.VolumeMounts
116+
117+
volumeMount = append(volumeMount, []corev1.VolumeMount{
138118
{
139119
Name: "config",
140120
MountPath: "/etc/vector/",
@@ -143,18 +123,6 @@ func (ctrl *Controller) generateVectorAgentVolumeMounts() []corev1.VolumeMount {
143123
Name: "data",
144124
MountPath: "/vector-data-dir",
145125
},
146-
{
147-
Name: "var-log",
148-
MountPath: "/var/log/",
149-
},
150-
{
151-
Name: "journal",
152-
MountPath: "/run/log/journal",
153-
},
154-
{
155-
Name: "var-lib",
156-
MountPath: "/var/lib/",
157-
},
158126
{
159127
Name: "procfs",
160128
MountPath: "/host/proc",
@@ -163,7 +131,7 @@ func (ctrl *Controller) generateVectorAgentVolumeMounts() []corev1.VolumeMount {
163131
Name: "sysfs",
164132
MountPath: "/host/sys",
165133
},
166-
}
134+
}...)
167135

168136
return volumeMount
169137
}

controllers/factory/vector/vectoragent/vectoragent_default.go

Lines changed: 46 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,52 @@ func (ctrl *Controller) SetDefault() {
4444
}
4545

4646
if ctrl.Vector.Spec.Agent.DataDir == "" {
47-
ctrl.Vector.Spec.Agent.DataDir = "/vector-data-dir"
47+
ctrl.Vector.Spec.Agent.DataDir = "/var/lib/vector"
4848
}
4949

50+
if ctrl.Vector.Spec.Agent.Volumes == nil {
51+
ctrl.Vector.Spec.Agent.Volumes = []corev1.Volume{
52+
{
53+
Name: "var-log",
54+
VolumeSource: corev1.VolumeSource{
55+
HostPath: &corev1.HostPathVolumeSource{
56+
Path: "/var/log/",
57+
},
58+
},
59+
},
60+
{
61+
Name: "journal",
62+
VolumeSource: corev1.VolumeSource{
63+
HostPath: &corev1.HostPathVolumeSource{
64+
Path: "/var/log/journal",
65+
},
66+
},
67+
},
68+
{
69+
Name: "var-lib",
70+
VolumeSource: corev1.VolumeSource{
71+
HostPath: &corev1.HostPathVolumeSource{
72+
Path: "/var/lib/",
73+
},
74+
},
75+
},
76+
}
77+
}
78+
79+
if ctrl.Vector.Spec.Agent.VolumeMounts == nil {
80+
ctrl.Vector.Spec.Agent.VolumeMounts = []corev1.VolumeMount{
81+
{
82+
Name: "var-log",
83+
MountPath: "/var/log/",
84+
},
85+
{
86+
Name: "journal",
87+
MountPath: "/run/log/journal",
88+
},
89+
{
90+
Name: "var-lib",
91+
MountPath: "/var/lib/",
92+
},
93+
}
94+
}
5095
}

docs/specification.md

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
# Specification
22

3-
- [Vector](#vector-spec)
4-
- [VectorPipeline](#vectorpipelinespec-clustervectorpipelinespec)
5-
- [ClusterVectorPipeline](#vectorpipelinespec-clustervectorpipelinespec)
3+
- [Specification](#specification)
4+
- [Vector Spec](#vector-spec)
5+
- [Api Spec](#api-spec)
6+
- [VectorPipelineSpec (ClusterVectorPipelineSpec)](#vectorpipelinespec-clustervectorpipelinespec)
67

78

89

@@ -45,6 +46,10 @@
4546
<td>securityContext</td>
4647
<td>SecurityContext holds pod-level security attributes and common container settings. By default - not set</td>
4748
</tr>
49+
<tr>
50+
<td>containerSecurityContext</td>
51+
<td>securityContext holds security configuration that will be applied to a container.</td>
52+
</tr>
4853
<tr>
4954
<td>schedulerName</td>
5055
<td>SchedulerName - defines kubernetes scheduler name. By default - not set</td>
@@ -61,6 +66,14 @@
6166
<td>podSecurityPolicyName</td>
6267
<td>PodSecurityPolicyName - defines name for podSecurityPolicy in case of empty value, prefixedName will be used.</td>
6368
</tr>
69+
<tr>
70+
<td>volumes</td>
71+
<td>List of volumes that can be mounted by containers belonging to the pod.</td>
72+
</tr>
73+
<tr>
74+
<td>volumeMounts</td>
75+
<td>Pod volumes to mount into the container's filesystem.</td>
76+
</tr>
6477
<tr>
6578
<td>priorityClassName</td>
6679
<td>PriorityClassName assigned to the Pods.</td>
@@ -109,4 +122,4 @@
109122
<td>sinks</td>
110123
<td>List of Sinks</td>
111124
</tr>
112-
</table>
125+
</table>

0 commit comments

Comments
 (0)