Skip to content

Commit

Permalink
Merge pull request #255 from omersch381/mdns_to_statefulset
Browse files Browse the repository at this point in the history
Change Mdns deployment type to StatefulSet
  • Loading branch information
openshift-merge-bot[bot] authored Nov 28, 2024
2 parents ad65ea9 + 3efb9f1 commit 21fa99a
Show file tree
Hide file tree
Showing 12 changed files with 205 additions and 135 deletions.
12 changes: 12 additions & 0 deletions api/bases/designate.openstack.org_designatemdnses.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,11 @@ spec:
description: ContainerImage - Designate Container Image URL (will
be set to environmental default if empty)
type: string
controlNetworkName:
default: designate
description: ControlNetworkName - specify which network attachment
is to be used for control, notifys and zone transfers.
type: string
customServiceConfig:
description: CustomServiceConfig - customize the service config using
this parameter to change service defaults, or overwrite rendered
Expand Down Expand Up @@ -126,6 +131,13 @@ spec:
from the Secret
type: string
type: object
replicas:
default: 1
description: Replicas - Designate Mdns 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 api/bases/designate.openstack.org_designates.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -827,6 +827,11 @@ spec:
description: ContainerImage - Designate Container Image URL (will
be set to environmental default if empty)
type: string
controlNetworkName:
default: designate
description: ControlNetworkName - specify which network attachment
is to be used for control, notifys and zone transfers.
type: string
customServiceConfig:
description: CustomServiceConfig - customize the service config
using this parameter to change service defaults, or overwrite
Expand Down Expand Up @@ -884,6 +889,13 @@ spec:
password from the Secret
type: string
type: object
replicas:
default: 1
description: Replicas - Designate Mdns 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 api/v1beta1/designatemdns_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,13 @@ type DesignateMdnsSpecBase struct {
// Common input parameters for all Designate services
DesignateTemplate `json:",inline"`

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

// +kubebuilder:validation:Optional
// DatabaseHostname - Designate Database Hostname
DatabaseHostname string `json:"databaseHostname,omitempty"`
Expand All @@ -60,6 +67,11 @@ type DesignateMdnsSpecBase struct {
// +operator-sdk:csv:customresourcedefinitions:type=spec
// TLS - Parameters related to the TLS
TLS tls.Ca `json:"tls,omitempty"`

// +kubebuilder:default="designate"
// +kubebuilder:validation:Optional
// ControlNetworkName - specify which network attachment is to be used for control, notifys and zone transfers.
ControlNetworkName string `json:"controlNetworkName"`
}

// DesignateMdnsStatus defines the observed state of DesignateMdns
Expand Down
9 changes: 7 additions & 2 deletions api/v1beta1/zz_generated.deepcopy.go

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

12 changes: 12 additions & 0 deletions config/crd/bases/designate.openstack.org_designatemdnses.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,11 @@ spec:
description: ContainerImage - Designate Container Image URL (will
be set to environmental default if empty)
type: string
controlNetworkName:
default: designate
description: ControlNetworkName - specify which network attachment
is to be used for control, notifys and zone transfers.
type: string
customServiceConfig:
description: CustomServiceConfig - customize the service config using
this parameter to change service defaults, or overwrite rendered
Expand Down Expand Up @@ -126,6 +131,13 @@ spec:
from the Secret
type: string
type: object
replicas:
default: 1
description: Replicas - Designate Mdns 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/crd/bases/designate.openstack.org_designates.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -827,6 +827,11 @@ spec:
description: ContainerImage - Designate Container Image URL (will
be set to environmental default if empty)
type: string
controlNetworkName:
default: designate
description: ControlNetworkName - specify which network attachment
is to be used for control, notifys and zone transfers.
type: string
customServiceConfig:
description: CustomServiceConfig - customize the service config
using this parameter to change service defaults, or overwrite
Expand Down Expand Up @@ -884,6 +889,13 @@ spec:
password from the Secret
type: string
type: object
replicas:
default: 1
description: Replicas - Designate Mdns 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
19 changes: 0 additions & 19 deletions config/rbac/role.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,6 @@ metadata:
creationTimestamp: null
name: manager-role
rules:
- apiGroups:
- ""
resources:
- nodes
verbs:
- get
- list
- apiGroups:
- ""
resources:
Expand All @@ -35,18 +28,6 @@ rules:
- patch
- update
- watch
- apiGroups:
- apps
resources:
- daemonsets
verbs:
- create
- delete
- get
- list
- patch
- update
- watch
- apiGroups:
- apps
resources:
Expand Down
56 changes: 22 additions & 34 deletions controllers/designate_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,6 @@ type DesignateReconciler struct {
// +kubebuilder:rbac:groups=rabbitmq.openstack.org,resources=transporturls,verbs=get;list;watch;create;update;patch;delete
// +kubebuilder:rbac:groups=redis.openstack.org,resources=redises,verbs=get;list;watch;create;update;patch;delete
// +kubebuilder:rbac:groups=k8s.cni.cncf.io,resources=network-attachment-definitions,verbs=get;list;watch
// +kubebuilder:rbac:groups="",resources=nodes,verbs=get;list
// +kubebuilder:rbac:groups=apps,resources=statefulsets,verbs=get;list;create;update;patch;delete;watch

// service account, role, rolebinding
Expand Down Expand Up @@ -775,25 +774,14 @@ func (r *DesignateReconciler) reconcileNormal(ctx context.Context, instance *des
allocatedIPs[predIP] = true
}

// Get a list of the nodes in the cluster

// TODO(oschwart):
// * confirm whether or not this lists only the nodes we want (i.e. ones
// that will host the daemonset)
// * do we want to provide a mechanism to temporarily disabling this list
// for maintenance windows where nodes might be "coming and going"

nodes, err := helper.GetKClient().CoreV1().Nodes().List(ctx, metav1.ListOptions{})
if err != nil {
return ctrl.Result{}, err
}

var nodeNames []string
for _, node := range nodes.Items {
nodeNames = append(nodeNames, fmt.Sprintf("mdns_%s", node.Name))
// Handle Mdns predictable IPs configmap
mdnsReplicaCount := int(*instance.Spec.DesignateMdns.Replicas)
var mdnsNames []string
for i := 0; i < mdnsReplicaCount; i++ {
mdnsNames = append(mdnsNames, fmt.Sprintf("mdns_address_%d", i))
}

updatedMap, allocatedIPs, err := r.allocatePredictableIPs(ctx, predictableIPParams, nodeNames, mdnsConfigMap.Data, allocatedIPs)
updatedMap, allocatedIPs, err := r.allocatePredictableIPs(ctx, predictableIPParams, mdnsNames, mdnsConfigMap.Data, allocatedIPs)
if err != nil {
return ctrl.Result{}, err
}
Expand Down Expand Up @@ -959,7 +947,7 @@ func (r *DesignateReconciler) reconcileNormal(ctx context.Context, instance *des
Log.Info("Deployment Worker task reconciled")

// deploy designate-mdns
designateMdns, op, err := r.mdnsDaemonSetCreateOrUpdate(ctx, instance)
designateMdns, op, err := r.mdnsStatefulSetCreateOrUpdate(ctx, instance)
if err != nil {
instance.Status.Conditions.Set(condition.FalseCondition(
designatev1beta1.DesignateMdnsReadyCondition,
Expand Down Expand Up @@ -1585,8 +1573,8 @@ func (r *DesignateReconciler) workerDeploymentCreateOrUpdate(ctx context.Context
return deployment, op, err
}

func (r *DesignateReconciler) mdnsDaemonSetCreateOrUpdate(ctx context.Context, instance *designatev1beta1.Designate) (*designatev1beta1.DesignateMdns, controllerutil.OperationResult, error) {
daemonset := &designatev1beta1.DesignateMdns{
func (r *DesignateReconciler) mdnsStatefulSetCreateOrUpdate(ctx context.Context, instance *designatev1beta1.Designate) (*designatev1beta1.DesignateMdns, controllerutil.OperationResult, error) {
statefulSet := &designatev1beta1.DesignateMdns{
ObjectMeta: metav1.ObjectMeta{
Name: fmt.Sprintf("%s-mdns", instance.Name),
Namespace: instance.Namespace,
Expand All @@ -1597,28 +1585,28 @@ func (r *DesignateReconciler) mdnsDaemonSetCreateOrUpdate(ctx context.Context, i
instance.Spec.DesignateMdns.NodeSelector = instance.Spec.NodeSelector
}

op, err := controllerutil.CreateOrUpdate(ctx, r.Client, daemonset, func() error {
daemonset.Spec = instance.Spec.DesignateMdns
op, err := controllerutil.CreateOrUpdate(ctx, r.Client, statefulSet, func() error {
statefulSet.Spec = instance.Spec.DesignateMdns
// Add in transfers from umbrella Designate CR (this instance) spec
// TODO: Add logic to determine when to set/overwrite, etc
daemonset.Spec.ServiceUser = instance.Spec.ServiceUser
daemonset.Spec.DatabaseHostname = instance.Status.DatabaseHostname
daemonset.Spec.DatabaseAccount = instance.Spec.DatabaseAccount
daemonset.Spec.Secret = instance.Spec.Secret
daemonset.Spec.TransportURLSecret = instance.Status.TransportURLSecret
daemonset.Spec.ServiceAccount = instance.RbacResourceName()
daemonset.Spec.TLS = instance.Spec.DesignateAPI.TLS.Ca
daemonset.Spec.NodeSelector = instance.Spec.DesignateMdns.NodeSelector

err := controllerutil.SetControllerReference(instance, daemonset, r.Scheme)
statefulSet.Spec.ServiceUser = instance.Spec.ServiceUser
statefulSet.Spec.DatabaseHostname = instance.Status.DatabaseHostname
statefulSet.Spec.DatabaseAccount = instance.Spec.DatabaseAccount
statefulSet.Spec.Secret = instance.Spec.Secret
statefulSet.Spec.TransportURLSecret = instance.Status.TransportURLSecret
statefulSet.Spec.ServiceAccount = instance.RbacResourceName()
statefulSet.Spec.TLS = instance.Spec.DesignateAPI.TLS.Ca
statefulSet.Spec.NodeSelector = instance.Spec.DesignateMdns.NodeSelector

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

return nil
})

return daemonset, op, err
return statefulSet, op, err
}

func (r *DesignateReconciler) producerDeploymentCreateOrUpdate(ctx context.Context, instance *designatev1beta1.Designate) (*designatev1beta1.DesignateProducer, controllerutil.OperationResult, error) {
Expand Down
1 change: 0 additions & 1 deletion controllers/designateapi_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,6 @@ var keystoneServices = []map[string]string{
// +kubebuilder:rbac:groups=core,resources=pods,verbs=get;list;
// +kubebuilder:rbac:groups=route.openshift.io,resources=routes,verbs=get;list;watch;create;update;patch;delete
// +kubebuilder:rbac:groups=batch,resources=jobs,verbs=get;list;create;update;patch;delete;watch
// +kubebuilder:rbac:groups=apps,resources=daemonsets,verbs=get;list;create;update;patch;delete;watch
// +kubebuilder:rbac:groups=apps,resources=deployments,verbs=get;list;create;update;patch;delete;watch
// +kubebuilder:rbac:groups=keystone.openstack.org,resources=keystoneservices,verbs=get;list;watch;create;update;patch;delete
// +kubebuilder:rbac:groups=keystone.openstack.org,resources=keystoneendpoints,verbs=get;list;watch;create;update;patch;delete
Expand Down
Loading

0 comments on commit 21fa99a

Please sign in to comment.