Skip to content

Commit

Permalink
Convert AmphoraControllers to DaemonSet
Browse files Browse the repository at this point in the history
  • Loading branch information
gthiemonge committed Dec 14, 2023
1 parent c143deb commit 1918e5f
Show file tree
Hide file tree
Showing 10 changed files with 76 additions and 123 deletions.
12 changes: 5 additions & 7 deletions api/bases/octavia.openstack.org_octaviaamphoracontrollers.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -139,13 +139,6 @@ spec:
from the Secret
type: string
type: object
replicas:
default: 1
description: Replicas - Octavia Worker Replicas
format: int32
maximum: 32
minimum: 0
type: integer
resources:
description: Resources - Compute Resources required by this service
(Limits/Requests). https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/
Expand Down Expand Up @@ -276,6 +269,11 @@ spec:
databaseHostname:
description: Octavia Database Hostname
type: string
desiredNumberScheduled:
description: DesiredNumberScheduled - total number of the nodes which
should be running Daemon
format: int32
type: integer
hash:
additionalProperties:
type: string
Expand Down
21 changes: 0 additions & 21 deletions api/bases/octavia.openstack.org_octavias.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -546,13 +546,6 @@ spec:
from the Secret
type: string
type: object
replicas:
default: 1
description: Replicas - Octavia Worker Replicas
format: int32
maximum: 32
minimum: 0
type: integer
resources:
description: Resources - Compute Resources required by this service
(Limits/Requests). https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/
Expand Down Expand Up @@ -728,13 +721,6 @@ spec:
from the Secret
type: string
type: object
replicas:
default: 1
description: Replicas - Octavia Worker Replicas
format: int32
maximum: 32
minimum: 0
type: integer
resources:
description: Resources - Compute Resources required by this service
(Limits/Requests). https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/
Expand Down Expand Up @@ -910,13 +896,6 @@ spec:
from the Secret
type: string
type: object
replicas:
default: 1
description: Replicas - Octavia Worker Replicas
format: int32
maximum: 32
minimum: 0
type: integer
resources:
description: Resources - Compute Resources required by this service
(Limits/Requests). https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/
Expand Down
10 changes: 3 additions & 7 deletions api/v1beta1/amphoracontroller_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,6 @@ type OctaviaAmphoraControllerSpec struct {
// Role - the role for the controller (one of worker, housekeeping, healthmanager)
Role string `json:"role"`

// +kubebuilder:validation:Optional
// +kubebuilder:default=1
// +kubebuilder:validation:Maximum=32
// +kubebuilder:validation:Minimum=0
// Replicas - Octavia Worker Replicas
Replicas *int32 `json:"replicas"`

// +kubebuilder:validation:Required
// Secret containing OpenStack password information for octavia OctaviaDatabasePassword, AdminPassword
Secret string `json:"secret"`
Expand Down Expand Up @@ -138,6 +131,9 @@ type OctaviaAmphoraControllerStatus struct {
// ReadyCount of Octavia Amphora Controllers
ReadyCount int32 `json:"readyCount,omitempty"`

// DesiredNumberScheduled - total number of the nodes which should be running Daemon
DesiredNumberScheduled int32 `json:"desiredNumberScheduled,omitempty"`

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

Expand Down
5 changes: 0 additions & 5 deletions api/v1beta1/zz_generated.deepcopy.go

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

Original file line number Diff line number Diff line change
Expand Up @@ -139,13 +139,6 @@ spec:
from the Secret
type: string
type: object
replicas:
default: 1
description: Replicas - Octavia Worker Replicas
format: int32
maximum: 32
minimum: 0
type: integer
resources:
description: Resources - Compute Resources required by this service
(Limits/Requests). https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/
Expand Down Expand Up @@ -276,6 +269,11 @@ spec:
databaseHostname:
description: Octavia Database Hostname
type: string
desiredNumberScheduled:
description: DesiredNumberScheduled - total number of the nodes which
should be running Daemon
format: int32
type: integer
hash:
additionalProperties:
type: string
Expand Down
21 changes: 0 additions & 21 deletions config/crd/bases/octavia.openstack.org_octavias.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -546,13 +546,6 @@ spec:
from the Secret
type: string
type: object
replicas:
default: 1
description: Replicas - Octavia Worker Replicas
format: int32
maximum: 32
minimum: 0
type: integer
resources:
description: Resources - Compute Resources required by this service
(Limits/Requests). https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/
Expand Down Expand Up @@ -728,13 +721,6 @@ spec:
from the Secret
type: string
type: object
replicas:
default: 1
description: Replicas - Octavia Worker Replicas
format: int32
maximum: 32
minimum: 0
type: integer
resources:
description: Resources - Compute Resources required by this service
(Limits/Requests). https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/
Expand Down Expand Up @@ -910,13 +896,6 @@ spec:
from the Secret
type: string
type: object
replicas:
default: 1
description: Replicas - Octavia Worker Replicas
format: int32
maximum: 32
minimum: 0
type: integer
resources:
description: Resources - Compute Resources required by this service
(Limits/Requests). https://kubernetes.io/docs/concepts/configuration/manage-resources-containers/
Expand Down
12 changes: 12 additions & 0 deletions config/rbac/role.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,18 @@ rules:
- list
- update
- watch
- apiGroups:
- apps
resources:
- daemonsets
verbs:
- create
- delete
- get
- list
- patch
- update
- watch
- apiGroups:
- apps
resources:
Expand Down
44 changes: 20 additions & 24 deletions controllers/amphoracontroller_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import (
"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/configmap"
"github.com/openstack-k8s-operators/lib-common/modules/common/deployment"
"github.com/openstack-k8s-operators/lib-common/modules/common/daemonset"
"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 @@ -329,17 +329,17 @@ func (r *OctaviaAmphoraControllerReconciler) reconcileNormal(ctx context.Context
common.AppSelector: instance.ObjectMeta.Name,
}

// Define a new Deployment object
depl := deployment.NewDeployment(
amphoracontrollers.Deployment(
// Define a new DaemonSet object
dset := daemonset.NewDaemonSet(
amphoracontrollers.DaemonSet(
instance,
inputHash,
serviceLabels,
serviceAnnotations),
5,
)

ctrlResult, err = depl.CreateOrPatch(ctx, helper)
ctrlResult, err = dset.CreateOrPatch(ctx, helper)
if err != nil {
instance.Status.Conditions.Set(condition.FalseCondition(
condition.DeploymentReadyCondition,
Expand All @@ -358,21 +358,15 @@ func (r *OctaviaAmphoraControllerReconciler) reconcileNormal(ctx context.Context
}

// verify if network attachment matches expectations
networkReady := false
networkAttachmentStatus := map[string][]string{}
if *instance.Spec.Replicas > 0 {
networkReady, networkAttachmentStatus, err = nad.VerifyNetworkStatusFromAnnotation(
ctx,
helper,
instance.Spec.NetworkAttachments,
serviceLabels,
instance.Status.ReadyCount,
)
if err != nil {
return ctrl.Result{}, err
}
} else {
networkReady = true
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
Expand All @@ -390,12 +384,14 @@ func (r *OctaviaAmphoraControllerReconciler) reconcileNormal(ctx context.Context
return ctrl.Result{}, err
}

instance.Status.ReadyCount = depl.GetDeployment().Status.ReadyReplicas
if instance.Status.ReadyCount > 0 {
instance.Status.DesiredNumberScheduled = dset.GetDaemonSet().Status.DesiredNumberScheduled
// TODO(gthiemonge) change for NumberReady?
instance.Status.ReadyCount = dset.GetDaemonSet().Status.NumberReady
if instance.Status.ReadyCount == instance.Status.DesiredNumberScheduled {
instance.Status.Conditions.MarkTrue(condition.DeploymentReadyCondition, condition.DeploymentReadyMessage)
}

// create Deployment - end
// create DaemonSet - end

Log.Info("Reconciled Service successfully")
return ctrl.Result{}, nil
Expand Down Expand Up @@ -509,6 +505,6 @@ func (r *OctaviaAmphoraControllerReconciler) SetupWithManager(mgr ctrl.Manager)
Owns(&corev1.Service{}).
Owns(&corev1.Secret{}).
Owns(&corev1.ConfigMap{}).
Owns(&appsv1.Deployment{}).
Owns(&appsv1.DaemonSet{}).
Complete(r)
}
43 changes: 22 additions & 21 deletions controllers/octavia_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ func (r *OctaviaReconciler) GetLogger(ctx context.Context) logr.Logger {
// +kubebuilder:rbac:groups=core,resources=services,verbs=get;list;watch;create;update;patch;delete;
// +kubebuilder:rbac:groups=batch,resources=jobs,verbs=get;list;watch;create;update;patch;delete;
// +kubebuilder:rbac:groups=apps,resources=deployments,verbs=get;list;watch;create;update;patch;delete;
// +kubebuilder:rbac:groups=apps,resources=daemonsets,verbs=get;list;watch;create;update;patch;delete;
// +kubebuilder:rbac:groups=route.openshift.io,resources=routes,verbs=get;list;watch;create;update;patch;delete;
// +kubebuilder:rbac:groups=mariadb.openstack.org,resources=mariadbdatabases,verbs=get;list;watch;create;update;patch;delete;
// +kubebuilder:rbac:groups=keystone.openstack.org,resources=keystoneapis,verbs=get;list;watch;
Expand Down Expand Up @@ -588,7 +589,7 @@ func (r *OctaviaReconciler) reconcileNormal(ctx context.Context, instance *octav
instance.Status.Conditions.MarkTrue(octaviav1.OctaviaAPIReadyCondition, condition.DeploymentReadyMessage)
}

octaviaHousekeeping, op, err := r.amphoraControllerDeploymentCreateOrUpdate(instance, instance.Spec.OctaviaHousekeeping, octaviav1.Housekeeping)
octaviaHousekeeping, op, err := r.amphoraControllerDaemonSetCreateOrUpdate(instance, instance.Spec.OctaviaHousekeeping, octaviav1.Housekeeping)
if err != nil {
instance.Status.Conditions.Set(condition.FalseCondition(
amphoraControllerReadyCondition(octaviav1.Housekeeping),
Expand All @@ -611,7 +612,7 @@ func (r *OctaviaReconciler) reconcileNormal(ctx context.Context, instance *octav
instance.Status.Conditions.MarkTrue(amphoraControllerReadyCondition(octaviav1.Housekeeping), condition.DeploymentReadyMessage)
}

octaviaHealthManager, op, err := r.amphoraControllerDeploymentCreateOrUpdate(instance, instance.Spec.OctaviaHealthManager, octaviav1.HealthManager)
octaviaHealthManager, op, err := r.amphoraControllerDaemonSetCreateOrUpdate(instance, instance.Spec.OctaviaHealthManager, octaviav1.HealthManager)
if err != nil {
instance.Status.Conditions.Set(condition.FalseCondition(
amphoraControllerReadyCondition(octaviav1.HealthManager),
Expand All @@ -634,7 +635,7 @@ func (r *OctaviaReconciler) reconcileNormal(ctx context.Context, instance *octav
instance.Status.Conditions.MarkTrue(amphoraControllerReadyCondition(octaviav1.HealthManager), condition.DeploymentReadyMessage)
}

octaviaWorker, op, err := r.amphoraControllerDeploymentCreateOrUpdate(instance, instance.Spec.OctaviaWorker, octaviav1.Worker)
octaviaWorker, op, err := r.amphoraControllerDaemonSetCreateOrUpdate(instance, instance.Spec.OctaviaWorker, octaviav1.Worker)
if err != nil {
instance.Status.Conditions.Set(condition.FalseCondition(
amphoraControllerReadyCondition(octaviav1.Worker),
Expand Down Expand Up @@ -794,43 +795,43 @@ func (r *OctaviaReconciler) transportURLCreateOrUpdate(
return transportURL, op, err
}

func (r *OctaviaReconciler) amphoraControllerDeploymentCreateOrUpdate(
func (r *OctaviaReconciler) amphoraControllerDaemonSetCreateOrUpdate(
instance *octaviav1.Octavia,
controllerSpec octaviav1.OctaviaAmphoraControllerSpec,
role string,
) (*octaviav1.OctaviaAmphoraController,
controllerutil.OperationResult, error) {

deployment := &octaviav1.OctaviaAmphoraController{
daemonset := &octaviav1.OctaviaAmphoraController{
ObjectMeta: metav1.ObjectMeta{
Name: fmt.Sprintf("%s-%s", instance.Name, role),
Namespace: instance.Namespace,
},
}

op, err := controllerutil.CreateOrUpdate(context.TODO(), r.Client, deployment, func() error {
deployment.Spec = controllerSpec
deployment.Spec.Role = role
deployment.Spec.DatabaseInstance = instance.Spec.DatabaseInstance
deployment.Spec.DatabaseHostname = instance.Status.DatabaseHostname
deployment.Spec.DatabaseUser = instance.Spec.DatabaseUser
deployment.Spec.ServiceUser = instance.Spec.ServiceUser
deployment.Spec.Secret = instance.Spec.Secret
deployment.Spec.TransportURLSecret = instance.Status.TransportURLSecret
deployment.Spec.ServiceAccount = instance.RbacResourceName()
deployment.Spec.LbMgmtNetworks.ManageLbMgmtNetworks = instance.Spec.LbMgmtNetworks.ManageLbMgmtNetworks
deployment.Spec.LbMgmtNetworks.SubnetIPVersion = instance.Spec.LbMgmtNetworks.SubnetIPVersion
if len(deployment.Spec.NodeSelector) == 0 {
deployment.Spec.NodeSelector = instance.Spec.NodeSelector
op, err := controllerutil.CreateOrUpdate(context.TODO(), r.Client, daemonset, func() error {
daemonset.Spec = controllerSpec
daemonset.Spec.Role = role
daemonset.Spec.DatabaseInstance = instance.Spec.DatabaseInstance
daemonset.Spec.DatabaseHostname = instance.Status.DatabaseHostname
daemonset.Spec.DatabaseUser = instance.Spec.DatabaseUser
daemonset.Spec.ServiceUser = instance.Spec.ServiceUser
daemonset.Spec.Secret = instance.Spec.Secret
daemonset.Spec.TransportURLSecret = instance.Status.TransportURLSecret
daemonset.Spec.ServiceAccount = instance.RbacResourceName()
daemonset.Spec.LbMgmtNetworks.ManageLbMgmtNetworks = instance.Spec.LbMgmtNetworks.ManageLbMgmtNetworks
daemonset.Spec.LbMgmtNetworks.SubnetIPVersion = instance.Spec.LbMgmtNetworks.SubnetIPVersion
if len(daemonset.Spec.NodeSelector) == 0 {
daemonset.Spec.NodeSelector = instance.Spec.NodeSelector
}
err := controllerutil.SetControllerReference(instance, deployment, r.Scheme)
err := controllerutil.SetControllerReference(instance, daemonset, r.Scheme)
if err != nil {
return err
}
return nil
})

return deployment, op, err
return daemonset, op, err
}

func amphoraControllerReadyCondition(role string) condition.Type {
Expand Down
Loading

0 comments on commit 1918e5f

Please sign in to comment.