mirror of https://github.com/grafana/loki
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
225 lines
6.2 KiB
225 lines
6.2 KiB
|
5 years ago
|
package manifests
|
||
|
|
|
||
|
|
import (
|
||
|
|
"fmt"
|
||
|
|
"path"
|
||
|
|
|
||
|
5 years ago
|
"github.com/ViaQ/loki-operator/internal/manifests/internal/config"
|
||
|
5 years ago
|
appsv1 "k8s.io/api/apps/v1"
|
||
|
|
corev1 "k8s.io/api/core/v1"
|
||
|
5 years ago
|
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
|
||
|
|
"k8s.io/apimachinery/pkg/labels"
|
||
|
|
"k8s.io/apimachinery/pkg/util/intstr"
|
||
|
|
"k8s.io/utils/pointer"
|
||
|
|
"sigs.k8s.io/controller-runtime/pkg/client"
|
||
|
|
)
|
||
|
|
|
||
|
|
// BuildQueryFrontend returns a list of k8s objects for Loki QueryFrontend
|
||
|
5 years ago
|
func BuildQueryFrontend(opts Options) ([]client.Object, error) {
|
||
|
|
deployment := NewQueryFrontendDeployment(opts)
|
||
|
|
if opts.Flags.EnableTLSServiceMonitorConfig {
|
||
|
|
if err := configureQueryFrontendServiceMonitorPKI(deployment, opts.Name); err != nil {
|
||
|
|
return nil, err
|
||
|
|
}
|
||
|
5 years ago
|
}
|
||
|
5 years ago
|
|
||
|
|
return []client.Object{
|
||
|
|
deployment,
|
||
|
|
NewQueryFrontendGRPCService(opts),
|
||
|
|
NewQueryFrontendHTTPService(opts),
|
||
|
|
}, nil
|
||
|
5 years ago
|
}
|
||
|
|
|
||
|
|
// NewQueryFrontendDeployment creates a deployment object for a query-frontend
|
||
|
5 years ago
|
func NewQueryFrontendDeployment(opts Options) *appsv1.Deployment {
|
||
|
5 years ago
|
podSpec := corev1.PodSpec{
|
||
|
|
Volumes: []corev1.Volume{
|
||
|
5 years ago
|
{
|
||
|
|
Name: configVolumeName,
|
||
|
5 years ago
|
VolumeSource: corev1.VolumeSource{
|
||
|
|
ConfigMap: &corev1.ConfigMapVolumeSource{
|
||
|
4 years ago
|
DefaultMode: &defaultConfigMapMode,
|
||
|
5 years ago
|
LocalObjectReference: corev1.LocalObjectReference{
|
||
|
5 years ago
|
Name: lokiConfigMapName(opts.Name),
|
||
|
5 years ago
|
},
|
||
|
|
},
|
||
|
|
},
|
||
|
|
},
|
||
|
|
{
|
||
|
|
Name: storageVolumeName,
|
||
|
5 years ago
|
VolumeSource: corev1.VolumeSource{
|
||
|
|
EmptyDir: &corev1.EmptyDirVolumeSource{},
|
||
|
5 years ago
|
},
|
||
|
|
},
|
||
|
|
},
|
||
|
5 years ago
|
Containers: []corev1.Container{
|
||
|
5 years ago
|
{
|
||
|
5 years ago
|
Image: opts.Image,
|
||
|
5 years ago
|
Name: "loki-query-frontend",
|
||
|
|
Resources: corev1.ResourceRequirements{
|
||
|
5 years ago
|
Limits: opts.ResourceRequirements.QueryFrontend.Limits,
|
||
|
|
Requests: opts.ResourceRequirements.QueryFrontend.Requests,
|
||
|
5 years ago
|
},
|
||
|
5 years ago
|
Args: []string{
|
||
|
|
"-target=query-frontend",
|
||
|
|
fmt.Sprintf("-config.file=%s", path.Join(config.LokiConfigMountDir, config.LokiConfigFileName)),
|
||
|
5 years ago
|
fmt.Sprintf("-runtime-config.file=%s", path.Join(config.LokiConfigMountDir, config.LokiRuntimeConfigFileName)),
|
||
|
5 years ago
|
},
|
||
|
5 years ago
|
ReadinessProbe: &corev1.Probe{
|
||
|
|
Handler: corev1.Handler{
|
||
|
|
HTTPGet: &corev1.HTTPGetAction{
|
||
|
5 years ago
|
Path: "/metrics",
|
||
|
|
Port: intstr.FromInt(httpPort),
|
||
|
5 years ago
|
Scheme: corev1.URISchemeHTTP,
|
||
|
5 years ago
|
},
|
||
|
|
},
|
||
|
4 years ago
|
PeriodSeconds: 10,
|
||
|
5 years ago
|
InitialDelaySeconds: 15,
|
||
|
|
TimeoutSeconds: 1,
|
||
|
4 years ago
|
SuccessThreshold: 1,
|
||
|
|
FailureThreshold: 3,
|
||
|
5 years ago
|
},
|
||
|
5 years ago
|
LivenessProbe: &corev1.Probe{
|
||
|
|
Handler: corev1.Handler{
|
||
|
|
HTTPGet: &corev1.HTTPGetAction{
|
||
|
5 years ago
|
Path: "/metrics",
|
||
|
|
Port: intstr.FromInt(httpPort),
|
||
|
5 years ago
|
Scheme: corev1.URISchemeHTTP,
|
||
|
5 years ago
|
},
|
||
|
|
},
|
||
|
|
TimeoutSeconds: 2,
|
||
|
|
PeriodSeconds: 30,
|
||
|
|
FailureThreshold: 10,
|
||
|
4 years ago
|
SuccessThreshold: 1,
|
||
|
5 years ago
|
},
|
||
|
5 years ago
|
Ports: []corev1.ContainerPort{
|
||
|
5 years ago
|
{
|
||
|
4 years ago
|
Name: lokiHTTPPortName,
|
||
|
5 years ago
|
ContainerPort: httpPort,
|
||
|
4 years ago
|
Protocol: protocolTCP,
|
||
|
5 years ago
|
},
|
||
|
|
{
|
||
|
4 years ago
|
Name: lokiGRPCPortName,
|
||
|
5 years ago
|
ContainerPort: grpcPort,
|
||
|
4 years ago
|
Protocol: protocolTCP,
|
||
|
5 years ago
|
},
|
||
|
|
},
|
||
|
5 years ago
|
VolumeMounts: []corev1.VolumeMount{
|
||
|
5 years ago
|
{
|
||
|
|
Name: configVolumeName,
|
||
|
|
ReadOnly: false,
|
||
|
|
MountPath: config.LokiConfigMountDir,
|
||
|
|
},
|
||
|
|
{
|
||
|
|
Name: storageVolumeName,
|
||
|
|
ReadOnly: false,
|
||
|
|
MountPath: dataDirectory,
|
||
|
|
},
|
||
|
|
},
|
||
|
4 years ago
|
TerminationMessagePath: "/dev/termination-log",
|
||
|
|
TerminationMessagePolicy: "File",
|
||
|
|
ImagePullPolicy: "IfNotPresent",
|
||
|
5 years ago
|
},
|
||
|
|
},
|
||
|
|
}
|
||
|
|
|
||
|
5 years ago
|
if opts.Stack.Template != nil && opts.Stack.Template.QueryFrontend != nil {
|
||
|
|
podSpec.Tolerations = opts.Stack.Template.QueryFrontend.Tolerations
|
||
|
|
podSpec.NodeSelector = opts.Stack.Template.QueryFrontend.NodeSelector
|
||
|
5 years ago
|
}
|
||
|
|
|
||
|
5 years ago
|
l := ComponentLabels(LabelQueryFrontendComponent, opts.Name)
|
||
|
|
a := commonAnnotations(opts.ConfigSHA1)
|
||
|
5 years ago
|
|
||
|
5 years ago
|
return &appsv1.Deployment{
|
||
|
5 years ago
|
TypeMeta: metav1.TypeMeta{
|
||
|
|
Kind: "Deployment",
|
||
|
5 years ago
|
APIVersion: appsv1.SchemeGroupVersion.String(),
|
||
|
5 years ago
|
},
|
||
|
|
ObjectMeta: metav1.ObjectMeta{
|
||
|
5 years ago
|
Name: QueryFrontendName(opts.Name),
|
||
|
5 years ago
|
Labels: l,
|
||
|
|
},
|
||
|
5 years ago
|
Spec: appsv1.DeploymentSpec{
|
||
|
5 years ago
|
Replicas: pointer.Int32Ptr(opts.Stack.Template.QueryFrontend.Replicas),
|
||
|
5 years ago
|
Selector: &metav1.LabelSelector{
|
||
|
|
MatchLabels: labels.Merge(l, GossipLabels()),
|
||
|
|
},
|
||
|
5 years ago
|
Template: corev1.PodTemplateSpec{
|
||
|
5 years ago
|
ObjectMeta: metav1.ObjectMeta{
|
||
|
5 years ago
|
Name: fmt.Sprintf("loki-query-frontend-%s", opts.Name),
|
||
|
5 years ago
|
Labels: labels.Merge(l, GossipLabels()),
|
||
|
|
Annotations: a,
|
||
|
5 years ago
|
},
|
||
|
|
Spec: podSpec,
|
||
|
|
},
|
||
|
5 years ago
|
Strategy: appsv1.DeploymentStrategy{
|
||
|
|
Type: appsv1.RollingUpdateDeploymentStrategyType,
|
||
|
5 years ago
|
},
|
||
|
|
},
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
5 years ago
|
// NewQueryFrontendGRPCService creates a k8s service for the query-frontend GRPC endpoint
|
||
|
5 years ago
|
func NewQueryFrontendGRPCService(opts Options) *corev1.Service {
|
||
|
|
l := ComponentLabels(LabelQueryFrontendComponent, opts.Name)
|
||
|
|
|
||
|
5 years ago
|
return &corev1.Service{
|
||
|
5 years ago
|
TypeMeta: metav1.TypeMeta{
|
||
|
|
Kind: "Service",
|
||
|
5 years ago
|
APIVersion: corev1.SchemeGroupVersion.String(),
|
||
|
5 years ago
|
},
|
||
|
|
ObjectMeta: metav1.ObjectMeta{
|
||
|
5 years ago
|
Name: serviceNameQueryFrontendGRPC(opts.Name),
|
||
|
5 years ago
|
Labels: l,
|
||
|
|
},
|
||
|
5 years ago
|
Spec: corev1.ServiceSpec{
|
||
|
5 years ago
|
ClusterIP: "None",
|
||
|
5 years ago
|
Ports: []corev1.ServicePort{
|
||
|
5 years ago
|
{
|
||
|
4 years ago
|
Name: lokiGRPCPortName,
|
||
|
4 years ago
|
Port: grpcPort,
|
||
|
|
Protocol: protocolTCP,
|
||
|
|
TargetPort: intstr.IntOrString{IntVal: grpcPort},
|
||
|
5 years ago
|
},
|
||
|
|
},
|
||
|
|
Selector: l,
|
||
|
|
},
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
5 years ago
|
// NewQueryFrontendHTTPService creates a k8s service for the query-frontend HTTP endpoint
|
||
|
5 years ago
|
func NewQueryFrontendHTTPService(opts Options) *corev1.Service {
|
||
|
|
serviceName := serviceNameQueryFrontendHTTP(opts.Name)
|
||
|
|
l := ComponentLabels(LabelQueryFrontendComponent, opts.Name)
|
||
|
|
a := serviceAnnotations(serviceName, opts.Flags.EnableCertificateSigningService)
|
||
|
|
|
||
|
5 years ago
|
return &corev1.Service{
|
||
|
5 years ago
|
TypeMeta: metav1.TypeMeta{
|
||
|
|
Kind: "Service",
|
||
|
5 years ago
|
APIVersion: corev1.SchemeGroupVersion.String(),
|
||
|
5 years ago
|
},
|
||
|
|
ObjectMeta: metav1.ObjectMeta{
|
||
|
5 years ago
|
Name: serviceName,
|
||
|
|
Labels: l,
|
||
|
|
Annotations: a,
|
||
|
5 years ago
|
},
|
||
|
5 years ago
|
Spec: corev1.ServiceSpec{
|
||
|
|
Ports: []corev1.ServicePort{
|
||
|
5 years ago
|
{
|
||
|
4 years ago
|
Name: lokiHTTPPortName,
|
||
|
4 years ago
|
Port: httpPort,
|
||
|
|
Protocol: protocolTCP,
|
||
|
|
TargetPort: intstr.IntOrString{IntVal: httpPort},
|
||
|
5 years ago
|
},
|
||
|
|
},
|
||
|
|
Selector: l,
|
||
|
|
},
|
||
|
|
}
|
||
|
|
}
|
||
|
5 years ago
|
|
||
|
5 years ago
|
func configureQueryFrontendServiceMonitorPKI(deployment *appsv1.Deployment, stackName string) error {
|
||
|
5 years ago
|
serviceName := serviceNameQueryFrontendHTTP(stackName)
|
||
|
5 years ago
|
return configureServiceMonitorPKI(&deployment.Spec.Template.Spec, serviceName)
|
||
|
5 years ago
|
}
|