Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Switch ovn-controller to StatefulSets #183

Draft
wants to merge 8 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion api/bases/ovn.openstack.org_ovncontrollers.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ spec:
hash:
additionalProperties:
type: string
description: Map of hashes to track e.g. job status
description: Map of hashes to track
type: object
networkAttachments:
additionalProperties:
Expand Down
4 changes: 2 additions & 2 deletions api/v1beta1/ovncontroller_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ type OVNControllerStatus struct {
// Conditions
Conditions condition.Conditions `json:"conditions,omitempty" optional:"true"`

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

// NetworkAttachments status of the deployment pods
Expand Down Expand Up @@ -145,7 +145,7 @@ func (instance OVNController) IsReady() bool {
type OVSExternalIDs struct {
// +kubebuilder:validation:Optional
// +kubebuilder:default="random"
SystemID string `json:"system-id,omitempty"`
SystemID string `json:"system-id,omitempty"`

// +kubebuilder:validation:Optional
// +kubebuilder:default="br-int"
Expand Down
2 changes: 1 addition & 1 deletion config/crd/bases/ovn.openstack.org_ovncontrollers.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ spec:
hash:
additionalProperties:
type: string
description: Map of hashes to track e.g. job status
description: Map of hashes to track
type: object
networkAttachments:
additionalProperties:
Expand Down
12 changes: 0 additions & 12 deletions config/rbac/role.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -63,18 +63,6 @@ rules:
- patch
- update
- watch
- apiGroups:
- batch
resources:
- jobs
verbs:
- create
- delete
- get
- list
- patch
- update
- watch
- apiGroups:
- ""
resources:
Expand Down
100 changes: 21 additions & 79 deletions controllers/ovncontroller_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -38,18 +38,16 @@ 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/daemonset"
"github.com/openstack-k8s-operators/lib-common/modules/common/env"
"github.com/openstack-k8s-operators/lib-common/modules/common/helper"
"github.com/openstack-k8s-operators/lib-common/modules/common/job"
"github.com/openstack-k8s-operators/lib-common/modules/common/labels"
nad "github.com/openstack-k8s-operators/lib-common/modules/common/networkattachment"
common_rbac "github.com/openstack-k8s-operators/lib-common/modules/common/rbac"
"github.com/openstack-k8s-operators/lib-common/modules/common/statefulset"
"github.com/openstack-k8s-operators/lib-common/modules/common/util"
"github.com/openstack-k8s-operators/ovn-operator/api/v1beta1"
"github.com/openstack-k8s-operators/ovn-operator/pkg/ovncontroller"
appsv1 "k8s.io/api/apps/v1"
batchv1 "k8s.io/api/batch/v1"
corev1 "k8s.io/api/core/v1"
rbacv1 "k8s.io/api/rbac/v1"
)
Expand Down Expand Up @@ -94,7 +92,6 @@ func (r *OVNControllerReconciler) GetClient() client.Client {
//+kubebuilder:rbac:groups=core,resources=configmaps,verbs=get;list;watch;create;update;patch;delete;
//+kubebuilder:rbac:groups=core,resources=pods,verbs=get;list;
//+kubebuilder:rbac:groups=apps,resources=daemonsets,verbs=create;delete;get;list;patch;update;watch
//+kubebuilder:rbac:groups=batch,resources=jobs,verbs=get;list;watch;create;patch;update;delete;
//+kubebuilder:rbac:groups=ovn.openstack.org,resources=ovndbclusters,verbs=get;list;watch;
//+kubebuilder:rbac:groups=k8s.cni.cncf.io,resources=network-attachment-definitions,verbs=create;delete;get;list;patch;update;watch

Expand Down Expand Up @@ -205,9 +202,8 @@ func (r *OVNControllerReconciler) SetupWithManager(mgr ctrl.Manager, ctx context
return ctrl.NewControllerManagedBy(mgr).
For(&v1beta1.OVNController{}).
Owns(&corev1.ConfigMap{}).
Owns(&batchv1.Job{}).
Owns(&netattdefv1.NetworkAttachmentDefinition{}).
Owns(&appsv1.DaemonSet{}).
Owns(&appsv1.StatefulSet{}).
Owns(&corev1.ServiceAccount{}).
Owns(&rbacv1.Role{}).
Owns(&rbacv1.RoleBinding{}).
Expand Down Expand Up @@ -405,18 +401,29 @@ func (r *OVNControllerReconciler) reconcileNormal(ctx context.Context, instance
return ctrlResult, nil
}

// Define a new DaemonSet object
ovnDaemonSet, err := ovncontroller.DaemonSet(instance, inputHash, serviceLabels, serviceAnnotations)
sbCluster, err := v1beta1.GetDBClusterByType(ctx, helper, instance.Namespace, map[string]string{}, v1beta1.SBDBType)
if err != nil {
Log.Error(err, "Failed to create OVNController DaemonSet")
Log.Info("No SB OVNDBCluster defined, deleting external ConfigMap")
cleanupConfigMapErr := r.deleteExternalConfigMaps(ctx, helper, instance)
if cleanupConfigMapErr != nil {
Log.Error(cleanupConfigMapErr, "Failed to delete external ConfigMap")
return ctrl.Result{}, cleanupConfigMapErr
}
return ctrl.Result{}, err
}
dset := daemonset.NewDaemonSet(
ovnDaemonSet,

// Define a new StatefulSet object
ovnStatefulSet, err := ovncontroller.StatefulSet(instance, sbCluster, inputHash, serviceLabels, serviceAnnotations)
if err != nil {
return ctrl.Result{}, err
}

sset := statefulset.NewStatefulSet(
ovnStatefulSet,
time.Duration(5)*time.Second,
)

ctrlResult, err = dset.CreateOrPatch(ctx, helper)
ctrlResult, err = sset.CreateOrPatch(ctx, helper)
if err != nil {
instance.Status.Conditions.Set(condition.FalseCondition(
condition.DeploymentReadyCondition,
Expand All @@ -434,8 +441,8 @@ func (r *OVNControllerReconciler) reconcileNormal(ctx context.Context, instance
return ctrlResult, nil
}

instance.Status.DesiredNumberScheduled = dset.GetDaemonSet().Status.DesiredNumberScheduled
instance.Status.NumberReady = dset.GetDaemonSet().Status.NumberReady
instance.Status.DesiredNumberScheduled = sset.GetStatefulSet().Status.Replicas
instance.Status.NumberReady = sset.GetStatefulSet().Status.ReadyReplicas

// verify if network attachment matches expectations
networkReady, networkAttachmentStatus, err := nad.VerifyNetworkStatusFromAnnotation(ctx, helper, networkAttachmentsNoPhysNet, serviceLabels, instance.Status.NumberReady)
Expand Down Expand Up @@ -463,17 +470,6 @@ func (r *OVNControllerReconciler) reconcileNormal(ctx context.Context, instance
}
// create DaemonSet - end

sbCluster, err := v1beta1.GetDBClusterByType(ctx, helper, instance.Namespace, map[string]string{}, v1beta1.SBDBType)
if err != nil {
Log.Info("No SB OVNDBCluster defined, deleting external ConfigMap")
cleanupConfigMapErr := r.deleteExternalConfigMaps(ctx, helper, instance)
if cleanupConfigMapErr != nil {
Log.Error(cleanupConfigMapErr, "Failed to delete external ConfigMap")
return ctrl.Result{}, cleanupConfigMapErr
}
return ctrl.Result{}, nil
}

ep, err := sbCluster.GetExternalEndpoint()
if err != nil || ep == "" {
Log.Info("No external endpoint defined for SB OVNDBCluster, deleting external ConfigMap")
Expand All @@ -494,60 +490,6 @@ func (r *OVNControllerReconciler) reconcileNormal(ctx context.Context, instance
}
}

// create OVN Config Job - start
if instance.Status.NumberReady == instance.Status.DesiredNumberScheduled {
jobsDef, err := ovncontroller.ConfigJob(ctx, helper, r.Client, instance, sbCluster, serviceLabels)
if err != nil {
Log.Error(err, "Failed to create OVN controller configuration Job")
return ctrl.Result{}, err
}
for _, jobDef := range jobsDef {
configHashKey := v1beta1.OvnConfigHash + "-" + jobDef.Spec.Template.Spec.NodeName
configHash := instance.Status.Hash[configHashKey]
configJob := job.NewJob(
jobDef,
configHashKey,
false,
time.Duration(5)*time.Second,
configHash,
)
ctrlResult, err = configJob.DoJob(ctx, helper)
if (ctrlResult != ctrl.Result{}) {
instance.Status.Conditions.Set(
condition.FalseCondition(
condition.ServiceConfigReadyCondition,
condition.RequestedReason,
condition.SeverityInfo,
condition.ServiceConfigReadyMessage,
),
)
return ctrlResult, nil
}
if err != nil {
Log.Error(err, "Failed to configure OVN controller")
instance.Status.Conditions.Set(
condition.FalseCondition(
condition.ServiceConfigReadyCondition,
condition.RequestedReason,
condition.SeverityInfo,
condition.ServiceConfigReadyErrorMessage,
err.Error(),
),
)
return ctrl.Result{}, err
}
if configJob.HasChanged() {
instance.Status.Hash[configHashKey] = configJob.GetHash()
Log.Info(fmt.Sprintf("Job %s hash added - %s", jobDef.Name, instance.Status.Hash[configHashKey]))
}
}
instance.Status.Conditions.MarkTrue(condition.ServiceConfigReadyCondition, condition.ServiceConfigReadyMessage)
} else {
Log.Info("OVNController DaemonSet not ready yet. Configuration job cannot be started.")
return ctrl.Result{Requeue: true}, nil
}
// create OVN Config Job - end

Log.Info("Reconciled Service successfully")

return ctrl.Result{}, nil
Expand Down
110 changes: 0 additions & 110 deletions pkg/ovncontroller/configjob.go

This file was deleted.

Loading