Skip to content

Commit

Permalink
Merge pull request #128 from anisimovdk/add-probes
Browse files Browse the repository at this point in the history
Add probes attribute to vector-agent
  • Loading branch information
zvlb committed Nov 18, 2023
2 parents fba63d8 + d7159fb commit 31adc97
Show file tree
Hide file tree
Showing 8 changed files with 390 additions and 3 deletions.
4 changes: 2 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
# - use the VERSION as arg of the bundle target (e.g make bundle VERSION=0.0.2)
# - use environment variables to overwrite this value (e.g export VERSION=0.0.2)
VERSION ?= 0.0.1
DOCKER_PLATFORM ?= linux/amd64

# CHANNELS define the bundle channels used in the bundle.
# Add a new line here if you would like to change its default config. (E.g CHANNELS = "candidate,fast,stable")
Expand Down Expand Up @@ -117,7 +118,7 @@ run: manifests generate fmt vet ## Run a controller from your host.

.PHONY: docker-build
docker-build: test ## Build docker image with the manager.
docker build -t ${IMG} .
docker build --platform ${DOCKER_PLATFORM} -t ${IMG} .

.PHONY: docker-push
docker-push: ## Push docker image with the manager.
Expand Down Expand Up @@ -233,4 +234,3 @@ catalog-build: opm ## Build a catalog image.
.PHONY: catalog-push
catalog-push: ## Push a catalog image.
$(MAKE) docker-push IMG=$(CATALOG_IMG)

12 changes: 12 additions & 0 deletions api/v1alpha1/vector_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,14 @@ type VectorAgent struct {
// +optional
Volumes []v1.Volume `json:"volumes,omitempty"`

// Periodic probe of container service readiness. Container will be removed from service endpoints if the probe fails.
// +optional
ReadinessProbe *v1.Probe `json:"readinessProbe,omitempty"`

// Periodic probe of container liveness. Container will be restarted if the probe fails.
// +optional
LivenessProbe *v1.Probe `json:"livenessProbe,omitempty"`

// Pod volumes to mount into the container's filesystem.
// +optional
VolumeMounts []v1.VolumeMount `json:"volumeMounts,omitempty"`
Expand All @@ -132,6 +140,10 @@ type VectorAgent struct {
type ApiSpec struct {
Enabled bool `json:"enabled,omitempty"`
Playground bool `json:"playground,omitempty"`
// Enable ReadinessProbe and LivenessProbe via api /health endpoint.
// If probe enabled via VectorAgent, this setting will be ignored for that probe.
// +optional
Healthcheck bool `json:"healthcheck,omitempty"`
}

// ConfigCheck is the Schema for control params for ConfigCheck pods
Expand Down
10 changes: 10 additions & 0 deletions api/v1alpha1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

303 changes: 303 additions & 0 deletions config/crd/bases/observability.kaasops.io_vectors.yaml

Large diffs are not rendered by default.

9 changes: 9 additions & 0 deletions controllers/factory/utils/k8s/k8s.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ func createOrUpdateDeployment(ctx context.Context, obj runtime.Object, c client.
}

// Compare
// FIXME: DeepDerivative does not compare fields, if they omitted in desiredFields
if !equality.Semantic.DeepDerivative(desiredFields, existingFields) {
// Update if not equal
existing.Labels = desired.Labels
Expand Down Expand Up @@ -133,6 +134,7 @@ func createOrUpdateStatefulSet(ctx context.Context, obj runtime.Object, c client
}

// Compare
// FIXME: DeepDerivative does not compare fields, if they omitted in desiredFields
if !equality.Semantic.DeepDerivative(desiredFields, existingFields) {
// Update if not equal
existing.Labels = desired.Labels
Expand Down Expand Up @@ -171,6 +173,7 @@ func createOrUpdateDaemonSet(ctx context.Context, obj runtime.Object, c client.C
}

// Compare
// FIXME: DeepDerivative does not compare fields, if they omitted in desiredFields
if !equality.Semantic.DeepDerivative(desiredFields, existingFields) {
// Update if not equal
existing.Labels = desired.Labels
Expand Down Expand Up @@ -209,6 +212,7 @@ func createOrUpdateSecret(ctx context.Context, obj runtime.Object, c client.Clie
}

// Compare
// FIXME: DeepDerivative does not compare fields, if they omitted in desiredFields
if !equality.Semantic.DeepDerivative(desiredFields, existingFields) {
// Update if not equal
existing.Labels = desired.Labels
Expand Down Expand Up @@ -247,6 +251,7 @@ func createOrUpdateService(ctx context.Context, obj runtime.Object, c client.Cli
}

// Compare
// FIXME: DeepDerivative does not compare fields, if they omitted in desiredFields
if !equality.Semantic.DeepDerivative(desiredFields, existingFields) {
// Update if not equal
existing.Labels = desired.Labels
Expand Down Expand Up @@ -283,6 +288,7 @@ func createOrUpdateServiceAccount(ctx context.Context, obj runtime.Object, c cli
}

// Compare
// FIXME: DeepDerivative does not compare fields, if they omitted in desiredFields
if !equality.Semantic.DeepDerivative(desiredFields, existingFields) {
// Update if not equal
existing.Labels = desired.Labels
Expand Down Expand Up @@ -320,6 +326,7 @@ func createOrUpdateClusterRole(ctx context.Context, obj runtime.Object, c client
}

// Compare
// FIXME: DeepDerivative does not compare fields, if they omitted in desiredFields
if !equality.Semantic.DeepDerivative(desiredFields, existingFields) {
// Update if not equal
existing.Labels = desired.Labels
Expand Down Expand Up @@ -360,6 +367,7 @@ func createOrUpdateClusterRoleBinding(ctx context.Context, obj runtime.Object, c
}

// Compare
// FIXME: DeepDerivative does not compare fields, if they omitted in desiredFields
if !equality.Semantic.DeepDerivative(desiredFields, existingFields) {
// Update if not equal
existing.Labels = desired.Labels
Expand Down Expand Up @@ -401,6 +409,7 @@ func createOrUpdatePodMonitor(ctx context.Context, obj runtime.Object, c client.
}

// Compare
// FIXME: DeepDerivative does not compare fields, if they omitted in desiredFields
if !equality.Semantic.DeepDerivative(desiredFields, existingFields) {
// Update if not equal
existing.Labels = desired.Labels
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,8 @@ func (ctrl *Controller) VectorAgentContainer() *corev1.Container {
},
},
VolumeMounts: ctrl.generateVectorAgentVolumeMounts(),
ReadinessProbe: ctrl.Vector.Spec.Agent.ReadinessProbe,
LivenessProbe: ctrl.Vector.Spec.Agent.LivenessProbe,
Resources: ctrl.Vector.Spec.Agent.Resources,
SecurityContext: ctrl.Vector.Spec.Agent.ContainerSecurityContext,
ImagePullPolicy: ctrl.Vector.Spec.Agent.ImagePullPolicy,
Expand Down
39 changes: 39 additions & 0 deletions controllers/factory/vector/vectoragent/vectoragent_default.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import (
"github.com/kaasops/vector-operator/api/v1alpha1"
corev1 "k8s.io/api/core/v1"
resourcev1 "k8s.io/apimachinery/pkg/api/resource"
"k8s.io/apimachinery/pkg/util/intstr"
)

func (ctrl *Controller) SetDefault() {
Expand Down Expand Up @@ -76,6 +77,43 @@ func (ctrl *Controller) SetDefault() {
}
}

if ctrl.Vector.Spec.Agent.ReadinessProbe == nil && ctrl.Vector.Spec.Agent.Api.Enabled && ctrl.Vector.Spec.Agent.Api.Healthcheck {
ctrl.Vector.Spec.Agent.ReadinessProbe = &corev1.Probe{
ProbeHandler: corev1.ProbeHandler{
HTTPGet: &corev1.HTTPGetAction{
Path: "/health",
Port: intstr.IntOrString{
Type: intstr.Type(0),
IntVal: 8686,
},
},
},
PeriodSeconds: 20,
InitialDelaySeconds: 15,
TimeoutSeconds: 3,
SuccessThreshold: 0,
FailureThreshold: 0,
}
}
if ctrl.Vector.Spec.Agent.LivenessProbe == nil && ctrl.Vector.Spec.Agent.Api.Enabled && ctrl.Vector.Spec.Agent.Api.Healthcheck {
ctrl.Vector.Spec.Agent.LivenessProbe = &corev1.Probe{
ProbeHandler: corev1.ProbeHandler{
HTTPGet: &corev1.HTTPGetAction{
Path: "/health",
Port: intstr.IntOrString{
Type: intstr.Type(0),
IntVal: 8686,
},
},
},
PeriodSeconds: 20,
InitialDelaySeconds: 15,
TimeoutSeconds: 3,
SuccessThreshold: 0,
FailureThreshold: 0,
}
}

if ctrl.Vector.Spec.Agent.VolumeMounts == nil {
ctrl.Vector.Spec.Agent.VolumeMounts = []corev1.VolumeMount{
{
Expand Down Expand Up @@ -107,4 +145,5 @@ func (ctrl *Controller) SetDefault() {
corev1.ResourceCPU: resourcev1.MustParse("1000m"),
}
}

}
14 changes: 13 additions & 1 deletion docs/specification.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,14 @@
<td>podSecurityPolicyName</td>
<td>PodSecurityPolicyName - defines name for podSecurityPolicy in case of empty value, prefixedName will be used.</td>
</tr>
<tr>
<td>readinessProbe</td>
<td>Periodic probe of container service readiness. Container will be removed from service endpoints if the probe fails. By default - not set</td>
</tr>
<tr>
<td>livenessProbe</td>
<td>Periodic probe of container liveness. Container will be restarted if the probe fails. By default - not set</td>
</tr>
<tr>
<td>volumes</td>
<td>List of volumes that can be mounted by containers belonging to the pod.</td>
Expand All @@ -91,7 +99,7 @@
## Api Spec
<table>
<tr>
<td rowspan="4"><a href="https://vector.dev/docs/reference/api/">api</a></td>
<td rowspan="5"><a href="https://vector.dev/docs/reference/api/">api</a></td>
</tr>
<tr>
<td>address</td>
Expand All @@ -105,6 +113,10 @@
<td>playground</td>
<td>Whether the GraphQL Playground is enabled for the API. The Playground is accessible via the /playground endpoint of the address set using the bind parameter. By default - <code>false</code></td>
</tr>
<tr>
<td>healthcheck</td>
<td>Enable ReadinessProbe and LivenessProbe via API <code>/health</code> endpoint. If probes enabled via VectorAgent, this setting will be ignored for that probe. By default - <code>false</code></td>
</tr>
</table>


Expand Down

0 comments on commit 31adc97

Please sign in to comment.