// Copyright (c) 2023 Volvo Car Corporation
// SPDX-License-Identifier: Apache-2.0

// Code generated by lingon. EDIT AS MUCH AS YOU LIKE.

package vector

import (
	ku "github.com/golingon/lingon/pkg/kubeutil"
	appsv1 "k8s.io/api/apps/v1"
	corev1 "k8s.io/api/core/v1"
	metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
	"k8s.io/apimachinery/pkg/util/intstr"
)

var STS = &appsv1.StatefulSet{
	TypeMeta:   ku.TypeStatefulSetV1,
	ObjectMeta: V.ObjectMeta(),
	Spec: appsv1.StatefulSetSpec{
		UpdateStrategy: appsv1.StatefulSetUpdateStrategy{
			RollingUpdate: &appsv1.RollingUpdateStatefulSetStrategy{MaxUnavailable: P(intstr.FromInt(1))},
			Type:          appsv1.RollingUpdateStatefulSetStrategyType,
		},
		PodManagementPolicy: appsv1.OrderedReadyPodManagement,
		Selector:            &metav1.LabelSelector{MatchLabels: V.MatchLabels()},
		ServiceName:         HeadlessSVC.Name,
		Template: corev1.PodTemplateSpec{
			ObjectMeta: metav1.ObjectMeta{
				Annotations: map[string]string{"checksum/config": V.Config.Hash()},
				Labels:      V.LabelsVectorExclude(),
			},
			Spec: corev1.PodSpec{
				Containers: []corev1.Container{
					{
						Name:            V.Name,
						Image:           V.Img.URL(),
						ImagePullPolicy: corev1.PullIfNotPresent,
						Args: []string{
							"--config-dir",
							V.Config.VolumeMount.MountPath,
						},
						Ports: []corev1.ContainerPort{
							V.Fluent.Container,
							V.Vector.Container,
							V.PromExp.Container,
						},
						VolumeMounts: []corev1.VolumeMount{
							V.Config.VolumeMount,
							V.Storage.VolumeMount,
						},
					},
				},
				DNSPolicy:                     corev1.DNSClusterFirst,
				ServiceAccountName:            V.SA.Name,
				TerminationGracePeriodSeconds: P(int64(60)),
				Volumes: []corev1.Volume{
					V.Storage.Volume(),
					V.Config.VolumeAndMount().Volume(),
				},
			},
		},
	},
}
