Skip to content

Commit

Permalink
Deploy KSM as StatefulSet
Browse files Browse the repository at this point in the history
... for the sake of consistency.
  • Loading branch information
paramite committed Sep 23, 2024
1 parent fa34911 commit 68abf93
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 19 deletions.
14 changes: 5 additions & 9 deletions controllers/ceilometer_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,6 @@ import (
logr "github.com/go-logr/logr"
common "github.com/openstack-k8s-operators/lib-common/modules/common"
condition "github.com/openstack-k8s-operators/lib-common/modules/common/condition"
deployment "github.com/openstack-k8s-operators/lib-common/modules/common/deployment"
endpoint "github.com/openstack-k8s-operators/lib-common/modules/common/endpoint"
env "github.com/openstack-k8s-operators/lib-common/modules/common/env"
helper "github.com/openstack-k8s-operators/lib-common/modules/common/helper"
Expand Down Expand Up @@ -654,16 +653,13 @@ func (r *CeilometerReconciler) reconcileKSM(
common.AppSelector: availability.KSMServiceName,
}

deployDef, err := availability.KSMDeployment(instance, serviceLabels)
ssDef, err := availability.KSMStatefulSet(instance, serviceLabels)
if err != nil {
return ctrl.Result{}, err
}
deploy := deployment.NewDeployment(
deployDef,
time.Duration(5)*time.Second,
)
ss := statefulset.NewStatefulSet(ssDef, time.Duration(5)*time.Second)

ctrlResult, err = deploy.CreateOrPatch(ctx, helper)
ctrlResult, err = ss.CreateOrPatch(ctx, helper)
if err != nil {
instance.Status.Conditions.Set(condition.FalseCondition(
condition.DeploymentReadyCondition,
Expand All @@ -681,12 +677,12 @@ func (r *CeilometerReconciler) reconcileKSM(
return ctrlResult, nil
}

err = controllerutil.SetControllerReference(instance, deployDef, r.Scheme)
err = controllerutil.SetControllerReference(instance, ssDef, r.Scheme)
if err != nil {
return ctrl.Result{}, err
}

instance.Status.ReadyCount = deploy.GetDeployment().Status.ReadyReplicas
instance.Status.ReadyCount = ss.GetStatefulSet().Status.ReadyReplicas
if instance.Status.ReadyCount > 0 {
instance.Status.Conditions.MarkTrue(condition.DeploymentReadyCondition, condition.DeploymentReadyMessage)
}
Expand Down
21 changes: 11 additions & 10 deletions pkg/availability/deployment.go → pkg/availability/statefulset.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,21 @@ import (
"fmt"
"strings"

"k8s.io/utils/ptr"

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"
"k8s.io/utils/pointer"

telemetryv1 "github.com/openstack-k8s-operators/telemetry-operator/api/v1beta1"
)

// KSMDeployment requests Deployment of kube-state-metrics
func KSMDeployment(
func KSMStatefulSet(
instance *telemetryv1.Ceilometer,
labels map[string]string,
) (*appsv1.Deployment, error) {
) (*appsv1.StatefulSet, error) {

livenessProbe := &corev1.Probe{
ProbeHandler: corev1.ProbeHandler{
Expand All @@ -58,12 +59,12 @@ func KSMDeployment(
}

secCtx := &corev1.SecurityContext{
AllowPrivilegeEscalation: pointer.BoolPtr(false),
AllowPrivilegeEscalation: ptr.To(false),
Capabilities: &corev1.Capabilities{
Drop: []corev1.Capability{"ALL"},
},
ReadOnlyRootFilesystem: pointer.BoolPtr(true),
RunAsNonRoot: pointer.BoolPtr(true),
ReadOnlyRootFilesystem: ptr.To(true),
RunAsNonRoot: ptr.To(true),
SeccompProfile: &corev1.SeccompProfile{
Type: corev1.SeccompProfileTypeRuntimeDefault,
},
Expand Down Expand Up @@ -96,13 +97,13 @@ func KSMDeployment(
labels["app.kubernetes.io/name"] = KSMServiceName
labels["app.kubernetes.io/version"] = instance.Spec.KSMImage[strings.LastIndex(instance.Spec.KSMImage, ":")+1:]

deployment := &appsv1.Deployment{
ss := &appsv1.StatefulSet{
ObjectMeta: metav1.ObjectMeta{
Name: KSMServiceName,
Namespace: instance.Namespace,
Labels: labels,
},
Spec: appsv1.DeploymentSpec{
Spec: appsv1.StatefulSetSpec{
Replicas: &KSMReplicas,
Selector: &metav1.LabelSelector{
MatchLabels: map[string]string{
Expand All @@ -114,13 +115,13 @@ func KSMDeployment(
Labels: labels,
},
Spec: corev1.PodSpec{
AutomountServiceAccountToken: pointer.BoolPtr(true),
AutomountServiceAccountToken: ptr.To(true),
ServiceAccountName: KSMServiceName,
Containers: []corev1.Container{container},
},
},
},
}

return deployment, nil
return ss, nil
}

0 comments on commit 68abf93

Please sign in to comment.