Skip to content

Commit

Permalink
Changes to make a deployment of the barbican-worker
Browse files Browse the repository at this point in the history
  • Loading branch information
xek committed Sep 13, 2023
1 parent 714be5a commit 1c91652
Show file tree
Hide file tree
Showing 5 changed files with 124 additions and 115 deletions.
97 changes: 47 additions & 50 deletions controllers/barbicanworker_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import (
//keystonev1 "github.com/openstack-k8s-operators/keystone-operator/api/v1beta1"
"github.com/openstack-k8s-operators/lib-common/modules/common"
"github.com/openstack-k8s-operators/lib-common/modules/common/condition"
//"github.com/openstack-k8s-operators/lib-common/modules/common/deployment"
"github.com/openstack-k8s-operators/lib-common/modules/common/deployment"
//"github.com/openstack-k8s-operators/lib-common/modules/common/endpoint"
"github.com/openstack-k8s-operators/lib-common/modules/common/env"
"github.com/openstack-k8s-operators/lib-common/modules/common/helper"
Expand Down Expand Up @@ -579,60 +579,57 @@ func (r *BarbicanWorkerReconciler) reconcileNormal(ctx context.Context, instance
// Define a new Deployment object
deplDef := barbicanworker.Deployment(instance, inputHash, serviceLabels, serviceAnnotations)
r.Log.Info(fmt.Sprintf("[Worker] Getting deployment '%s'", instance.Name))
r.Log.Info(fmt.Sprintf("[Worker] '%s'", deplDef))
/*
depl := deployment.NewDeployment(
deplDef,
time.Duration(5)*time.Second,
)
r.Log.Info(fmt.Sprintf("[API] Got deployment '%s'", instance.Name))
ctrlResult, err = depl.CreateOrPatch(ctx, helper)
if err != nil {
instance.Status.Conditions.Set(condition.FalseCondition(
condition.DeploymentReadyCondition,
condition.ErrorReason,
condition.SeverityWarning,
condition.DeploymentReadyErrorMessage,
err.Error()))
return ctrlResult, err
} else if (ctrlResult != ctrl.Result{}) {
instance.Status.Conditions.Set(condition.FalseCondition(
condition.DeploymentReadyCondition,
condition.RequestedReason,
condition.SeverityInfo,
condition.DeploymentReadyRunningMessage))
return ctrlResult, nil
}
instance.Status.ReadyCount = depl.GetDeployment().Status.ReadyReplicas
depl := deployment.NewDeployment(
deplDef,
time.Duration(5)*time.Second,
)
r.Log.Info(fmt.Sprintf("[Worker] Got deployment '%s'", instance.Name))
ctrlResult, err = depl.CreateOrPatch(ctx, helper)
if err != nil {
instance.Status.Conditions.Set(condition.FalseCondition(
condition.DeploymentReadyCondition,
condition.ErrorReason,
condition.SeverityWarning,
condition.DeploymentReadyErrorMessage,
err.Error()))
return ctrlResult, err
} else if (ctrlResult != ctrl.Result{}) {
instance.Status.Conditions.Set(condition.FalseCondition(
condition.DeploymentReadyCondition,
condition.RequestedReason,
condition.SeverityInfo,
condition.DeploymentReadyRunningMessage))
return ctrlResult, nil
}
instance.Status.ReadyCount = depl.GetDeployment().Status.ReadyReplicas

// verify if network attachment matches expectations
networkReady, networkAttachmentStatus, err := nad.VerifyNetworkStatusFromAnnotation(ctx, helper, instance.Spec.NetworkAttachments, serviceLabels, instance.Status.ReadyCount)
if err != nil {
return ctrl.Result{}, err
}
// verify if network attachment matches expectations
networkReady, networkAttachmentStatus, err := nad.VerifyNetworkStatusFromAnnotation(ctx, helper, instance.Spec.NetworkAttachments, serviceLabels, instance.Status.ReadyCount)
if err != nil {
return ctrl.Result{}, err
}

instance.Status.NetworkAttachments = networkAttachmentStatus
if networkReady {
instance.Status.Conditions.MarkTrue(condition.NetworkAttachmentsReadyCondition, condition.NetworkAttachmentsReadyMessage)
} else {
err := fmt.Errorf("not all pods have interfaces with ips as configured in NetworkAttachments: %s", instance.Spec.NetworkAttachments)
instance.Status.Conditions.Set(condition.FalseCondition(
condition.NetworkAttachmentsReadyCondition,
condition.ErrorReason,
condition.SeverityWarning,
condition.NetworkAttachmentsReadyErrorMessage,
err.Error()))
instance.Status.NetworkAttachments = networkAttachmentStatus
if networkReady {
instance.Status.Conditions.MarkTrue(condition.NetworkAttachmentsReadyCondition, condition.NetworkAttachmentsReadyMessage)
} else {
err := fmt.Errorf("not all pods have interfaces with ips as configured in NetworkAttachments: %s", instance.Spec.NetworkAttachments)
instance.Status.Conditions.Set(condition.FalseCondition(
condition.NetworkAttachmentsReadyCondition,
condition.ErrorReason,
condition.SeverityWarning,
condition.NetworkAttachmentsReadyErrorMessage,
err.Error()))

return ctrl.Result{}, err
}
return ctrl.Result{}, err
}

if instance.Status.ReadyCount > 0 {
instance.Status.Conditions.MarkTrue(condition.DeploymentReadyCondition, condition.DeploymentReadyMessage)
}
// create Deployment - end
if instance.Status.ReadyCount > 0 {
instance.Status.Conditions.MarkTrue(condition.DeploymentReadyCondition, condition.DeploymentReadyMessage)
}
// create Deployment - end

r.Log.Info(fmt.Sprintf("Reconciled Service '%s' in barbicanAPI successfully", instance.Name))
*/
r.Log.Info(fmt.Sprintf("Reconciled Service '%s' in barbicanAPI successfully", instance.Name))
return ctrl.Result{}, nil
}

Expand Down
7 changes: 7 additions & 0 deletions pkg/barbican/const.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ const (
CustomServiceConfigSecretsFileName = "03-secrets.conf"
// BarbicanAPI defines the barbican-api group
BarbicanAPI storage.PropagationType = "BarbicanAPI"
// BarbicanWorker defines the barbican-worker group
BarbicanWorker storage.PropagationType = "BarbicanWorker"
// Barbican is the global ServiceType that refers to all the components deployed
// by the barbican operator
Barbican storage.PropagationType = "Barbican"
Expand All @@ -40,3 +42,8 @@ var DbsyncPropagation = []storage.PropagationType{storage.DBSync}
// It allows the BarbicanAPI pod to mount volumes destined to Barbican related
// ServiceTypes
var BarbicanAPIPropagation = []storage.PropagationType{Barbican, BarbicanAPI}

// BarbicanWorkerPropagation is the definition of the BarbicanWorker propagation group
// It allows the BarbicanWorker pod to mount volumes destined to Barbican related
// ServiceTypes
var BarbicanWorkerPropagation = []storage.PropagationType{Barbican, BarbicanWorker}
120 changes: 59 additions & 61 deletions pkg/barbicanworker/deployment.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,31 +27,33 @@ func Deployment(
annotations map[string]string,
) *appsv1.Deployment {
runAsUser := int64(0)
//var config0644AccessMode int32 = 0644
var config0644AccessMode int32 = 0644
envVars := map[string]env.Setter{}
envVars["KOLLA_CONFIG_STRATEGY"] = env.SetValue("COPY_ALWAYS")
envVars["CONFIG_HASH"] = env.SetValue(configHash)
livenessProbe := &corev1.Probe{
// TODO might need tuning
TimeoutSeconds: 5,
PeriodSeconds: 3,
InitialDelaySeconds: 5,
}
readinessProbe := &corev1.Probe{
// TODO might need tuning
TimeoutSeconds: 5,
PeriodSeconds: 5,
InitialDelaySeconds: 5,
}
/*
livenessProbe := &corev1.Probe{
// TODO might need tuning
TimeoutSeconds: 5,
PeriodSeconds: 3,
InitialDelaySeconds: 5,
}
readinessProbe := &corev1.Probe{
// TODO might need tuning
TimeoutSeconds: 5,
PeriodSeconds: 5,
InitialDelaySeconds: 5,
}
*/
args := []string{"-c"}
if instance.Spec.Debug.Service {
args = append(args, common.DebugCommand)
livenessProbe.Exec = &corev1.ExecAction{
Command: []string{
"/bin/true",
},
}
readinessProbe.Exec = livenessProbe.Exec
//livenessProbe.Exec = &corev1.ExecAction{
// Command: []string{
// "/bin/true",
// },
//}
//readinessProbe.Exec = livenessProbe.Exec
} else {
args = append(args, ServiceCommand)
//
Expand All @@ -64,32 +66,30 @@ func Deployment(
//readinessProbe.HTTPGet = livenessProbe.HTTPGet
}

/*
workerVolumes := []corev1.Volume{
{
Name: "config-data-custom",
VolumeSource: corev1.VolumeSource{
Secret: &corev1.SecretVolumeSource{
DefaultMode: &config0644AccessMode,
SecretName: instance.Name + "-config-data",
},
workerVolumes := []corev1.Volume{
{
Name: "config-data-custom",
VolumeSource: corev1.VolumeSource{
Secret: &corev1.SecretVolumeSource{
DefaultMode: &config0644AccessMode,
SecretName: instance.Name + "-config-data",
},
},
}
},
}

workerVolumes = append(apiVolumes, barbican.GetLogVolume()...)
workerVolumeMounts := []corev1.VolumeMount{
{
Name: "config-data",
MountPath: "/var/lib/kolla/config_files/config.json",
SubPath: "barbican-worker-config.json",
ReadOnly: true,
},
}
*/
workerVolumes = append(workerVolumes, barbican.GetLogVolume()...)
workerVolumeMounts := []corev1.VolumeMount{
{
Name: "config-data",
MountPath: "/var/lib/kolla/config_files/config.json",
SubPath: "barbican-worker-config.json",
ReadOnly: true,
},
}
// Append LogVolume to the apiVolumes: this will be used to stream
// logging
//apiVolumeMounts = append(apiVolumeMounts, barbican.GetLogVolumeMount()...)
workerVolumeMounts = append(workerVolumeMounts, barbican.GetLogVolumeMount()...)

deployment := &appsv1.Deployment{
ObjectMeta: metav1.ObjectMeta{
Expand Down Expand Up @@ -120,11 +120,11 @@ func Deployment(
SecurityContext: &corev1.SecurityContext{
RunAsUser: &runAsUser,
},
Env: env.MergeEnvs([]corev1.EnvVar{}, envVars),
VolumeMounts: barbican.GetLogVolumeMount(),
Resources: instance.Spec.Resources,
ReadinessProbe: readinessProbe,
LivenessProbe: livenessProbe,
Env: env.MergeEnvs([]corev1.EnvVar{}, envVars),
VolumeMounts: barbican.GetLogVolumeMount(),
Resources: instance.Spec.Resources,
//ReadinessProbe: readinessProbe,
//LivenessProbe: livenessProbe,
},
{
Name: barbican.ServiceName + "-worker",
Expand All @@ -137,27 +137,25 @@ func Deployment(
RunAsUser: &runAsUser,
},
Env: env.MergeEnvs([]corev1.EnvVar{}, envVars),
//VolumeMounts: append(barbican.GetVolumeMounts(
// instance.Spec.CustomServiceConfigSecrets,
// barbican.BarbicanAPIPropagation),
// apiVolumeMounts...,
//),
Resources: instance.Spec.Resources,
ReadinessProbe: readinessProbe,
LivenessProbe: livenessProbe,
VolumeMounts: append(barbican.GetVolumeMounts(
instance.Spec.CustomServiceConfigSecrets,
barbican.BarbicanWorkerPropagation),
workerVolumeMounts...,
),
Resources: instance.Spec.Resources,
//ReadinessProbe: readinessProbe,
//LivenessProbe: livenessProbe,
},
},
},
},
},
}
/*
deployment.Spec.Template.Spec.Volumes = append(barbican.GetVolumes(
instance.Name,
barbican.ServiceName,
instance.Spec.CustomServiceConfigSecrets,
barbican.BarbicanAPIPropagation),
apiVolumes...)
*/
deployment.Spec.Template.Spec.Volumes = append(barbican.GetVolumes(
instance.Name,
barbican.ServiceName,
instance.Spec.CustomServiceConfigSecrets,
barbican.BarbicanWorkerPropagation),
workerVolumes...)
return deployment
}
7 changes: 7 additions & 0 deletions templates/barbican/config/barbican-worker
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/usr/bin/python3
import sys

from barbican.cmd.worker import main
if __name__ == "__main__":
sys.exit(main())

8 changes: 4 additions & 4 deletions templates/barbican/config/barbican-worker-config.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"command": "/usr/sbin/httpd -DFOREGROUND",
"command": "barbican-worker",
"config_files": [
{
"source": "/var/lib/config-data/default/00-default.conf",
Expand All @@ -22,9 +22,9 @@
"optional": true
},
{
"source": "/var/lib/config-data/default/kolla_extend_start",
"dest": "/usr/local/bin/kolla_extend_start",
"owner": "root",
"source": "/var/lib/config-data/default/barbican-worker",
"dest": "/usr/bin/barbican-worker",
"owner": "barbican",
"perm": "0755",
"optional": true
}
Expand Down

0 comments on commit 1c91652

Please sign in to comment.