make ReconcileDeployment
Change-Id: I6641f51234c808ff51213b87c7b52ad3eae208c8
This commit is contained in:
parent
2831114e37
commit
4b299a7477
@ -80,53 +80,9 @@ func (r *McrouterReconciler) Reconcile(req ctrl.Request) (ctrl.Result, error) {
|
||||
log.WithValues("resource", "ConfigMap").WithValues("op", op).Info("Reconciled")
|
||||
|
||||
// Deployment
|
||||
deployment := &appsv1.Deployment{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Namespace: req.Namespace,
|
||||
Name: fmt.Sprintf("mcrouter-%s", req.Name),
|
||||
},
|
||||
if res, err := r.ReconcileDeployment(ctx, req, &mcrouter, log, labels); err != nil || res != (ctrl.Result{}) {
|
||||
return res, err
|
||||
}
|
||||
op, err = k8sutils.CreateOrUpdate(ctx, r, deployment, func() error {
|
||||
return builders.Deployment(deployment, &mcrouter, r.Scheme).
|
||||
Labels(labels).
|
||||
Replicas(2).
|
||||
PodTemplateSpec(
|
||||
builders.PodTemplateSpec().
|
||||
PodSpec(
|
||||
builders.PodSpec().
|
||||
NodeSelector(mcrouter.Spec.NodeSelector).
|
||||
Tolerations(mcrouter.Spec.Tolerations).
|
||||
Containers(
|
||||
builders.Container("mcrouter", "vexxhost/mcrouter:latest").
|
||||
Args("-p", "11211", "-f", "/data/config.json").
|
||||
Port("mcrouter", 11211).PortProbe("mcrouter", 10, 30).
|
||||
Resources(500, 128, 500, 2).
|
||||
Volume("config", "/data").
|
||||
SecurityContext(
|
||||
builders.SecurityContext().
|
||||
RunAsUser(999).
|
||||
RunAsGroup(999),
|
||||
),
|
||||
builders.Container("exporter", "vexxhost/mcrouter-exporter:latest").
|
||||
Args("-mcrouter.address", "localhost:11211").
|
||||
Port("metrics", 9442).HTTPProbe("metrics", "/metrics", 10, 30).
|
||||
Resources(500, 128, 500, 2).
|
||||
SecurityContext(
|
||||
builders.SecurityContext().
|
||||
RunAsUser(1001),
|
||||
),
|
||||
).
|
||||
Volumes(
|
||||
builders.Volume("config").FromConfigMap(configMap.GetName()),
|
||||
),
|
||||
),
|
||||
).
|
||||
Build()
|
||||
})
|
||||
if err != nil {
|
||||
return ctrl.Result{}, err
|
||||
}
|
||||
log.WithValues("resource", "Deployment").WithValues("op", op).Info("Reconciled")
|
||||
|
||||
// PodMonitor
|
||||
if res, err := r.ReconcilePodMonitor(ctx, req, &mcrouter, log, typeLabels); err != nil || res != (ctrl.Result{}) {
|
||||
@ -246,3 +202,55 @@ func (r *McrouterReconciler) ReconcilePrometheusRule(ctx context.Context, req ct
|
||||
log.WithValues("resource", "mcrouter-alertrule").WithValues("op", op).Info("Reconciled")
|
||||
return ctrl.Result{}, nil
|
||||
}
|
||||
|
||||
// ReconcileDeployment reconciles the deployment
|
||||
func (r *McrouterReconciler) ReconcileDeployment(ctx context.Context, req ctrl.Request, mcrouter *infrastructurev1alpha1.Mcrouter, log logr.Logger, labels map[string]string) (ctrl.Result, error) {
|
||||
deployment := &appsv1.Deployment{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Namespace: req.Namespace,
|
||||
Name: fmt.Sprintf("mcrouter-%s", req.Name),
|
||||
},
|
||||
}
|
||||
op, err := k8sutils.CreateOrUpdate(ctx, r, deployment, func() error {
|
||||
return builders.Deployment(deployment, mcrouter, r.Scheme).
|
||||
Labels(labels).
|
||||
Replicas(2).
|
||||
PodTemplateSpec(
|
||||
builders.PodTemplateSpec().
|
||||
PodSpec(
|
||||
builders.PodSpec().
|
||||
NodeSelector(mcrouter.Spec.NodeSelector).
|
||||
Tolerations(mcrouter.Spec.Tolerations).
|
||||
Containers(
|
||||
builders.Container("mcrouter", "vexxhost/mcrouter:latest").
|
||||
Args("-p", "11211", "-f", "/data/config.json").
|
||||
Port("mcrouter", 11211).PortProbe("mcrouter", 10, 30).
|
||||
Resources(500, 128, 500, 2).
|
||||
Volume("config", "/data").
|
||||
SecurityContext(
|
||||
builders.SecurityContext().
|
||||
RunAsUser(999).
|
||||
RunAsGroup(999),
|
||||
),
|
||||
builders.Container("exporter", "vexxhost/mcrouter-exporter:latest").
|
||||
Args("-mcrouter.address", "localhost:11211").
|
||||
Port("metrics", 9442).HTTPProbe("metrics", "/metrics", 10, 30).
|
||||
Resources(500, 128, 500, 2).
|
||||
SecurityContext(
|
||||
builders.SecurityContext().
|
||||
RunAsUser(1001),
|
||||
),
|
||||
).
|
||||
Volumes(
|
||||
builders.Volume("config").FromConfigMap(fmt.Sprintf("mcrouter-%s", req.Name)),
|
||||
),
|
||||
),
|
||||
).
|
||||
Build()
|
||||
})
|
||||
if err != nil {
|
||||
return ctrl.Result{}, err
|
||||
}
|
||||
log.WithValues("resource", "Deployment").WithValues("op", op).Info("Reconciled")
|
||||
return ctrl.Result{}, nil
|
||||
}
|
||||
|
@ -62,9 +62,6 @@ func (r *MemcachedReconciler) Reconcile(req ctrl.Request) (ctrl.Result, error) {
|
||||
return ctrl.Result{}, client.IgnoreNotFound(err)
|
||||
}
|
||||
|
||||
// Calculate size per shared
|
||||
size := memcached.Spec.Megabytes / 2
|
||||
|
||||
// Labels
|
||||
typeLabels := baseutils.MergeMapsWithoutOverwrite(map[string]string{
|
||||
"app.kubernetes.io/name": "memcached",
|
||||
@ -83,51 +80,10 @@ func (r *MemcachedReconciler) Reconcile(req ctrl.Request) (ctrl.Result, error) {
|
||||
}, memcached.Labels)
|
||||
|
||||
// Deployment
|
||||
deployment := &appsv1.Deployment{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Namespace: req.Namespace,
|
||||
Name: fmt.Sprintf("memcached-%s", req.Name),
|
||||
Labels: labels,
|
||||
},
|
||||
if res, err := r.ReconcileDeployment(ctx, req, &memcached, log, labels); err != nil || res != (ctrl.Result{}) {
|
||||
return res, err
|
||||
}
|
||||
|
||||
op, err := k8sutils.CreateOrUpdate(ctx, r, deployment, func() error {
|
||||
return builders.Deployment(deployment, &memcached, r.Scheme).
|
||||
Labels(labels).
|
||||
Replicas(2).
|
||||
PodTemplateSpec(
|
||||
builders.PodTemplateSpec().
|
||||
Labels(labels).
|
||||
PodSpec(
|
||||
builders.PodSpec().
|
||||
NodeSelector(memcached.Spec.NodeSelector).
|
||||
Tolerations(memcached.Spec.Tolerations).
|
||||
Containers(
|
||||
builders.Container("memcached", "vexxhost/memcached:latest").
|
||||
Args("-m", strconv.Itoa(size)).
|
||||
Port("memcached", 11211).PortProbe("memcached", 10, 30).
|
||||
Resources(1000, int64(size), 500, 1.10).
|
||||
SecurityContext(
|
||||
builders.SecurityContext().
|
||||
RunAsUser(1001),
|
||||
),
|
||||
builders.Container("exporter", "vexxhost/memcached-exporter:latest").
|
||||
Port("metrics", 9150).HTTPProbe("metrics", "/metrics", 10, 30).
|
||||
Resources(500, 128, 500, 2).
|
||||
SecurityContext(
|
||||
builders.SecurityContext().
|
||||
RunAsUser(1001),
|
||||
),
|
||||
),
|
||||
),
|
||||
).
|
||||
Build()
|
||||
})
|
||||
if err != nil {
|
||||
return ctrl.Result{}, err
|
||||
}
|
||||
log.WithValues("resource", "Deployment").WithValues("op", op).Info("Reconciled")
|
||||
|
||||
// PodMonitor
|
||||
if res, err := r.ReconcilePodMonitor(ctx, req, &memcached, log, typeLabels); err != nil || res != (ctrl.Result{}) {
|
||||
return res, err
|
||||
@ -266,3 +222,53 @@ func (r *MemcachedReconciler) ReconcileMcrouter(ctx context.Context, req ctrl.Re
|
||||
log.WithValues("resource", "Mcrouter").WithValues("op", op).Info("Reconciled")
|
||||
return ctrl.Result{}, nil
|
||||
}
|
||||
|
||||
// ReconcileDeployment reconciles the deployment
|
||||
func (r *MemcachedReconciler) ReconcileDeployment(ctx context.Context, req ctrl.Request, memcached *infrastructurev1alpha1.Memcached, log logr.Logger, labels map[string]string) (ctrl.Result, error) {
|
||||
// Calculate size per shared
|
||||
size := memcached.Spec.Megabytes / 2
|
||||
deployment := &appsv1.Deployment{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Namespace: req.Namespace,
|
||||
Name: fmt.Sprintf("memcached-%s", req.Name),
|
||||
Labels: labels,
|
||||
},
|
||||
}
|
||||
op, err := k8sutils.CreateOrUpdate(ctx, r, deployment, func() error {
|
||||
return builders.Deployment(deployment, memcached, r.Scheme).
|
||||
Labels(labels).
|
||||
Replicas(2).
|
||||
PodTemplateSpec(
|
||||
builders.PodTemplateSpec().
|
||||
Labels(labels).
|
||||
PodSpec(
|
||||
builders.PodSpec().
|
||||
NodeSelector(memcached.Spec.NodeSelector).
|
||||
Tolerations(memcached.Spec.Tolerations).
|
||||
Containers(
|
||||
builders.Container("memcached", "vexxhost/memcached:latest").
|
||||
Args("-m", strconv.Itoa(size)).
|
||||
Port("memcached", 11211).PortProbe("memcached", 10, 30).
|
||||
Resources(1000, int64(size), 500, 1.10).
|
||||
SecurityContext(
|
||||
builders.SecurityContext().
|
||||
RunAsUser(1001),
|
||||
),
|
||||
builders.Container("exporter", "vexxhost/memcached-exporter:latest").
|
||||
Port("metrics", 9150).HTTPProbe("metrics", "/metrics", 10, 30).
|
||||
Resources(500, 128, 500, 2).
|
||||
SecurityContext(
|
||||
builders.SecurityContext().
|
||||
RunAsUser(1001),
|
||||
),
|
||||
),
|
||||
),
|
||||
).
|
||||
Build()
|
||||
})
|
||||
if err != nil {
|
||||
return ctrl.Result{}, err
|
||||
}
|
||||
log.WithValues("resource", "Deployment").WithValues("op", op).Info("Reconciled")
|
||||
return ctrl.Result{}, nil
|
||||
}
|
||||
|
@ -65,44 +65,9 @@ func (r *RabbitmqReconciler) Reconcile(req ctrl.Request) (ctrl.Result, error) {
|
||||
}
|
||||
|
||||
// Deployment
|
||||
deployment := &appsv1.Deployment{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Namespace: req.Namespace,
|
||||
Name: fmt.Sprintf("rabbitmq-%s", req.Name),
|
||||
},
|
||||
if res, err := r.ReconcileDeployment(ctx, req, &Rabbitmq, log, labels); err != nil || res != (ctrl.Result{}) {
|
||||
return res, err
|
||||
}
|
||||
op, err := k8sutils.CreateOrUpdate(ctx, r, deployment, func() error {
|
||||
return builders.Deployment(deployment, &Rabbitmq, r.Scheme).
|
||||
Labels(labels).
|
||||
Replicas(1).
|
||||
PodTemplateSpec(
|
||||
builders.PodTemplateSpec().
|
||||
PodSpec(
|
||||
builders.PodSpec().
|
||||
NodeSelector(Rabbitmq.Spec.NodeSelector).
|
||||
Tolerations(Rabbitmq.Spec.Tolerations).
|
||||
Containers(
|
||||
builders.Container("rabbitmq", "vexxhost/rabbitmq:latest").
|
||||
EnvVarFromSecret("RABBITMQ_DEFAULT_USER", Rabbitmq.Spec.AuthSecret, _rabbitmqDefaultUsernameCfgKey).
|
||||
EnvVarFromSecret("RABBITMQ_DEFAULT_PASS", Rabbitmq.Spec.AuthSecret, _rabbitmqDefaultPasswordCfgKey).
|
||||
Port("rabbitmq", _rabbitmqPort).
|
||||
Port("metrics", _rabbitmqBuiltinMetricPort).
|
||||
PortProbe("rabbitmq", 15, 30).
|
||||
Resources(500, 512, 500, 2).
|
||||
SecurityContext(
|
||||
builders.SecurityContext().
|
||||
RunAsUser(_rabbitmqRunAsUser).
|
||||
RunAsGroup(_rabbitmqRunAsGroup),
|
||||
),
|
||||
),
|
||||
),
|
||||
).
|
||||
Build()
|
||||
})
|
||||
if err != nil {
|
||||
return ctrl.Result{}, err
|
||||
}
|
||||
log.WithValues("resource", "Deployment").WithValues("op", op).Info("Reconciled")
|
||||
|
||||
// PodMonitor
|
||||
if res, err := r.ReconcilePodMonitor(ctx, req, &Rabbitmq, log, typeLabels); err != nil || res != (ctrl.Result{}) {
|
||||
@ -229,3 +194,46 @@ func (r *RabbitmqReconciler) ReconcilePrometheusRule(ctx context.Context, req ct
|
||||
log.WithValues("resource", "rabbitmq-alertrule").WithValues("op", op).Info("Reconciled")
|
||||
return ctrl.Result{}, nil
|
||||
}
|
||||
|
||||
// ReconcileDeployment reconciles the deployment
|
||||
func (r *RabbitmqReconciler) ReconcileDeployment(ctx context.Context, req ctrl.Request, rabbitmq *infrastructurev1alpha1.Rabbitmq, log logr.Logger, labels map[string]string) (ctrl.Result, error) {
|
||||
deployment := &appsv1.Deployment{
|
||||
ObjectMeta: metav1.ObjectMeta{
|
||||
Namespace: req.Namespace,
|
||||
Name: fmt.Sprintf("rabbitmq-%s", req.Name),
|
||||
},
|
||||
}
|
||||
op, err := k8sutils.CreateOrUpdate(ctx, r, deployment, func() error {
|
||||
return builders.Deployment(deployment, rabbitmq, r.Scheme).
|
||||
Labels(labels).
|
||||
Replicas(1).
|
||||
PodTemplateSpec(
|
||||
builders.PodTemplateSpec().
|
||||
PodSpec(
|
||||
builders.PodSpec().
|
||||
NodeSelector(rabbitmq.Spec.NodeSelector).
|
||||
Tolerations(rabbitmq.Spec.Tolerations).
|
||||
Containers(
|
||||
builders.Container("rabbitmq", "vexxhost/rabbitmq:latest").
|
||||
EnvVarFromSecret("RABBITMQ_DEFAULT_USER", rabbitmq.Spec.AuthSecret, _rabbitmqDefaultUsernameCfgKey).
|
||||
EnvVarFromSecret("RABBITMQ_DEFAULT_PASS", rabbitmq.Spec.AuthSecret, _rabbitmqDefaultPasswordCfgKey).
|
||||
Port("rabbitmq", _rabbitmqPort).
|
||||
Port("metrics", _rabbitmqBuiltinMetricPort).
|
||||
PortProbe("rabbitmq", 15, 30).
|
||||
Resources(500, 512, 500, 2).
|
||||
SecurityContext(
|
||||
builders.SecurityContext().
|
||||
RunAsUser(_rabbitmqRunAsUser).
|
||||
RunAsGroup(_rabbitmqRunAsGroup),
|
||||
),
|
||||
),
|
||||
),
|
||||
).
|
||||
Build()
|
||||
})
|
||||
if err != nil {
|
||||
return ctrl.Result{}, err
|
||||
}
|
||||
log.WithValues("resource", "Deployment").WithValues("op", op).Info("Reconciled")
|
||||
return ctrl.Result{}, nil
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user