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

Clean up volumes list for ovn-controller pod #182

Draft
wants to merge 6 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
82 changes: 12 additions & 70 deletions controllers/ovncontroller_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,15 +41,13 @@ import (
"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/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,7 +202,6 @@ 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(&corev1.ServiceAccount{}).
Expand Down Expand Up @@ -405,8 +401,19 @@ func (r *OVNControllerReconciler) reconcileNormal(ctx context.Context, instance
return ctrlResult, nil
}

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{}, err
}

// Define a new DaemonSet object
ovnDaemonSet, err := ovncontroller.DaemonSet(instance, inputHash, serviceLabels, serviceAnnotations)
ovnDaemonSet, err := ovncontroller.DaemonSet(instance, sbCluster, inputHash, serviceLabels, serviceAnnotations)
if err != nil {
Log.Error(err, "Failed to create OVNController DaemonSet")
return ctrl.Result{}, err
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.

17 changes: 16 additions & 1 deletion pkg/ovncontroller/daemonset.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ limitations under the License.
package ovncontroller

import (
"fmt"

"github.com/openstack-k8s-operators/lib-common/modules/common"
"github.com/openstack-k8s-operators/lib-common/modules/common/env"
"github.com/openstack-k8s-operators/ovn-operator/api/v1beta1"
Expand All @@ -25,6 +27,7 @@ import (
// DaemonSet func
func DaemonSet(
instance *v1beta1.OVNController,
sbCluster *v1beta1.OVNDBCluster,
configHash string,
labels map[string]string,
annotations map[string]string,
Expand Down Expand Up @@ -123,16 +126,28 @@ func DaemonSet(
}

ovnControllerArgs = []string{
"/usr/local/bin/container-scripts/net_setup.sh && ovn-controller --pidfile unix:/run/openvswitch/db.sock",
"/usr/local/bin/container-scripts/init.sh && /usr/local/bin/container-scripts/net_setup.sh && ovn-controller --pidfile unix:/run/openvswitch/db.sock",
}
// sleep is required as workaround for https://github.com/kubernetes/kubernetes/issues/39170
ovnControllerPreStopCmd = []string{
"/usr/share/ovn/scripts/ovn-ctl", "stop_controller", ";", "sleep", "2",
}
}

internalEndpoint, err := sbCluster.GetInternalEndpoint()
if err != nil {
return nil, err
}

envVars := map[string]env.Setter{}
envVars["CONFIG_HASH"] = env.SetValue(configHash)
envVars["OVN_RUNDIR"] = env.SetValue("/tmp")
envVars["OvnBridge"] = env.SetValue(instance.Spec.ExternalIDS.OvnBridge)
envVars["OvnRemote"] = env.SetValue(internalEndpoint)
envVars["OvnEncapType"] = env.SetValue(instance.Spec.ExternalIDS.OvnEncapType)
envVars["EnableChassisAsGateway"] = env.SetValue(fmt.Sprintf("%t", instance.Spec.ExternalIDS.EnableChassisAsGateway))
envVars["PhysicalNetworks"] = env.SetValue(getPhysicalNetworks(instance))
envVars["OvnHostName"] = EnvDownwardAPI("spec.nodeName")

daemonset := &appsv1.DaemonSet{
ObjectMeta: metav1.ObjectMeta{
Expand Down
Loading