Skip to content

Commit

Permalink
initial changes for barbican-worker
Browse files Browse the repository at this point in the history
  • Loading branch information
xek committed Sep 12, 2023
1 parent f2d76cc commit 714be5a
Show file tree
Hide file tree
Showing 13 changed files with 979 additions and 49 deletions.
19 changes: 19 additions & 0 deletions api/v1beta1/barbicanworker_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ limitations under the License.
package v1beta1

import (
"github.com/openstack-k8s-operators/lib-common/modules/common/condition"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
)

Expand All @@ -33,6 +34,7 @@ type BarbicanWorkerSpec struct {
BarbicanTemplate `json:",inline"`

BarbicanWorkerTemplate `json:",inline"`
DatabaseHostname string `json:"databaseHostname"`

TransportURLSecret string `json:"transportURLSecret,omitempty"`
}
Expand All @@ -41,6 +43,23 @@ type BarbicanWorkerSpec struct {
type BarbicanWorkerStatus struct {
// INSERT ADDITIONAL STATUS FIELD - define observed state of cluster
// Important: Run "make" to regenerate code after modifying this file
// ReadyCount of barbican API instances
ReadyCount int32 `json:"readyCount,omitempty"`

// Map of hashes to track e.g. job status
Hash map[string]string `json:"hash,omitempty"`

// API endpoint
//APIEndpoints map[string]string `json:"apiEndpoint,omitempty"`

// Conditions
Conditions condition.Conditions `json:"conditions,omitempty" optional:"true"`

// NetworkAttachments status of the deployment pods
NetworkAttachments map[string][]string `json:"networkAttachments,omitempty"`

// Barbican Database Hostname
DatabaseHostname string `json:"databaseHostname,omitempty"`
}

//+kubebuilder:object:root=true
Expand Down
2 changes: 2 additions & 0 deletions api/v1beta1/conditions.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ const (
BarbicanAPIReadyErrorMessage = "BarbicanAPI error occured %s"
// BarbicanWorkerReadyInitMessage -
BarbicanWorkerReadyInitMessage = "BarbicanWorker not started"
// BarbicanWorkerReadyErrorMessage -
BarbicanWorkerReadyErrorMessage = "BarbicanWorker error occured %s"

// BarbicanRabbitMQTransportURLReadyRunningMessage -
BarbicanRabbitMQTransportURLReadyRunningMessage = "BarbicanRabbitMQTransportURL creation in progress"
Expand Down
31 changes: 30 additions & 1 deletion api/v1beta1/zz_generated.deepcopy.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

68 changes: 68 additions & 0 deletions config/crd/bases/barbican.openstack.org_barbicanworkers.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ spec:
items:
type: string
type: array
databaseHostname:
type: string
databaseInstance:
description: 'MariaDB instance name TODO(dmendiza): Is this comment
right? Right now required by the maridb-operator to get the credentials
Expand Down Expand Up @@ -207,12 +209,78 @@ spec:
type: string
required:
- containerImage
- databaseHostname
- databaseInstance
- rabbitMqClusterName
- serviceAccount
type: object
status:
description: BarbicanWorkerStatus defines the observed state of BarbicanWorker
properties:
conditions:
description: Conditions
items:
description: Condition defines an observation of a API resource
operational state.
properties:
lastTransitionTime:
description: Last time the condition transitioned from one status
to another. This should be when the underlying condition changed.
If that is not known, then using the time when the API field
changed is acceptable.
format: date-time
type: string
message:
description: A human readable message indicating details about
the transition.
type: string
reason:
description: The reason for the condition's last transition
in CamelCase.
type: string
severity:
description: Severity provides a classification of Reason code,
so the current situation is immediately understandable and
could act accordingly. It is meant for situations where Status=False
and it should be indicated if it is just informational, warning
(next reconciliation might fix it) or an error (e.g. DB create
issue and no actions to automatically resolve the issue can/should
be done). For conditions where Status=Unknown or Status=True
the Severity should be SeverityNone.
type: string
status:
description: Status of the condition, one of True, False, Unknown.
type: string
type:
description: Type of condition in CamelCase.
type: string
required:
- lastTransitionTime
- status
- type
type: object
type: array
databaseHostname:
description: Barbican Database Hostname
type: string
hash:
additionalProperties:
type: string
description: Map of hashes to track e.g. job status
type: object
networkAttachments:
additionalProperties:
items:
type: string
type: array
description: NetworkAttachments status of the deployment pods
type: object
readyCount:
description: 'INSERT ADDITIONAL STATUS FIELD - define observed state
of cluster Important: Run "make" to regenerate code after modifying
this file ReadyCount of barbican API instances'
format: int32
type: integer
type: object
type: object
served: true
Expand Down
26 changes: 0 additions & 26 deletions config/rbac/role.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -79,32 +79,6 @@ rules:
- get
- patch
- update
- apiGroups:
- barbican.openstack.org
resources:
- barbicanworkers
verbs:
- create
- delete
- get
- list
- patch
- update
- watch
- apiGroups:
- barbican.openstack.org
resources:
- barbicanworkers/finalizers
verbs:
- update
- apiGroups:
- barbican.openstack.org
resources:
- barbicanworkers/status
verbs:
- get
- patch
- update
- apiGroups:
- batch
resources:
Expand Down
2 changes: 0 additions & 2 deletions config/samples/barbican_v1beta1_barbican.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -56,5 +56,3 @@ spec:
defautlConfigOverwrite:
optional_policy.json: |
{"some": "custom policy"}
networkAttachments:
- internal
50 changes: 50 additions & 0 deletions controllers/barbican_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,20 @@ func (r *BarbicanReconciler) reconcileNormal(ctx context.Context, instance *barb
r.Log.Info(fmt.Sprintf("Deployment %s successfully reconciled - operation: %s", instance.Name, string(op)))
}

// create or update Barbican Worker deployment
_, op, err = r.workerDeploymentCreateOrUpdate(ctx, instance, helper)
if err != nil {
instance.Status.Conditions.Set(condition.FalseCondition(
barbicanv1beta1.BarbicanWorkerReadyCondition,
condition.ErrorReason,
condition.SeverityWarning,
barbicanv1beta1.BarbicanWorkerReadyErrorMessage,
err.Error()))
return ctrl.Result{}, err
}
if op != controllerutil.OperationResultNone {
r.Log.Info(fmt.Sprintf("Deployment %s successfully reconciled - operation: %s", instance.Name, string(op)))
}
// TODO(dmendiza): Handle API endpoints

// TODO(dmendiza): Understand what Glance is doing with the API conditions and maybe do it here too
Expand Down Expand Up @@ -505,6 +519,42 @@ func (r *BarbicanReconciler) apiDeploymentCreateOrUpdate(ctx context.Context, in
return deployment, op, err
}

func (r *BarbicanReconciler) workerDeploymentCreateOrUpdate(ctx context.Context, instance *barbicanv1beta1.Barbican, helper *helper.Helper) (*barbicanv1beta1.BarbicanWorker, controllerutil.OperationResult, error) {

r.Log.Info(fmt.Sprintf("Creating barbican Worker spec. transporturlsecret: '%s'", instance.Status.TransportURLSecret))
r.Log.Info(fmt.Sprintf("database hostname: '%s'", instance.Status.DatabaseHostname))
workerSpec := barbicanv1beta1.BarbicanWorkerSpec{
BarbicanTemplate: instance.Spec.BarbicanTemplate,
BarbicanWorkerTemplate: instance.Spec.BarbicanWorker,
DatabaseHostname: instance.Status.DatabaseHostname,
TransportURLSecret: instance.Status.TransportURLSecret,
}

deployment := &barbicanv1beta1.BarbicanWorker{
ObjectMeta: metav1.ObjectMeta{
Name: fmt.Sprintf("%s-worker", instance.Name),
Namespace: instance.Namespace,
},
}

op, err := controllerutil.CreateOrUpdate(ctx, r.Client, deployment, func() error {
r.Log.Info("Setting deployment spec to be workerspec")
deployment.Spec = workerSpec

err := controllerutil.SetControllerReference(instance, deployment, r.Scheme)
if err != nil {
return err
}

// Add a finalizer to prevent user from manually removing child BarbicanAPI
controllerutil.AddFinalizer(deployment, helper.GetFinalizer())

return nil
})

return deployment, op, err
}

func (r *BarbicanReconciler) reconcileInit(
ctx context.Context,
instance *barbicanv1beta1.Barbican,
Expand Down
Loading

0 comments on commit 714be5a

Please sign in to comment.